atmega8535 Ad conversion c program
#include
#define uchar unsigned char
#define uint unsigned int
uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Data[4]={0,0,0,0};
void DelayMs(uint i) //0.25ms
{uchar j;
for(;i!=0;i--)
{for(j=250;j !=0;j--) {;}}
}
void Display(uchar *p) //Display
{uchar i,sel=0x01 at 5ms interval;
for(i=0;i<4;i++)
{PORTD=sel;
PORTB=0xff-Table[p[i]];
DelayMs(20);
sel=sel<<1;
}
}
uint ADC_Convert(void)
{uint temp1,temp2;
temp1=(uint)ADCL;
temp2=(uint)ADCH ;
temp2=(temp2<<8)+temp1;
return(temp2);
}
void Process(uint i,uchar *p)
{p[0]=i/1000;
i=i%1000;
p[1]=i/100;
i=i%100;
p[2]=i/10;
i=i%10;
p[3]=i;
}
void main(void)
{ uint i;
DDRA=0x00; //Set port A to input without pull-up;
PORTA=0x00;
DDRB=0xff; //Set port B to push-pull 1 output;
PORTB=0xff;
DDRD=0xff; //Set port C PORTD
=0xff;
PORTB=0x00; //Port B initializes output 1; Port C initializes output 0; Light up all digital tubes ;
PORTD=0xff;
ADMUX=0x01; //Select the second channel ADC1 ;
ADCSR=0xe6; //125K conversion rate , free conversion mode; start AD converter;
DelayMs(3000); //delay until the system is stable;
while(1)
{i=ADC_Convert();
Process(i,Data);
Display(Data);
}
}
#include
#define uchar unsigned char
#define uint unsigned int
void DelayMs(uint i)
{uchar j;
for(;i!=0;i--)
{for(j=255;j!=0;j--) {;}}
}
main()
{DDRA=0xff; //Port A 1 output
PORTA=0xff;
DDRB=0xff; //Port B 1 output
PORTB=0xff;
while(1)
{DelayMs(0);
PORTA=0xff;
PORTB=0x00;}
}
Previous article:ATmega8535L Eeprom Example Program
Next article:AVR microcontroller digital tube display clock
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
- ST MEMS Creative Competition Post 6 - Machine Learning Core Learning (1) (MLC)
- Ten milestones on the road to 5G future development
- Big question: Experts, can such a PCB be made?
- Talking about 50 cents: After domestic substitution, is it really good? Continue to replace or return?
- Arteli AT32F415_Getting Started Guide_V1.00
- Questions about rotary transformer and AD2S83
- BYD employee died suddenly in a rental house: worked night shifts for a month before death, each shift lasted 12 hours
- MicroPython Hands-on (15) - AB Buttons on the Control Panel
- Security Tools Bombercat
- The solid state drive doesn't seem to be as good as I thought