Sunday, April 12, 2009
Learn PIC Assembly Language Part - 8
Reading input from PORTS
This program teaches you to read the state of a port pin and makes the LED on if the switch is closed.
Here we use PORTA bit 1 to input the data, and PORTD bit 1 for flashing the LED. This programs reads the state of pin RA1 and flashes an LED on RD1, if the state is 1.
Program9.asm
list p = 18F452
#include < P18F452.INC >
org 00000 h
goto Start
org 0002A h
Start :
BSF TRISA,1,0 ; Setting bit1 of TRISA to make it as input
BCF TRISD,1,0 ; Clearing bit1 or TRISD to make it as output
Check :
BTFSS PORTA,1,0 ; Checking for RA1 ,whether its closed or open
goto Check
BSF PORTD,1,0 ; Making LED on RD1 – ON , when RA1 is set
Main :
goto Main ; Your program waits here
end
This program blinks an LED on RD1, when the switch on RA1 is pressed. I have given comment after the mnemonics for your clarity. If you have any doubts/clarifications, please contact me at my email address provided in the blog.
Wire up the circuit in a breadboard and press the switch on RA1 and check whether the LED is turning ON.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment