* File name: main.c
* Program author: kidcao1987
* Program version: V1.0
* Function description: Connect the serial port and open the serial port debugging assistant. The following is displayed in a loop:
"Current voltage value: V
http://bbs.cepark.com
A big pumpkin fell from the sky!!!
Author: kidcao1987 QQ: 289718970
"
* Compiler: WinAVR-20090313
* Chip: ATmega16, external 11.0592MHZ crystal oscillator
* Technical support: http://bbs.cepark.com
*******************************************************************/
#include
#include
#define BAUD 9600
unsigned int uiResult; //Conversion result
float fVoltage; //
unsigned char const ucStr1[]={"Current voltage value:"};
unsigned char const ucStr2[]={"http://bbs.cepark.com"};
unsigned char const ucStr3[]={"A big pumpkin fell from the sky!!!"};
unsigned char const ucStr4[]={"Author: kidcao1987 QQ: 289718970"};
unsigned char const ucStr5[]={"Volt"};
unsigned int GetADCData(void); //Get the value of ADC
void ADCInit(void); //ADC initialization
void USARTInit(void); //Initialization
void USARTTransmitData(unsigned char); //Send data
void USARTTransmitString(unsigned char const *pStr); //Send string
void USARTTransmitString1(unsigned char const *pStr); //Send string
int main(void)
{
PORTD = 0x03;
DDRD = 0x02; //PD0 input PD1 output
PORTA = 0x00;
DDRA = 0xFE; //Set as output, PA0 as input, set as input, high impedance
USARTInit(); //Serial port initialization
ADCInit();
while(1)
{
uiResult = GetADCData();
fVoltage = (float)(uiResult)/1024*500;
uiResult = (unsigned int)(fVoltage); //Convert voltage value into display value
USARTTransmitString1(ucStr1);
USARTTransmitData((unsigned char)(uiResult/100) + 48);
USARTTransmitData('.');
USARTTransmitData((unsigned char)(uiResult%100/10) + 48);
USARTTransmitData((unsigned char)(uiResult%10) + 48);
USARTTransmitString1(ucStr5);
USARTTransmitData(0x0d);
USARTTransmitData(0x0a); //Enter and line feed
USARTTransmitString(ucStr2);
USARTTransmitString(ucStr3);
USARTTransmitString(ucStr4);
USARTTransmitData(0x0d); Data
(0x0a); //Carriage return and line feed
USARTTransmitData(0x0d);
USARTTransmitData(0x0a); //Carriage return and line
feed_delay_ms(1000);
}
}
unsigned int GetADCData(void)
{
ADCSRA |= (1<
return ADC;
}
void ADCInit(void)
{
ADMUX = (1<
void USARTInit(void) //initialization
{
UCSRA = 0X00;
UCSRC |= (1<
UBRRH = (11059200 / BAUD / 16 - 1) / 256;
UCSRB |= (1 << RXCIE) | (1 << RXEN) | (1 << TXEN); //Receive interrupt enable, receive enable, transmit enable
}
void USARTTransmitData(unsigned char ucTransmitData)
{
while(!(UCSRA & (1<
UDR = ucTransmitData; //发送
}
void USARTTransmitString(const unsigned char* pStr)
{
while(*pStr != '')
{
USARTTransmitData(*pStr++);
}
USARTTransmitData(0x0d);
USARTTransmitData(0x0a);
}
void USARTTransmitString1(const unsigned char* pStr)
{
while(*pStr != '')
{
USARTTransmitData(*pStr++);
}
}
Video address:
Previous article:How to use the delay function in WinAVR
Next article:AVR M16 Experiment 10 Serial Port
Recommended ReadingLatest update time:2024-11-17 06:33
- Popular Resources
- Popular amplifiers
- Learning PLC is easy - PLC ladder diagram and statement table with pictures (Li Changjun, Zhou Hua)
- A Complete Illustrated Guide to Operational Amplifier Applications (Written by Wang Zhenhong)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- The basic format of PIC microcontroller programming
- HuaDa MCU FLASH operation instructions and precautions
- I am working on a product for traffic security equipment recently. The project has high safety requirements and heavy tasks. I am having a headache recently...
- Several issues on key-controlled 8X8LED dot matrix screen displaying graphics program
- FAQ: PolarFire SoC FPGA Secure Boot | Microchip Security Solutions Seminar Series 12
- Some Problems on Measuring AC Current with Current Transformer
- Simulation of staying up late is harmful to health
- [RVB2601 Creative Application Development] + RTC Clock Display Experiment
- From traditional substation to smart substation
- [Raspberry Pi Pico Review] Xiaohui Review