- This topic has 2 replies, 2 voices, and was last updated 9 years, 10 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
|
Microcontroller › PIC › confusion in using latch register and port register
Sir,
I am new to pic microcontroller and trying to learn from friends.
I am doing led blink program on pic 16f877a.
I am confused whether to use port register or latch register.
When i used latch register in blinking led
LATB=~LATB
Delay();
complier shows error like undefined LATB
When i used port registr led start blinking
PORTA=~PORTA
Delay();
Engineergarage is using latch register in their tutorial but some are using port register in led blinking.
I am totally confused whether to use latch or port register.
I am also unable to understand what is Read modify write operation.
Hi,
Avoid using statements like this in your ‘C’ code.
LATB=~LATB
PORTA=~PORTA
Take a temperory variable, say ‘t’ and convert the above statements like,
t = LATB;
LATB = ~t;
t = PORTA;
PORTA = ~t;
Port registers are connected to the port pin through Latch registers,
PORT REGISTER >> LATCH REGISTER >> PORT PIN
Even if you write a value to the port register, it will not appear at the port pin until you enable the latching using the lacth registers.
For a simple LED blinking, writing a ‘1’ or ‘0’ to port register (according to whether the anode or cathode of LED is connected to the pin) and then keep on enabling and disabling the latching will do the purpose.
Thank u