#include"../Inc/MyCommon.h"
#include
#include
#include"../Inc/CH451.h"
#include"../Inc/MyDelay.h"
#defineVref2.5//外部參考電壓,通過底板RP2來調(diào)節(jié)
uintn=0;//采集到的數(shù)值
ucharflag=0;//采集完成標(biāo)志
ucharDisplayData[8]={0x11,0x11,0x11,0x11,0x10,0x10,0x10,0x10};//數(shù)碼管各位要顯示的數(shù)據(jù)
//ADC12初始化
voidInitADC10(){
ADMUX=0x00;//ADC0AREF
ADCSRA=(1<分頻啟動連續(xù)轉(zhuǎn)換
}
//ADC中斷函數(shù)
ISR(SIG_ADC){
n=ADC;
flag=1;
}
//主函數(shù)
intmain(){
uchari;
DDRA=0xA8;//PA3PA5PA7設(shè)置為輸出
CH451_Init();//初始化CH451
for(i=0;i<8;i++)CH451_DisplayDig(7-i,DisplayData[i],0);
InitADC10();//初始化ADC10
sei();//關(guān)閉中斷
while(1){
if(flag){
n=(int)((n*Vref*1000)/1023);//溫度擴(kuò)大1000倍
//計算數(shù)碼管各位要顯示的數(shù)值
DisplayData[4]=n/1000;
DisplayData[5]=n%1000/100;
DisplayData[6]=n%100/10;
DisplayData[7]=n%10;
flag=0;
}
for(i=0;i<8;i++){//顯示電壓
if(i==4)CH451_DisplayDig(7-i,DisplayData[i],1);//顯示小數(shù)點
elseCH451_DisplayDig(7-i,DisplayData[i],0);
}
}
return0;
}