Saturday, April 30, 2016

8051 Program – timer based led blinking

; timer 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
MAIN:
init:
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:
JNB TF0,$ ;wait for timer to over flow
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
DJNZ delay,WAIT ;decrement delay by 1 & check if its 0
MOV delay,#time ;reload delay constant
RET
END



Related topics:
8051 Program - send ascii to port   |   8051 Program - serializing data   |   8051 Program - simple serial transmission   |   8051 Program - timer interrupt 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