//===================================
//串口0 串口1发送函数
//===================================
void Uart0_SendData(uchar dat0)
{
SBUF0=dat0; //写SBUF0,开始发送
while(!TI0); //等待发送
TI0=0; //清发送标志位
}
void Uart1_SendData(uchar dat1)
{
SBUF1=dat1; //写SBUF1,开始发送
while(!(SCON1&0x02));
SCON1 = (SCON1&0xfd);
}
void Timer2_Init(int ct2s)
{
RCAP2H = -ct2s/0xff;
RCAP2L = -ct2s;
}
//-----------------------------------------------------------------------------
// Main 年:0xC4EA 月:0xD4C2 日:0xC8D5 时:0xCAB1: 分0xB7D6: 秒:0xC3EB 的汉字内码
//-----------------------------------------------------------------------------
void main(void)
{
//uint TEMP1,TEMP2,TEMP3,TEMP4,HT,HR,HP; //8路AD通道变量四路来料温度 环境温度湿度 横坡度
uchar i,j,Page1,BEW1,BEW2,BEW3,BEW4; //BEW1,BEW2,BEW3,BEW4; 拆分显示的百,十,个位,小数点位中间变量
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增益设为1
AD0EN = 1; //使能AC0启动转换
ADC1CN &=~(0x80); //使能AC1启动转换
TMR3CN = 0x04; //启动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:显示当前
{
string_disp (0x80,16,page1);
number_disp (0x89,1,0x32,0x30); //数字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); //时
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; //时
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; //保存当前页面值
}break;
case 2:
{
string_disp (0x82,8,page2); //显示实时采集量
string_disp (0x90,10,tab5);
if(HTF)
{
string_disp (0x97,2,tab8); //显示℃
BEW2 = HT/100; //环境温度十位
BEW3 = (HT%100)/10; //环境温度个位
BEW4 = (HT%100)%10; //环境温度小数位
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; //环境湿度十位
BEW3 = (HR%100)/10; //环境湿度个位
BEW4 = (HR%100)%10; //环境湿度小数位
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; //横坡度个位
BEW4 = (HP%100)%10; //横坡度小数位
if(HPF == 0) //负度数标志位
{
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) //正度数标志位
{
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度数标志位
{
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) //未连接标志位
{
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; //温度个位
BEW4 = ((TEMP1%1000)%100)%10; //温度小数位
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; //温度个位
BEW4 = ((TEMP2%1000)%100)%10; //温度小数位
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; //温度个位
BEW4 = ((TEMP3%1000)%100)%10; //温度小数位
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; //温度个位
BEW4 = ((TEMP4%1000)%100)%10; //温度小数位
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;
评论
查看更多