//===================================
//串口0 串口1發(fā)送函數(shù)
//===================================
void Uart0_SendData(uchar dat0)
{
SBUF0=dat0; //寫SBUF0,開始發(fā)送
while(!TI0); //等待發(fā)送
TI0=0; //清發(fā)送標(biāo)志位
}
void Uart1_SendData(uchar dat1)
{
SBUF1=dat1; //寫SBUF1,開始發(fā)送
while(!(SCON1&0x02));
SCON1 = (SCON1&0xfd);
}
void Timer2_Init(int ct2s)
{
RCAP2H = -ct2s/0xff;
RCAP2L = -ct2s;
}
//-----------------------------------------------------------------------------
// Main 年:0xC4EA 月:0xD4C2 日:0xC8D5 時(shí):0xCAB1: 分0xB7D6: 秒:0xC3EB 的漢字內(nèi)碼
//-----------------------------------------------------------------------------
void main(void)
{
//uint TEMP1,TEMP2,TEMP3,TEMP4,HT,HR,HP; //8路AD通道變量四路來料溫度 環(huán)境溫度濕度 橫坡度
uchar i,j,Page1,BEW1,BEW2,BEW3,BEW4; //BEW1,BEW2,BEW3,BEW4; 拆分顯示的百,十,個(gè)位,小數(shù)點(diǎn)位中間變量
Init_Device();
P5 = 0xff;
delayms(200);
Ds1302_Init();
init_lcd ();
clrram ();
ADC0CF = ((SYSCLK/SAR_CLK)-1)《《3; // set SAR clock to 3MHz
ADC1CF = ((SYSCLK/SAR_CLK)-1)《《3; // set SAR clock to 3MHz
ADC1CF |= 0x01; //ADC1增益設(shè)為1
AD0EN = 1; //使能AC0啟動(dòng)轉(zhuǎn)換
ADC1CN &=~(0x80); //使能AC1啟動(dòng)轉(zhuǎn)換
TMR3CN = 0x04; //啟動(dòng)TM3
EA = 1;
Timer2_Init(SYSCLK/12/100); //10ms
//Ds1302_Write_Time() ;
// Ds1302_Read_Time();
for(j=0;j《7;j++)
{
Between[j] = CSSZ_c[j]; //讀取FLASH
}
SZH0 = Between[0]/10;
SZL0 = Between[0]%10;
SZH1 = Between[1]/10;
SZL1 = Between[1]%10;
SZH2 = Between[2]/10;
SZL2 = Between[2]%10;
SZH3 = Between[3]/10;
SZL3 = Between[3]%10;
SZH4 = Between[4]/10;
SZL4 = Between[4]%10;
SZH5 = Between[5]/10;
SZL5 = Between[5]%10;
SZH6 = Between[6]/10;
SZL6 = Between[6]%10;
if(SZL0》9) SZL0 = 0;
if(SZH0》9) SZH0 = 0;
if(SZL1》9) SZL1 = 0;
if(SZH1》9) SZH1 = 0;
if(SZL2》9) SZL2 = 0;
if(SZH2》9) SZH2 = 0;
if(SZL3》9) SZL3 = 0;
if(SZH3》9) SZH3 = 0;
if(SZL4》9) SZL4 = 0;
if(SZH4》9) SZH4 = 0;
if(SZL5》9) SZL5 = 0;
if(SZH5》9) SZH5 = 0;
if(SZL6》9) SZL6 = 0;
if(SZH6》9) SZH6 = 0;
img_disp (tab32);
delayms(5000);
ET2 = 1;
TR2 = 1;
BLK = 0;
//Ds1302_Write_Time() ;
while(1)
{
key_scan();
Ds1302_Read_Time();
if(Page!=Page1)
{
clrram (); //如果頁面變化,需要清屏;
}
switch(Page)
{
case 1: //畫面1:顯示當(dāng)前
{
string_disp (0x80,16,page1);
number_disp (0x89,1,0x32,0x30); //數(shù)字20
number_disp (0x8b,1,0xc4,0xea); //年
number_disp (0x8d,1,0xd4,0xc2); //月
number_disp (0x8f,1,0xc8,0xd5); //日
number_disp (0x9b,1,0xca,0xb1); //時(shí)
number_disp (0x9d,1,0xb7,0xd6); //分
number_disp (0x9f,1,0xc3,0xeb); //秒
TH = time_buf1[1]/10; //年
TL = time_buf1[1]%10;
number_disp (0x8a,1,TAB[TH],TAB[TL]);
TH = time_buf1[2]/10; //月
TL = time_buf1[2]%10;
number_disp (0x8C,1,TAB[TH],TAB[TL]);
TH = time_buf1[3]/10; //日
TL = time_buf1[3]%10;
number_disp (0x8E,1,TAB[TH],TAB[TL]);
TH = time_buf1[4]/10; //時(shí)
TL = time_buf1[4]%10;
number_disp (0x9A,1,TAB[TH],TAB[TL]);
TH = time_buf1[5]/10; //分
TL = time_buf1[5]%10;
number_disp (0x9C,1,TAB[TH],TAB[TL]);
TH = time_buf1[6]/10; //秒
TL = time_buf1[6]%10;
number_disp (0x9E,1,TAB[TH],TAB[TL]);
Page1=Page; //保存當(dāng)前頁面值
}break;
case 2:
{
string_disp (0x82,8,page2); //顯示實(shí)時(shí)采集量
string_disp (0x90,10,tab5);
if(HTF)
{
string_disp (0x97,2,tab8); //顯示℃
BEW2 = HT/100; //環(huán)境溫度十位
BEW3 = (HT%100)/10; //環(huán)境溫度個(gè)位
BEW4 = (HT%100)%10; //環(huán)境溫度小數(shù)位
if(!BEW2) //滅零處理
{
BEW2 = 10;
}
number_disp (0x95,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x96,1,0x2E,TAB[BEW4]);
}
else
{
string_disp (0x95,6,run2);
}
string_disp (0x88,10,tab6);
if(HRF)
{
string_disp (0x8f,2,run3); //顯示% //顯示%
BEW2 = HR/100; //環(huán)境濕度十位
BEW3 = (HR%100)/10; //環(huán)境濕度個(gè)位
BEW4 = (HR%100)%10; //環(huán)境濕度小數(shù)位
if(!BEW2) //滅零處理
{
BEW2 = 10;
}
number_disp (0x8D,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x8E,1,0x2E,TAB[BEW4]);
}
else
{
string_disp (0x8D,6,run2);
}
string_disp (0x98,8,tab7);
BEW2 = HP/100; //橫坡度十位
BEW3 = (HP%100)/10; //橫坡度個(gè)位
BEW4 = (HP%100)%10; //橫坡度小數(shù)位
if(HPF == 0) //負(fù)度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x2d,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 1) //正度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x2b,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 2) //0度數(shù)標(biāo)志位
{
number_disp (0x9C,1,0x20,0x20);
number_disp (0x9D,1,TAB[BEW2],0x2E);
number_disp (0x9E,1,TAB[BEW3],TAB[BEW4]);
number_disp (0x9f,1,0x20,0x20);
}
if(HPF == 3) //未連接標(biāo)志位
{
string_disp (0x9d,6,run2);
number_disp (0x9C,1,0x20,0x20);
}
Page1=Page;
}break;
case 3: //顯示來料溫度 ADC04V 645
{
string_disp (0x80,6,tab1);
if(KT1F)
{
string_disp (0x86,2,tab8); //顯示℃
BEW1 = TEMP1/1000; //溫度百位
BEW2 = (TEMP1%1000)/100; //溫度十位
BEW3 = ((TEMP1%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP1%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x85,1,0x2E,TAB[BEW4]);
number_disp (0x84,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x83,1,0x20,TAB[BEW1]);
}
else
{
string_disp (0x84,6,run2); //顯示“未連接”
number_disp (0x83,1,0x20,0x20);
}
string_disp (0x90,6,tab2);
if(KT2F)
{
string_disp (0x96,2,tab8); //顯示℃
BEW1 = TEMP2/1000; //溫度百位
BEW2 = (TEMP2%1000)/100; //溫度十位
BEW3 = ((TEMP2%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP2%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x95,1,0x2E,TAB[BEW4]);
number_disp (0x94,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x93,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x93,1,0x20,0x20);
string_disp (0x94,6,run2);
}
string_disp (0x88,6,tab3);
if(KT3F)
{
string_disp (0x8E,2,tab8); //顯示℃
BEW1 = TEMP3/1000; //溫度百位
BEW2 = (TEMP3%1000)/100; //溫度十位
BEW3 = ((TEMP3%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP3%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x8D,1,0x2E,TAB[BEW4]);
number_disp (0x8C,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x8B,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x8B,1,0x20,0x20);
string_disp (0x8C,6,run2);
}
string_disp (0x98,6,tab4);
if(KT4F)
{
string_disp (0x9E,2,tab8); //顯示℃
BEW1 = TEMP4/1000; //溫度百位
BEW2 = (TEMP4%1000)/100; //溫度十位
BEW3 = ((TEMP4%1000)%100)/10; //溫度個(gè)位
BEW4 = ((TEMP4%1000)%100)%10; //溫度小數(shù)位
if(!BEW1) //滅零處理
{
BEW1 = 10;
if(!BEW2)
{
BEW2 = 10;
}
}
number_disp (0x9D,1,0x2E,TAB[BEW4]);
number_disp (0x9C,1,TAB[BEW2],TAB[BEW3]);
number_disp (0x9B,1,0x20,TAB[BEW1]);
}
else
{
number_disp (0x9B,1,0x20,0x20);
string_disp (0x9C,6,run2);
}
Page1=Page;
}break;
評論
查看更多