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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
main:
mov TMOD, #15h ; 15h= 0001 0101, so CT1 is a timer in mode 1 and CT0 is a counter in mode 1
mov R5, #6 ; we loop 167 times cause TL1 0f8h to 0e1h should takes 1ms, so the counter will run for 0.167s
mov TL1, #0CEh ;theory is to set -1843167 in order to loop every 1843167 pulse the timer, if the frequency of the
mov TH1, #0F8h ; microcontroller is around 11.0592Mhz and the clock frequency is the oscillator crystal divided by 12
mov TL0, #0 ; 1843167 pulse is 2second latency but we need a 16bits register...
mov TH0, #0 ; Load the counter 0 with 0
;mov r6, #10
;loopouter:
;mov r5, #167
loop:
setb TCON.6 ; Start CT1, timer
setb TCON.4 ; Start CT0, counter (bit 4 of port 3)
jnb TCON.7, loop ; waits 0.001 s
clr TCON.6
clr TCON.4
clr TCON.7 ; so here is 167 times, so give total cycle of 0.167s
djnz R5, loop ; since there is 6 arms on the wheel, we dont need to multiple or divide the
;djnz r6, loopouter ; counter
mov R5, TL0
mov TL0, #0
acall display
acall delay
sjmp main
Display:
mov a, R5
jz zero
dec a
jz one
dec a
jz two
dec a
jz three
dec a
jz four
dec a
jz five
dec a
jz six
dec a
jz seven
dec a
jz eight
dec a
jz nine
dec a
jz aaaa
dec a
jz bbbb
dec a
jz cccc
dec a
jz dddd
dec a
jz eeee
sjmp ffff
zero:
mov P0, #0xC0
ret
one:
mov P0, #0xF9
ret
two:
mov P0, #0xA4
ret
three:
mov P0, #0xB0
ret
four:
mov P0, #0x99
ret
five:
mov P0, #0x92
ret
six:
mov P0, #0x82
ret
seven:
mov P0, #0xF8
ret
eight:
mov P0, #0x80
ret
nine:
mov P0, #0x90
ret
aaaa:
mov P0, #0x88
ret
bbbb:
mov P0, #0x83
ret
cccc:
mov P0, #0xC6
ret
dddd:
mov P0, #0xA1
ret
eeee:
mov P0, #0x86
ret
ffff:
mov P0, #0x8E
ret ;END OF DISPLAY SUB-ROUTINE
;******************************************
;This is a simple routine that makes the processor
;waste time for about 1/4 sec.
delay:
mov R1, #0ffh
outer: mov R0, #0ffh
inner: inc a
dec a
djnz R0, inner
djnz R1, outer
ret
end |