Port bit manipulation
Posted: 15 Sep 2011 13:09
Hello,
I am new to MikroC, since now I've used CCS C compiler.
I have MikroProg, and Microchip Ethernet starter kit + starter kit I/O expansion board.
Pic32MX795F512L
Used pins: RD0, RD1, RD2 (leds)
Because I am new, I started with very simple code posted below:
FIRST:
void main() {
AD1PCFG = 0xFFFF;
TRISD = 0xFFF8;
PORTD = 0x0000;
while(1){
PORTD = 0x01;
Delay_ms(100);
PORTD = 0x02;
Delay_ms(100);
PORTD = 0x04;
Delay_ms(100);
}
}
SECOND:
void main() {
AD1PCFG = 0xFFFF;
TRISD = 0xFFF8;
PORTD = 0x0000;
while(1){
RD0_bit = 1;
RD1_bit = 0;
RD2_bit = 0;
Delay_ms(100);
RD0_bit = 0;
RD1_bit = 1;
RD2_bit = 0;
Delay_ms(100);
RD0_bit = 0;
RD1_bit = 0;
RD2_bit = 1;
Delay_ms(100);
}
}
When I use first code led blinking works as it should, but when I use second code where led blinking should be almost the same, it's not.
RD0 and RD2 are blinking correctly but RD1 is all the time off.
If I tray the second program in debug mode it works correctly.
What I am missing?
Thanks in advance!
I am new to MikroC, since now I've used CCS C compiler.
I have MikroProg, and Microchip Ethernet starter kit + starter kit I/O expansion board.
Pic32MX795F512L
Used pins: RD0, RD1, RD2 (leds)
Because I am new, I started with very simple code posted below:
FIRST:
void main() {
AD1PCFG = 0xFFFF;
TRISD = 0xFFF8;
PORTD = 0x0000;
while(1){
PORTD = 0x01;
Delay_ms(100);
PORTD = 0x02;
Delay_ms(100);
PORTD = 0x04;
Delay_ms(100);
}
}
SECOND:
void main() {
AD1PCFG = 0xFFFF;
TRISD = 0xFFF8;
PORTD = 0x0000;
while(1){
RD0_bit = 1;
RD1_bit = 0;
RD2_bit = 0;
Delay_ms(100);
RD0_bit = 0;
RD1_bit = 1;
RD2_bit = 0;
Delay_ms(100);
RD0_bit = 0;
RD1_bit = 0;
RD2_bit = 1;
Delay_ms(100);
}
}
When I use first code led blinking works as it should, but when I use second code where led blinking should be almost the same, it's not.
RD0 and RD2 are blinking correctly but RD1 is all the time off.
If I tray the second program in debug mode it works correctly.
What I am missing?
Thanks in advance!