欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
矩陣鍵盤12864液晶實時時鐘程序
[打印本頁]
作者:
wudawei
時間:
2014-12-31 13:40
標題:
矩陣鍵盤12864液晶實時時鐘程序
#include <reg51.h>
#include <intrins.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar shijian[6]={0x1,0x1,0x0,0x2,0x5,0x8};
uchar zi[]={"時分秒"};
uchar j,key;
char z,z1;
uchar m,mark=0,bz=0;
uint k=4000;
uchar i;
/* 端口定義*/
sbit LCD_RS = P2^7; //寄存器選擇輸入
sbit LCD_RW = P2^6; //液晶讀/寫控制
sbit LCD_EN = P2^5; //液晶使能控制
sbit LCD_PSB = P2^4; //串/并方式控制
void delay_1ms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
/*******************************************************************/
/* */
/*寫指令數據到LCD */
/*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。 */
/* */
/*******************************************************************/
void jud()
{char n=0,m=0,temp;
if(P1!=0xf0)
{delay_1ms(15);
if(P1!=0xf0)
bz=1;
}
if(bz==1)
{
uchar scan[4]={0xfe,0xfd,0xfb,0xf7};
uchar table[4][4]={0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,0x7b,0xbb,0xdb,0xeb,0x77,0xb7,0xd7,0xe7};
uchar num[4][4]={0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15};
while(n<4)
{P1=scan[n];temp=P1;m=0;
while(m<4)
{if(temp==table[n][m])
goto next;
else
m++;
}
n++;
}
next: key=num[n][m];
bz=1;
if(key==10)
mark=1;
}
P1=0XF0;
while(P1!=0xf0);
delay_1ms(15);
P1=0XF0;
}
void write_cmd(uchar cmd)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
P0 = cmd;
delay_1ms(5);
LCD_EN = 1;
delay_1ms(5);
LCD_EN = 0;
}
/*******************************************************************/
/* */
/*寫顯示數據到LCD */
/*RS=H,RW=L,E=高脈沖,D0-D7=數據。 */
/* */
/*******************************************************************/
void write_dat(uchar dat)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P0 = dat;
delay_1ms(5);
LCD_EN = 1;
delay_1ms(5);
LCD_EN = 0;
}
/*********************************************************/
/* */
/* 設定顯示位置 */
/* */
/*********************************************************/
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
pos = X+Y ;
write_cmd(pos); //顯示地址
}
/*******************************************************************/
/* */
/* LCD初始化設定 */
/* */
/*******************************************************************/
void lcd_init()
{
LCD_PSB = 1; //并口方式
write_cmd(0x30); //基本指令操作
delay_1ms(5);
write_cmd(0x0C); //顯示開,關光標
delay_1ms(5);
write_cmd(0x01); //清除LCD的顯示內容
delay_1ms(5);
}
/*********************************************************/
/* */
/* 主程序 */
/* */
/*********************************************************/
main()
{ uchar x;
EA=1;
P1=0XF0;
TMOD=0X2;
TH0=0X6;
TL0=0X6;
EA=1;ET0=1;TR0=1;
i=0;
delay_1ms(10); //延時
lcd_init();
lcd_pos(0,1);
write_dat(zi[0]);
write_dat(zi[1]);
lcd_pos(0,3);
write_dat(zi[2]);
write_dat(zi[3]);
lcd_pos(0,5);
write_dat(zi[4]);
write_dat(zi[5]);
while(1)
{
z=1;
z1=0;
P1=0XF0;
lcd_pos(0,0);
i = 0;
while(i<2)
{
write_dat(shijian[i]+0x30);
i++;
}
lcd_pos(0,2);
while(i<4)
{
write_dat(shijian[i]+0x30);
i++;
}
lcd_pos(0,4);
while(i<6)
{
write_dat(shijian[i]+0x30);
i++;
}
jud();
if(key==10)
{TR0=0;
lcd_pos(0,0);delay_1ms(5);
write_cmd(0x0f);
delay_1ms(5);
bz=0;
while(!bz)
{jud();}
while(mark)
{jud();
if(key==12)
{z--;write_cmd(0x10);delay_1ms(5);write_cmd(0x10);delay_1ms(5);bz=0;if((2*(z-1)+(z1-1))==-3){for(x=0;x<6;x++){write_cmd(0x14);delay_1ms(5);}z=3;z1=0;}}
else if(key==13)
{z++;write_cmd(0x14);delay_1ms(5);write_cmd(0x14);delay_1ms(5);bz=0;if((2*(z-1)+(z1-1))>=5){for(x=0;x<6;x++){write_cmd(0x10);delay_1ms(5);}z=1;z1=0;}}
else if(key<=9)
{z1++;write_dat(key+48);delay_1ms(5);shijian[2*(z-1)+(z1-1)]=key;if((2*(z-1)+(z1-1)<5)&&(z1%2==0)){write_cmd(0x14);delay_1ms(5);}else if(2*(z-1)+(z1-1)>=5){for(x=0;x<5;x++){write_cmd(0x10);delay_1ms(5);}z=1;z1=0;}bz=0;}
else if(key==11)
{write_cmd(0x0c);delay_1ms(5);mark=0;}
while(!bz)
{ jud();}
}
bz=0;
TR0=1;
}
}
}
/*************************************/
count0 (void) interrupt 1
{
k--;
if(k==0x0)
{++shijian[5];k=4000;
if (shijian[5]==0x0a)
{shijian[5]=0x0;
++shijian[4];
if(shijian[4]==0x6)
{shijian[4]=0x0;
++shijian[3];
if (shijian[3]==0x0a)
{shijian[3]=0x0;
++shijian[2];
if(shijian[2]==0x6)
{shijian[2]=0x0;
++shijian[1];
if((shijian[0]==0x0)&&(shijian[1]==0x0a))
{shijian[1]=0x0;
++shijian[0];
}
else if((shijian[0]==0x1)&&(shijian[1]==0x2))
{shijian[1]=0x0;
shijian[0]=0x0;
}
}
}
}
}
}
}
/*******************************************/
復制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1