新手上路
- 积分
- 48
- 金钱
- 48
- 注册时间
- 2019-5-27
- 在线时间
- 11 小时
|
10金钱
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
//lcd_data = P0
sbit lcdrs = P2^2;
sbit lcdrw = P2^1;
sbit lcden = P2^0;
sbit k1 = P3^3;
sbit k2 = P3^2;
sbit k3 = P3^1;
sbit Led = P1^0; //led light
uchar i,t=0,k1num = 0;
uint year = 2019;
char h = 00,m = 00,s = 00,w = 55,month = 01,day = 01 ;
uchar code table1[] = {"2019-12-22 SUN"}; //初始日期
uchar code table2[] = {" 00:00:00 "}; //初始时间
uchar code table3[] = {" smhwdmy "}; //模式状态选择(秒s,分m,时h,周w,日d,月m,年y)
void delay(uchar z)
{
uchar x,y;
for(x = z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //写命令函数
{
lcdrs = 0;
lcdrw = 0;
P0 = com;
delay(10);
lcden = 1;
delay(10);
lcden = 0;
}
void write_dat(uchar dat) //LCD写数据
{
lcdrs = 1;
lcdrw = 0;
P0 = dat;
delay(10);
lcden = 1;
delay(10);
lcden = 0;
}
void Monday(void) //调用星期一子函数
{
write_com(0x80 + 12);
write_dat('M');
write_com(0x80 + 13);
write_dat('O');
write_com(0x80 + 14);
write_dat('N');
}
void Tuesday(void) //调用星期二子函数
{
write_com(0x80 + 12);
write_dat('T');
write_com(0x80 + 13);
write_dat('U');
write_com(0x80 + 14);
write_dat('E');
}
void Wednesday(void) //调用星期三子函数
{
write_com(0x80 + 12);
write_dat('W');
write_com(0x80 + 13);
write_dat('E');
write_com(0x80 + 14);
write_dat('D');
}
void Thursday(void) //调用星期四子函数
{
write_com(0x80 + 12);
write_dat('T');
write_com(0x80 + 13);
write_dat('H');
write_com(0x80 + 14);
write_dat('U');
}
void Friday(void) //调用星期五子函数
{
write_com(0x80 + 12);
write_dat('F');
write_com(0x80 + 13);
write_dat('R');
write_com(0x80 + 14);
write_dat('I');
}
void Saturday(void) //调用星期六子函数
{
write_com(0x80 + 12);
write_dat('S');
write_com(0x80 + 13);
write_dat('A');
write_com(0x80 + 14);
write_dat('T');
}
void Sunday(void) //调用星期日子函数
{
write_com(0x80 + 12);
write_dat('S');
write_com(0x80 + 13);
write_dat('U');
write_com(0x80 + 14);
write_dat('N');
}
void display_week(uchar week) //星期显示
{
switch(week)
{
case 1: Monday();break;
case 2: Tuesday();break;
case 3: Wednesday();break;
case 4: Thursday();break;
case 5: Friday();break;
case 6: Saturday();break;
case 7: Sunday();break;
}
}
void init(void) //LCD初始显示
{
lcden = 0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
TMOD = 0x01;
ET0 = 1;
EA = 1;
TH0 = 0x3c;TL0 = 0xb0;
TR0 = 1;
write_com(0x80);
for(i=0;i<15;i++)
{
write_dat(table1[i]);delay(5);
}
write_com(0x80 + 0x40);
for(i=0;i<11;i++)
{
write_dat(table2[i]);delay(5);
}
}
void display_time(uchar ad,uchar time) //时间显示
{
uchar a,b;
a = time/10;
b = time%10;
write_com(0x80 + 0x40 + ad);
write_dat(0x30 + a);
write_com(0x80 + 0x40 + 1 + ad);
write_dat(0x30 + b);
}
void display_date(uint nian,char yue,char ri) //日期显示
{
uint y1,y2,y3,y4;
char a,b,c,d;
y1 = nian/1000;
y2 = nian%1000/100;
y3 = nian%1000%100/10;
y2 = nian%1000%100%10;
a = yue/10;
b = yue%10;
c = ri/10;
d = ri%10;
write_com(0x80 + 1);
write_dat(0x30 + y1);
write_com(0x80 + 2);
write_dat(0x30 + y2);
write_com(0x80 + 3);
write_dat(0x30 + y3);
write_com(0x80 + 4);
write_dat(0x30 + y4);
write_com(0x80 + 6);
write_dat(0x30 + a);
write_com(0x80 + 7);
write_dat(0x30 + b);
write_com(0x80 + 9);
write_dat(0x30 + c);
write_com(0x80 + 10);
write_dat(0x30 + d);
}
void display_state(uchar s) //模式状态屏幕显示
{
write_com(0x80 + 0x40 + 14);
write_dat(table3[s]);
}
void keyscan() //按键扫描
{
if(k1==0)
{
delay(10);
if(k1==0)
{
Led = 0;
k1num++;TR0 = 0;t = 0;
while(!k1);
if(k1num==1)
{write_com(0x80 + 0x40 + 11);write_com(0x0f);display_state(k1num - 1);} //s
if(k1num==2)
{write_com(0x80 + 0x40 + 8);display_state(k1num - 1);} //m
if(k1num==3)
{write_com(0x80 + 0x40 + 5);display_state(k1num - 1);} //h
if(k1num==4)
{write_com(0x80 + 14);display_state(k1num - 1);} //week
if(k1num==5)
{write_com(0x80 + 10);display_state(k1num - 1);} //day
if(k1num==6)
{write_com(0x80 + 7);display_state(k1num - 1);} //month
if(k1num==7)
{write_com(0x80 + 4);display_state(k1num - 1);} //year
if(k1num==8)
{k1num = 0;write_com(0x0c);TR0 = 1;Led = 1;display_state(7);}
}
}
if(k1num!=0)
{
if(k2==0)
{
delay(10);
if(k2==0)
{
while(!k2);
if(k1num==1)
{
s++;
if(s==60)
s = 0;
display_time(10,s);
}
if(k1num==2)
{
m++;
if(m==60)
m = 0;
display_time(7,m);
}
if(k1num==3)
{
h++;
if(h==24)
h = 0;
display_time(4,h);
}
if(k1num==4)
{
w++;
if(w==8)
w = 1;
display_week(w);
}
if(k1num==5)
{
day++;
if(day==32)
day = 1;
display_date(year,month,day);
}
if(k1num==6)
{
month++;
if(month==13)
month = 1;
display_date(year,month,day);
}
if(k1num==7)
{
year++;
display_date(year,month,day);
}
}
}
if(k3==0)
{
delay(10);
if(k3==0)
{
while(!k3);
if(k1num==1)
{ s--;
if(s==-1)
s=59;
display_time(10,s);
}
if(k1num==2)
{ m--;
if(m==-1)
m=59;
display_time(7,m);
}
if(k1num==3)
{ h--;
if(h==-1)
h=23;
display_time(4,h);
}
if(k1num==4)
{ w--;
if(w==0)
w=7;
display_week(w);
}
if(k1num==5)
{ day--;
if(day==0)
day=31;
display_date(year,month,day);
}
if(k1num==6)
{ month--;
if(month==0)
month=12;
display_date(year,month,day);
}
if(k1num==7)
{ year--;
display_date(year,month,day);
}
}
}
}
display_date(year,month,day);
display_week(w);
display_time(10,s);
display_time(7,m);
display_time(4,h);
}
void timer0()interrupt 1
{
t++;
TH0=0x3c;
TL0=0xb0;
if(t==20)
{s++;t=0;}
if(s==60)
{m++;s=0;}
if(m==60)
{h++;m=0;}
if(h==24)
{w++;day++;h=0;}
if(w==8)
{w=1;}
if(day==32)
{month++;day=1;}
if(month==13)
{year++;month=1;}
}
void main()
{
init();
while(1);
{
keyscan();
}
}
为什么我的keyscan函数调用不了
求助大神
|
-
|