org 0000h
ljmp main
org 001bh
ljmp isrt1 //isr routine
org 0100h
main:mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
mov ie,#88h //timer interrupt for timer1
mov th1,#00h
mov tl1,#00h
mov r0,#0eh //for 1 second delay
setb tr0
k1:setb tr1 //start timer
cjne r0,#00h,k1
clr tr0
o1:mov p1,tl0
sjmp o1
isrt1: //isr routine
clr tr1
djnz r0,l12
l12: //creating 1 second delay
mov th1,#00h
mov tl1,#00h
reti
end
org 0000h
jmp main
org 001bh
reti //not in use
//isr routine
org 0100h
Initialize:
mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
main:
mov th0,#00h
mov tl0,#00h
mov th1,#03ch
mov tl1,#0b0h
mov r0,#014h //for 1 second delay, assuming 12MHz clock
setb tr0
loop:
setb tr1
jnb tf1,$
clr tf1
clr tr1
djnz r0,loop
clr tr0
clr tf0
cjne th0,#00h,overflow //check if rpm exceeded the reading capacity
mov p1,tl0
setb p3.7 //connect a LED here
jmp main
overflow:
clr p3.7 //pin will set again only when rpm is readable
jmp main
end
yes i have written it so that the display is retained.Actually uc is not taught yet to us just i am taking my chances but as per your code i got to know that if we want program to remain in infinite loop then we have to use $ sign right?In your code, after 1 sec of run time, your program will stuck & keep looping under "o1" subroutine. I don't see any way out...
(65536-xxxx)*1.086us= 50 ms [50ms is a round-up value for easy calculations]
(65536-xxxx)=46040 [50ms/1.086us]
xxxx=19496
in hex it is
xxxx=0x3CB0
So TH1=04Ch
and TL1=028h
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ORG 0 MOV P1,#00h ; PORT P0 CONFIGURED AS OUTPUT PORT mov p2,#00h MOV P3,#0FFH ; PORT P3 CONFIGURED AS INPUT PORT MOV TMOD,#51h ; TIMER CONFIGURATION SETB TR1 ; START COUNTING PULSES ON P3.5 MOV R7,#20 ; TIMING REPEATED 20 TIMES AGN: MOV TH0,#4cH ; VALUE IN TH0 FOR 1/20 S DELAY MOV TL0,#01H ; VALUE IN TL0 FOR 1/20 S DELAY SETB TR0 ; START TIMER (FOR 1/20 S DELAY) JNB TF0,$ ; WAIT TILL COUNTING IS OVER CLR TF0 ; CLEAR TIMER FLAG TF0 DJNZ R7,AGN ; REPEAT THIS TIMER 20 TIMES FOR 1S CLR TR1 ; STOP COUNTING MOV P1,TL1 ; Display Lower byte of count on P0 MOV P2,TH1 ; Display Higher byte of count on P2 SJMP $ ; ENDLESS LOOP (Keep Display) END
ORG 0
MOV P1,#00h ; PORT P0 CONFIGURED AS OUTPUT PORT
mov p2,#00h
MOV P3,#0FFH ; PORT P3 CONFIGURED AS INPUT PORT
MOV TMOD,#51h ; TIMER CONFIGURATION
SETB TR1 ; START COUNTING PULSES ON P3.5
MOV R7,#20 ; TIMING REPEATED 20 TIMES
AGN: MOV TH0,#4cH ; VALUE IN TH0 FOR 1/20 S DELAY
MOV TL0,#01H ; VALUE IN TL0 FOR 1/20 S DELAY
SETB TR0 ; START TIMER (FOR 1/20 S DELAY)
JNB TF0,$ ; WAIT TILL COUNTING IS OVER
CLR TF0 ; CLEAR TIMER FLAG TF0
DJNZ R7,AGN ; REPEAT THIS TIMER 20 TIMES FOR 1S
CLR TR1 ; STOP COUNTING
MOV P1,TL1 ; Display Lower byte of count on P0
MOV P2,TH1 ; Display Higher byte of count on P2
SJMP $ ; ENDLESS LOOP (Keep Display)
END
org 0000h
jmp main
org 001bh
reti //not in use
//isr routine
org 0100h
Initialize:
mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
main:
mov th0,#00h
mov tl0,#00h
mov th1,#03ch
mov tl1,#0b0h
mov r0,#014h //for 1 second delay, assuming 12MHz clock
setb tr0
loop:
setb tr1
jnb tf1,$
clr tf1
clr tr1
mov th1,#04ch
mov tl1,#028h
djnz r0,loop
clr tr0
clr tf0
cjne th0,#00h,overflow //check if rpm exceeded the reading capacity
mov p1,tl0
setb p3.7 //connect a LED here
jmp main
overflow:
clr p3.7 //pin will set again only when rpm is readable
jmp main
end
Code:[CODE]org 0000h cjne th0,#00h,overflow //check if rpm exceeded the reading capacity setb p3.7 //connect a LED here jmp main overflow: clr p3.7 //pin will set again only when rpm is readable jmp main end
org 0000h
jmp main
org 001bh
reti //not in use
//isr routine
org 0100h
Initialize:
mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
main:
mov th0,#00h
mov tl0,#00h
mov th1,#04ch
mov tl1,#01h
mov r0,#014h //for 1 second delay, assuming 12MHz clock
setb tr0
loop:
setb tr1
jnb tf1,$
clr tf1
clr tr1
mov th1,#04ch
mov tl1,#028h
djnz r0,loop
clr tr0
clr tf0
mov p1,tl0
jmp main
end
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 org 0000h ljmp main org 0100h main:mov p1,#00h mov p3,#0ffh mov tmod,#11h//timer 0,timer 1 mov th0,#0a6h //these are values tried by trial & error method mov tl0,#05h //these are values tried by trial & error method mov th1,0a0h //these are values tried by trial & error method mov tl1,80h //these are values tried by trial & error method j1:jb p3.3,j1 //sensor senses to start the display? lcall delay //delay from sensor position to 1/4th of the circumference setb p1.7 //lighting only one led lcall delay1// retaining the led light for few ms clr p1.7 //clearing the set led lcall delay2 //keeping the led off for remaining 3/4th distance of the circumference sjmp main //continuously doing this delay: setb tr0 l1:jnb tf0,l1 clr tf0 clr tr0 ret delay1: setb tr1 l:jnb tf1,l clr tf1 clr tr1 ret delay2: mov th1,#0d9h mov tl1,#0d9h setb tr1 m:jnb tf1,m clr tf1 clr tr1 ret end
org 0000h
jmp main
org 0100h
Initialize:
mov p1,#00h
mov p3,#0ffh
mov tmod,#15h //timer0 as counter & timer1 as timer
main:
mov th0,#00h
mov tl0,#00h
mov th1,#04ch
mov tl1,#028h
mov r0,#014h //for 1 second delay
setb tr0
loop:
setb tr1
jnb tf1,$
clr tf1
clr tr1
mov th1,#04ch
mov tl1,#028h
djnz r0,loop
clr tr0
clr tf0
mov p1,tl0
jmp main
end
org 0000h
jmp main
org 0100h
mov p1,#00h
mov p3,#0ffh
main:
mov r0,#20
mov tmod,#01h
mov th0,#04ch
mov tl0,#028h
setb tr0
jmp loop
timer:
mov th0,#04ch
mov tl0,#028h
setb tr0
loop:
jb p3.5,increment
jnb tf0,loop
jmp reload
increment:
inc r1
jb p3.5,$
jmp loop
reload:
clr tr0
clr tf0
djnz r0,timer
mov p1,r1 //r1 contains rps value
mov r1,#00h
jmp main
end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?