我有自己写的程序,编译时总是报错,程序挺长的__
[复制链接]
#include
#define uchar unsigned char
#define uint unsigned int
//=====================================
sbit RS=P1^4;
sbit RW=P1^5;
sbit DE=P1^6;
sbit PSB=P1^7;
uchar keyval;
uchar num[]="按1键读分站信息";
uchar num1[]="按2键改分站信息";
uchar num2[]="请输入分站号";
uchar num3[]="原分站号";
uchar num4[]="新分站号";
uchar num5[]="输入错误";
//全局函数=============================
void Delay(uchar a)//延时函数1ms
{
uchar i;
while(--a!=0)
for(i=0;i<125;i++);
}
void com(uchar com)//液晶初始化
//MCU给ST7920写指令
{
RS=0;
RW=0;
P2=com;
Delay(2);
DE=1;
Delay(2);
DE=0;
}
void dat(uchar dat)//MCU给ST7920写数据
{
RS=1;
RW=0;
P2=dat;
Delay(2);
DE=1;
Delay(2);
DE=0;
}
void init()
{
PSB=1;
com(0x30);//0x30是ST7920的RE=0基本操作指令,是一个操作字
Delay(2);
com(0x0f);//显示开关设置,开游标
Delay(2);
com(0x01);//清屏指令
Delay(2);
}
/*============================
开机显示:
==============================*/
void welcom()//显示按1键读分站信息
{
uchar i,j;
com(0x80);
for(i=0;i<18;i++)
{
dat(num);
Delay(2);
}
com(0x90);//显示按2键改分站信息
for(j=0;j<18;j++)
{
dat(num1[j]);
Delay(2);
}
}
void disp()//显示请输入分站号
{
uchar i;
com(0x90);
for(i=0;i<13;i++)
{
dat(num2);
Delay(2000);
}
}
void disp1()
{
uchar i;
com(0x80);
for(i=0;i<7;i++)
{
dat(num3);
Delay(2000);
}
}
void disp2()//输入新分站号
{
uchar i;
com(0x90);
for(i=0;i<7;i++)
{
dat(num4);
Delay(2000);
}
}
void disp3()//键入错误处理
{
uchar i;
com(0x01);
com(0x90);
for(i=0;i<10;i++)
{
dat(num5);
Delay(2000);
}
}
/*==========================================
键盘实时扫描
============================================*/
void Timer0init()
{
TMOD=0x01;//定时器0,工作方式1
TH0=0x4c;//赋初值,一次50ms;
TL0=0x00;//
ET0=1;
EA=1;
TR0=1;
}
char keyscan()
{
uchar cord_h,cord_l,temp;
P0=0x0f;
cord_h=P0&0x0f;//读行线值
if(cord_h!=0x0f)
{
Delay(5);
if(cord_h!=0x0f)
{
cord_h=P0&0x0f;
if(P0!=0xf0)
cord_l=P0&0xf0;//读列线值
temp=cord_h|cord_l;
}
}
return temp;
}
void dispkey()//显示键盘键入的数值
{
uchar keycn;
keycn=keyscan();
switch(keycn)
{
{
case 0xde:
keyval=0x30;break;
case 0xdd:
keyval=0x31;break;
case 0xdb:
keyval=0x32;break;
case 0xd7:
keyval=0x33;break;
case 0xbe:
keyval=0x34;break;
case 0xbd:
keyval=0x35;break;
case 0xbb:
keyval=0x36;break;
case 0xb7:
keyval=0x37;break;
case 0x7e:
keyval=0x38;break;
case 0x7d:
keyval=0x39;break;
case 0x7b:
keyval=0x41;break;
case 0x77:
keyval=0x42;break;
default:keyval=0xff; break;
}
}
com(0x80);
Timer0init();
}
void Timer0_int()interrupt 1
{
Delay(5000);
dat(keyval);
Delay(5000);
}
/*=========================
串口通信
==========================*/
#define count 5
uchar disnum,disnum1,disnum2;
uchar table[];
uchar table1[];
uchar table_2[];
uchar restable[];
uchar point;
void Timer1init()
{
TMOD=0x20;//定时器1,工作方式2
TH1=0xf4;//波特率为2400
TL1=0xf4;//
ET1=1;
EA=1;
TR1=1;
PCON=0X80;
SCON=0XD0;
}
com_interrupt()interrupt 4 using 3
{
uchar RESIVE_buffer;
if(RI)
{
RI=0;
RESIVE_buffer=SBUF;
if(RESIVE_buffer==disnum)
{
com(0x80);
if(point>=0||point<=30)
{point++;
restable[point]=RESIVE_buffer;
dat(restable[point]);
}
else
point=0;
}
else if(RESIVE_buffer==disnum1)
{
com(0x90);
dat(restable[point]);
++point;
restable[point]=RESIVE_buffer;
}
}
if(TI)
TI=0;
}
void num_ins(int num)//ASCII转成十六进制
{
if(0x31<=num<=0x39)
{disnum=num%10;
disnum1=num%10;}
else if(0x40
{disnum=num%10+9;
disnum1=num%10+9;}
else
disp3();
}
void scantwo()
{
uchar j;
disp1();
Delay(5000);
com(0x01);
keyscan();
dispkey();
table1[count]={0xA0;disnum1;0xD7;disnum2;0xB0};
Timer1init();
if(keyval!=0xff)
{
num_ins(keyval);
if(disnum1<0x64)
{
Delay(1000);
disp2();
Delay(5000);
com(0x01);
keyscan();
dispkey();
num_ins(keyval);
if(disnum2<0x64)
{
uchar i;
if(keyval==0xee)//按确定键时
{
for(i=0;i<6;i++)
{
SBUF=table1;
Delay(2);
}
}
else if(keyval==0xed)
scantwo();
}
}
if(disnum1==0xAB)
{disp3();
scantwo();}
}
}
void scanone()
{
uchar res,j;
disp();
Delay(5000);
com(0x01);
keyscan();
dispkey();
table[count]={0xA0,disnum,0xD0,0xB0};
table_2[count]={0xA0,0xC8,0xD0,0xB0};
Timer1init();
if(keyval!=0xff)
{
num_ins(keyval);
if(disnum==0xAB)
{
if(keyval==0xee)
{
uchar i;
for(i=0;i<5;i++)
{
SBUF=table_2;
Delay(2);
}
}
}
else
if(disnum1<0x64)
{
uchar i;
if(keyval==0xee)
{
for(i=0;i<5;i++)
{
ES=0;
SBUF=table1;
Delay(2);
}
}
else if(keyval==0xed)
scanone();
}
else
{disp3();
scanone();}
}
}
void shutdown()
{
com(0x01);
Delay(5000);
com(0x08);
}
/*=======================
主程序,主要由按键扫描程序开始
=========================*/
void main()
{
init();
sbit basic_0=P1^1;
sbit basic_on=P1^2;
sbit basic_off=P1^0;
while(1)
{
basic_0=0;
if(basic_on==0)
{
Delay(10);
if(basic_on==0)
{
welcom();
Delay(5000);
if(keyval==0x31)
{
com(0x01);
scanone();
}
else if( keyval==0x32)
{
scantwo();
}
}
else
{
Delay(50000);//延时50S关机
shutdown();
}
}
else if(basic_off==0)
{
Delay(10);
if(basic_off==0)
shutdown();
}
}
}