STC12C5410AD AD的測(cè)試LCD12864顯示程序
//---------------------------------------
//名稱: 指定位置寫16*16漢字函數(shù)
//-----------------------------------------
void write_chinese(unsigned char x,unsigned char y, unsigned char hz)
{
unsigned char j=0,i=0;
for(j=0;j2;j++)
{
werite_x_y(x+j,y);
for(i=0;i16;i++) write_data(han[hz*32+16*j+i]);
}
}
//---------------------------------------
//名稱: 寫一個(gè)字符到LCD函數(shù)(8*16點(diǎn)陣)
//參數(shù):x,y:寫入字符的地址 c: 寫入字符在shuzi表格中的位置
//-----------------------------------------
void write_zifu(unsigned char x,unsigned char y, unsigned char zi)
{
unsigned char j=0,i=0;
for(j=0;j2;j++)
{
werite_x_y(x+j,y);
for(i=0;i8;i++) write_data(shuzi[zi*16+8*j+i]); //
}
}
//---------------------------------------
//名稱: 初始化12864函數(shù)
//-----------------------------------------
void init_lcd(void)
{
Cs1=1;
Cs2=1;
delay(250);
write_com(Rssp_Off);
write_com(Page_Add+0);
write_com(Start_Line+0);
write_com(Col_Add+0);
write_com(Rssp_On);
}
//---------------------------------------
//名稱: 延時(shí)約1毫秒函數(shù)
//-----------------------------------------
void delay1ms()
{
unsigned int k;
for(k=0;k12000;k++);
}
//---------------------------------------
//名稱: 模數(shù)轉(zhuǎn)換函數(shù)(8位)
//-----------------------------------------
void adpro()
{
ADC_DATA = 0; //清A/D轉(zhuǎn)換結(jié)果寄存器
adbuf=0;
ADC_CONTR = ADC_CONTR|0x08; //0000,1000ADCS = 1,啟動(dòng)轉(zhuǎn)換
delay1ms();
do{ ; }
while((ADC_CONTR0x10)==0); //0001,0000等待A/D轉(zhuǎn)換結(jié)束
ADC_CONTR = ADC_CONTR0xE7; //1110,0111清ADC_FLAG位,停止A/D轉(zhuǎn)換
adbuf = ADC_DATA;
}
//---------------------------------------
//名稱: 初始化函數(shù)函數(shù)
//-----------------------------------------
void init()
{
P1M0=0x01; //設(shè)置P1.0為高阻輸入,以準(zhǔn)備AD
P1M1=0x00;
ADC_CONTR = ADC_CONTR|0x80; //1000,0000打開A/D轉(zhuǎn)換電源
delay1ms();
delay1ms();
ADC_CONTR = ADC_CONTR0xe0; //1110,0000 清ADC_FLAG,ADC_START位和低3位
}
//---------------------------------------
//名稱: AD值轉(zhuǎn)電壓值函數(shù)
//-----------------------------------------
unsigned int dianya_zhuanhuan()
{
unsigned int k;
float i_val, f_val;
i_val=(float)adbuf;
i_val=i_val/255;
i_val=i_val*500;
f_val = modf(i_val, i_val);
if(i_val>999) i_val=999;
k=(int)i_val;
return k;
}
//---------------------------------------
//名稱: 主函數(shù)
//作者:huangjianxin
//郵箱:hjx5548@163.com
//日期:2009-12-9
//-----------------------------------------
void main()
{
unsigned int dianyabuf;
init();
init_lcd(); //初始化液晶
Clr_Scr();
while(1)
{
adpro();
write_zifu(0,0,10); //A
write_zifu(0,8,13); //D
write_chinese(0,16,0); //值
write_zifu(0,32,47); //:
write_zifu(0,40,((adbuf%1000)/100)); //
write_zifu(0,48,((adbuf%100)/10)); //
write_zifu(0,56,(adbuf%10)); //
dianyabuf=dianya_zhuanhuan();
write_chinese(2,0,1); //電
write_chinese(2,16,2); //壓
write_zifu(2,32,47); //:
write_zifu(2,40,dianyabuf/100);
write_zifu(2,48,45);
write_zifu(2,56,(dianyabuf%100)/10);
write_zifu(2,64,dianyabuf%10);
write_zifu(2,72,31);
write_chinese(4,0,3); // 專
write_chinese(4,16,4); // 注
write_chinese(4,32,5); // 于
write_chinese(4,48,6); // 消
write_chinese(4,64,7); // 費(fèi)
write_chinese(4,80,8); // 類
write_chinese(4,96,9); // 控
write_chinese(4,112,10); // 制
write_zifu(6,0,26); //q
write_zifu(6,8,26); //q
write_zifu(6,16,47); //:
write_zifu(6,24,2); //2
write_zifu(6,32,7); //7
write_zifu(6,40,9); //9
write_zifu(6,48,0); //0
write_zifu(6,56,6); //6
write_zifu(6,64,8); //8
write_zifu(6,72,0); //0
write_zifu(6,80,7); //7
write_zifu(6,88,9); //9
}
}
萬能遙控器相關(guān)文章:萬能遙控器代碼
評(píng)論