Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Code:

ORG 0000H
LJMP MAIN

;ISR for Timer 1


ORG 001BH
CLR TR1
CLR TR0
CLR TF1
CLR TF0
MOV TH1, #3CH
MOV TL1, #0B0H
INC R6
CJNE R6, #10, OMIT
OMIT: JC DONE ;if R6 >= 10, update rpm
MOV R6, #0
LCALL GETRPM
MOV TH0, #0
MOV TL0, #0
DONE: CLR C
SETB TR1
SETB TR0
RETI

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

LOOP: MOV 43H, #200 ;time length of student number


P_HIGH: SETB P2.4
CLR C
MOV A, P0 ;other = 18 cycles
MOV B, #5
DIV AB
MOV B, #2
MUL AB
CJNE A, #10, CHECK
CHECK: JNC READY ;jump if A>10 (C==0)
MOV A, #10 ;lowest is 10%
READY: MOV 42H, A ;save A for LOW
MOV 40H, A
OUT1: MOV 41H, #48 ;2*40H
IN1:DJNZ 41H, IN1 ;2*40H*48
DJNZ 40H, OUT1 ;2*40H

P_LOW: CLR P2.4


CLR C
MOV A, #75 ;must be bigger than maximum HIGH duty cycle
SUBB A, 42H ;but in addition with other instruction cycles
MOV 40H, A ;is set to 75 instead of 100 => 91 Hz
OUT2: MOV 41H, #48
IN2:DJNZ 41H, IN2
DJNZ 40H, OUT2

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

UPDATE: MOV 44H, #4


AGAIN:CLR P2.3
MOV A, @R0
MOVC A, @A+DPTR
MOV P1, A
ACALL SHORT
SETB P2.3

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

DJNZ 44H, AGAIN

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

LOOK: ;MOVC A, @A+DPTR


;DB 11000000B, 11111001B, 10100100B, 10110000B, 10011001B,
10010010B, 10000010B, 11111000B, 10000000B, 10010000B
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H, 92H, 82H, 0F8H, 80H, 90H ;0~9

END
Video:
https://youtu.be/mkly0WGlXFU?si=SqGaDWVQwMJiT8As

Breadboard Layout:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy