下位机传递程序
/*******************************************
下位机发送信息
***************************************/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit DDD=P3^6;
uint TT;
void delay(uchar time)
{
uchar i;
while(time--)
for(i=0;i<60;i++);
}
void send(uchar state)
{
SBUF=state;
while(TI==0);
TI=0;
}
void SCON_init()
{
SCON=0X40;//选择串口通信方式1
TMOD=0x20;//设置计数器T1为计数方式2(自动重装初值)
PCON=0x00;//设置波特率倍增
TH1=0xFD;
TL1=0xFD;
TI=0;
TR1=1;
}
void main()
{
SCON_init();
while(1)
{
TT=P1;
if(TT!=0xff)
{
delay(1);
if(TT!=0xff)
{
DDD=0;
send(P1);
DDD=1;
}
else DDD=1;
}
else DDD=1;
}
}
/*********************************************/
/* 上位机接收和处理程序 */
/**********************************************/
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
sbit DDD=P1^6;
sbit DD=P3^6;
sbit CS1=P1^3;
sbit CS2=P1^4;
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9
};
uchar code spd0[]=
{//速
0x40,0x42,0x44,0xCC,0x00,0xF4,0x94,0x94,
0x94,0xFF,0x94,0x94,0x94,0xF6,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x51,0x48,0x44,
0x42,0x7F,0x42,0x44,0x4C,0x61,0x20,0x00
};
uchar code spd1[]=
{//度
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,
0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00
};
uchar code lgth0[]=
{//距
0x00,0x3E,0x22,0xE2,0x22,0x3E,0x00,0xFE,
0x22,0x22,0x22,0x22,0xF3,0x22,0x00,0x00,
0x20,0x7F,0x20,0x3F,0x12,0x12,0x00,0x7F,
0x42,0x42,0x42,0x42,0x47,0x60,0x40,0x00
};
uchar code lgth1[]=
{//离
0x04,0x04,0x04,0xF4,0x04,0x8C,0x55,0x26,
0x54,0x8C,0x04,0xF4,0x04,0x06,0x04,0x00,
0x00,0xFC,0x04,0x05,0x25,0x35,0x2D,0x27,
0x25,0x35,0x25,0x45,0x84,0x7E,0x04,0x00
};
uchar code mh[]=
{
0x00,0x00,0x8C,0x8C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code qian[]=
{//千
0x80,0x80,0x84,0x84,0x84,0x84,0x84,0xFC,
0x82,0x82,0x83,0x82,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code mi[]=
{//米
0x40,0x40,0x42,0x44,0x4C,0x58,0xC0,0xFF,
0x40,0x50,0x48,0x44,0x46,0x60,0x40,0x00,
0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,
0x01,0x02,0x04,0x08,0x10,0x30,0x10,0x00
};
uchar code gong[]=
{//斜杠/
0x00,0x00,0x00,0x0,0x00,0x00,0x00,0x40,
0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,
0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code shi[]=
{//时
0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,
0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,
0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00
};
int k,m,n,i,times=0,min,state;
int xs,ys,d1,d0,wd0,wd1,dw2,dw3;
int time,sec,d,v,dist,spd00,spd01;
void delay(int ms)
{
while(ms--)
for(i=0;i<20;i++);
}
void write_comd(char dat)
{
RW=0;
RS=0;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void write_data(char dat)
{
RW=0;
RS=1;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void disp(char x,char y,char dat)
{
if(y>=64)
{
y=y-1;
}
write_comd(0x40|y);
delay(5);
write_comd(0xb8|x);
write_data(dat);
}
void LCD_init(void)
{
write_comd(0x0c);//整体显示,关光标,不闪烁
write_comd(0x06);//设定输入方式,增量不移位
write_comd(0x01);//清除屏幕显示---
}
void mov(void)
{
SCON=0X50;//选择串口通信方式1,允许接受
TMOD=0x20;//设置计数器T1为计数方式2(自动重装初值)
PCON=0x00;//设置波特率倍增
TH1=0xFD; //计数器工作与方式2,高位存放初值,计数溢出后自动装入TL0
TL1=0xFD; //计数单元,从FD开始计数
RI=0;
TR1=1;
/******************/
while(RI==0);
state=SBUF;
P0=state;
RI=0;
}
void main(void)
{
IT0=1;//中断触发方式,IT0=1下降沿产生中断信号,IT0=0,低电平产生中断信号
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
EX0=1;//EX0=1允许外中断,即分中断开关,1打开,0禁止外中断
ET0=1;
PX0=1;//外中断0优先
PT0=0;
EA=1; //打开总中断开关
//LCD_init();
CS1=1;
CS2=0;
for(xs=0;xs<6;xs++)
for(ys=0;ys<63;ys++)
{
switch(xs)
{
case 0:if(ys<16)
disp(xs,ys,~qian[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys-16]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~gong[ys-32]);
if(ys>47)
disp(xs,ys,~shi[ys-48]);
break;
case 1:if(ys<16)
disp(xs,ys,~qian[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~gong[ys-16]);
if(ys>47)
disp(xs,ys,~shi[ys-32]);
break;
case 2:if(ys<16)
disp(xs,ys,~qian[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys-16]);
break;
case 3:if(ys<16)
disp(xs,ys,~qian[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys]);
break;
};
};
CS1=0;
CS2=1;
for(xs=0;xs<6;xs++)
for(ys=0;ys<63;ys++)
{
switch(xs)
{
case 0:if(ys<16)
disp(xs,ys,~spd0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys-16]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~mh[ys-32]);
break;
case 1:if(ys<16)
disp(xs,ys,~spd0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~mh[ys-16]);
break;
case 2:if(ys<16)
disp(xs,ys,~lgth0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys-16]);
if((ys>31)&&(ys<=44))
disp(xs,ys,~mh[ys-32]);
break;
case 3:if(ys<16)
disp(xs,ys,~lgth0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys]);
if((ys>31)&&(ys<=44))
disp(xs+1,ys,~mh[ys-16]);
break;
};
};
TR0=1;
while(1)
{
if(DDD==0)
mov();
for(xs=0;xs<6;xs++)
for(ys=0;ys<60;ys++)
{
switch(xs)
{
case 0:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[spd00][ys-44]);
if(ys>52)
disp(xs,ys,~num[spd01][ys-52]);
break;
case 1:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[spd00][ys-36]);
if(ys>52)
disp(xs,ys,~num[spd01][ys-44]);
break;
case 2:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-44]);
if(ys>52)
disp(xs,ys,~num[d1][ys-52]);
break;
case 3:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-36]);
if(ys>52)
disp(xs,ys,~num[d1][ys-44]);
break;
};
};
};
}
void distant() interrupt 0
{
d++; //跑步机圈数计数?
dist=d+d/2; //假定一圈1.5米,根据跑步机一圈定
//一下看显示距离,也可在主程序中根据情况确定如果显示
wd0=(dist)/100; //显示以百米为单位,可根据情况显示
wd1=((dist)%100)/10;
dw2=((dist)%100)%10;
}
void time0() interrupt 1
{
time++;
if (time==20) //50ms计数20次为1秒
{
time=0;
sec++; //秒
if(sec==60)
min++;//分钟
}
TL0=0xb0;//重装计数初值
TH0=0x3c;
d0=min/10;//秒显示
d1=min%10;
v=(dist*36)/(10*sec);//速度计算。速度,千米/小时
spd00=v/10;//速度显示
spd01=v%10;
}
/********************************************/
=================================================================
/********************************************/
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
uint time,sec,d,v,dist;
void main()
{
TMOD=0x01;//T0技术方式为十六位计数器
TL0=0xb0; //50ms计数初值
TH0=0x3c;
EA=1;
ET0=1;
EX0=1;
PX0=1;
PT0=0;
TR0=1;
while(1)
{
P0=dist; //距离
P1=sec; //时间
P3=dist/sec; //速度
}
}
void distant() interrupt 0
{
d++; //跑步机圈数计数?
dist=d+d/2; //假定一圈1.5米,根据跑步机一圈定
//一下看显示距离,也可在主程序中根据情况确定如果显示
wd0=(dist)/100; //显示以百米为单位,可根据情况显示
wd1=((dist)%100)/10;
dw2=((dist)%100)%10;
}
void time0() interrupt 1
{
time++;
if (time==20) //50ms计数20次为1秒
{
time=0;
sec++; //秒
}
TL0=0xb0;//重装计数初值
TH0=0x3c;
d0=sec/10;//秒显示
d1=sec%10;
v=(dist*36)/(10*sec);//速度计算。速度,千米/小时
spd00=v/10;//速度显示
spd01=v%10;
}
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
sbit CS1=P1^3;
sbit CS2=P1^4;
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9
};
int k,m,n,i;
void delay(int ms)
{
while(ms--)
for(i=0;i<120;i++);
}
void write_comd(char dat)
{
RW=0;
RS=0;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void write_data(char dat)
{
RW=0;
RS=1;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void disp(char x,char y,char dat)
{
if(y>=64)
{
y=y-1;
}
write_comd(0x40|y);
delay(5);
write_comd(0xb8|x);
write_data(dat);
}
void LCD_init(void)
{
write_comd(0x38);//设置8位格式,2行,5x7
write_comd(0x0c);//整体显示,关光标,不闪烁
write_comd(0x06);//设定输入方式,增量不移位
write_comd(0x01);//清除屏幕显示---
}
void main(void)
{
LCD_init();
while(1)
{
for(k=0;k<8;k++)
{
for(n=0;n<10;n++)
{
if (n<8)
{
CS1=0;
CS2=1;
}
else
{
CS1=1;
CS2=0;
}
for(m=0;m<16;m++)
{
if(m<8)
disp(2*k,m+8*n,num[n][m]);
else
disp(2*k+1,m+8*n-8,num[n][m]);
delay(10);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
sbit CS1=P1^3;
sbit CS2=P1^4;
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9
};
uchar code spd0[]=
{
0x40,0x42,0x44,0xCC,0x00,0xF4,0x94,0x94,
0x94,0xFF,0x94,0x94,0x94,0xF6,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x51,0x48,0x44,
0x42,0x7F,0x42,0x44,0x4C,0x61,0x20,0x00
};
uchar code spd1[]=
{
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,
0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00
};
uchar code lgth0[]=
{
0x00,0x3E,0x22,0xE2,0x22,0x3E,0x00,0xFE,
0x22,0x22,0x22,0x22,0xF3,0x22,0x00,0x00,
0x20,0x7F,0x20,0x3F,0x12,0x12,0x00,0x7F,
0x42,0x42,0x42,0x42,0x47,0x60,0x40,0x00
};
uchar code lgth1[]=
{
0x04,0x04,0x04,0xF4,0x04,0x8C,0x55,0x26,
0x54,0x8C,0x04,0xF4,0x04,0x06,0x04,0x00,
0x00,0xFC,0x04,0x05,0x25,0x35,0x2D,0x27,
0x25,0x35,0x25,0x45,0x84,0x7E,0x04,0x00
};
int k,m,n,i,times;
int xs,ys;
void delay(int ms)
{
while(ms--)
for(i=0;i<120;i++);
}
void write_comd(char dat)
{
RW=0;
RS=0;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void write_data(char dat)
{
RW=0;
RS=1;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void disp(char x,char y,char dat)
{
if(y>=64)
{
y=y-1;
}
write_comd(0x40|y);
delay(5);
write_comd(0xb8|x);
write_data(dat);
}
void LCD_init(void)
{
write_comd(0x38);//设置8位格式,2行,5x7
write_comd(0x0c);//整体显示,关光标,不闪烁
write_comd(0x06);//设定输入方式,增量不移位
write_comd(0x01);//清除屏幕显示---
}
void main(void)
{
IT0=0;//中断触发方式,IT0=1下降沿产生中断信号,IT0=0,低电平产生中断信号
EX0=1;//EX0=1允许外中断,即分中断开关,1打开,0禁止外中断
PX0=1;//外中断0优先
EA=1; //打开总中断开关
LCD_init();
CS1=0;
CS2=1;
while(1)
{
for(xs=0;xs<4;xs++)
for(ys=0;ys<32;ys++)
{
if(xs==0)
{
if(ys<16)
disp(xs+1,ys,~spd0[ys]);
else
disp(xs+1,ys,~spd1[ys-16]);
}
if(xs==1)
{
if(ys<16)
disp(xs+1,ys,~spd0[ys+16]);
else
disp(xs+1,ys,~spd1[ys]);
};
////////////////////////
if(xs==2)
{
if(ys<16)
disp(xs+3,ys,~lgth0[ys]);
else
disp(xs+3,ys,~lgth1[ys-16]);
}
if(xs==3)
{
if(ys<16)
disp(xs+3,ys,~lgth0[ys+16]);
else
disp(xs+3,ys,~lgth1[ys]);
};
};
};
}
void ddd() interrupt 0
{
times++;
}
////////////////////////////////////////////////////////////////////////////////////////
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
sbit CS1=P1^3;
sbit CS2=P1^4;
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9
};
uchar code spd0[]=
{//速
0x40,0x42,0x44,0xCC,0x00,0xF4,0x94,0x94,
0x94,0xFF,0x94,0x94,0x94,0xF6,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x51,0x48,0x44,
0x42,0x7F,0x42,0x44,0x4C,0x61,0x20,0x00
};
uchar code spd1[]=
{//度
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,
0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00
};
uchar code lgth0[]=
{//距
0x00,0x3E,0x22,0xE2,0x22,0x3E,0x00,0xFE,
0x22,0x22,0x22,0x22,0xF3,0x22,0x00,0x00,
0x20,0x7F,0x20,0x3F,0x12,0x12,0x00,0x7F,
0x42,0x42,0x42,0x42,0x47,0x60,0x40,0x00
};
uchar code lgth1[]=
{//离
0x04,0x04,0x04,0xF4,0x04,0x8C,0x55,0x26,
0x54,0x8C,0x04,0xF4,0x04,0x06,0x04,0x00,
0x00,0xFC,0x04,0x05,0x25,0x35,0x2D,0x27,
0x25,0x35,0x25,0x45,0x84,0x7E,0x04,0x00
};
uchar code mh[]=
{
0x00,0x00,0x8C,0x8C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
int k,m,n,i,times=0;
int xs,ys,d1,d0,wd0,wd1;
void delay(int ms)
{
while(ms--)
for(i=0;i<20;i++);
}
void write_comd(char dat)
{
RW=0;
RS=0;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void write_data(char dat)
{
RW=0;
RS=1;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void disp(char x,char y,char dat)
{
if(y>=64)
{
y=y-1;
}
write_comd(0x40|y);
delay(5);
write_comd(0xb8|x);
write_data(dat);
}
void LCD_init(void)
{
// write_comd(0x38);//设置8位格式,2行,5x7
write_comd(0x0c);//整体显示,关光标,不闪烁
write_comd(0x06);//设定输入方式,增量不移位
write_comd(0x01);//清除屏幕显示---
}
void main(void)
{
IT0=1;//中断触发方式,IT0=1下降沿产生中断信号,IT0=0,低电平产生中断信号
IT1=1;
EX0=1;//EX0=1允许外中断,即分中断开关,1打开,0禁止外中断
EX1=1;
PX0=0;//外中断0优先
PX1=1;
EA=1; //打开总中断开关
LCD_init();
CS1=0;
CS2=1;
for(xs=0;xs<6;xs++)
for(ys=0;ys<60;ys++)
{
switch(xs)
{
case 1:if(ys<16)
disp(xs,ys,~spd0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys-16]);
if((ys>31)&&(ys<=44))
disp(xs,ys,~mh[ys-32]);
break;
case 2:if(ys<16)
disp(xs,ys,~spd0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys]);
if((ys>31)&&(ys<=44))
disp(xs+1,ys,~mh[ys-16]);
break;
case 4:if(ys<16)
disp(xs,ys,~lgth0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys-16]);
if((ys>31)&&(ys<=44))
disp(xs,ys,~mh[ys-32]);
break;
case 5:if(ys<16)
disp(xs,ys,~lgth0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys]);
if((ys>31)&&(ys<=44))
disp(xs+1,ys,~mh[ys-16]);
break;
};
};
while(1)
{
for(xs=0;xs<6;xs++)
for(ys=0;ys<60;ys++)
{
switch(xs)
{
case 1:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[wd0][ys-44]);
if(ys>52)
disp(xs,ys,~num[wd1][ys-52]);
break;
case 2:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[wd0][ys-36]);
if(ys>52)
disp(xs,ys,~num[wd1][ys-44]);
break;
case 4:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-44]);
if(ys>52)
disp(xs,ys,~num[d1][ys-52]);
break;
case 5:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-36]);
if(ys>52)
disp(xs,ys,~num[d1][ys-44]);
break;
};
};
};
}
void ddd0() interrupt 0
{
if (times==39)
times=0;
else
times++;
d0=times/10;
d1=times%10;
wd0=((3*times)/2)/10;
wd1=((3*times)/2)%10;
}
///////////////////////////////////////////////////////////////////////////////
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit EN=P1^2;
sbit CS1=P1^3;
sbit CS2=P1^4;
uchar code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},
//"0",0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},
//"1",1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},
//"2",2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},
//"3",3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},
//"4",4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},
//"5",5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},
//"6",6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},
//"7",7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},
//"8",8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9
};
uchar code spd0[]=
{//速
0x40,0x42,0x44,0xCC,0x00,0xF4,0x94,0x94,
0x94,0xFF,0x94,0x94,0x94,0xF6,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x51,0x48,0x44,
0x42,0x7F,0x42,0x44,0x4C,0x61,0x20,0x00
};
uchar code spd1[]=
{//度
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,
0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,
0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00
};
uchar code lgth0[]=
{//距
0x00,0x3E,0x22,0xE2,0x22,0x3E,0x00,0xFE,
0x22,0x22,0x22,0x22,0xF3,0x22,0x00,0x00,
0x20,0x7F,0x20,0x3F,0x12,0x12,0x00,0x7F,
0x42,0x42,0x42,0x42,0x47,0x60,0x40,0x00
};
uchar code lgth1[]=
{//离
0x04,0x04,0x04,0xF4,0x04,0x8C,0x55,0x26,
0x54,0x8C,0x04,0xF4,0x04,0x06,0x04,0x00,
0x00,0xFC,0x04,0x05,0x25,0x35,0x2D,0x27,
0x25,0x35,0x25,0x45,0x84,0x7E,0x04,0x00
};
uchar code mh[]=
{
0x00,0x00,0x8C,0x8C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code qian[]=
{//千
0x80,0x80,0x84,0x84,0x84,0x84,0x84,0xFC,
0x82,0x82,0x83,0x82,0x80,0xC0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code mi[]=
{//米
0x40,0x40,0x42,0x44,0x4C,0x58,0xC0,0xFF,
0x40,0x50,0x48,0x44,0x46,0x60,0x40,0x00,
0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,
0x01,0x02,0x04,0x08,0x10,0x30,0x10,0x00
};
uchar code gong[]=
{//斜杠/
0x00,0x00,0x00,0x0,0x00,0x00,0x00,0x40,
0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,
0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uchar code shi[]=
{//时
0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,
0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,
0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00
};
int k,m,n,i,times=0;
int xs,ys,d1,d0,wd0,wd1;
int time,sec,d,v,dist;
void delay(int ms)
{
while(ms--)
for(i=0;i<20;i++);
}
void write_comd(char dat)
{
RW=0;
RS=0;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void write_data(char dat)
{
RW=0;
RS=1;
P2=dat;
EN=1;
delay(1);
EN=0;
}
void disp(char x,char y,char dat)
{
if(y>=64)
{
y=y-1;
}
write_comd(0x40|y);
delay(5);
write_comd(0xb8|x);
write_data(dat);
}
void LCD_init(void)
{
write_comd(0x0c);//整体显示,关光标,不闪烁
write_comd(0x06);//设定输入方式,增量不移位
write_comd(0x01);//清除屏幕显示---
}
void main(void)
{
IT0=1;//中断触发方式,IT0=1下降沿产生中断信号,IT0=0,低电平产生中断信号
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
EX0=1;//EX0=1允许外中断,即分中断开关,1打开,0禁止外中断
ET0=1;
PX0=1;//外中断0优先
PT0=0;
EA=1; //打开总中断开关
//LCD_init();
CS1=1;
CS2=0;
for(xs=0;xs<6;xs++)
for(ys=0;ys<63;ys++)
{
switch(xs)
{
case 0:if(ys<16)
disp(xs,ys,~qian[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys-16]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~gong[ys-32]);
if(ys>47)
disp(xs,ys,~shi[ys-48]);
break;
case 1:if(ys<16)
disp(xs,ys,~qian[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~gong[ys-16]);
if(ys>47)
disp(xs,ys,~shi[ys-32]);
break;
case 2:if(ys<16)
disp(xs,ys,~qian[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys-16]);
break;
case 3:if(ys<16)
disp(xs,ys,~qian[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~mi[ys]);
break;
};
};
CS1=0;
CS2=1;
for(xs=0;xs<6;xs++)
for(ys=0;ys<63;ys++)
{
switch(xs)
{
case 0:if(ys<16)
disp(xs,ys,~spd0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys-16]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~mh[ys-32]);
break;
case 1:if(ys<16)
disp(xs,ys,~spd0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~spd1[ys]);
if((ys>31)&&(ys<=48))
disp(xs,ys,~mh[ys-16]);
break;
case 2:if(ys<16)
disp(xs,ys,~lgth0[ys]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys-16]);
if((ys>31)&&(ys<=44))
disp(xs,ys,~mh[ys-32]);
break;
case 3:if(ys<16)
disp(xs,ys,~lgth0[ys+16]);
if((ys>15)&&(ys<32))
disp(xs,ys,~lgth1[ys]);
if((ys>31)&&(ys<=44))
disp(xs+1,ys,~mh[ys-16]);
break;
};
};
TR0=1;
while(1)
{
for(xs=0;xs<6;xs++)
for(ys=0;ys<60;ys++)
{
switch(xs)
{
case 0:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[wd0][ys-44]);
if(ys>52)
disp(xs,ys,~num[wd1][ys-52]);
break;
case 1:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[wd0][ys-36]);
if(ys>52)
disp(xs,ys,~num[wd1][ys-44]);
break;
case 2:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-44]);
if(ys>52)
disp(xs,ys,~num[d1][ys-52]);
break;
case 3:
if((ys>44)&&(ys<=52))
disp(xs,ys,~num[d0][ys-36]);
if(ys>52)
disp(xs,ys,~num[d1][ys-44]);
break;
};
};
};
}
void distant() interrupt 0
{
d++; //跑步机圈数计数
dist=d;
wd0=(dist)/10;
wd0=(dist)%10;
}
void time0() interrupt 1
{
time++;
if (time==20) //50ms计数20次为1秒
{
time=0;
sec++; //秒
}
d0=sec/10;
d1=sec%10;
}
|