PIC16F722A . PORTB Bits not latching

Status
Not open for further replies.

1230

Member level 3
Joined
Jun 18, 2002
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
355
hi all...
writing a simple code to make understand the problem.
PORTB bit 4 should remain high all the time. but its going low after making change to portb. bit5.
cannot trace the problem, pls help.
int main()
{
TRISB=0X00;

PORTB |=(1<<4);
Delay_ms(2000);

while(1)
{
PORTB |=(1<<5);
}
}
 

Probably a RMW problem which is well documented. The PIC16 series doesn't simply set individual bits when you write to a port, it reads the whole port, sets the bit then writes it all back again. If bit 4 is externally floating low or pulled low, the write (OR operation) to bit 5 reads bit 4 as zero so it writes it back as zero.

The PIC18 series uses LAT registers to overcome the problem but the simple solution to your issue is to keep a variable for the bit operations and write it to PORTB whenever you change its contents.

Brian.
 
Reactions: 1230

    1230

    Points: 2
    Helpful Answer Positive Rating
Thanks sir...
but i found the problem.
pic16 series write an individual pins of a port. in my code, i have to disable the ANSELB registor. after disabling my problem solved
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…