📄 fuc.c
字号:
void init_cpu(void)
{
TMOD=0x21; //设置定时器0为16位定时器,定时器1为8为自动重装
PCON=0x80; //SMOD=1
WDCON=0X80; //SMOD_1=1
TCON=0x01; //定时器0停止计时,外部中断0设为下降沿触发
TL0=0x5c;
TH0=0x95; //
//TL1=0xCA;
//TH1=0xCA; //波特率设为9600
//TL1=0xE5;
//TH1=0xE5; //波特率设为19200
TL1=0x94;
TH1=0x94; //波特率设为4800
TR1=1;
IE=0x53; //关闭总中断,使能串口1、2中断,定时器0中断,外部中断0中断
CKCON=0X10; //定时器0的时钟源为系统时钟的12分频,定时器1为4分频,计时频率为32MHz
SCON=0x50; //串行口1模式1通讯,使能接收
SCON1=0x50; //串行口2模式1通讯,使能接收
PMR=0x01; //使能片上RAM
}
void init_data(void)
{
uchar i;
for(i=0;i<32;i++)
data_buf[i]=0x11;
t_temp=0;
t_temp2=0;
key_data=1;
key_temp=0;
DE=1;
re_temp=0;re_temp1=0;re_temp2=0;re_no=0;re_mudi=0;re_yuan=0;re_xinxi=0;
tx_temp=0;tx_temp1=0;tx_temp2=0;tx_no=0;tx_xinxi=0;data_no=0;
re1_temp=0;re1_temp1=0;re1_temp2=0;re1_no=0;re1_mudi=0;re1_yuan=0;re1_xinxi=0;
tx1_temp=0;tx1_temp1=0;tx1_temp2=0;tx1_no=0;tx1_xinxi=0;tx_mudi=0x01;
//mudi_no=0x03;mudi_sn=0;shuju_sn=0;
ov_buf[0]=0x20;ov_buf[1]=0x33;ov_buf[2]=0x38;ov_buf[3]=0x30;
lv_buf[0]=0x20;lv_buf[1]=0x33;lv_buf[2]=0x31;lv_buf[3]=0x30;
vot_buf[0]=0x20;vot_buf[1]=0x32;vot_buf[2]=0x32;vot_buf[3]=0x30;
for(i=1;i<4;i++)
{
ov_temp[i]=ov_buf[i];
lv_temp[i]=lv_buf[i];
vot_temp[i]=vot_buf[i];
}
ovv=380;lv=310;vot=220;
ovv_val=380;lv_val=310;vot_val=220;
dis_flag3=1;
P2=0xFF;
sn=P2&0x0f;
}
void show_log(void)
{
uchar j=0,k=0,l=0;
int t;
RST=0; //复位
ms_delay(5);
RST=1;
ms_delay(5);
write_command(0x30,0); //8位并行口,基本指令集
us_delay(100);
write_command(0x30,0); //8位并行口,基本指令集
us_delay(100);
write_command(0x0c,1); //开显示
us_delay(100);
write_command(0x01,1); //清显示屏
ms_delay(20);
write_command(0x34,0); //8位并行口,扩充指令集,显示off
us_delay(100);
write_command(0x34,0); //8位并行口,扩充指令集,显示off
us_delay(100);
write_command(0x80,0); //GDRAM垂直地址为0
us_delay(100);
write_command(0x80,0); //GDRAM水平地址为0
us_delay(100);
write_command(0x30,0); //8位并行口,基本指令集
us_delay(100);
for(t=0;t<1024;t++)
{
write_data(sunoasis[t]);
us_delay(10);
//write_data(0x0f);
j++;
if(j==16)
t=t+496;
if(j==32)
{
t=t-512;
j=0;k++;
write_command(0x34,0); //8位并行口,扩充指令集
// us_delay(100);
write_command(0x80+k,1);
// us_delay(100);
write_command(0x80,1);
us_delay(10);
write_command(0x30,0); //8位并行口,基本指令集
us_delay(10);
}
}
write_command(0x36,0); //8位并行口,扩充指令集,显示on
us_delay(100);
}
void init_lcd(void)
{ uchar i;
write_command(0x30,0); //8位并行口,基本指令集
us_delay(100);
write_command(0x30,0); //8位并行口,基本指令集
us_delay(100);
write_command(0x06,1); //进入点设定
us_delay(100);
write_command(0x02,1); //位地址清零
us_delay(100);
write_command(0x40,1); //选定CGRAM
us_delay(100);
for(i=0;i<32;i++)
{
write_data(du[i]);
us_delay(100);
}
}
void write_command(uchar cmd,uchar i) //写命令函数
{
if(i)
{busy_test();}
RS=0;
RW=0;
E=1;
P0=cmd;
us_delay(10);
E=0;
}
void write_data(uchar cmd) //写数据函数
{
RS=1;
RW=0;
E=1;
P0=cmd;
us_delay(10);
E=0;
}
void busy_test(void) //判断忙函数
{
P0=0x0ff;
RS=0;
RW=1;
do {
E=1;
busy=P0;
E=0;
}
while(busy>0x7F);
}
void us_delay(uint t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<32;j++)
{;}
}
void ms_delay(uint t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<8000;j++)
{;}
}
uchar crc(uchar *ptr) using 3
{
uchar i,crc_t=0x00;
for(i=0;i<5;i++)
{
crc_t=crc_t^ptr[i];
crc_t=crc_table[crc_t];
}
crc_t=~crc_t;
return(crc_t);
}
void get_tx(void) using 3
{ uchar i;
tx_buf[0]=0x09-tx_xinxi;
for(i=1;i<5;i++)
tx_buf[i]=data_buf[data_no++];
tx_buf[5]=crc(tx_buf);
}
void tx_data(uchar zlb,uchar md_add) using 3
{
if(tx_flag)
{
tx_fifo=1;
tx_zlb_temp=zlb;
tx_add_temp=md_add;
}
else
{
DE=0;
tx_temp=0;
tx_temp1=1;
tx_temp2=0;
SBUF=0xD7;
tx_add=md_add;
tx_flag=1;
tx_zlb=zlb;
}
}
void tx1_data(uchar zlb,uchar md_add) using 3
{
if(tx1_flag)
{
tx1_fifo=1;
tx1_zlb_temp=zlb;
tx1_add_temp=md_add;
}
else
{
tx1_temp=0;
tx1_temp1=1;
tx1_temp2=0;
SBUF1=0xD7;
tx1_add=md_add;
tx1_zlb=zlb;
tx1_flag=1;
}
}
void tx1_data1(uchar zlb,uchar md_add) //非中断调用
{
if(tx1_flag)
{
tx1_fifo=1;
tx1_zlb_temp=zlb;
tx1_add_temp=md_add;
}
else
{
tx1_temp=0;
tx1_temp1=1;
tx1_temp2=0;
SBUF1=0xD7;
tx1_add=md_add;
tx1_zlb=zlb;
tx1_flag=1;
}
}
/*void tx_cmd(uchar cmd) using 3 //判断是否给每个下位机均发了命令
{
uchar temp;
re1_data();
if(re1_yuan!=tx_mudi[mudi_sn])
tx_data(0xe0,re_yuan); //如果设置的目标地址不一致,返回设置错误信息
else
{
mudi_sn++;
if(mudi_sn==mudi_no)
{mudi_sn=0;temp=cmd+0x10;tx_data(temp,re_yuan);}
else
{
tx1_data(cmd,tx_mudi[mudi_sn]);
}
}
} */
void get_shuzi(uchar cmd)
{
uchar a,b,c,t=0;
unsigned long int n=0,m=0;
int l=0,k=0;
float j;
a=cmd*8;
b=cmd*4;
for(c=0;c<4;c++)
{
shuzi_buf[t++]=0x20;
m=0;
m=data_buf[a++];
m=(m+data_buf[a++])<<8;
j=bili_buf[b++]*3.3;
m= m*(int)(j);
m=m>>10;
if (m>9999)
m=999;
l=m/1000;
if(l!=0)
shuzi_buf[t++]=l+0x30;
else
shuzi_buf[t++]=0x20;
m=m%1000;
k=m/100;
if((k!=0)||(l!=0))
shuzi_buf[t++]=k+0x30;
else
shuzi_buf[t++]=0x20;
m=m%100;
shuzi_buf[t++]=m/10+0x30;
shuzi_buf[t++]=0x2E;
m=m%10;
shuzi_buf[t++]=m+0x30;
}
}
void re_data(void) using 3
{
re_temp=0;
re_temp1=0;
re_temp2=0;
}
void re1_data(void) using 3
{
re1_temp=0;
re1_temp1=0;
re1_temp2=0;
}
void dis_oper(void)
{
if(ping==0)
{
write_command(0x01,1); //清显示屏
ms_delay(1);
dis_data(dis_buf[0],4,8,0x80); //显示第一屏中的左边四行
dis_data(dis_buf3,4,1,0x84); //显示第一屏中的四行:;
dis_data(dis_buf21[p_flag],1,6,0x85); //显示第一屏右边的第一行
dis_data(dis_buf22[b_flag],1,4,0x95); //显示第一屏右边的第二行
dis_data(dis_buf23[c_flag],1,4,0x8d); //显示第一屏右边的第三行
dis_data(dis_buf23[n_flag],1,4,0x9d); //显示第一屏右边的第四行
}
else
{
dis_data(dis_buf[ping],4,8,0x80); //显示该屏的左边四行数据
dis_data(dis_buf1[ping-1],4,2,0x87); //显示该屏数据中的符号
dis_data(shuzi_buf,4,6,0x84);
dis_data(dis_buf3,4,1,0x84); //显示四行:
}
ping=ping+1;
if(ping>=4)
ping=0;
}
void dis_data(uchar *ptr,uchar hangshu,uchar lieshu,uchar ddram)//显示字符函数
{
uchar i,j,x,hang,lie,k=0; //hang为显示数据的行,lie为显示数据的列
if((ddram>=0x80)&&(ddram<=0x9f))
{
if(ddram<0x88)
{ hang=0; } //定位行地址:第一行
else if(ddram<0x90)
{ hang=2; } //定位行地址:第三行
else if(ddram<0x98)
{ hang=1; } //定位行地址:第二行
else
{ hang=3; } //定位行地址:第四行
lie=0x07&ddram; //定位列地址
write_command(ddram,1); // 定位显示起始地址
do
{
for (i=0;i<lieshu;i++)
{
write_data(ptr[k++]);
us_delay(10);} //输出单个字符
if(hangshu)
{
hang++;
switch (hang)
{
case 0:write_command(0x80+lie,1);break;
case 1:write_command(0x90+lie,1);break;
case 2:write_command(0x88+lie,1);break;
case 3:write_command(0x98+lie,1);break;
default:{write_command(0x80+lie,1);hang=0;} break;
}
}
}
while(--hangshu);
}
}
void dis_set(uchar cmd)
{
write_command(0x01,1); //清显示屏
ms_delay(1);
switch(cmd)
{
case 0x02:{
dis_data(set_buf[0],1,12,0x81);
dis_data(set_buf[1],1,12,0x91);
dis_data(set_buf[2],1,12,0x89);
dis_data(set_buf[3],1,12,0x99);
switch(key_data)
{
case 0x01: {
set_flag=1;
dis_data(key_buf,1,2,0x80);
} break;
case 0x02:{
set_flag=2;
dis_data(key_buf,1,2,0x90);
} break;
case 0x03:{
set_flag=3;
dis_data(key_buf,1,2,0x88);
} break;
case 0x04:{
set_flag=4;
dis_data(key_buf,1,2,0x98);
} break;
default: break;}
}break;
case 0x04: {
dis_data(cd_buf,3,8,0x80);
dis_data(back,1,12,0x99);
dis_data(key_buf,1,2,0x98);
dis_data(dis_buf3,3,1,0x84); //显示:
dis_data(dis_buf23[c_flag],1,4,0x85); //显示第一屏右边的第一行
dis_data(dis_buf21[p_flag],1,6,0x95); //显示第一屏右边的第二行
dis_data(dis_buf22[b_flag],1,4,0x8d); //显示第一屏右边的第三行
} break;
case 0x06: {
dis_data(nb_buf,3,4,0x80);
dis_data(back,1,12,0x99);
dis_data(key_buf,1,2,0x98);
dis_data(dis_buf3,3,1,0x82); //显示:
dis_data(nb_buf1[ap_flag],1,4,0x83); //显示第一屏右边的第一行
dis_data(nb_buf1[bp_flag],1,4,0x93); //显示第一屏右边的第二行
dis_data(nb_buf1[cp_flag],1,4,0x8b); //显示第一屏右边的第三行
} break;
case 0x07: {
dis_data(set_vari[0],1,8,0x81);
dis_data(set_vari[1],1,8,0x91);
dis_data(set_vari[2],1,8,0x89);
dis_data(back,1,12,0x99);
dis_data(set_unit,3,2,0x87); //显示v
dis_data(ov_buf,1,4,0x85);
dis_data(lv_buf,1,4,0x95);
dis_data(vot_buf,1,4,0x8d);
dis_data(dis_buf3,3,1,0x85); //显示:
switch(key_data)
{
case 0x01: {
set_flag=1;
dis_data(key_buf,1,2,0x80);
} break;
case 0x02:{
set_flag=2;
dis_data(key_buf,1,2,0x90);
} break;
case 0x03:{
set_flag=3;
dis_data(key_buf,1,2,0x88);
} break;
case 0x04:{
set_flag=4;
dis_data(key_buf,1,2,0x98);
} break;
default: break;}
} break;
default:break;
}
}
void get_ovbuf(void) using 3
{
uchar temp ;
ovv=o_v[1]*256+o_v[0];
temp=ovv/100;
ov_buf[1]=temp+0x30;
temp=ovv%100;
ov_buf[2]=temp/10+0x30;
ov_buf[3]=temp%10+0x30;
}
void get_lvbuf(void) using 3
{
uchar temp ;
lv=l_v[1]*256+l_v[0];
temp=lv/100;
lv_buf[1]=temp+0x30;
temp=lv%100;
lv_buf[2]=temp/10+0x30;
lv_buf[3]=temp%10+0x30;
}
void get_ovvbuf(void) using 3
{
uchar temp ;
vot=ov_v[1]*256+ov_v[0];
temp=vot/100;
vot_buf[1]=temp+0x30;
temp=lv%100;
vot_buf[2]=temp/10+0x30;
vot_buf[3]=temp%10+0x30;
}
void get_setov(void)
{
uint temp;
temp=(ov_buf[1]-0x30)*100+(uint)(ov_buf[2]-0x30)*10+(uint)(ov_buf[3]-0x30);
set_ov[0]=(uchar)(temp%256);
set_ov[1]=(uchar)(temp/256);
}
void get_setlv(void)
{
uint temp;
temp=(uint)(lv_buf[1]-0x30)*100+(uint)(lv_buf[2]-0x30)*10+(uint)(lv_buf[3]-0x30);
set_lv[0]=temp%256;
set_lv[1]=temp/256;
}
void get_setvot(void)
{
uint temp;
temp=(uint)(vot_buf[1]-0x30)*100+(uint)(vot_buf[2]-0x30)*10+(uint)(vot_buf[3]-0x30);
set_ovv[0]=temp%256;
set_ovv[1]=temp/256;
}
void get_ov(bit bt)
{ uchar temp;
if(bt) //bt=1;加1
{
if(ovv++>=390)
ovv=370;
}
else
{
if(ovv--<=370)
ovv=390;
}
temp=ovv/100;
ov_buf[1]=temp+0x30;
temp=ovv%100;
ov_buf[2]=temp/10+0x30;
ov_buf[3]=temp%10+0x30;
}
void get_lv(bit bt)
{
uchar temp;
if(bt) //bt=1;加1
{
if(lv++>=330)
lv=310;
}
else
{
if(lv--<=310)
lv=330;
}
temp=lv/100;
lv_buf[1]=temp+0x30;
temp=lv%100;
lv_buf[2]=temp/10+0x30;
lv_buf[3]=temp%10+0x30;
}
void get_vot(bit bt)
{
uchar temp;
if(bt) //bt=1;加1
{
if(vot++>=230)
vot=210;
}
else
{
if(vot--<=210)
vot=230;
}
temp=vot/100;
vot_buf[1]=temp+0x30;
temp=vot%100;
vot_buf[2]=temp/10+0x30;
vot_buf[3]=temp%10+0x30;
dis_data(key_buf,1,2,0x88);
dis_data(vot_buf,1,4,0x8d);
dis_data(dis_buf3,1,1,0x8d);
}
void light_led(void)
{
t_temp2=0;
LED=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -