#include <reg52.h> #include <math.h> #include <string.h> #include <STDIO.H> #include <absacc.h> #include "fileshow.h"
extern volatile unsigned char whole_state=0;//目前系统状态,0为测量,1为输入密码状态,2为设定状态,3为标定状态 ,4为系统参数设定 extern volatile unsigned char whole_display_state=0;//为显示状态下的自状态 0流量状态,1流量热能,2掉电状态,3流量热量报表1,4流量热量报表2 extern volatile unsigned char whole_currentchannel=0;//目前系统所处的通道,最大为CHANNEL_MAX extern volatile unsigned int whole_historydatacursor=0;//在测量状态下,显示历史数据的指针 extern volatile unsigned char whole_setcursor=0;//目前正在设定参数的指针00开始 extern volatile unsigned char whole_setnumber=0;//目前正在设定的参数编号 extern volatile unsigned char print_buffer[9]; extern volatile bit whole_lcdclear=TRUE; extern volatile unsigned char whole_setbuffer[3]={0,0,0};//设定的参数临时存储器 extern volatile unsigned char whole_time[TIME_BLOCK]={0,0,0,0,0,0,0};//存储系统的瞬时时间 //year,6;day,5;month,4;date,3;hour,2;minute,1;second,0; ///////////////////////////////////////////////////////////////////// //外数据空间数据 1024b 使用前先 STARTUP。ASM进行设置 //STARTUP。ASM 是由 STARTUP。A51 改后缀然后拷贝到本目录下,再加入到项目中 //通道数据全局变量 // 大小等于MAX×28 最大5×28= 140 地址范围是0000-008B static volatile float xdata whole_data[CHANNEL_MAX][7] _at_ 0x00; static volatile float xdata whole_data2[2]; float xdata gd_t[CHANNEL_MAX],gd_p[CHANNEL_MAX],gd_q[CHANNEL_MAX],gd_h[CHANNEL_MAX],gd_tq[CHANNEL_MAX],gd_th[CHANNEL_MAX]; unsigned char xdata temp[1]; int xdata i; nsigned char xdata Address=0x11;//串行通讯地址 static int idata main_timecount=0; //计时时使用
//////////////////////////////////////////////////////////////////// //全局外部函数 extern void time_init(void); extern void time_readclock(unsigned char current_clock[]); extern void key(void); extern void eeprom_read(unsigned int e_address,unsigned char r_data[],unsigned char r_long); extern void eeprom_write(unsigned int e_address,unsigned char e_data); /////////////////////////////////////////////////////////////////////// //本程序使用的 void lcd_display(void); void lcd_init(unsigned int tempi); void calculate_data(unsigned char channel); void db2str(char * cBuf,int dpoint,double db,int kd) ; void lcd_delayus(unsigned char us); void lcd_delayms(unsigned char ms); unsigned char xdata dec_t[3],dec_p[3],dec_q[3],dec_h[3],dec_tq[3],dec_th[3];
void main() { key (); lcd_display(); } void lcd_delayus(unsigned char us) //延时us的程序 ; { us=us/8; for(; us>0;us--) {;} }
void lcd_delayms(unsigned char ms) //延时ms的程序; { register unsigned int i; for(;ms>0;ms--) { for(i=125;i>0;i--) {;} } }
void lcd_write_asc(unsigned int asc_code) { lcd_writedata(asc_code,DATA_WRITE); lcd_delayus(72); }
void lcd_write_china(unsigned int sino_code) { unsigned char temp; temp=(char)((sino_code>>8)&0x00ff); lcd_writedata(temp,DATA_WRITE); lcd_delayus(72);//72US temp=(char)(sino_code&0x00ff); //取后八位 lcd_writedata(temp,DATA_WRITE); lcd_delayus(72);//72us } void lcd_writebyte(unsigned char w_data) { register unsigned char i; for (i=0;i<8;i++) { LCD_SCLK=LOW; LCD_IO=(bit)(w_data&0x80); LCD_SCLK=HIGH; w_data=w_data<<1; } } //ww_data 是要写入的数据,w_cmd=DATA_WRITE(写入数据)或是CMD_WRITE(写入命令) void lcd_writedata(unsigned char ww_data,unsigned char w_cmd) { unsigned char temp; P2=LCD_CS;//片选 lcd_writebyte(w_cmd); temp=ww_data&0xf0; lcd_writebyte(temp); temp=ww_data<<4; temp=temp&0xf0; lcd_writebyte(temp); P2=LCD_STOP; }
void lcd_setlocation(unsigned char xy) { lcd_writedata(xy,CMD_WRITE); lcd_delayus(72); //72us } extern void lcd_display(void); { unsigned char lcd_high,lcd_low; unsigned char i,j; unsigned char decimal; float temp2; float tempfloat; unsigned char temp[4]; if(whole_lcdclear==TRUE) { whole_lcdclear=fulse; lcd_writedata(0x01,CMD_WRITE); lcd_delayms(6); } lcd_writedata(0x0c,CMD_WRITE); delayus(72); switch(whole_display_state) { case0: { lcd_setlocation(LCD_FIRST); lcd_write_china(lcd_china_ll[0]); lcd_write_china(lcd_china_ll[1]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_lldw[0]); lcd_write_asc(lcd_asc_lldw[1]); lcd_write_asc(lcd_asc_lldw[2]); lcd_setlocation(LCD_SECOND eeprom_readEEPROM_ORIGIN+whole_currentchannel*EEPROM_SIZE*EEPROM_NUMBER+10*EEPROM_SIZE+1,temp,1);
decimal=(temp[0]>>4)&0xff; tempfloat=whole_data[whole_currentchannel][0]; for(i=decimal;i>0;i--) {tempfloat=tempfloat*10.0; } for(i=4;i>i--) {temp2=1; for(j=0;j<(i-1);j++) { temp2=temp2*10.0; } lcd_low=tempfloat/temp2; if(lcd_low>=10)&&(i==4) { goto text0;} tempfloat=tempfloat-temp2*lcd_low; if(i==decimal) {
lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[lcd_low]);
} else{ lcd_write(lcd_sz[lcd_low]); } } text0:for(i=4;i>0;i--) { if( i==decimal) {lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[5][72]);
} else { lcd_write(lcd_sz[5][72]); } } }//case0 over
case1: { lcd_setlocation(LCD_FIRST); lcd_write_china(lcd_china_wd[0]); lcd_write_china(lcd_china_wd[1]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_wddw[0]); eeprom_read(EEPROM_ORIGIN+whole_currentchannel*EEPROM_SIZE*EEPROM_NUMBER+10*EEPROM_SIZE+2,temp,1);
decimal=(temp[0]>>4)&0xff; tempfloat=whole_data[whole_currentchannel][1];
for(i=decimal;i>0;i--) {tempfloat=tempfloat*10.0; } for(i=4;i>i--) {temp2=1; for(j=0;j<(i-1);j++) { temp2=temp2*10.0; } lcd_low=tempfloat/temp2; if(lcd_low>=10)&&(i==4) { goto text1;} tempfloat=tempfloat-temp2*lcd_low; if(i==decimal) { lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[lcd_low]);
} else{ lcd_write(lcd_sz[lcd_low]) } } text1:for(i=4;i>0;i--) { if( i==decimal) { lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[5][72]); } else { lcd_write(lcd_sz[5][72]); } }
}// case1 over
case2: {lcd_setlocation(LCD_FIRST); lcd_write_china(lcd_china_yl[0]); lcd_write_china(lcd_china_yl[1]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_kb[0]); lcd_write_asc(lcd_asc_yldw[0]); lcd_write_asc(lcd_asc_yldw[1]); lcd_write_asc(lcd_asc_yldw[2]);
eeprom_read(EEPROM_ORIGIN+whole_currentchannel*EEPROM_SIZE*EEPROM_NUMBER+10*EEPROM_SIZE+2,temp,1);
decimal=(temp[0]>>4)&0xff; tempfloat=whole_data[whole_currentchannel][3];
tempfloat=tempfloat-0.101325; for(i=decimal;i>0;i--) {tempfloat=tempfloat*10.0; } for(i=4;i>i--) {temp2=1; for(j=0;j<(i-1);j++) { temp2=temp2*10.0; } lcd_low=tempfloat/temp2; if(lcd_low>=10)&&(i==4) { goto text2;} tempfloat=tempfloat-temp2*lcd_low; if(i==decimal) {
lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[lcd_low]);
} else{ lcd_write(lcd_sz[lcd_low]) } } text1:for(i=4;i>0;i--) { if( i==decimal) { lcd_write(lcd_dian[8*8]); lcd_write(lcd_sz[5][72]); }
else { lcd_write(lcd_sz[5][72]); } }
}// case2 over
} //SWICH OVER }
|