/** 函數(shù)庫說明:ATMEGE8 AD模數(shù)轉(zhuǎn)換 * 版本: v1.0 * 修改: 龐輝 * 修改日期: 2011年08月06日 * * 說明: 中斷方式AD采集* * 版本更新: 詳見readme.txt * *注意: res PC5 * CE PB0* RST PB1* DC PB2* SDIN PB3* SCLK PB4 */#include "includes.h"/*名 稱:void AD_Init(void)功 能:AD初始化入口參數(shù):無出口參數(shù):無使用說明:無/void AD_Init(void){//參考電壓AREF,左對(duì)齊,ADC5單端輸入 ADMUX |= (1 << ADLAR) | (1 << MUX2) | (1 << MUX0); //AD使能, 連續(xù)轉(zhuǎn)換,中斷使能,32分頻, 6M / 32 = 187.5khzADCSRA |= (1 << ADEN) | (1 << ADFR) | (1 << ADIE) | (1 << ADPS2) | (1 << ADPS0);//AD開始轉(zhuǎn)換ADCSRA |= (1 << ADSC); }int main(void){ //LCD初始化 LCD_Init();//AD初始化AD_Init();LCD_Write_Chinese_String(0, 0, 12, 5, Chinese_Font, 0, 0);//開總中斷sei();while(1){}return 0;}int result = 0;char buf[] = "5.00V";SIGNAL(SIG_ADC){result = ADCH;result = result * 500.0 / 255;//數(shù)據(jù)更新buf[0] = result / 100 + 0;buf[2] = result / 10 % 10 + 0;buf[3] = result % 10 + 0;//數(shù)據(jù)顯示LCD_Write_English_String(0, 3, buf); }
評(píng)論