Port bit manipulation

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
discorange
Posts: 1
Joined: 01 Sep 2011 11:44

Port bit manipulation

#1 Post by discorange » 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!

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Port bit manipulation

#2 Post by filip » 19 Sep 2011 15:49

Hi,

This seems to be a Read/Modify/Write issue.
There is a difference when writing to the whole port (PORTD = 0x02) and when writing to the single pin (RD1_bit = 1).
In the second example, more steps are needed to be performed and this may cause this issue.

For writing to port, I suggest you using LAT register.
Also, it would be helpful if you can read about Read/Modify/Write problem in the Help file.

Regards,
Filip.

basowsky
Posts: 48
Joined: 13 Sep 2011 16:07

Re: Port bit manipulation

#3 Post by basowsky » 29 Jan 2012 21:43

hi
i have notice the same problem; with pic18f26k22 i have solve the problem by setting to 0 the SLRCON (SLEW RATE CONTROL) register,
in this case the problem is similar???

thank you

Post Reply

Return to “mikroC PRO for PIC32 General”