1)两个单片机系统分别作为服务器和答题终端。服务器负责验正考生个人信息,发送试愿到降端,定时收卷及判分功能。答题终端负责输入考生个人信息,答题,修改答案及传送答案到服务器。
2)服务器验证考生个人信息,若信息不正确则向终端发出提示信息。信息验证正确后将试题发送到答题终端,同时开始计时。无论答题是否完成。考试时间到则强制收题。也可在考试时同尚有剩余时接收答题终端发送过来的答案。收题后进行判分工作并给出最终得分及答题情况统计信息。对回答错误的题日则给出原题及正确答案。
3)答题终端在收到试题后向考生显示试题内容(可逐道显示)并接受考生输入的答案。试题显示应具备翻页功能以允许考生反复浏览试题或检查所作答案。当考生检查完毕且考试时间尚有剩余,允许考生向服务器发送最终答案。
4)实现服务器和答题终端的两个单片机系统均应包含键盘和LCD液品显示模块。两个单片机系统通过串口进行通信。
*************************************************
(1)给出使用说明,包括按键的定义,操作方法等。
(2)所有功能用途均可实现且各功能转换正常(模拟5道题即可)。
(3)考生个人信息包括考生姓名(可用拼音表示)和6位的学号。
(4)验收时需要演示考生个人信息不正确时的处理情况:
(5)服务器和终端都应实时显示考试剩余时间:
(6)四则运算应覆盖加减乘除四种运算:
(7)终端答题时,在未提交答案前应允许反复浏览或修改答案
服务端
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#define uchar unsigned char
#define uint unsigned int
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
sbit wr=P2^0; //数据写
sbit rd=P2^1; //数据读
sbit ce=P2^2; //片选
sbit cd=P2^3; //指令数据通道,1指令,0数据
sbit rst=P2^4; //复位信号
sbit key = P3^2;
uchar S_datt[2][6]={{1,2,3,4,5,6},{1,1,1,1,1,1}};
uchar Title[10] = {5,1,3,2,1,5,6,3,1,1};
uchar Answer[5] = {6,1,5,2,2};
uchar R_mode;
uchar R_wei;
uchar R_buff[20];
uint dis_tim;
uint ALL_time=30;
uchar flag_mode;
uchar C_T[6];
uchar bl;
uchar code HZ0[][32]={
{0x00,0x00,0x3E,0xFC,0x22,0x84,0x22,0x84,0x22,0x94,0x3E,0x88,0x22,0x80,0x22,0xFC,
0x22,0xA4,0x3E,0xA4,0x22,0xA8,0x22,0xA8,0x22,0x90,0x42,0xA8,0x4A,0xC4,0x84,0x82},/*"服",0*/
{0x04,0x00,0x04,0x00,0x0F,0xF0,0x18,0x20,0x24,0xC0,0x03,0x00,0x0C,0xC0,0x32,0x30,
0xC2,0x0E,0x1F,0xF0,0x02,0x10,0x04,0x10,0x04,0x10,0x08,0x10,0x10,0xA0,0x20,0x40},/*"务",1*/
{0x00,0x00,0x3E,0x7C,0x22,0x44,0x22,0x44,0x3E,0x7C,0x01,0x20,0x01,0x10,0xFF,0xFE,
0x02,0x80,0x0C,0x60,0x30,0x18,0xC0,0x06,0x3E,0x7C,0x22,0x44,0x22,0x44,0x3E,0x7C},/*"器",2*/
{0x01,0x00,0x21,0x08,0x11,0x08,0x09,0x10,0x09,0x20,0x01,0x00,0x7F,0xF8,0x00,0x08,
0x00,0x08,0x00,0x08,0x3F,0xF8,0x00,0x08,0x00,0x08,0x00,0x08,0x7F,0xF8,0x00,0x08},/*"当",3*/
{0x10,0x10,0x08,0x10,0x08,0x20,0xFF,0xFE,0x00,0x00,0x3E,0x08,0x22,0x48,0x22,0x48,
0x3E,0x48,0x22,0x48,0x22,0x48,0x3E,0x48,0x22,0x08,0x22,0x08,0x2A,0x28,0x24,0x10},/*"前",4*/
{0x08,0x40,0x08,0x20,0x0B,0xFE,0x10,0x00,0x10,0x00,0x31,0xFC,0x30,0x00,0x50,0x00,
0x91,0xFC,0x10,0x00,0x10,0x00,0x11,0xFC,0x11,0x04,0x11,0x04,0x11,0xFC,0x11,0x04},/*"信",5*/
{0x01,0x00,0x02,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x1F,0xF0,0x10,0x10,0x01,0x00,0x08,0x84,0x48,0x92,0x48,0x12,0x87,0xF0,0x00,0x00},/*"息",6*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00},/*":",7*/
{0x07,0x02,0x78,0x02,0x08,0x02,0xFF,0x82,0x2A,0x12,0x2A,0x92,0xEB,0x12,0x2A,0x92,
0x6A,0x92,0xA9,0x92,0x1C,0x12,0x2A,0x12,0x49,0x02,0x88,0x82,0x08,0x0A,0x08,0x04},/*"剩",8*/
{0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x40,0x08,0x20,0x10,0x10,0x2F,0xE8,0xC1,0x06,
0x01,0x00,0x3F,0xF8,0x01,0x00,0x11,0x10,0x11,0x08,0x21,0x04,0x45,0x04,0x02,0x00},/*"余",9*/
{0x00,0x08,0x00,0x08,0x7C,0x08,0x44,0x08,0x45,0xFE,0x44,0x08,0x44,0x08,0x7C,0x08,
0x44,0x88,0x44,0x48,0x44,0x48,0x44,0x08,0x7C,0x08,0x44,0x08,0x00,0x28,0x00,0x10},/*"时",10*/
{0x20,0x00,0x13,0xFC,0x10,0x04,0x40,0x04,0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,
0x47,0xC4,0x44,0x44,0x44,0x44,0x44,0x44,0x47,0xC4,0x40,0x04,0x40,0x14,0x40,0x08},/*"间",11*/
{0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x00,0x00,0xFF,0xFE,0x22,0x00,
0x3E,0xF8,0x22,0x88,0x3E,0x90,0x22,0x50,0x2F,0x20,0xF2,0x50,0x42,0x88,0x03,0x06},/*"最",12*/
{0x10,0x80,0x10,0x80,0x20,0xF8,0x21,0x08,0x4B,0x10,0xFC,0xA0,0x10,0x40,0x20,0xA0,
0x43,0x18,0xFC,0x06,0x40,0xC0,0x00,0x20,0x18,0x10,0xE1,0x80,0x40,0x60,0x00,0x10},/*"终",13*/
{0x00,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,0x20,0x08,0x40,0x04,0x9F,0xE2,
0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x20,0x08,0x20,0x10,0x20,0x21,0x40,0x40,0x80},/*"分",14*/
{0x08,0x20,0x49,0x20,0x2A,0x20,0x08,0x3E,0xFF,0x44,0x2A,0x44,0x49,0x44,0x88,0xA4,
0x10,0x28,0xFE,0x28,0x22,0x10,0x42,0x10,0x64,0x28,0x18,0x28,0x34,0x44,0xC2,0x82},/*"数",15*/
{0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x11,0x00,0x11,0xF8,
0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0xFF,0xFE,0x00,0x00},/*"正",16*/
{0x00,0x40,0x00,0x40,0xFC,0x7C,0x10,0x84,0x11,0x08,0x22,0xFE,0x3C,0x92,0x64,0x92,
0x64,0xFE,0xA4,0x92,0x24,0x92,0x24,0xFE,0x3C,0x92,0x25,0x12,0x21,0x0A,0x02,0x04},/*"确",17*/
{0x21,0x10,0x21,0x10,0x39,0x10,0x27,0xFC,0x41,0x10,0x79,0x10,0xAF,0xFE,0x20,0x00,
0xFB,0xF8,0x22,0x08,0x22,0x08,0x23,0xF8,0x2A,0x08,0x32,0x08,0x23,0xF8,0x02,0x08},/*"错",18*/
{0x00,0x00,0x43,0xF8,0x22,0x08,0x22,0x08,0x03,0xF8,0x00,0x00,0xE0,0x00,0x27,0xFC,
0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x40,0x28,0xA0,0x31,0x10,0x22,0x08,0x0C,0x06},/*"误",19*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",20*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
uchar code SZ[][16]={
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
{0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",1*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",3*/
{0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",4*/
{0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/
{0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",6*/
{0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/
{0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",9*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",10*/
{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",12*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",13*/
{0x00,0x00,0x02,0x04,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x20,0x20,0x40,0x40,0x00},/*"/",14*/
{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"=",15*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",16*/
};
void delay(uint t) //延时函数
{
uint i,j;
for(i=0;i< 1;i++);
}
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i< x;i++)
for(j=0;j< 112;j++);
}
uchar read_status() //读取lcd12864的状态
{
uchar status;
P0=0;//端口b置为输入
rd=0;
wr=1;
ce=0;
cd=1;
status=P1;
return status;
}
void check_status()//检查lcd12864的状态
{
uchar s;
P0=0Xff;//端口b置为输出
while((s&0x80)!=0x80)
s=read_status();//等待位1,2置为。命令读写准备好。数据读写准备好
}
void write_data(uchar dat)//写数据
{
rd=1;
cd=0;
ce=0;
wr=0;
P0=dat;
delay(1);
wr=1;
ce=1;
cd=1;
}
void write_cmd1(uchar cmd)//写数据1
{
rd=1;
cd=1;
ce=0;
wr=0;
P0=cmd;
delay(1);
wr=1;
ce=1;
cd=0;
}
//先送参数,再送指令
void write_cmd2(uchar dat,uchar cmd)
{
check_status();
write_data(dat);
check_status();
write_cmd1(cmd);
}
void write_cmd3(uchar data1,uchar data2,uchar cmd)//发送参数并发指令再发送数据
{
check_status();
write_data(data1);
check_status();
write_data(data2);
check_status();
write_cmd1(cmd);
}
void init()//LCD12864的初始化
{
P2=0Xff;
P1=0Xff;
rst=1;
delay(10);
rst=0;
wr=1;
rd=1;
ce=1;
cd=1;
rst=1;
check_status();
write_cmd3(0x01,0x00,0x21);//光标指针设置
check_status();
write_cmd3(0x00,0x00,0x42);//图形区首地址
check_status();
write_cmd3(16,0x00,0x43);//图形区宽度
check_status();
write_cmd1(0x80);//显示方式设置,正常显示
check_status();
write_cmd1(0x98);//图形方式显示,不显示字母,只打点
check_status();
write_cmd1(0xa0);//光标形状设置1 0 1 0 0 N2 N1 N0
}
//汉字显示函数,处在x y处显示汉字
void display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j/2)< <4)|(y*2),x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
write_cmd2(hz[j++],0xc0);
}
}
void display_SZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-14
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j)< <4)|y,x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
}
}
void Uart1Send(uchar c)
{
SBUF=c;
while(!TI);
TI=0;
}
void Uart1Sends(uchar *str)
{
while(*str!='�')
{
SBUF=*str;
while(!TI);
TI=0;
str++;
}
}
void UsartInit()
{
TMOD=0x21;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
TH0=0XFC; //给定时器赋初值,定时1ms TH1
TL0=0X18; //TL1
ET0=1; //定时器0中断打开 ET1
TR0=1; //定时器0开关打开 TR1
}
void CLear_N(uchar num)
{
uchar i;
for(i=0;i< 7;i++)
{
display_HZ(num,i,HZ0[20]);
}
}
void main()
{
UsartInit(); // 串口初始化
init();
Delay_xms(10);
display_HZ(0,1,HZ0[0]);
display_HZ(0,3,HZ0[1]);
display_HZ(0,5,HZ0[2]);
display_HZ(1,0,HZ0[3]);
display_HZ(1,1,HZ0[4]);
display_HZ(1,2,HZ0[5]);
display_HZ(1,3,HZ0[6]);
display_HZ(1,4,HZ0[7]);
display_HZ(2,0,HZ0[8]);
display_HZ(2,1,HZ0[9]);
display_HZ(2,2,HZ0[10]);
display_HZ(2,3,HZ0[11]);
display_HZ(2,4,HZ0[7]);
display_HZ(3,0,HZ0[12]);
display_HZ(3,1,HZ0[13]);
display_HZ(3,2,HZ0[14]);
display_HZ(3,3,HZ0[15]);
display_HZ(3,4,HZ0[7]);
while(1)
{
if(key == 0)
{
Delay_xms(10);
if(key == 0)
{
while(key==0);
if(flag_mode == 3)
{
CLear_N(0);
CLear_N(1);
CLear_N(2);
CLear_N(3);
for(bl=0;bl< C_T[0];bl++)
{
display_SZ(bl,0,SZ[Title[(C_T[bl+1]-1)*2]]);
display_SZ(bl,1,SZ[C_T[bl+1]+10]);
display_SZ(bl,2,SZ[Title[(C_T[bl+1]-1)*2+1]]);
display_SZ(bl,3,SZ[16]);
display_SZ(bl,10,SZ[C_T[bl+1]]);
display_SZ(bl,4,SZ[Answer[C_T[bl+1]-1]]);
}
}
}
}
}
}
void Send_Title()
{
uchar i;
Uart1Send('T');
for(i=0;i< 10;i++)
{
Uart1Send(Title[i]);
}
}
void Usart_rec() interrupt 4
{
unsigned char datt;
if(RI == 1)
{
RI=0;
datt=SBUF;//出去接收到的数据
if(R_mode==1)
{
R_buff[R_wei] = datt;
R_wei++;
if(R_wei == 7)
{
if(R_buff[0] == 1)
{
if(R_buff[1] == 1 && R_buff[2] == 2 && R_buff[3] == 3 && R_buff[4] == 4 && R_buff[5] == 5 && R_buff[6] == 6 )
{
Uart1Send('D');
display_HZ(1,5,HZ0[16]);
display_HZ(1,6,HZ0[17]);
Send_Title();
flag_mode = 2;
}else
{
Uart1Send('X');
display_HZ(1,5,HZ0[18]);
display_HZ(1,6,HZ0[19]);
}
}else if(R_buff[0] == 2)
{
if(R_buff[1] == 1 && R_buff[2] == 1 && R_buff[3] == 1 && R_buff[4] == 1 && R_buff[5] == 1 && R_buff[6] == 1 )
{
Uart1Send('D');
display_HZ(1,5,HZ0[16]);
display_HZ(1,6,HZ0[17]);
Send_Title();
flag_mode = 2;
}else
{
Uart1Send('X');
display_HZ(1,5,HZ0[18]);
display_HZ(1,6,HZ0[19]);
}
}
R_wei = 0;
R_mode = 0;
}
}else if(R_mode == 2)
{
R_buff[R_wei] = datt;
R_wei++;
if(R_wei == 5)
{
if(R_buff[0] != Answer[0])
{
C_T[0] ++;
C_T[C_T[0]] = 1;
}
if(R_buff[1] != Answer[1])
{
C_T[0] ++;
C_T[C_T[0]] = 2;
}
if(R_buff[2] != Answer[2])
{
C_T[0] ++;
C_T[C_T[0]] = 3;
}
if(R_buff[3] != Answer[3])
{
C_T[0] ++;
C_T[C_T[0]] = 4;
}
if(R_buff[4] != Answer[4])
{
C_T[0] ++;
C_T[C_T[0]] = 5;
}
display_SZ(3,10,SZ[5-C_T[0]]);
R_wei = 0;
R_mode = 0;
}
}
if(datt == 'x')
{
R_mode = 1;
R_wei = 0;
}else if(datt == 'W')
{
R_mode = 2;
R_wei = 0;
flag_mode = 3;
}
}
}
void Timer0() interrupt 1 //参考上图 定时器1时为3
{
TH0=0XFC; //给定时器赋初值,定时1ms TH1
TL0=0X18; //TL1
dis_tim++;
if(dis_tim==1000)
{
dis_tim=0;
if(flag_mode == 2)
{
if(ALL_time!=0)
{
ALL_time -- ;
}
display_SZ(2,10,SZ[ALL_time/10]);
display_SZ(2,11,SZ[ALL_time%10]);
}
}
}
答题端:
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#define uchar unsigned char
#define uint unsigned int
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
u8 data_send;
sbit wr=P2^0; //数据写
sbit rd=P2^1; //数据读
sbit ce=P2^2; //片选
sbit cd=P2^3; //指令数据通道,1指令,0数据
sbit rst=P2^4; //复位信号
sbit h1 = P1^0;
sbit h2 = P1^1;
sbit h3 = P1^2;
sbit h4 = P1^3;
sbit l1 = P1^4;
sbit l2 = P1^5;
sbit l3 = P1^6;
sbit l4 = P1^7;
uchar flag_mode;//当前输入模式 0为考生号 1为学号
uchar S_num; //考生号
uchar S_buff[6]; //学号
uchar S_wei;
uchar R_mode;
uchar R_wei;
uchar R_buff[20];
uchar Tit[10];
uchar Tit_Now;
uchar Answer[5];
uint dis_tim;
uint ALL_time=30;
uchar code HZ0[][32]={
{0x10,0x40,0x10,0x40,0x3F,0x7E,0x28,0x90,0x45,0x08,0x82,0x80,0x0C,0x60,0x30,0x18,
0xCF,0xE6,0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10},/*"答",0*/
{0x00,0x00,0x3E,0xFE,0x22,0x10,0x3E,0x20,0x22,0x7C,0x3E,0x44,0x00,0x54,0xFF,0x54,
0x08,0x54,0x08,0x54,0x2F,0x28,0x28,0x44,0x28,0x82,0x58,0x00,0x4F,0xFE,0x80,0x00},/*"题",1*/
{0x00,0xF8,0x3F,0x00,0x04,0x00,0x08,0x20,0x10,0x40,0x3F,0x80,0x01,0x00,0x06,0x10,
0x18,0x08,0x7F,0xFC,0x01,0x04,0x09,0x20,0x11,0x10,0x21,0x08,0x45,0x04,0x02,0x00},/*"系",2*/
{0x10,0x40,0x10,0x20,0x20,0x20,0x23,0xFE,0x48,0x40,0xF8,0x88,0x11,0x04,0x23,0xFE,
0x40,0x92,0xF8,0x90,0x40,0x90,0x00,0x90,0x19,0x12,0xE1,0x12,0x42,0x0E,0x04,0x00},/*"统",3*/
{0x00,0x40,0x40,0x40,0x27,0xFC,0x20,0x40,0x03,0xF8,0x00,0x40,0xE7,0xFE,0x20,0x00,
0x23,0xF8,0x22,0x08,0x23,0xF8,0x22,0x08,0x2B,0xF8,0x32,0x08,0x22,0x28,0x02,0x10},/*"请",4*/
{0x20,0x40,0x20,0xA0,0x21,0x10,0xFA,0x08,0x25,0xF6,0x40,0x00,0x53,0xC4,0x92,0x54,
0xFA,0x54,0x13,0xD4,0x1A,0x54,0xF2,0x54,0x53,0xD4,0x12,0x44,0x12,0x54,0x12,0xC8},/*"输",5*/
{0x04,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80,0x02,0x80,
0x04,0x40,0x04,0x40,0x08,0x20,0x08,0x20,0x10,0x10,0x20,0x10,0x40,0x08,0x80,0x06},/*"入",6*/
{0x02,0x00,0x02,0x08,0x3F,0xD0,0x02,0x20,0x02,0x40,0xFF,0xFE,0x01,0x00,0x02,0x00,
0x0F,0xF8,0x12,0x00,0x24,0x00,0x47,0xF0,0x80,0x10,0x00,0x10,0x00,0xA0,0x00,0x40},/*"考",7*/
{0x01,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x3F,0xFC,0x21,0x00,0x41,0x00,0x81,0x00,
0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00},/*"生",8*/
{0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,0xFF,0xFE,
0x08,0x00,0x10,0x00,0x1F,0xF0,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0xA0,0x00,0x40},/*"号",9*/
{0x00,0x40,0x40,0x40,0x27,0xFC,0x20,0x40,0x03,0xF8,0x00,0x40,0xE7,0xFE,0x20,0x00,
0x23,0xF8,0x22,0x08,0x23,0xF8,0x22,0x08,0x2B,0xF8,0x32,0x08,0x22,0x28,0x02,0x10},/*"请",10*/
{0x20,0x40,0x20,0xA0,0x21,0x10,0xFA,0x08,0x25,0xF6,0x40,0x00,0x53,0xC4,0x92,0x54,
0xFA,0x54,0x13,0xD4,0x1A,0x54,0xF2,0x54,0x53,0xD4,0x12,0x44,0x12,0x54,0x12,0xC8},/*"输",11*/
{0x04,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80,0x02,0x80,
0x04,0x40,0x04,0x40,0x08,0x20,0x08,0x20,0x10,0x10,0x20,0x10,0x40,0x08,0x80,0x06},/*"入",12*/
{0x22,0x08,0x11,0x08,0x11,0x10,0x00,0x20,0x7F,0xFE,0x40,0x02,0x80,0x04,0x1F,0xE0,
0x00,0x40,0x01,0x80,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00},/*"学",13*/
{0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,0xFF,0xFE,
0x08,0x00,0x10,0x00,0x1F,0xF0,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0xA0,0x00,0x40},/*"号",14*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00},/*":",15*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",16*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x11,0x00,0x11,0xF8,
0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0xFF,0xFE,0x00,0x00},/*"正",17*/
{0x00,0x40,0x00,0x40,0xFC,0x7C,0x10,0x84,0x11,0x08,0x22,0xFE,0x3C,0x92,0x64,0x92,
0x64,0xFE,0xA4,0x92,0x24,0x92,0x24,0xFE,0x3C,0x92,0x25,0x12,0x21,0x0A,0x02,0x04},/*"确",18*/
{0x21,0x10,0x21,0x10,0x39,0x10,0x27,0xFC,0x41,0x10,0x79,0x10,0xAF,0xFE,0x20,0x00,
0xFB,0xF8,0x22,0x08,0x22,0x08,0x23,0xF8,0x2A,0x08,0x32,0x08,0x23,0xF8,0x02,0x08},/*"错",19*/
{0x00,0x00,0x43,0xF8,0x22,0x08,0x22,0x08,0x03,0xF8,0x00,0x00,0xE0,0x00,0x27,0xFC,
0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x40,0x28,0xA0,0x31,0x10,0x22,0x08,0x0C,0x06},/*"误",20*/
};
uchar code SZ[][16]={
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",0*/
{0x00,0x00,0x00,0x08,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",1*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",2*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x02,0x04,0x18,0x04,0x02,0x42,0x42,0x3C,0x00,0x00},/*"3",3*/
{0x00,0x00,0x00,0x04,0x0C,0x0C,0x14,0x24,0x24,0x44,0x7F,0x04,0x04,0x1F,0x00,0x00},/*"4",4*/
{0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x78,0x44,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",5*/
{0x00,0x00,0x00,0x18,0x24,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00},/*"6",6*/
{0x00,0x00,0x00,0x7E,0x42,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",7*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",8*/
{0x00,0x00,0x00,0x38,0x44,0x42,0x42,0x42,0x46,0x3A,0x02,0x02,0x24,0x18,0x00,0x00},/*"9",9*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",10*/
{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",12*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",13*/
{0x00,0x00,0x02,0x04,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x20,0x20,0x40,0x40,0x00},/*"/",14*/
{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x00,0x00,0x00,0x00},/*"=",15*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",16*/
};
void delay(uint t) //延时函数
{
uint i,j;
for(i=0;i< 1;i++);
}
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i< x;i++)
for(j=0;j< 112;j++);
}
uchar read_status() //读取lcd12864的状态
{
uchar status;
P0=0;//端口b置为输入
rd=0;
wr=1;
ce=0;
cd=1;
status=P1;
return status;
}
void check_status()//检查lcd12864的状态
{
uchar s;
P0=0Xff;//端口b置为输出
while((s&0x80)!=0x80)
s=read_status();//等待位1,2置为。命令读写准备好。数据读写准备好
}
void write_data(uchar dat)//写数据
{
rd=1;
cd=0;
ce=0;
wr=0;
P0=dat;
delay(1);
wr=1;
ce=1;
cd=1;
}
void write_cmd1(uchar cmd)//写数据1
{
rd=1;
cd=1;
ce=0;
wr=0;
P0=cmd;
delay(1);
wr=1;
ce=1;
cd=0;
}
//先送参数,再送指令
void write_cmd2(uchar dat,uchar cmd)
{
check_status();
write_data(dat);
check_status();
write_cmd1(cmd);
}
void write_cmd3(uchar data1,uchar data2,uchar cmd)//发送参数并发指令再发送数据
{
check_status();
write_data(data1);
check_status();
write_data(data2);
check_status();
write_cmd1(cmd);
}
void init()//LCD12864的初始化
{
P2=0Xff;
P1=0Xff;
rst=1;
delay(10);
rst=0;
wr=1;
rd=1;
ce=1;
cd=1;
rst=1;
check_status();
write_cmd3(0x01,0x00,0x21);//光标指针设置
check_status();
write_cmd3(0x00,0x00,0x42);//图形区首地址
check_status();
write_cmd3(16,0x00,0x43);//图形区宽度
check_status();
write_cmd1(0x80);//显示方式设置,正常显示
check_status();
write_cmd1(0x98);//图形方式显示,不显示字母,只打点
check_status();
write_cmd1(0xa0);//光标形状设置1 0 1 0 0 N2 N1 N0
}
//汉字显示函数,处在x y处显示汉字
void display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j/2)< <4)|(y*2),x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
write_cmd2(hz[j++],0xc0);
}
}
void display_SZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-14
{
uchar i,j=0;
for(i=0;i< 16;i++)
{
write_cmd3(((j)< <4)|y,x,0x24);//地址指针设置..低地址,高地址,命令
write_cmd2(hz[j++],0xc0);
}
}
void Uart1Send(uchar c)
{
SBUF=c;
while(!TI);
TI=0;
}
void Uart1Sends(uchar *str)
{
while(*str!='�')
{
SBUF=*str;
while(!TI);
TI=0;
str++;
}
}
void UsartInit()
{
TMOD=0x21;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
TH0=0XFC; //给定时器赋初值,定时1ms TH1
TL0=0X18; //TL1
ET0=1; //定时器0中断打开 ET1
TR0=1; //定时器0开关打开 TR1
}
void CLear_N(uchar num)
{
uchar i;
for(i=0;i< 15;i++)
{
display_HZ(num,i,SZ[10]);
}
}
void SEND_X()
{
uchar datt[8];
datt[0] = 'x';
datt[1] = S_num;
datt[2] = S_buff[0];
datt[3] = S_buff[1];
datt[4] = S_buff[2];
datt[5] = S_buff[3];
datt[6] = S_buff[4];
datt[7] = S_buff[5];
Uart1Sends(datt);
}
void SEND_A()
{
uchar datt[6];
uchar dd;
datt[0] = 'W';
datt[1] = Answer[0];
datt[2] = Answer[1];
datt[3] = Answer[2];
datt[4] = Answer[3];
datt[5] = Answer[4];
for(dd=0;dd< 6;dd++)
{
Uart1Send(datt[dd]);
Delay_xms(20);
}
}
void key_scan()
{
h1=1;
h2=1;
h3=1;
h4=1;
l1=1;
l2=1;
l3=1;
l4=1;
h1=0;
if(l1==0 && h1==0 && h2==1 && l2==1 && l3==1 && l4==1 ) //1
{
while(l1==0);
if(flag_mode == 0)
{
S_num = 1;
display_SZ(2,6,SZ[S_num]);
}else if(flag_mode == 1)
{
S_buff[S_wei] = 1;
display_SZ(2,S_wei,SZ[1]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 1;
display_SZ(3,4,SZ[1]);
}
}else if(l1==1 && h1==0 && h2==1 && l2==0 && l3==1 && l4==1 ) //2
{
while(l2==0);
if(flag_mode == 0)
{
S_num = 2;
display_SZ(2,6,SZ[S_num]);
}else if(flag_mode == 1)
{
S_buff[S_wei] = 2;
display_SZ(2,S_wei,SZ[2]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 2;
display_SZ(3,4,SZ[2]);
}
}else if(l1==1 && h1==0 && h2==1 && l2==1 && l3==0 && l4==1)//3
{
while(l3==0);
if(flag_mode == 0)
{
S_num = 3;
display_SZ(2,6,SZ[S_num]);
}else if(flag_mode == 1)
{
S_buff[S_wei] = 3;
display_SZ(2,S_wei,SZ[3]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 3;
display_SZ(3,4,SZ[3]);
}
}else if(l1==1 && h1==0 && h2==1 && l2==1 && l3==1 && l4==0)//4
{
while(l4==0);
if(flag_mode == 2)
{
if(Tit_Now >1)
{
Tit_Now--;
display_SZ(3,0,SZ[Tit[(Tit_Now-1)*2]]);
display_SZ(3,1,SZ[Tit_Now+10]);
display_SZ(3,2,SZ[Tit[(Tit_Now-1)*2+1]]);
display_SZ(3,3,SZ[16]);
display_SZ(3,10,SZ[Tit_Now]);
display_SZ(3,4,SZ[Answer[Tit_Now-1]]);
}
}
}
else
{
h1=1;
h2=0;
if(l1==0 && h1==1 && h2==0 && l2==1 && l3==1 && l4==1 )//6
{
while(l1==0);
if(flag_mode == 0)
{
S_num = 4;
display_SZ(2,6,SZ[S_num]);
}else if(flag_mode == 1)
{
S_buff[S_wei] = 4;
display_SZ(2,S_wei,SZ[4]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 4;
display_SZ(3,4,SZ[4]);
}
}else if(l1==1 && h1==1 && h2==0 && l2==0 && l3==1 && l4==1 )//7
{
while(l2==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 5;
display_SZ(2,S_wei,SZ[5]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 5;
display_SZ(3,4,SZ[5]);
}
}else if(l1==1 && h1==1 && h2==0 && l2==1 && l3==0 && l4==1)//8
{
while(l3==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 6;
display_SZ(2,S_wei,SZ[6]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 6;
display_SZ(3,4,SZ[6]);
}
}else if(l1==1 && h1==1 && h2==0 && l2==1 && l3==1 && l4==0)//9
{
while(l4==0);
}else
{
h1=1;
h2=1;
h3=0;
if(l1==0 && h1==1 && h2==1 && h3==0 && l2==1 && l3==1 && l4==1)//11
{
while(l1==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 7;
display_SZ(2,S_wei,SZ[7]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 7;
display_SZ(3,4,SZ[7]);
}
}else if(l1==1 && h1==1 && h2==1 && h3==0 && l2==0 && l3==1 && l4==1)//12
{
while(l2==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 8;
display_SZ(2,S_wei,SZ[8]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 8;
display_SZ(3,4,SZ[8]);
}
}else if(l1==1 && h1==1 && h2==1 && h3==0 && l2==1 && l3==0 && l4==1)//13
{
while(l3==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 9;
display_SZ(2,S_wei,SZ[9]);
S_wei++;
}else if(flag_mode == 2)
{
Answer[Tit_Now-1] = 9;
display_SZ(3,4,SZ[9]);
}
}else if(l1==1 && h1==1 && h2==1 && h3==0 && l2==1 && l3==1 && l4==0 )//14
{
while(l4==0);
if(flag_mode == 2)
{
if(Tit_Now< 5)
{
Tit_Now++;
display_SZ(3,0,SZ[Tit[(Tit_Now-1)*2]]);
display_SZ(3,1,SZ[Tit_Now+10]);
display_SZ(3,2,SZ[Tit[(Tit_Now-1)*2+1]]);
display_SZ(3,3,SZ[16]);
display_SZ(3,10,SZ[Tit_Now]);
display_SZ(3,4,SZ[Answer[Tit_Now-1]]);
}
}
}
else
{
h3=1;
h4=0;
if(l1==0 && h1==1 && h2==1 && h3==4 && l2==1 && l3==1 && l4==1)//11
{
while(l1==0);
if(flag_mode == 1)
{
S_wei = 0;
CLear_N(1);
CLear_N(2);
display_HZ(1,0,HZ0[4]);
display_HZ(1,1,HZ0[5]);
display_HZ(1,2,HZ0[6]);
display_HZ(1,3,HZ0[7]);
display_HZ(1,4,HZ0[8]);
display_HZ(1,5,HZ0[9]);
display_HZ(1,6,HZ0[15]);
flag_mode = 0;
}
}else if(l1==1 && h1==1 && h2==1 && h3==4 && l2==0 && l3==1 && l4==1)//12
{
while(l2==0);
if(flag_mode == 1)
{
S_buff[S_wei] = 0;
display_SZ(2,S_wei,SZ[0]);
S_wei++;
}
}else if(l1==1 && h1==1 && h2==1 && h3==4 && l2==1 && l3==0 && l4==1)//13
{
while(l3==0);
if(flag_mode==2)
{
SEND_A();
flag_mode = 3;
}
}else if(l1==1 && h1==1 && h2==1 && h3==4 && l2==1 && l3==1 && l4==0 )//14
{
while(l4==0);
if(flag_mode == 0)
{
flag_mode = 1;
display_HZ(1,0,HZ0[10]);
display_HZ(1,1,HZ0[11]);
display_HZ(1,2,HZ0[12]);
display_HZ(1,3,HZ0[13]);
display_HZ(1,4,HZ0[14]);
display_HZ(1,5,HZ0[15]);
display_HZ(1,6,HZ0[16]);
CLear_N(2);
}else if(flag_mode == 1)
{
SEND_X();
}
}
}
}
}
}
void main()
{
UsartInit(); // 串口初始化
init();
Delay_xms(10);
display_HZ(0,0,HZ0[0]);
display_HZ(0,2,HZ0[1]);
display_HZ(0,4,HZ0[2]);
display_HZ(0,6,HZ0[3]);
display_HZ(1,0,HZ0[4]);
display_HZ(1,1,HZ0[5]);
display_HZ(1,2,HZ0[6]);
display_HZ(1,3,HZ0[7]);
display_HZ(1,4,HZ0[8]);
display_HZ(1,5,HZ0[9]);
display_HZ(1,6,HZ0[15]);
//display_SZ(1,6,SZ[2]);
while(1)
{
KEY_Scan();
}
}
void Usart_rec() interrupt 4
{
unsigned char datt;
if(RI == 1)
{
RI=0;
datt=SBUF;//出去接收到的数据
if(R_mode == 1)
{
R_buff[R_wei] = datt;
Tit[R_wei] = datt;
R_wei++;
if(R_wei == 10)
{
R_wei = 0;
R_mode = 0;
Tit_Now = 1;
display_SZ(3,0,SZ[Tit[0]]);
display_SZ(3,1,SZ[11]);
display_SZ(3,2,SZ[Tit[1]]);
display_SZ(3,3,SZ[16]);
display_SZ(3,10,SZ[Tit_Now]);
flag_mode = 2;
}
}
if(datt == 'D')
{
display_HZ(2,4,HZ0[17]);
display_HZ(2,6,HZ0[18]);
}else if(datt == 'X')
{
display_HZ(2,4,HZ0[19]);
display_HZ(2,6,HZ0[20]);
}else if(datt == 'T')
{
R_mode = 1;
}
}
}
void Timer0() interrupt 1 //参考上图 定时器1时为3
{
TH0=0XFC; //给定时器赋初值,定时1ms TH1
TL0=0X18; //TL1
dis_tim++;
if(dis_tim==1000)
{
dis_tim=0;
if(flag_mode == 2)
{
if(ALL_time!=0)
{
ALL_time -- ;
}else
{
SEND_A();
flag_mode = 3;
}
display_SZ(3,13,SZ[ALL_time/10]);
display_SZ(3,14,SZ[ALL_time%10]);
}
}
}
审核编辑:汤梓红
-
单片机
+关注
关注
6032文章
44513浏览量
632690 -
Proteus
+关注
关注
79文章
1692浏览量
106356 -
服务器
+关注
关注
12文章
9010浏览量
85160 -
仿真系统
+关注
关注
1文章
95浏览量
20621
发布评论请先 登录
相关推荐
评论