📄 text2.c
字号:
#include <reg51.h>
#include <intrins.h>
//--------LCD control bit---------------
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_EN = P2^4;
sbit INT_0 =P3^2;
#define LCDDATA P0
unsigned char KeyValue,timer0_tick=0,Flag_time=0;
typedef struct {
char hour;
char minute;
char second;
}time;
time now={11,28,45} ;
void delay_10ms()
{
unsigned char k;
for (k=0;k<20;k++);
}
void delay()
{
unsigned char j,k;
for (j=0;j<100;j++);
for (k=0;k<200;k++);
}
void WriteCommand(unsigned char c)
{
delay_10ms();
LCD_RS=0;
LCD_RW=0;
_nop_();
LCD_EN=1;
LCDDATA=c;
LCD_EN=0;
}
void WriteData(unsigned char c)
{
delay_10ms();
LCD_RS=1;
LCD_RW=0;
_nop_();
LCD_EN=1;
LCDDATA=c;
LCD_EN=0;
}
void ShowChar(unsigned char pos,unsigned char c)
{
WriteCommand(pos+0x80);
WriteData(c);
}
void ShowString(unsigned char ptr)
{
unsigned char i=0,j=0x80;
while(i<8)
{
if(ptr&j)
{
ShowChar(3+i,'1') ;
}
else {
ShowChar(3+i,'0') ;
}
i++;
j=j>>1;
}
ShowChar(11,' ') ;
}
void InitLCD(void)
{
delay_10ms();
WriteCommand(0x38);
WriteCommand(0x38);
WriteCommand(0x06);
WriteCommand(0x0C);
//WriteCommand(0x01);
WriteCommand(0x80);
}
void Ex0_Key() interrupt 0 using 0
{
unsigned char x,y;
EA=0;
delay();
x=P1;
P1=0xff;
P1=0xf0;
y=P1;
KeyValue=x+y;
ShowString(KeyValue);
//ShowChar(6,KeyValue+0x30) ;
switch(KeyValue)
{
// case 0xee: Flag_time=1;
}
P1=0x0f;
EA=1;
}
void initTimer (void)
{
EA=0;
TMOD=0x01;
TH0=-9460/256;
TL0=-9460%256; //初始化计数器初值,
PT0=1;
TR0=1;
ET0=1;
EA =1;
}
void ShowTime()
{
ShowChar(4,now.hour/10+0x30);
ShowChar(5,now.hour%10+0x30);
ShowChar(6,':');
ShowChar(7,now.minute/10+0x30);
ShowChar(8,now.minute%10+0x30);
ShowChar(9,':');
ShowChar(10,now.second/10+0x30);
ShowChar(11,now.second%10+0x30);
}
void timer0 (void) interrupt 1
{
TR0=0;
TH0=-9460/256;
TL0=-9460%256; //初始化计数器初值
TR0=1;
timer0_tick++;
if (timer0_tick==100)
{
timer0_tick=0;
/***********************************************************/
if(now.second==59)
{
now.second=0;
if (now.minute==59)
{
now.minute=0;
if (now.hour==23)
{
now.hour = 0;
now.minute =0;
now.second =0;
}else now.hour++;
}else now.minute++;
}else now.second++;
if(Flag_time)
{
ShowTime();
}
/* else if(Flag_xhtime)
{
CycShow();
} */
}
}
void main (void)
{
InitLCD();
initTimer();
P1=0x0f;
IT0=1;
EX0=1;
EA=1;
ShowChar(2,'r') ;
while(1)
{
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -