AVR M16實驗之十一 片內AD
* 文件名稱: main.c
* 程序作者: kidcao1987
* 程序版本: V1.0
* 功能描述: 接上串口,打開串口調試助手。在上面循環顯示:
“當前電壓值: 伏
http://bbs.cepark.com
天上掉下一個大南瓜!!!
作者:kidcao1987 QQ:289718970
”
* 編譯器:WinAVR-20090313
* 芯片:ATmega16,外部11.0592MHZ晶振
* 技術支持:http://bbs.cepark.com
**********************************************************************/
#include
#include
#define BAUD 9600
unsigned int uiResult; //轉換結果
float fVoltage; //
unsigned char const ucStr1[]={"當前電壓值:"};
unsigned char const ucStr2[]={"http://bbs.cepark.com"};
unsigned char const ucStr3[]={"天上掉下一個大南瓜!!!"};
unsigned char const ucStr4[]={"作者:kidcao1987 QQ:289718970"};
unsigned char const ucStr5[]={"伏"};
unsigned int GetADCData(void); //獲取ADC的數值
void ADCInit(void); //ADC初始化
void USARTInit(void); //初始化
void USARTTransmitData(unsigned char); //發送數據
void USARTTransmitString(unsigned char const *pStr); //發送字符串
void USARTTransmitString1(unsigned char const *pStr); //發送字符串
int main(void)
{
PORTD = 0x03;
DDRD = 0x02; //PD0輸入 PD1輸出
PORTA = 0x00;
DDRA = 0xFE;//設置為輸出,PA0為輸入端,設置為輸入,高阻態
USARTInit(); //串口初始化
ADCInit();
while(1)
{
uiResult = GetADCData();
fVoltage = (float)(uiResult)/1024*500;
uiResult = (unsigned int)(fVoltage); //電壓值轉換成顯示值
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); //回車換行
USARTTransmitString(ucStr2);
USARTTransmitString(ucStr3);
USARTTransmitString(ucStr4);
USARTTransmitData(0x0d);
USARTTransmitData(0x0a); //回車換行
USARTTransmitData(0x0d);
USARTTransmitData(0x0a); //回車換行
_delay_ms(1000);
}
}
unsigned int GetADCData(void)
{
ADCSRA |= (1
}
void ADCInit(void)
{
ADMUX = (1<
void USARTInit(void) //初始化
{
UCSRA = 0X00;
UCSRC |= (1<
UBRRH = (11059200 / BAUD / 16 - 1) / 256;
UCSRB |= (1 << RXCIE) | (1 << RXEN) | (1 << TXEN); //接收中斷使能,接收使能,發送使能
}
void USARTTransmitData(unsigned char ucTransmitData)
{
while(!(UCSRA & (1<
UDR = ucTransmitData; //發送
}
void USARTTransmitString(const unsigned char* pStr)
{
while(*pStr != 主站蜘蛛池模板: 高邮市| 全椒县| 台山市| 遵义市| 元朗区| 罗平县| 辽源市| 陆良县| 甘孜| 沐川县| 阳曲县| 故城县| 贵德县| 越西县| 乳源| 张掖市| 宝鸡市| 绵竹市| 岳阳市| 朔州市| 噶尔县| 鹤峰县| 江都市| 通江县| 江西省| 高台县| 绥滨县| 红原县| 新民市| 龙里县| 泰兴市| 唐河县| 莲花县| 饶平县| 姚安县| 澜沧| 武乡县| 大冶市| 商水县| 连江县| 沅江市|