新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > pic168xa ADC程序(c語言)

pic168xa ADC程序(c語言)

作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
#i nclude

#i nclude <pic168xa.h>
__CONFIG(0x1832);
//芯片配置字,看門狗關(guān),上電延時開,掉電檢測關(guān),低壓編程關(guān),加密,4M晶體HS振蕩
const char TABLE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DELAY();
void DELAY11();
void init();
void display(unsigned int x);
void main()
{unsigned int result=0x0000;
do
{
int i;
result=0x0000;

本文引用地址:http://butianyuan.cn/article/201611/315955.htm

//for(i=4;i--;)
// {
init();
DELAY();
ADGO=0X01;

while(ADGO)
{result=ADRESH;
result=result<<8;
result=result+ADRESL;};
// }
// result=result>>3;
for(i=10;--i;)
{display(result);};
//DELAY11();};

}while(1);

}
void init()
{
TRISD=0X00;
TRISB=0XE1;
PORTD=0X00;
ADCON1=0X8E;
ADCON0=0XC1;
DELAY();
}
void display(unsigned int x)
{int qian,bai,shi,ge;
unsigned int temp;
temp=x;
qian=temp/0x3e8;
PORTD=TABLE[qian]; //查表得百位顯示的代碼
PORTB=0xef; //RA3輸出低電平,點亮百位顯示
// DELAY11();
bai=(temp%0x3e8)/0x64;
PORTD=TABLE[bai]; //查表得百位顯示的代碼
PORTB=0xf7; //RA3輸出低電平,點亮百位顯示
//DELAY11();
shi=((temp%0x3e8)%0x64)/0xa; //延時一定時間,保證顯示亮度
PORTD=TABLE[shi]; //查表得十位顯示的代碼
PORTB=0xfb; //RA4輸出低電平,點亮十位顯示
//DELAY11();
ge=((temp%0x3e8)%0x64)%0xa; //延時一定時間,保證亮度
PORTD=TABLE[ge]; //求個位顯示的代碼
PORTB=0xfd; //RA5輸出低電平,點亮個位顯示
DELAY11();
}
void DELAY()
{
int i;
for(i=0x100;i--;);
}
void DELAY11()
{
int i;
for(i=0;i<=30;i++)
continue;
}


關(guān)鍵詞: pic168xaADC程序c語

評論


技術(shù)專區(qū)

關(guān)閉