8-bit resolution ADC inside Songhan MCU

Publisher:dswecdLatest update time:2013-04-03 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;Purpose: To learn the internal 8-bit resolution ADC and data processing
;Full code download: http://www.51hei.com/f/shrad.rar
 CHIP SN8F27E65
//{{SONIX_CODE_OPTION
 .Code_Option WDT_CLK Flosc/4
 .Code_Option Reset_Pin P04
 .Code_Option LVD LVD_Max ; 3.3V Reset
 .Code_Option Watch_Dog Disable ;Turn off watchdog
 .Code_Option Low_Fcpu Flosc/1
 .Code_Option High_Clk IHRC_16M ; Internal 16M RC Oscillator
 .Code_Option High_Fcpu Fhosc/1
 .Code_Option Security Enable
 .Code_Option Noise_Filter Enable
//}}SONIX_CODE_OPTION
 
 
 DATAC EQU P4M
 DATA EQU P4
 LEDC EQU P0M
 LED EQU P0

.DATA; data
 ORG 0
 TEMP DS 1
 ACCBUF DS 1
 PflagBUF DS 1

.CODE;Program code
 ORG 0000H
 JMP A0
 ORG 000BH
 JMP T0
 ORG 0015H
A0: B0BCLR FT0IEN;Turn off T0 interrupt
 B0BCLR FT0ENB;Disable T0 interrupt
 MOV A,#16;Set T0 clock
 B0MOV T0M,A;
 MOV A,#16;Load initial value
 B0MOV T0C,A;
 B0BCLR FT0IRQ;Clear interrupt flag
 B0BSET FT0IEN;Turn on T0 interrupt
 B0BSET FT0ENB;Enable T0 interrupt
 B0BSET FGIE;Turn on general interrupt
 MOV A,#3;Display value
 MOV 41H,A
 
 MOV A,#2;Display value
 MOV 42H,A
 MOV A,#1;Display value
 MOV 43H,A
 MOV A,#0;Display value
 MOV 44H,A
;****************************************************
;Display settings
;************************************************
A1: MOV A,#11111110B ;Display bit code
 MOV 31H,A
 MOV A,#4;Display bit number
 MOV 33H,A
 B0MOV H,#0 ; Clear "H" to address RAM bank 0.
 B0MOV L,#41H ; Set register address.
 
A2:
 CLR ADM; Clear ADC mode register ADM
 
 CLR ADR; Clear ADR register
 
 MOV A,#00000001B
 B0MOV P5CON,A; Select P5.0 as ADC input channel
 
 MOV A,#00000000B
 B0MOV P5M,A; Set P5 port to input mode
 
 MOV A,#00000000B
 B0MOV P5UR,A; Disable P5 port to pull-up mode
 
 B0BSET FADENB; Enable ADC
 CALL M005; Delay
 MOV A,#00001000B
 OR ADM,A; Set ADCHS[3:0] to select ADC input channel
 
 B0BSET FGCHS; Enable ADC input channel
 
 B0BSET FADS; Start AD conversion.
A3:
 B0BTS1 FEOC; Determine whether the conversion is completed
 JMP A3
;****************************
; MOV A,ADB
 MOV A,#0
 MOV 60H,A
 MOV A,ADB; In 8-bit mode, the converted data is stored in ADB
 MOV 61H,A
;****************************
 CALL CL1; Call data processing
 MOV A,64H; Display the processed data
 MOV 44H,A; Thousands
 MOV A,63H
 MOV 43H,A; Hundreds
 
 MOV A,62H
 MOV 42H,A; Tens
 
 MOV A,61H
 MOV 41H,A; Units

 B0BCLR FEOC; clear flag
 CALL M008; delay
 
 JMP A2
 
; ***************************************************
; T0 interrupt
; **************************************************
T0: B0BCLR FT0IEN; turn off T0 interrupt
 B0BCLR FT0ENB; disable T0 interrupt
 B0XCH A,ACCBUF; push stack
 B0MOV A,PFLAG;
 B0MOV PFLAGBUF,A;
 MOV A,#0FFH; clear display
 B0MOV DATAC,A;
 B0MOV DATA,A;
 MOV A,#0FFH;
 B0MOV LEDC,A;
 MOV A,#0FFH;
 B0MOV LED,A;
T1:
 MOV A,#0FFH; set as output port
 B0MOV DATAC,A;
 B0MOV Y,#Q1$M; encoding table address
 B0MOV Z,#Q1$L; encoding table address
 B0MOV A, @HL; indirect addressing
 ADD Z, A; find the code to be displayed
 MOVC; check the table, the upper eight bits exist R, the lower eight bits exist ACC
 B0MOV DATA, A; data output
 
 
 MOV A, #0FFH; set to output port
 B0MOV LEDC, A

 MOV A,31H;Bit code
 B0MOV LED,A
 MOV A,31H;To process the bit code, since there is no RL but only RLC, now process C here
 MOV 32H,A
 RLC 32H
 RLCM 31H;Move bit code
 INCMS L;Display data control register processing
 CALL M001;Delay to increase brightness
 MOV A,#0FFH;Clear display
 B0MOV DATAC,A
 B0MOV DATA,A
 MOV A,#0FFH
 B0MOV LEDC,A
 MOV A,#0FFH
 B0MOV LED,A
 DECMS 33H;Automatically subtract 1 to determine whether it is also displayed. Complete
 JMP T1[page]
 
 MOV A,#11111110B ;Display bit code
 MOV 31H,A
 MOV A,#4;Display bit number
 MOV 33H,A
 B0MOV H,#0 ; Clear "H" to address RAM bank 0.
 B0MOV L,#41H; Set register address.
 B0MOV A,PFLAGBUF; Pop stack
 B0MOV PFLAG,A;
 B0XCH A,ACCBUF;
 MOV A,#16; Set T0 clock
 B0MOV T0M,A;
 MOV A,#16; Reload initial value
 B0MOV T0C,A;
 B0BCLR FT0IRQ; Clear interrupt flag
 B0BSET FT0IEN; Enable interrupt
 B0BSET FT0ENB; Enable interrupt
 B0BSET FGIE; Enable general interrupt
 RETI;

CL1:
;******************************
; MOV A,#60H
; MOV 62H,A
;
; MOV A,# 11111111b
;MOV 61H,A
 
 

;****************************
 CALL CL2
 MOV A,65H
 AND A,#11110000B
 MOV 60H,A
 SWAP 60H
 MOV 62H,A; Tens digit
 MOV A,65H
 AND A,#00001111B
 MOV 61H,A; Units digit
 MOV A,63H; Ten thousand digit
 MOV 65H,A
 
 MOV A,64H
 AND A,#00001111B
 MOV 63H,A; Hundreds digit
 MOV A,64H
 AND A,#11110000B
 MOV 64H,A
 SWAPM 64H;Thousand digit
 RET
 
 
CL2: MOV A,#0
 MOV 63H,A
 MOV 64H,A
 MOV 65H,A
 MOV A,#16
 MOV 67H,A
CL3: B0BCLR FC
 RLCM 61H; (low 8 bits)
 RLCM 60H; (high 8 bits)
 MOV A,65H; tens digit
 ADC A,65H;
 DAA;
 MOV 65H,A;
 MOV A,64H; hundreds digit
 ADC A,64H;
 DAA;
 MOV 64H,A;
 MOV A,63H; 10,000-bit
 ADC A,63H;
 DAA;
 MOV 63H,A;
 
 DECMS 67H;
 JMP CL3;
 RET;
 
 
 
 
 
 
 
;***************** *************************
;Delay subroutine
;******************* ***********************
M001: MOV A,#1
 MOV 51H,A
M002: MOV A,#24
 MOV 52H,A
M003: MOV A, #250
 MOV 53H,A
M004: DECMS 53H
 JMP M004
 DECMS 52H
 JMP M003
 DECMS 51H
 JMP M002
 RET

M005: MOV A,#200
 MOV 55H,A
M006: DECMS 55H
 JMP M006 
 RET
M007: MOV A,#1
 MOV 56H,A
M008: MOV A,#20
 MOV 57H,A
M009: MOV A,#250
 MOV 58H,A
M010: DECMS 58H
 JMP M010
 DECMS 57H
 JMP M009
 DECMS 56H
 JMP M008
 RET
 
 
 
;**********************************************
;Coding table
;******************************************
Q1: DW 00C0H ;0
      DW 00F9H ;1
      DW 00A4H ;2
      DW 00B0H ;3
      DW 0099H ;4
      DW 0092H ;5
      DW 0082H ;6
      DW 00F8H ;7
      DW 0080H ;8
      DW 0090H ;9
      DW 0088H ;A
      DW 0083H ;B
      DW 00C6H ;C
      DW 00A1H ;D
      DW 0086H ;E
      DW 008EH ;F
      endp

Reference address:8-bit resolution ADC inside Songhan MCU

Previous article:Songhan MCU external interrupt program
Next article:Chipsea microcontroller division operation

Recommended ReadingLatest update time:2024-11-16 14:31

STM32F407 ADC (operation register)
ADC The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 19 channels and can measure 16 external and 2 internal signal sources and Vbat channels. The A/D conversion of each channel can be performed in single, continuous, scan or intermittent mode. The result of the ADC can be stored
[Microcontroller]
STM32F407 ADC (operation register)
13. PIC32 Series - ADC Sampling Module
1. PIC32 Reference Resources PIC32 Family Reference Manual Chinese version Link address: PIC32 Family Reference Manual Chapter 17 10-bit AD Converter 2. Introduction to 10-bit ADC converter The PIC32MX 10-bit Analog-to-Digital (A/D) Converter (or ADC) has the following features; • Successive Approximation Register
[Microcontroller]
13. PIC32 Series - ADC Sampling Module
Logic analyzer used in ADC and related fields
Application of TWLA500 in ADC and related fields FAE: On-site technical support. Provide technical support to customers on the application of the products you sell, and handle quality issues raised by customers. FAE has direct contact with customers and has information advantages in product applicat
[Test Measurement]
Logic analyzer used in ADC and related fields
AD7768/AD7768-4 24-bit ADC Solution
Today, audio capabilities are integrated into nearly every personal electronic device. Whether walking down a busy city street or in a rural area, people of all ages can be seen listening to music while going about their daily business. In the last five years, the sheer number of audio devices has exploded. The aver
[Embedded]
AD7768/AD7768-4 24-bit ADC Solution
STM32 ADC multi-channel DMA transfer
 ADC multi-channel acquisition is written based on ADC single-channel DMA transmission. The code is as follows: volatile u16 adcconverdata ={0,0}; static void ADC_GPIO_Config(void) {   GPIO_InitTypeDef  GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1|GPI
[Microcontroller]
Principles and applications of embedded analog-to-digital converters
   Preface   In the data acquisition system, the analog-to-digital converter is a crucial link. The accuracy of the analog-to-digital converter and the cost of the system directly affect the practicality of the system. Therefore, how to improve the accuracy of the analog-to-digital converter and reduce the system c
[Analog Electronics]
N76E003 ADC Multi-channel Sampling
First, let's take a look at how the ADC of the N76E003 microcontroller works. From the figure below, we can see that the ADCHS register determines which channel's ADC is currently in use. Next, let's take a look at the specific meaning of the registers Next is the relevant macro definition contained in the N76e003
[Microcontroller]
N76E003 ADC Multi-channel Sampling
【STM32】The basic principles and registers of ADC
STM32F1xx official information: "STM32 Chinese Reference Manual V10" - Chapter 11 Analog/Digital Conversion (ADC) Basic Introduction to ADC Basic Definition of ADC The abbreviation of Analog-to-Digital Converter. It refers to an analog/digital converter or an analog/digital converter. It refers to a device that co
[Microcontroller]
【STM32】The basic principles and registers of ADC
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号