ORG 0000H ; Start of the MAIN
JMP MAIN
ORG 000BH ; Timer0 interrupt address
JMP T0ISR
ORG 0023H ; Serial Interrupt address
JMP SISR
ORG 0030
MOV R0, #12 ; motor speed on time
MOV R1, #0
MAIN: MOV SCON, #52H ; These 4 lines set up UART for 9600bps ..
MOV TMOD, #21H ; assuming clock 11,059200MHz ..
MOV TH1, #-3
SETB TR1
SETB TF0
MOV IE, #10010010B ; IE.7 = 1 enables all interrupts ..
; IE.4 = 1 enables serial port interrupt ..
; IE.1 = 1 enables Timer0 overflow interrupt
; Pins P3.7, P3.3, P3.4 and P3.5 are used as outputs ..
AGAIN: SETB P3.7 ; P3.7, 3.3 = 1 ( 5V)
SETB P3.3
CLR P3.4 ; P3.4, 3.5 = 0 (0V)
CLR P3.5
SCAN: CJNE R1, #20, JJ ; Check if Timer0 interrupt occured 20 times
MOV R1, #0 ; If yes, load speed reference R0 with 0
JMP AGAIN
JJ: MOV A, R1 ; If not, check what is current R0 reference value ..
MOV 22H, R0 ; 22H is just a memory address ..
CJNE A, 22H, J2
SETB C ; If current reference value = R1 goto SCAN ..
J2: JC SCAN
CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V
CLR P3.3
JMP SCAN
; ==================================
; Timer0 interrupt
T0ISR: CLR TR0
MOV TH0, #HIGH(-921) ; Reload values for TH0 and TL0 ..
MOV TL0, #LOW(-921)
INC R1 ; R1 counts Timer0 interrupts ..
SETB TR0
RETI
; ===================================
; Serial port interrupt
; F, M or S will load R0 (speed reference) with selected values ..
SISR: CLR RI
CLR TI
MOV A, SBUF
CJNE A, #"F", N1 ; If incoming character = 'F" load R0 with 17d ..
MOV R0, #17
RETI
N1: CJNE A, #"M", N2 ; If character = 'M' load R0 with 10d ..
MOV R0, #10
RETI
N2: CJNE A, #"S", N3 ; If character = 'S' load R0 with 04d ..
MOV R0, #4
N3: RETI
END
; add this declaration after MOVR0,#0 ..
Flags DATA 20h
Direction BIT Flags.0 ; If direction=0 =>CW if 1 =>CCW ..
...
; and change the following:
Loop: JB Direction, AgainCCW
AgainCW: ... ; as it is .. 6 and 7 =>1, 4 and 5 =>0
ScanCW:
...
JMP Loop ; old jump was to Again, this time it is Loop
AgainCCW: ; 6 and 7 =>0, 4 and 5 =>1
ScanCCW: ...
JMP Loop
; ===========================
; Serial port interrupt
; F, M or S will load R0 (speed reference) with selected values ..
SISR: CLR RI
CLR TI
MOV A, SBUF
CJNE A, #"F", N1 ; If incoming character = 'F" load R0 with 17d ..
MOV R0, #17
RETI
N1: CJNE A, #"M", N2 ; If character = 'M' load R0 with 10d ..
MOV R0, #10
RETI
N2: CJNE A, #"S", N3 ; If character = 'S' load R0 with 04d ..
MOV R0, #4
RETI
; added ..
N3: CJNE A, #"D", N4 ; If character='D' change direction ..
CPL Direction
N4: RETI
RETI
$NOPAGING
$MOD252
; Pins P3.7, P3.3, P3.4 and P3.5 are used as outputs ..
ORG 0000h ; Start of the MAIN ..
JMP MAIN
ORG 000Bh ; Timer0 interrupt address ..
JMP T0ISR
ORG 0023h ; Serial Interrupt address ..
JMP SISR
Flags DATA 20h
Speed0 BIT Flags.0 ; Speed0 = stop 0
SpeedS BIT Flags.1 ; SpeedS = slow 4
SpeedM BIT Flags.2 ; SpeedM = medium 10
SpeedF BIT Flags.3 ; SpeedF = fast 17
Any4 BIT Flags.4
Any5 BIT Flags.5
Any6 BIT Flags.6
TChange BIT Flags.7
TimeH Data 23h
TimeL Data 24h
ORG 0030h
MOV R0, #0 ; motor speed on time .. start from 0 ..
MOV R1, #0
MOV TimeH, #10h ; If TimeHTimeL=1000h-> speed change ..
MOV TimeL, #00h
MOV DPTR, #0000h
MOV Flags, #00h
MAIN:
MOV SCON, #52h ; These 4 lines set up UART for 9600bps ..
MOV TMOD, #21h ; assuming clock 11,059200MHz ..
MOV TH1, #-3
SETB TR1
SETB TF0
MOV IE, #10010010B ; IE.7 = 1 enables all interrupts ..
; IE.4 = 1 enables serial port interrupt ..
; IE.1 = 1 enables Timer0 overflow interrupt
Main_Loop:
AGAIN:
JB TChange, S5_Time ; Check if it is time to vary speed ..
SETB P3.7 ; P3.7, 3.3 = 1 ( 5V)
SETB P3.3
CLR P3.4 ; P3.4, 3.5 = 0 (0V)
CLR P3.5
SCAN: CJNE R1, #20, JJ ; Check if Timer0 interrupt occured 20 times
MOV R1, #0 ; If yes, load speed reference R0 with 0
JMP AGAIN
JJ: MOV A, R1 ; If not, check what is current R0 reference value ..
MOV 22h, R0 ; 22h is just a memory address ..
CJNE A, 22h, J2
SETB C ; If current reference value <= R1 goto SCAN ..
J2: JC SCAN
CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V ..
CLR P3.3
JMP SCAN
; ==================================
; Timer0 interrupt
T0ISR:
PUSH ACC
PUSH PSW
CLR TR0
MOV TH0, #HIGH(-921) ; Reload values for TH0 and TL0 ..
MOV TL0, #LOW(-921)
INC R1 ; R1 counts Timer0 interrupts ..
INC DPTR ; x sec time counter ..
CLR C
MOV A, DPH ; Check if DPTR = TimeH_TimeL =1000h ..
SUBB A, TimeH
JC T0ISR_Exit ; <
JNZ THbg ; >
CLR C ; =
MOV A, DPL
SUBB A, TimeL
JC T0ISR_Exit ; <
JNZ T0ISR_Exit ; >
CLR C ; =
SETB TChange
THbg: MOV DPTR, #0000h
T0ISR_Exit:
POP PSW
POP ACC
SETB TR0
RETI
; ===================================
; Serial port interrupt
; F, M or S will load R0 (speed reference) with selected values ..
SISR:
CLR RI
CLR TI
MOV A, SBUF
CJNE A, #'F', N1 ; If incoming character = 'F" load R0 with 17d ..
MOV R0, #17
RETI
N1: CJNE A, #'M', N2 ; If character = 'M' load R0 with 10d ..
MOV R0, #10
RETI
N2: CJNE A, #'S', N3 ; If character = 'S' load R0 with 04d ..
MOV R0, #4
N3: RETI
; ====================================
; time subs ..
S5_Time:
S_Change:
JB SpeedS, Speed_Up1
MOV R0, #4 ; speed slow ..
SETB SpeedS
SJMP S5_Exit
Speed_Up1:
JB SpeedM, Speed_Up2
MOV R0, #10 ; speed medium ..
SETB SpeedM
SJMP S5_Exit
Speed_Up2:
JB SpeedF, Speed_Up3
MOV R0, #17 ; speed fast ..
SETB SpeedF
SJMP S5_Exit
Speed_Up3:
CLR SpeedS
CLR SpeedM
CLR SpeedF
MOV R0, #0 ; speed = 0
S5_Exit:
CLR TChange
RET
END
T1ISR: CLR TR1
MOV TH1, #HIGH(-48000)
MOV TL1, #LOW(-48000)
DJNZ R7, J1
MOV R7, #20
SETB PSW.1
J1: RETI
This can be added at any time, but for now you have to address more important issue, which is related to:from the previous guide that you given to me, is about the direction control, you told me that if character = 'D', it changes direction. how can i set the character "D" using external input to control the direction??previously, you also mentioned that it can be done by adding a button to any pin. Let's say the pin is P3.1, how can i achieve this and how to write the assembly code?
Counting 5s time has to occur "behind" the main loop and as a result a bit is set/clear to tell the main loop that the time has passed ..i have setb TR1, so the 5x JNB PSW.1 can work well? (its main function is to let motor run in #12 speed for 5 seconds)then to the #8 speed.
; Timer0 interrupt
T0ISR:
PUSH ACC
PUSH PSW
CLR TR0
MOV TH0, #HIGH(-921) ; Reload values for TH0 and TL0 ..
MOV TL0, #LOW(-921)
INC R1 ; R1 counts Timer0 interrupts ..
INC DPTR ; x sec time counter ..
CLR C
MOV A, DPH ; Check if DPTR = TimeH_TimeL =1000h ..
SUBB A, TimeH
JC T0ISR_Exit ; <
JNZ THbg ; >
CLR C ; =
MOV A, DPL
SUBB A, TimeL
JC T0ISR_Exit ; <
JNZ T0ISR_Exit ; >
CLR C ; =
[u][b]SETB TChange[/b][/u]
THbg: MOV DPTR, #0000h
T0ISR_Exit:
POP PSW
POP ACC
SETB TR0
RETI
Main_Loop:
AGAIN:
JB TChange, S5_Time
...
S5_Time:
S_Change:
JB SpeedS, Speed_Up1
MOV R0, #4 ; speed slow ..
SETB SpeedS
SJMP S5_Exit
Speed_Up1:
JB SpeedM, Speed_Up2
MOV R0, #10 ; speed medium ..
SETB SpeedM
SJMP S5_Exit
Speed_Up2:
JB SpeedF, Speed_Up3
MOV R0, #17 ; speed fast ..
SETB SpeedF
SJMP S5_Exit
Speed_Up3:
CLR SpeedS
CLR SpeedM
CLR SpeedF
MOV R0, #0 ; speed = 0
S5_Exit:
CLR TChange
LJMP Main_Loop
..[code] option ..
It makes the code easier to read ..
5x JNB PSW.1
MOV R0, #12 ; motor speed on time
MOV R1, #0
JNB PSW.1, $ ; 1s delay ..
JNB PSW.1, $
JNB PSW.1, $
JNB PSW.1, $
JNB PSW.1, $
MOV R0, #8
MOV R1, #0
S5_Exit:
CLR TChange
RET
ORG 0000h ; Start of the MAIN ..
JMP MAIN
ORG 000Bh ; Timer0 interrupt address ..
JMP T0ISR
ORG 0023h ; Serial Interrupt address ..
JMP SISR
Flags DATA 20h
Speed0 BIT Flags.0 ; Speed0 = stop 0
SpeedS BIT Flags.1 ; SpeedS = slow 8
SpeedM BIT Flags.2 ; SpeedM = medium 10
SpeedF BIT Flags.3 ; SpeedF = fast 17
Any4 BIT Flags.4
Any5 BIT Flags.5
Any6 BIT Flags.6
TChange BIT Flags.7
TimeH Data 23h
TimeL Data 24h
ORG 0030h
MOV R0, #0 ; motor speed on time .. start from 0 ..
MOV R1, #0
MOV TimeH, #10h ; If TimeHTimeL=1000h-> speed change ..
MOV TimeL, #00h
MOV DPTR, #0000h
MOV Flags, #00h
MAIN:
MOV SCON, #52h ; These 4 lines set up UART for 9600bps ..
MOV TMOD, #21h ; assuming clock 11,059200MHz ..
MOV TH1, #-3
SETB TR1
SETB TF0
MOV IE, #10010010B ; IE.7 = 1 enables all interrupts ..
; IE.4 = 1 enables serial port interrupt ..
; IE.1 = 1 enables Timer0 overflow interrupt
Main_Loop:
AGAINCW:
JB TChange, S5_Time ; Check if it is time to vary speed ..
SETB P3.7 ; P3.7, 3.3 = 1 ( 5V)
SETB P3.3
CLR P3.4 ; P3.4, 3.5 = 0 (0V)
CLR P3.5
SCANCW: CJNE R1, #20, JJ ; Check if Timer0 interrupt occured 20 times
MOV R1, #0 ; If yes, load speed reference R0 with 0
JMP AGAINCW
JJCW: MOV A, R1 ; If not, check what is current R0 reference value ..
MOV 22h, R0 ; 22h is just a memory address ..
CJNE A, 22h, J2CW
SETB C ; If current reference value <= R1 goto SCAN ..
J2CW: JC SCANCW
CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V ..
CLR P3.3
JMP SCANCW
AGAINCCW:
JB TChange, S5_Time ; Check if it is time to vary speed ..
SETB P3.4 ; P3.7, 3.3 = 1 ( 5V)
SETB P3.5
CLR P3.7 ; P3.4, 3.5 = 0 (0V)
CLR P3.3
SCANCCW: CJNE R1, #20, JJ ; Check if Timer0 interrupt occured 20 times
MOV R1, #0 ; If yes, load speed reference R0 with 0
JMP AGAINCCW
JJCCW: MOV A, R1 ; If not, check what is current R0 reference value ..
MOV 22h, R0 ; 22h is just a memory address ..
CJNE A, 22h, J2CCW
SETB C ; If current reference value <= R1 goto SCAN ..
J2CCW: JC SCANCCW
CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V ..
CLR P3.3
JMP SCANCCW
; ==================================
; Timer0 interrupt
T0ISR:
PUSH ACC
PUSH PSW
CLR TR0
MOV TH0, #HIGH(-921) ; Reload values for TH0 and TL0 ..
MOV TL0, #LOW(-921)
INC R1 ; R1 counts Timer0 interrupts ..
INC DPTR ; x sec time counter ..
CLR C
MOV A, DPH ; Check if DPTR = TimeH_TimeL =1000h ..
SUBB A, TimeH
JC T0ISR_Exit ; <
JNZ THbg ; >
CLR C ; =
MOV A, DPL
SUBB A, TimeL
JC T0ISR_Exit ; <
JNZ T0ISR_Exit ; >
CLR C ; =
SETB TChange
THbg: MOV DPTR, #0000h
T0ISR_Exit:
POP PSW
POP ACC
SETB TR0
RETI
; ===================================
; Serial port interrupt
; F, M or S will load R0 (speed reference) with selected values ..
SISR:
CLR RI
CLR TI
MOV A, SBUF
CJNE A, #'F', N1 ; If incoming character = 'F" load R0 with 17d ..
MOV R0, #17
RETI
N1: CJNE A, #'M', N2 ; If character = 'M' load R0 with 10d ..
MOV R0, #10
RETI
N2: CJNE A, #'S', N3 ; If character = 'S' load R0 with 04d ..
MOV R0, #4
N3: RETI
; ====================================
; time subs ..
S5_Time:
S_Change:
JB SpeedS, Speed_Up1
MOV R0, #8 ; speed slow ..
SETB SpeedS
SJMP S5_Exit
Speed_Up1:
JB SpeedM, Speed_Up2
MOV R0, #10 ; speed medium ..
SETB SpeedM
SJMP S5_Exit
Speed_Up2:
JB SpeedF, Speed_Up3
MOV R0, #17 ; speed fast ..
SETB SpeedF
SJMP S5_Exit
Speed_Up3:
CLR SpeedS
CLR SpeedM
CLR SpeedF
MOV R0, #0 ; speed = 0
S5_Exit:
CLR TChange
RET
END
1 $NOPAGING
2 $MOD252
3
4
0000 5 ORG 0000h ; Start of the MAIN ..
0000 020040 6 JMP MAIN
000B 7 ORG 000Bh ; Timer0 interrupt address ..
000B 020095 8 JMP T0ISR
0023 9 ORG 0023h ; Serial Interrupt address ..
0023 0200CD 10 JMP SISR
11
0020 12 Flags DATA 20h
0000 13 Speed0 BIT Flags.0 ; Speed0 = stop 0
0001 14 SpeedS BIT Flags.1 ; SpeedS = slow 8
0002 15 SpeedM BIT Flags.2 ; SpeedM = medium 10
0003 16 SpeedF BIT Flags.3 ; SpeedF = fast 17
0004 17 Any4 BIT Flags.4
0005 18 Any5 BIT Flags.5
0006 19 Direction BIT Flags.6 ; Direction=0 ->CW .. Direction=1 ->CCW
0007 20 TChange BIT Flags.7 ; 1=5secs has elapsed
0022 21 Tmp DATA 22h
0023 22 TimeH Data 23h
0024 23 TimeL Data 24h
24
0030 25 ORG 0030h
26
0030 7800 27 MOV R0, #0 ; motor speed on time .. start from 0 ..
0032 7900 28 MOV R1, #0
0034 752315 29 MOV TimeH, #15h ; If TimeHTimeL=1534h-> speed change ..
0037 752434 30 MOV TimeL, #34h
003A 900000 31 MOV DPTR, #0000h
003D 752000 32 MOV Flags, #00h
33
0040 34 MAIN:
35
0040 759852 36 MOV SCON, #52h ; These 4 lines set up UART for 9600bps ..
0043 758921 37 MOV TMOD, #21h ; assuming clock 11,059200MHz ..
0046 758DFD 38 MOV TH1, #-3
0049 D28E 39 SETB TR1
40
004B D28D 41 SETB TF0
004D 75A892 42 MOV IE, #10010010b ; IE.7 = 1 enables all interrupts ..
43 ; IE.4 = 1 enables serial port interrupt ..
44 ; IE.1 = 1 enables Timer0 overflow interrupt ..
45
46 ; ==========
47
0050 48 Main_Loop:
49
0050 200621 50 JB Direction, Again_CCW
51
52 ; ==========
53
0053 54 AGAIN_CW:
0053 1200E5 55 CALL S5_Time ; Check if it is time to vary speed ..
56
0056 D2B7 57 SETB P3.7 ; P3.7, 3.3 = 1 ( 5V)
0058 D2B3 58 SETB P3.3
005A C2B4 59 CLR P3.4 ; P3.4, 3.5 = 0 (0V)
005C C2B5 60 CLR P3.5
61
005E 62 SCAN_CW:
005E B91404 63 CJNE R1, #20, JJ_CW ; Check if Timer0 interrupt occured 20 times
0061 7900 64 MOV R1, #0 ; If yes, load speed reference R0 with 0
0063 80EB 65 JMP Main_Loop
66
0065 67 JJ_CW:
0065 E9 68 MOV A, R1 ; If not, check current R1 reference value ..
0066 8822 69 MOV Tmp, R0
0068 B52201 70 CJNE A, Tmp, J2_CW
006B D3 71 SETB C ; If current reference value <= R0 goto SCAN ..
006C 72 J2_CW:
006C 40F0 73 JC SCAN_CW
006E C2B7 74 CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V ..
0070 C2B3 75 CLR P3.3
0072 80EA 76 JMP SCAN_CW
77
78 ; ==========
79
0074 80 AGAIN_CCW:
0074 1200E5 81 CALL S5_Time ; Check if it is time to vary speed ..
82
0077 D2B4 83 SETB P3.4 ; P3.7, 3.3 = 1 ( 5V)
0079 D2B5 84 SETB P3.5
007B C2B7 85 CLR P3.7 ; P3.4, 3.5 = 0 (0V)
007D C2B3 86 CLR P3.3
87
007F 88 SCAN_CCW:
007F B91404 89 CJNE R1, #20, JJ_CCW ; Check if Timer0 interrupt occured 20 times
0082 7900 90 MOV R1, #0 ; If yes, load speed reference R0 with 0
0084 80CA 91 JMP Main_Loop
92
0086 93 JJ_CCW:
0086 E9 94 MOV A, R1 ; If not, check current R0 reference value ..
0087 8822 95 MOV Tmp, R0
0089 B52201 96 CJNE A, Tmp, J2_CCW
008C D3 97 SETB C ; If current reference value <= R1 goto SCAN ..
008D 98 J2_CCW:
008D 40F0 99 JC SCAN_CCW
008F C2B7 100 CLR P3.7 ; Otherwise outputs P3.7 and P3.3 = 0V ..
0091 C2B3 101 CLR P3.3
0093 80EA 102 JMP SCAN_CCW
103
104
105 ; ==================================
106 ; Timer0 interrupt ..
107
0095 108 T0ISR:
0095 C0E0 109 PUSH ACC
0097 C0D0 110 PUSH PSW
0099 C28C 111 CLR TR0
009B 758CFC 112 MOV TH0, #HIGH(-921) ; Reload values for TH0 and TL0 ..
009E 758A67 113 MOV TL0, #LOW(-921)
00A1 09 114 INC R1 ; R1 counts Timer0 interrupts ..
00A2 A3 115 INC DPTR ; x sec time counter ..
116
00A3 C3 117 CLR C
00A4 E583 118 MOV A, DPH ; Check if DPTR = TimeH_TimeL =1534h ..
00A6 9523 119 SUBB A, TimeH
00A8 4011 120 JC T0_Exit ; <
00AA 700C 121 JNZ THbg ; >
00AC C3 122 CLR C ; =
00AD E582 123 MOV A, DPL
00AF 9524 124 SUBB A, TimeL
00B1 4008 125 JC T0_Exit ; <
00B3 7006 126 JNZ T0_Exit ; >
00B5 C3 127 CLR C ; =
00B6 D207 128 SETB TChange ; DPTR=1534h ..
129
00B8 130 THbg:
00B8 900000 131 MOV DPTR, #0000h
132
00BB 133 T0_Exit:
00BB A2B1 134 MOV C, P3.1 ; Test if P3.1 SW closed ..
00BD 4005 135 JC Set_Dir ; If closed (0V) -> CW ..
00BF C206 136 CLR Direction
00C1 0200C6 137 JMP T0ISR_Exit
00C4 138 Set_Dir:
00C4 D206 139 SETB Direction ; If open (5V) -> CCW ..
140
00C6 141 T0ISR_Exit:
00C6 D0D0 142 POP PSW
00C8 D0E0 143 POP ACC
00CA D28C 144 SETB TR0
00CC 32 145 RETI
146
147 ; ===================================
148 ; Serial port interrupt
149 ; F, M or S will load R0 (speed reference) with selected values ..
150
00CD 151 SISR:
00CD C298 152 CLR RI
00CF C299 153 CLR TI
00D1 E599 154 MOV A, SBUF
00D3 B44603 155 CJNE A, #'F', N1 ; If incoming character = 'F" load R0 with 17d ..
00D6 7811 156 MOV R0, #17
00D8 32 157 RETI
00D9 158 N1:
00D9 B44D03 159 CJNE A, #'M', N2 ; If character = 'M' load R0 with 10d ..
00DC 780A 160 MOV R0, #10
00DE 32 161 RETI
00DF 162 N2:
00DF B45302 163 CJNE A, #'S', N3 ; If character = 'S' load R0 with 04d ..
00E2 7804 164 MOV R0, #4
00E4 165 N3:
00E4 32 166 RETI
167
168 ; ====================================
169 ; time subs ..
170
00E5 171 S5_Time:
00E5 300723 172 JNB TChange, S5_Exit
00E8 173 S_Change:
00E8 200106 174 JB SpeedS, Speed_Up1
00EB 7808 175 MOV R0, #8 ; speed slow ..
00ED D201 176 SETB SpeedS
00EF 801A 177 SJMP S5_Exit
00F1 178 Speed_Up1:
00F1 200206 179 JB SpeedM, Speed_Up2
00F4 780A 180 MOV R0, #10 ; speed medium ..
00F6 D202 181 SETB SpeedM
00F8 8011 182 SJMP S5_Exit
00FA 183 Speed_Up2:
00FA 200306 184 JB SpeedF, Speed_Up3
00FD 7811 185 MOV R0, #17 ; speed fast ..
00FF D203 186 SETB SpeedF
0101 8008 187 SJMP S5_Exit
188
0103 189 Speed_Up3:
0103 C201 190 CLR SpeedS
0105 C202 191 CLR SpeedM
0107 C203 192 CLR SpeedF
0109 7800 193 MOV R0, #0 ; speed = 0 ..
194
010B 195 S5_Exit:
010B C207 196 CLR TChange
010D 22 197 RET
198
199 END
VERSION 1.2h ASSEMBLY COMPLETE, 0 ERRORS FOUND
T0_Exit:
MOV C, P3.1 ; Test if P3.1 SW closed ..
JC Set_Dir ; If closed (0V) -> CW ..
CLR Direction
JMP T0ISR_Exit
Set_Dir:
SETB Direction ; If open (5V) -> CCW ..
Flags DATA 20h
Speed0 BIT Flags.0 ; Speed0 = stop 0
SpeedS BIT Flags.1 ; SpeedS = slow 8
SpeedM BIT Flags.2 ; SpeedM = medium 10
SpeedF BIT Flags.3 ; SpeedF = fast 17
Any4 BIT Flags.4
Any5 BIT Flags.5
Direction BIT Flags.6 ; Direction=0 ->CW .. Direction=1 ->CCW
TChange BIT Flags.7 ; 1=5secs has elapsed
ORG 0000H
JMP MAIN
ORG 000BH
JMP T0ISR
ORG 0023H
JMP SISR
ORG 0030H
FLAGS DATA 20H
DIRECTION BIT FLAGS.0
MOV R0, #10 ; motor speed on time
MOV R1, #0
MAIN: MOV SCON, #52H
MOV TMOD, #21H
MOV TH1, #-3
MOV R7, #21
SETB TR1
SETB TF0
MOV IE, #10010010B
LOOP: JB DIRECTION, AGAINCCW
AGAINCW: SETB P3.7
SETB P3.3
CLR P3.4
CLR P3.5
SCANCW: CJNE R1, #20, JJCW
MOV R1, #0
JMP LOOP
JJCW: MOV A, R1
MOV 22H, R0
CJNE A, 22H, J2CW
SETB C
J2CW: JC SCANCW
CLR P3.7
CLR P3.3
JMP SCANCW
AGAINCCW: SETB P3.4
SETB P3.5
CLR P3.3
CLR P3.7
SCANCCW:CJNE R1, #20, JJCCW
MOV R1, #0
JMP LOOP
JJCCW: MOV A, R1
MOV 22H, R0
CJNE A, 22H, J2CCW
SETB C
J2CCW: JC SCANCCW
CLR P3.4
CLR P3.5
JMP SCANCCW
T0ISR: CLR TR0
MOV TH0, #HIGH(-921)
MOV TL0, #LOW(-921)
INC R1
SETB TR0
RETI
SISR: CLR RI
CLR TI
MOV A, SBUF
CJNE A, #"F", N1
MOV R0, #17
RETI
N1: CJNE A, #"M", N2
MOV R0, #10
RETI
N2: CJNE A, #"S", N3
MOV R0, #4
N3: RETI
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?