Saturday, April 30, 2016

8051 Program – timer interrupt based led blinking

; timer interrupt based led blinking
; 8051 with 12Mhz crystal
; led is connected to P1.0
ORG 0H
led EQU P1.0
delay EQU 30h ;ram location
time EQU 20 ;20 x 0.05 = 1 sec
START: AJMP MAIN ;jump to main program
ORG 0BH
AJMP TIMER0_ISR ;jump to interrupt subroutine
MAIN:
init:
SETB EA ;enable interrupt
SETB ET0 ;enable timer 0 interrupt
MOV delay,#time
MOV TMOD,#01h ;timer 0 mode 1(16 bit mode)
MOV TH0,#3ch ;0.05 sec
MOV TL0,#0b8h
SETB TR0 ;Start Timer 0
toggle:
SETB led ; turn on led
ACALL WAIT ; wait for a second
CLR led ; trun off led
ACALL WAIT ; wait for a second
SJMP toggle ; repeat
SJMP MAIN
WAIT:MOV R0,#delay
CJNE @R0,#time,WAIT
MOV @R0,#0
RET
TIMER0_ISR:
PUSH ACC
PUSH B
PUSH PSW
PUSH DPH
PUSH DPL
PUSH 00h ; R0
INC delay ; increment delay count
CLR TF0 ;clear TIMER 0 flag
CLR TR0 ;stop Timer 0
MOV TH0,#3ch ;0.05 sec, reload timer
MOV TL0,#0b8h
SETB TR0 ;Start Timer 0
POP 00h ;R0
POP DPL
POP DPH
POP PSW
POP B
POP ACC
RETI
END



Related topics:
8051 Program - send ascii to port   |   8051 Program - serializing data   |   8051 Program - simple serial transmission   |   8051 Program - timer based led blinking   |   8051 Program - detect switch debounce   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment