AVR M16 Experiment 11: On-chip AD

Publisher:素心悠远Latest update time:2015-11-12 Source: eefocusKeywords:AVR  M16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/**********************************************************************
* 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<while(!(ADCSRA & (1<ADCSRA |= (1<
return ADC;
}

void ADCInit(void)
{
ADMUX = (1<ADCSRA = (1<}


void USARTInit(void) //initialization
{
UCSRA = 0X00; 
UCSRC |= (1<UBRRL = (11059200 / BAUD / 16 - 1) % 256; //Set the baud rate to 9600
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:

http://v.youku.com/v_show/id_XMTYxNTE2NTA4.html

Keywords:AVR  M16 Reference address:AVR M16 Experiment 11: On-chip AD

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

AVR series microcontroller grades and applications
    AVR microcontroller series is complete, with 3 grades, which can meet the requirements of various occasions:      (1) Low-end Tiny series AVR microcontrollers: mainly Tinyll/12/13/15/26/28, etc.      (2) Mid-range AT90S series AVR microcontrollers: mainly AT90S1200/2313/8515/8535, etc.      (3) High-end ATmega ser
[Microcontroller]
Introduction to the characteristics of AVR microcontroller
RISC (Reduced Instruction Set Computer) is relative to CISC (Complex Instruction Set Computer). RISC does not simply reduce instructions, but improves the computing speed by making the computer structure simpler and more reasonable. RISC gives priority to simple instructions with the highest frequency of use and avoid
[Microcontroller]
How to choose an M16 connector manufacturer
Desuo Precision Industry pointed out that choosing a manufacturer for the M16 is an important decision that requires comprehensive consideration of multiple factors. Here are some suggestions for choosing a manufacturer: Quality and: Make sure the manufacturer you choose meets your quality standard
[robot]
Desuo connector manufacturer shares how to use M16 connector
Desuo Precision Industry pointed out that M16 is a commonly used German standard connector, mainly used for transmitting power and data. It has reliable sealing performance and is suitable for various environments. The following is how to use the M16 connector: Confirm the connector type: There a
[robot]
About the separate acquisition of two-channel AD signals of AVR microcontroller
I recently did a project related to AD, and needed to collect two AD signals separately. The specific steps are as follows: 1. Select the reference power supply 2. Select the acquisition channel 3. Select the AD conversion clock 4. Enable the AD module, 5. Start the conversion, 6. Wait for the conversion to end, 7. Re
[Microcontroller]
Simple Modbus protocol implementation based on AVR128
The Modbus communication protocol was developed by Modicon in 1979 and is a bus protocol used for industrial field control. The Modbus communication system consists of chip nodes with programmable control and public transmission lines, and its purpose is to collect and monitor multi-node data. The Modbus protocol adop
[Microcontroller]
Simple Modbus protocol implementation based on AVR128
KS0108_AVR driver[0617]
I've been playing this a few days ago. Because of RAM read timing problems, because of proteus simulation problems... Even simple things can be delayed for a long time... Only the code is listed here, and I won't add comments when I have time. The development platform is IAR EWAVR 5.20 (compilation/hardware debugging)
[Microcontroller]
AVR timer fast PWM mode use
PWM is very commonly used. AVR has its own internal PWM function, which is divided into fast PWM mode and phase correction PWM mode. Here we choose method 15, OCR1A saves the upper limit value, and OCR1B saves the matching value, so the output pin OCR1A cannot input PWM, and only OCR1B can output PWM signal. If
[Microcontroller]
AVR timer fast PWM mode use
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号