-
Notifications
You must be signed in to change notification settings - Fork 0
/
kit.asm
165 lines (143 loc) · 2.49 KB
/
kit.asm
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$NOMOD51 ;to suppress the pre-defined addresses by keil
$include (C8051F020.INC) ; to declare the device peripherals with it's addresses
ORG 0H ; to start writing the code from the base 0
;diable the watch dog
MOV WDTCN,#11011110B ;0DEH
MOV WDTCN,#10101101B ;0ADH
; config of clock
MOV OSCICN , #14H ; 2MH clock
;config cross bar
MOV XBR0 , #00H
MOV XBR1 , #00H
MOV XBR2 , #040H ; Cross bar enabled , weak Pull-up enabled
;config,setup
MOV P74OUT, #00001000B
MOV P1MDOUT, #0FFh
MOV P2MDOUT, #0FFh
MOV P3MDOUT, #0FFh
MOV R0,#3
MOV R1,#3
MOV A,P5
ORL A, #00010000B
MOV P5, A
MAX EQU 10
MIN EQU 0
INIT:
MOV R4,#10
MOV DPTR, #400h
MOV A,#10
CLR C
SUBB A,R0
MOVC A,@A+DPTR
MOV P1,A
AJMP COUNT
START:
MOV R4,#10
MOV DPTR, #400h
AJMP COUNT
MAIN:
DJNZ R4, COUNT
DJNZ R0, INIT
ACALL LED_TOGGLE
LED_TOGGLE_END:
AJMP RESTART
END_COUNT:
ACALL SWITCHS
AJMP MAIN
LED_TOGGLE:
CLR A
MOV A, P5
ANL A, #00010000B
CJNE A, #00010000B, RED_ON
RED_ON_END:
ACALL GREEN_ON
RET
RED_ON:
MOV A,P5
ORL A, #00010000B
MOV P5, A
AJMP LED_TOGGLE_END
GREEN_ON:
MOV A,P5
ORL A, #00100000B
MOV P5, A
RET
RESTART:
MOV A,R1
MOV R0, A
AJMP INIT
SWITCHS:
CLR A
MOV A, P4
ANL A, #00000001B
JNZ FAST
MOV A, P4
ANL A, #00000010B
JNZ MEDIUM
MOV A, P4
ANL A, #00000100B
JNZ SLOW
ACALL DEFULT_DELAY
SKIP_SPEED:
MOV A, P5
ANL A, #00000001B
JZ INCRENENT
MOV A, P5
ANL A, #00000010B
JZ DECREMENT
RET
SLOW:
ACALL SLOW_DELAY
AJMP SKIP_SPEED
MEDIUM:
ACALL DEFULT_DELAY
AJMP SKIP_SPEED
FAST:
ACALL FAST_DELAY
AJMP SKIP_SPEED
INCRENENT:
CJNE R1, #MAX, DO_INCREMENT
AJMP RESTART
DO_INCREMENT:
INC R1
AJMP RESTART
RET
DECREMENT:
CJNE R1, #MIN, DO_DECREMENT
AJMP RESTART
DO_DECREMENT:
DEC R1
AJMP RESTART
RET
COUNT: CLR A
MOVC A,@A+DPTR
MOV P2,A
INC DPTR
AJMP END_COUNT
FAST_DELAY:
MOV R7,#5
LOOP4:MOV R6,#200
LOOP5:MOV R5,#198
LOOP6:DJNZ R5,LOOP6
DJNZ R6,LOOP5
DJNZ R7,LOOP4
RET
DEFULT_DELAY:
MOV R7,#10
LOOP7:MOV R6,#200
LOOP8:MOV R5,#198
LOOP9:DJNZ R5,LOOP9
DJNZ R6,LOOP8
DJNZ R7,LOOP7
RET
SLOW_DELAY:
MOV R7,#20
LOOP10:MOV R6,#200
LOOP11:MOV R5,#198
LOOP12:DJNZ R5,LOOP12
DJNZ R6,LOOP11
DJNZ R7,LOOP10
RET
ORG 400H
DB 6FH,7FH,07H,7DH,6DH,66H,4FH,5BH,06H,3FH
END