Final
Final
Final
ORG 0000H
LJMP MAIN
ORG 0050H
MAIN: MOV P0, #0FFH
MOV DPTR, #LOOK
SETB P2.4 ;clear 7-segment display
SETB P2.3
SETB P2.2
SETB P2.1
MOV R0, #50H;set student number pointer
MOV R4, #0
MOV R3, #0
MOV R2, #0
MOV 50H, #4 ;student number
MOV 51H, #1
MOV 52H, #0
MOV 53H, #7
MOV 54H, #5
MOV 55H, #0
MOV 56H, #4
MOV 57H, #3
MOV 58H, #4
MOV R5, #8 ;checker if R0 cycled 1 time
MOV IE, #10001000B ;enable Timer 1 interrupt
CLR TF0
CLR TF1
MOV TMOD, #00010101B ;Timer 0 Counter, Timer 1 Timer, both Mode 1
MOV TH1, #3CH ;50000 cycle interrupt
MOV TL1, #0B0H
MOV TH0, #0
MOV TL0, #0
SETB P3.4 ;make P3.4 input
MOV R6, #0 ;calculate motor time for 1 turn
SETB TR1
SETB TR0
ACALL UPDATE
DJNZ 43H, P_HIGH
ACALL UPDATE ;create 5 wave => update student id
PASS: INC R0
DJNZ R5, CONTI
MOV R0, #50H ;if cycle 1 time, reset
MOV R5, #8
CONTI: SJMP LOOP ;total = 100*40H + 18 cycles
CLR P2.2
MOV A, R4
MOVC A, @A+DPTR
MOV P1, A
ACALL SHORT
SETB P2.2
CLR P2.1
MOV A, R3
MOVC A, @A+DPTR
MOV P1, A
ACALL SHORT
SETB P2.1
CLR P2.0
MOV A, R2
MOVC A, @A+DPTR
MOV P1, A
ACALL SHORT
SETB P2.0
RET
GETRPM:
;calculate pulses in 0.5 secs = X
;X*120/20 = X*6 = RPM
MOV A, TL0
MOV B, #6
MUL AB
TO_BCD:
MOV B, #10
DIV AB
MOV R2, B
MOV B, #10
DIV AB
MOV R3, B
MOV R4, A
RET
SHORT: MOV 45H, #70 ;change this to gett 100Hz, +10 => -3Hz
SHERE:DJNZ 45H, SHERE
RET
END
Video:
https://youtu.be/mkly0WGlXFU?si=SqGaDWVQwMJiT8As
Breadboard Layout: