/********************************************************************
Program name: On-chip analog-to-digital conversion demonstration experiment
Clock frequency: internal RC 1M
Pin: connected to keyboard and display part
**PC0.......PC7 keyboard and display a.....g**
**PD0.......PD7 keyboard and display 1.....8**
**PA0 analog voltage**
**Aref positive power supply**
************************************************************************/
#include
#include
#include
#include
#pragma interrupt_handler ad:15
unsigned long m=0;
unsigned int adc,adc1=0,adc2=0,adc3=0,adc4=0,l;
const unsigned char f[]=
{
0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xde
};//code segment conversion
void adcc(void)
{
PORTA=0x00;
DDRA=0xf0;
PORTD=0x00;
DDRD=0xff;
PORTC=0x00;
DDRC=0xff;
ADMUX=0x40; //ADC status register definition
ADCSRA=0x8e;//ADC status register definition
SREG=0x80;//Open global interrupt
ADCSRA|=BIT(ADSC);//Start a conversion
}
/*******************************************Status register setting *******************/
void Delay(void)
{
unsigned int a, b;
for (a = 1; a<20; a++)
for (b = 1; b<20; b++)
;
}
/****************************Delay*********************/
void ad(void)
{
if (adc3==2)
adc1=ADC;
if (adc3==4)
adc2=ADC;
if (adc1==adc2)
adc=adc1;
adc3++;
if (adc3>4)
adc3=0;
ADCSRA|=BIT(ADSC);
}
/************************AD sampling interrupt service subroutine**************************/
void main(void)//main program
{
char i=0;
adcc();
while(1)
{
if (i==20)
m=(long)adc*5000/1023,i=0;
PORTC=f[m%10];
PORTD=0xfe;
Delay();
PORTC=f[m/10%10];
PORTD=0xfd;
Delay() ;
PORTC=f[m/100%10];
PORTD=0xfb;
Delay() ;
PORTC=f[m/1000%10]|0x01;
PORTD=0xf7;
Delay() ;
i++;
}
}
Previous article:External interrupt, timer interrupt, serial port interrupt C51 program
Next article:DS18B20 Driver
Recommended ReadingLatest update time:2024-11-16 23:50
- Popular Resources
- Popular amplifiers
- Siemens PLC Programming Technology and Application Cases (Edited by Liu Zhenquan, Wang Hanzhi, Yang Kun, etc.)
- Siemens PLC from Beginner to Mastery with Color Illustrations (Yang Rui)
- Siemens PLC Project Tutorial
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
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
- The number of bits per byte in the stm32 ordinary serial port transmission method is different from that in the DMA serial port transmission method
- The gap between actual power supply and ideal power supply
- Is it possible for the LDO or DCDC output voltage to be lower than the internal reference voltage?
- [Zero-knowledge ESP8266 tutorial] Quick start 21 world clock demo
- A question about the schematic
- Annual review: 2019 TI training course highlights, good reviews and gifts!
- Which development environment do I use for C8051F58x/F59x?
- C2000 CLA FAQ: Accessing Peripherals
- When adding LIB library in PROTEL99 under WIN10, it prompts FILE IS NOT RECOGNIZED. Is it only possible to modify AdvSch?
- TI MSP430F55xx ultra-low-power MCUs enable smarter connectivity