12864(1).zip
(42.83 KB, 下载次数: 3)
液晶显示不理想,但编译是通过了的。也不知道哪里出错了。附源代码
#include<reg52.h>
#include<intrins.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
#define LCD_databus P0 //LCD12864的8位数据口
#define uint unsigned int
#define uchar unsigned char
uint heat=000,spurs=000;
uint c;
sbit EN=P2^2; //低电平写入高电平读取
sbit RS=P2^0; //高电平数据输入命令输入
sbit RW=P2^1; //高电平读取低电平写入
sbit CS2=P2^3; //
sbit CS1=P2^4;
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit key5=P1^4;
sbit key6=P1^5;
sbit key7=P1^6;
sbit key8=P1^7;
sbit BEEP=P3^0;
char chang=48;
char xiaoshu=0;
char xiaoshu2=0;
uchar f2;
uchar m2;
uchar x2;
uchar count;
char fen=12;
char miao=0;
char flag=24;
unsigned char code time[][16]={
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//"0",
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//"1",
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//"2",
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//"3",
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//"4",
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//"5",
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//"6",
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//"7",
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//"8",
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//"9",
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//"V",10
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//"S",11
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//":",12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//".",13
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//"T"14
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//"N"15
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//"D"16
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//"R"17
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//"H"18
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空格"19
};
uchar code HZ[][32]={
0x00,0x08,0x08,0x08,0x08,0x08,0x09,0xFE,
0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,
0x41,0x41,0x41,0x41,0x41,0x40,0x40,0x00,//"主"
0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0x08,0x10,0x88,0x47,0x20,0x18,
0x07,0x00,0x07,0x18,0x20,0x40,0x80,0x00,// "队",
0x10,0x0C,0x84,0x44,0x3C,0x54,0x95,0x96,
0x94,0x54,0x34,0x14,0x04,0x14,0x0C,0x00,
0x04,0x04,0x02,0x02,0xFD,0x45,0x44,0x44,
0x44,0x45,0xFD,0x02,0x02,0x06,0x02,0x00,//“客”
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"一",
};
void delay_10us(uint n) //延时n个10us@12M晶振
{
uint i;
for(i=n;i>0;i--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
}
void delay_50us(uint z)
{
uint x,y; for(x=z;x>0;x--)
for(y=19;y>0;y--);
}
void delay_ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay(uint i)
{
while(--i);
} /**?延时函数?**/
void delay_1ms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
void Read_busy()//读“忙”函数-----数据线的最高位DB71则busy
{
P0=0x00;
RS=0;
RW=1;
EN=1;
while(P0 & 0x80);
EN=0;
}
void write_LCD_command(uchar value) //写命令函数
{
Read_busy(); //对LCD的每次读写都要读忙
RS=0; //选择命令
RW=0; //读操作
LCD_databus=value;
EN=1; //EN由1----0锁存有效数据
_nop_();
_nop_();
EN=0;
}
void write_LCD_data(uchar value)//写数据函数
{
Read_busy();
RS=1; //选择数据
RW=0;
LCD_databus=value;
EN=1; //EN由1----0锁存有效数据
_nop_();
_nop_();
EN=0;
}
void Set_page(uchar page) //设置“页”LCD12864共8页,一页是8行点阵点
{
page=0xb8|page; //页的首地址为0xB8
write_LCD_command(page);
}
void Set_line(uchar startline) //设置显示的起始行
{
startline=0xC0|startline; //起始行地址为0xC0
write_LCD_command(startline); //设置从哪行开始:共0--63;一般从0 行开始显示
}
void Set_column(uchar column) //设置显示的列
{
column=column &0x3f; //列的最大值为64
column= 0x40|column; //列的首地址为0x40
write_LCD_command(column); //规定显示的列的位置
}
void SetOnOff(uchar onoff) //显示开关函数:0x3E是关显示,0x3F是开显示
{
onoff=0x3e|onoff; //onoff:1---开显示;0---关显示
write_LCD_command(onoff);
}
void SelectScreen(uchar screen) //选择屏幕
{
switch(screen)
{
case 0: CS1=0;CS2=0;break; //全屏
case 1: CS1=0;CS2=1;break;//左半屏
case 2: CS1=1;CS2=0;break;//右半屏
default:break;
}
}
void ClearScreen(uchar screen) //清屏函数
{
uchar i,j;
SelectScreen(screen); //0--全屏;1---左半屏;2---右半屏
for(i=0;i<8;i++) //控制页数0-7,共8页
{
Set_page(i);
Set_column(0);
for(j=0;j<64;j++) //控制列数0-63,共64列
{
write_LCD_data(0x00); //写入0,地址指针自加1
}
}
}
void init_LCD() //LCD的初始化
{
SetOnOff(1); //开显示
SelectScreen(0);//
ClearScreen(0); //清屏
Set_line(0); //开始行:0
}
void Display_ASCII(uchar screen,uchar page,uchar column,uchar a[][16],uchar h)
{
uchar i;
SelectScreen(screen);
Set_page(page);
Set_column(column*8);
for(i=0;i<8;i++) //显示字符上半部分:8*8
{
write_LCD_data(*(a[h]+i));
}
Set_page(page+1); //显示字符下半部分:8*8
Set_column(column*8);
for(i=0;i<8;i++)
{
write_LCD_data
(*(a[h]+i+8));
}
}
void Display_HZ(uchar screen,uchar page,uchar column,uchar a[][32],uchar h)
{
uchar i;
SelectScreen(screen);
Set_page(page); //写上半页:16*8
Set_column(column*16); //控制列
for(i=0;i<16;i++) //控制16列的数据输出
{
write_LCD_data(*(a[h]+i)); //汉字的上半部分
}
Set_page(page+1); //写下半页:16*8
Set_column(column*16); //控制列
for(i=0;i<16;i++) //控制16列的数据输出
{ write_LCD_data(*(a[h]+16+i)); //汉字的下半部分
}
}
void disp1()
{
Display_HZ(1,0,2,HZ,0);//主
Display_HZ(1,0,3,HZ,1);//队
Display_ASCII(2,0,0,time,10);
Display_ASCII(2,0,1,time,11);
Display_HZ(2,0,1,HZ,3);//客
Display_HZ(2,0,2,HZ,2);//队
}
void disp2() //
{
Display_HZ(1,0,2,HZ,3);// 客
Display_HZ(1,0,3,HZ,4);// 队
Display_ASCII(2,0,0,time,10);
Display_ASCII(2,0,1,time,11);
Display_HZ(2,0,1,HZ,0);//主
Display_HZ(2,0,2,HZ,1);//队
}
void disp3()
{
if(chang>36)
{
while(1)
{
Display_ASCII(1,4,0,time,1);
Display_ASCII(1,4,1,time,11);
Display_ASCII(1,4,2,time,14);
}
}
else if(chang>24)
{
while(1)
{
Display_ASCII(1,4,0,time,2);
Display_ASCII(1,4,1,time,15);
Display_ASCII(1,4,2,time,16);
}
}
else if(chang>12)
{
while(1)
{
Display_ASCII(1,4,0,time,3);
Display_ASCII(1,4,1,time,17);
Display_ASCII(1,4,2,time,16);
}
}
else if(chang>0)
{ while(1)
{
Display_ASCII(1,4,0,time,4);
Display_ASCII(1,4,1,time,14);
Display_ASCII(1,4,2,time,18);
}
}
}
void disp4()
{
chang=24;
fen=12;
miao=0;
xiaoshu=0;
xiaoshu2=0;
flag=0;
Display_ASCII(1,4,0,time,3);
Display_ASCII(1,4,1,time,17);
Display_ASCII(1,4,2,time,16);
}
void disp5()
{
if(fen==0&&miao==0&&xiaoshu==0)
{
BEEP=0;
delay_1ms(5000);
fen=12;
miao=0;
xiaoshu=0;
TR0=0;
BEEP=1;
}
if(flag==0&&xiaoshu2==0)
{
BEEP=0;
f2=fen;
m2=miao;
x2=xiaoshu;
delay_1ms(5000);
TR0=0;
fen=f2;
miao=m2;
xiaoshu=x2;
flag=24;
xiaoshu2=0;
BEEP=1;
}
}
void dingshiqi()
{
TMOD=0X01; //T1 jishu T0 jishi
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
}
void Key1()
{
if(key1==0)
{
delay_ms(10);
if(key1==0)
{
while(!key1)
{
while(!key1)
{}
disp2();
disp4();
c=spurs;
spurs=heat;
heat=c;
}
}
}
}
void Key2()
{
if(key2==0)
{
delay_ms(10);
if(key2==0)
{
while(!key2)
{ while(!key2)
{ }
heat++;
}
}
}
}
void Key3()
{
if(key3==0)
{
delay_ms(10);
if(key3==0)
{
while(!key3)
{
while(!key3)
{}
if (heat==0)
{}
else
{
heat--;
}
}
}
}
}
void Key4()
{
if(key4==0)
{
delay_ms(10);
if(key4==0)
{
while(!key4)
{
while(!key4)
{ }
spurs++;
}
}
}
}
void Key5()
{
if(key5==0)
{
delay_ms(10);
if(key5==0)
{
while(!key5)
{
while(!key5){ }
if (spurs==0)
{}
else
{spurs--;}
}
}
}
}
void Key6()
{
if(key6==0)
{
delay_ms(10);
if(key6==0)
{
while(!key6)
{
while(!key6)
{ }
TR0=0;
}
}
}
}
void Key7()
{
if(key7==0)
{
delay_ms(10);
if(key7==0)
{
while(!key7)
{
while(!key7)
{}
TR0=1;
}
}
}
}
void Key8()
{
if(key8==0)
{
delay_ms(10);
if(key8==0)
{
while(!key8)
{
while(!key8)
{ }
flag=24;
xiaoshu2=0;
}
}
}
}
void main(void)
{
uchar A,B,C,D,E,F;
uchar G,H,I,J,K,L;
init_LCD();
dingshiqi();
disp1();
disp3();
while(1)
{
disp5();
Key1();
Key2();
Key3();
Key4();
Key5();
Key6();
Key7();
Key8();
A=heat/100;
B=heat/10%10;
C=heat%10;
D=spurs/100;
E=spurs/10%10;
F=spurs%10;
G=fen/10;
H=fen%10;
I=miao/10;
J=miao%10;
K=flag/10;
L=flag%10;
Display_ASCII(1,2,5,time,A);
Display_ASCII(1,2,6,time,B);
Display_ASCII(1,2,7,time,C);//bifen
Display_ASCII(2,2,1,time,12);
Display_ASCII(2,2,3,time,D);
Display_ASCII(2,2,4,time,E);
Display_ASCII(2,2,5,time,F);
Display_ASCII(1,4,4,time,G);
Display_ASCII(1,4,5,time,H);
Display_ASCII(1,4,6,time,12);
Display_ASCII(1,4,7,time,I);
Display_ASCII(2,4,0,time,J);
Display_ASCII(2,4,1,time,13);
Display_ASCII(2,4,2,time,xiaoshu);
Display_ASCII(2,4,4,time,K);
Display_ASCII(2,4,5,time,L);
Display_ASCII(2,4,6,time,13);
Display_ASCII(2,4,7,time,xiaoshu2);
}
}
void timer0() interrupt 1 //3定时器1的中断号1定时器0的中断号0外部中断1 2外部中 断2 4串口中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==2)
{
count=0;
xiaoshu--;
if(xiaoshu==-1)
{ xiaoshu=9; miao--; } //计时时间小数
if(miao==-1)
{
miao=59;
fen--;
chang--;
if(fen==-1)
{
fen=12;
}
} //分钟跳动1st 2nd 3rd 4th
xiaoshu2--;
if(xiaoshu2==-1)
{
xiaoshu2=9;
flag--;
} //24秒时间小数
if(flag==-1)
{
flag=24;
xiaoshu2=0;
} //24秒重置
}
}
不排除proteus设置出错,但我也不清楚是哪里出错了
一般这种情况应该怎么处理?
|