;Digital tube segment code connection method A-PD0, B-PD1....G-PD6, H-PD7
;Digital tube bit code connection method OM0-PC0...COM4-PC3
;Full source code download: http://www.51hei.com/f/htadzh.rar
;;AD input pin-PA0
include HT66F50.inc
ORG 0000H
JMP A1
ORG 0014H ; Multi-function interrupt entry address
JMP ZD1
ORG 1CH ; ADC interrupt entry address
JMP ISR_ADC
ORG 0030H
Q1:
DC 03FH ; 0
DC 006H ; 1
DC 05BH ; 2
DC 04FH ; 3
DC 066H ; 4
DC 06DH ; 5
DC 07DH ; 6
DC 007H ; 7
DC 07FH ; 8
DC 06FH ; 9
DC 077H ; A
DC 07CH ; B
DC 039H ; C
DC 05EH ; D
DC 079H ; E
DC 071H ; F
A1:
CLR [98H] ; AD data high 8-bit memory
CLR [99H] ; AD data low 8-bit memory
MOV A,0 ;Display content
MOV [8AH],A ;The first digit of the digital tube segment code display content register
MOV A,0 ;Display content
MOV [8BH],A ;The second digit of the digital tube segment code display content register
MOV A,0 ;Display content
MOV [8CH],A ;The third digit of the digital tube segment code display content register
MOV A,0 ;Display content
MOV [8DH],A ;The fourth digit of the digital tube display content register
MOV A,08H ;Select data according to the CP1C register setting requirements
MOV CP1C,A ;Set PC port as I/0 port instead of interrupt port
CLR PBC ;Set PC port as output port
CLR PDC ;Set PD port as output port
MOV A,1 ;Set the initial display bit code to display the first bit
MOV [80H],A ;Bit code register
MOV A,8AH ;Set the corresponding first bit segment code register
MOV MP0,A ;Indirect register pointer
MOV A,00000000B ;Set TM2 count clock bit to fSYS/4
MOV TM2C0,A
MOV A,11000001B ;Set TM2 interrupt to timer/counter mode and select comparator A match
MOV TM2C1,A
MOV A,LOW 5000 ;Set interrupt time to 5000 clock cycles
MOV TM2AL,A ;Low 8 bits
MOV A,HIGH 5000 ;Set interrupt time to 5000 clock cycles
MOV TM2AH,A ;High 8 bits
MOV A,00010000B ;Turn on AD power and ADRFS=1
MOV ADCR0,A ;ADRH is bit 3~bit 0, ADRL is bit 7~bit 0
MOV A,00000110B ;AD conversion clock is fSYS/64,
MOV ADCR1,A ;VREFS=0 selects internal reference voltage
MOV A,00000001B ;Select AD channel as AN0
MOV ACERL,A
clr START ; Start AD conversion 0→1→0 start
set START ;
clr START ;
CLR ADF ; Clear flag
SET ADE ; Open AD interrupt
CLR MF0F ; Clear multi-function interrupt 0 flag
CLR T2AF ; Clear timer 2 comparator A interrupt flag
SET MF0E ; Enable multi-function 0 interrupt
SET T2AE ; Enable timer 2 comparator A interrupt
SET EMI ; Enable total interrupt
SET T2ON ; Start counting
A2:
CALL CL1 ; Call the subroutine of converting 2-digit hexadecimal number to 5-digit decimal number
MOV A,[9DH] ; Display content
MOV [8AH],A ; Display content register of the first digital tube segment code
MOV A,[9CH] ; Display content
MOV [8BH],A ; Display content register of the second digital tube segment code
MOV A,[9BH] ; Display content
MOV [8CH],A ;The third digital tube segment code display content register
MOV A,[9AH] ;Display content
MOV [8DH],A ;The fourth digital tube display content register
JMP A2
;*******************************************************
;2-digit hexadecimal number conversion to 5-digit decimal number subroutine (0ffh=65535)
;*******************************************************
CL1:
MOV A,[98H]
MOV [9AH],A
MOV A,[99H]
MOV [9BH],A
CALL CL2
MOV A,00001111B
AND A,[9EH]
MOV [9AH],A
SWAP [9EH]
MOV A,00001111B
AND A,[9EH]
MOV [9BH],A
MOV A,[9CH]
MOV [9EH],A
MOV A,00001111B
AND A,[9DH]
MOV [9CH],A
SWAP [9DH]
MOV A,00001111B
ANDM A,[9DH]
RET
CL2:
CLR [9CH]
CLR [9DH]
CLR [9EH]
MOV A,16
MOV [9FH],A
CL3:
CLR C
RLC [9BH]
RLC [9AH]
MOV A,[9EH] A
DC A,[9EH]
DAA [9EH]
MOV A,[9DH]
ADC A,[9DH]
DAA [9DH]
MOV A,[9CH]
ADC A,[9CH]
DAA [9CH]
SDZ [9FH]
JMP CL3
RET
;*******************************************************
; Interrupt service subroutine
;*******************************************************
ZD1:
MOV [0F0H],A ; Push ACC to 0F0H
MOV A,STATUS ;
MOV [0F1H],A ; Push status flag register to 0F1H
CLR PB ; Clear PC (clear screen)
MOV A,Q1 ; Data table address
CLR TBHP ; Clear data table address high bit or error
ADD A,IAR0 ; Use indirect register to find the address of the data table where the segment code to be displayed is located
MOV TBLP,A ; Table pointer register TBLP
TABRD PD ; Look up the table and store the data to the PD port register
MOV A,[80H] ; Bit code register
MOV PB,A ;Store the bit code register to the PC port register
;The segment code and bit code are both available, so the digital tube is lit
INC MP0;Indirect register pointer plus 1 points to the next segment code register
RL [80H];Left shift code register controls the next digital tube
SNZ [80H].5;Judge whether the 4 digital tubes are controlled
JMP ZD2;Exit interrupt and continue
MOV A,1;If yes, re-initialize register data
MOV [80H],A;
MOV A,8AH;Thousands digital tube corresponding register
MOV MP0,A;Store to indirect register 0
ZD2:
MOV A,[0F1H];Pop stack LIFO FIFO
MOV STATUS,A;Pop stack 0F1H number to flag register
MOV A,[0F0H];Pop stack 0F0H number to acc
CLR MF0F;Clear multi-function flag
CLR T2AF;Clear timer 2 comparator A flag
RETI;Interrupt return
ISR_ADC:
MOV [0F0H],A ; push ACC to 0F0H
MOV A,STATUS ;
MOV [0F1H],A ; push status flag register to 0F1H
MOV A,ADRH
MOV [98H],A
MOV A,ADRL
MOV [99H],A
MOV A,[0F1H] ;pop stack LIFO FIFO
MOV STATUS,A ;pop stack 0F1H to flag register
MOV A,[0F0H] ;pop stack 0F0H to acc
clr START ;high pulse on start bit to initiate conversion
set START ;reset A/D
clr START ;start A/D
RETI ;interrupt return
;*******************************************************
; Delay subroutine
;*******************************************************
M001:
MOV A,1
MOV [85H],A
M002:
MOV A,200
MOV [86H],A
M003:
MOV A,250
MOV [87H],A
M004:
SDZ [87H]
JMP M004
SDZ [86H]
JMP M003
SDZ [85H]
JMP M002
RET
END
Previous article:Hetai MCU controls 5-wire 4-phase stepper motor control program
Next article:Hetai MCU internal EEPROM, 4*4 buttons and storage area switching
Recommended ReadingLatest update time:2024-11-17 00:58
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Could you please tell me what are the functions of the two transistors in the flyback power supply?
- Tomorrow's live broadcast: Specially invited "Samadhi True Fire" who specializes in automotive electronics to analyze vehicle power supply design
- Design of a Compact Microstrip BPF Using ADS Simulation
- Find a professional instrument for testing transistors
- Share: TI MSP430 FRAM development reference and Q&A
- What kind of noise is the ripple generated by the power chip? Common mode noise or differential mode noise?
- About the suffix of static libaray. .
- [Shanghai Hangxin ACM32F070 development board review] 1. Unboxing and two disappointments
- [Project Source Code] Quartus Timing Constraint Tutorial
- PIC microcontroller project compilation failed