Hetai MCU ADC conversion program

Publisher:平和的心情Latest update time:2015-05-12 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
;Content: Rotate the rheostat to change the AD conversion number and display it through 4 LEDs

;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

Reference address:Hetai MCU ADC conversion program

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

Advantages of DAC/Comparator Architecture vs. Integrated ADC
This section lists the advantages of the DAC/comparator architecture compared to integrated ADCs. The application circuits discussed are common and simple, but they also share some common issues. First, consider low-cost methods for detecting and recording power-line voltage sags, surges, and transients.
[Analog Electronics]
Advantages of DAC/Comparator Architecture vs. Integrated ADC
STM32F0 ADC learning
At the beginning, I used the stdlib library. Recently, I found that the cube library is more and more widely used, so I started to use the cube library to complete the ADC multi-channel acquisition experiment.   The ADC driver is in the STM32F0XX_HAL_DRIVER, there is the stm32f0xx_hal_adc.c file, we can enable the mac
[Microcontroller]
s3c2440 bare metal-ADC programming
ADC hardware principle An analog-to-digital converter, or ADC for short, usually refers to an electronic component that converts analog signals into digital signals. As shown in the figure, the analog signal converted from the voltage value on the variable resistor is converted through ADC and a digital signal is outp
[Microcontroller]
s3c2440 bare metal-ADC programming
USB interface design based on high-resolution ADC and PGA to connect thermocouples
The circuitry in this design includes a mixed-signal microcontroller, a USBUART (universal asynchronous receiver/transmitter), and a novel adaptive analog sensor input circuit. This circuit can connect various types of sensors to the two analog input channels of the design, control these devices on a USB host, and rea
[Microcontroller]
USB interface design based on high-resolution ADC and PGA to connect thermocouples
ADI launches high-speed analog-to-digital converter to simplify FPGA application design
The new AD9250 dual-channel 14-bit, 250 MSPS ADC interfaces seamlessly with high-speed FPGAs through JESD204B-compliant outputs and supports precision multichannel converter synchronization. Beijing, China—Communication infrastructure, imaging equipment, industrial instrumentation, defense electronics and other
[Analog Electronics]
ADI launches high-speed analog-to-digital converter to simplify FPGA application design
Positive and negative voltage measurement based on ADC0831+LM358
Use 358 to make an adder, through ADC0831 AD conversion, 51 single-chip microcomputer control, it can measure the voltage value from positive 2.5V to negative 2.5V. It can be expanded to measure large voltages by adding voltage divider resistors. The circuit schematic diagram is as follows:   The single-chip microcom
[Microcontroller]
Positive and negative voltage measurement based on ADC0831+LM358
ATtiny13A ADC query method usage
void adc_init(void) {    ADCSRA = 0x00; //Disable ADC    ADMUX = 0x03;    ACSR = 0x80; //Disable analog comparator    ADCSRB = 0x00;    ADCSRA = 0x83; } uint read_adc(void) {    uint temp = 0;    ADCSRA |= (1 ADSC); // Enable AD conversion, first conversion, result discarded    while((ADCSRA & (1 ADIF)) == 0); //Wai
[Microcontroller]
Overview of the historical process of ADC and DAC
This article introduces the development of ADC and DAC from the aspects of ADC resolution and sampling frequency, ultra-high-speed and high-performance DAC, the need for portability, ADC and DAC in AV systems and microsystems, and introduces some new ADC and DAC devices from TI, ADI and MAXIM. The development a
[Power Management]
Overview of the historical process of ADC and DAC
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号