Sunday, April 12, 2009
Learn PIC Assembly Language Part - 7
Rotating the LEDs on PORTD
For rotating the LEDs on PORTD, make all the LEDs from RD0 to RD7 OFF. Then using your program , make RDO – ON and all other LEDs OFF. After a delay of around 0.5 seconds, make RD1 – ON, and all other LEDs off..then make RD2 – ON and make all other LEDs OFF.. then make RD3- ON and all other LEDs OFF.. Make this in an infinite loop...
Program8.asm
list p = 18F452
#include < P18F452.INC >
Count1 equ 0x00
Count2 equ 0x01
org 00000 h
goto Start
org 0002A h
Start :
MOVLW 0x00
MOVWF TRISD,0
Pos1 :
MOVLW 0x00 ; All LEDs OFF
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x01 ; LED connected to RD0 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x02 ; LED connected to RD1 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x04 ; LED connected to RD2 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x08 ; LED connected to RD3 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x10 ; LED connected to RD4 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x20 ; LED connected to RD5 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x40 ; LED connected to RD6 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
MOVLW 0x80 ; LED connected to RD7 - ON
MOVWF PORTD,0
CALL Delay
CALL Delay
goto Pos1 ; making an infinite loop here...
Delay :
MOVLW 0xFF ; Execution time = 1 μs
MOVWF Count1, 0 ; Execution time = 1 μs
Pos2 :
DECFSZ Count1,1,0 ; Execution time = 1 μs or 2 μs or 3 μs
goto Pos3 ; Execution time = 2 μs
RETURN ; Execution time = 2 μs
Pos3 :
MOVLW 0xFF ; Execution time = 1 μs
MOVWF Count2,0 ; Execution time = 1 μs
Pos4 :
DECFSZ Count2,1,0 ; Execution time = 1 μs or 2 μs or 3 μs
goto Pos4 ; Execution time = 2 μs
goto Pos2 ; Execution time = 2 μs
end
You can adjust the delays by adding delay routines in the middle. Here I have used a delay of around 400 milli-seconds.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment