?? mylcd.c
字號:
else day_temp=day_num[day_now.month-1];
day_now.day=1;
if(day_now.month==13){
day_now.month=1;
day_temp=day_num[day_now.month-1];
day_now.year++;
leap=leapf(day_now.year);
}
}
}
}
/****************************************************************
**begin()子函數系統參數初始化
**
****************************************************************/
void begin(){
//定時器0初始化
TMOD=0x21; //50ms int 12M
TH0=0x3c;
TL0=0xba;
TR0=1;
IE=0x92;
SCON|=0x40;
//狀態標志位初始化
//參量初始化
time_now.second=0;
time_now.minute=0;
time_now.hour=0;
day_now.year=1980;
day_now.month=6;
day_now.day=27;
leap=leapf(day_now.year);
day_temp=day_num[day_now.month-1];
}
/****************************************************************
**display()子函數
**參數說明:*cpoint:要顯示的字符地址指針
** x_line:橫軸坐標(1-16)
** y_line:縱軸坐標(1-16)
** s_l: 1為8*16字體;2為16*16字體
**返回值:無
****************************************************************/
void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l){
unsigned char xdata *xpoint;
unsigned char i,j;
xpoint=0x8000+x_line+y_line*16;
for(i=0;i<16;i++){
for(j=0;j<s_l;j++){
*xpoint=*cpoint;
cpoint++;
xpoint++;
}
xpoint=xpoint+16-s_l;
}
}
/****************************************************************
**display_begin()子函數顯示屏幕的初始值如:
** —————————
** | 1980年09月05日|
** | 23時03分09秒|
** —————————
**調用函數:display()
** display_time()
**
****************************************************************/
//指定位置顯示“年,月,日,時,分,秒”
//unsigned char code zhi_loc[]=
//{0x06,0x01,0x0a,0x01,0x0e,0x01,0x06,0x10,0x0a,0x10,0x0e,0x10};
void display_begin(){
unsigned char x_display,y_display,i,j=0;
unsigned char code *p_display;
p_display=&shi;
for (i=0;i<6;i++){
x_display=zhi_loc[j];
j++;
y_display=zhi_loc[j];
j++;
display(p_display,x_display,y_display,2);
p_display=p_display+32;
}
//指定位置顯示時間
display_time(time_now,day_now);
}
/****************************************************************
** display_time()顯示時間子函數
** 參數:struct time_str time
** struct day_str day
** 返回值:無
** 調用函數:display()
** hex_bcd()
****************************************************************/
void display_time(struct time_str time,struct day_str day){
unsigned char temp,temp1,temp_year,temp_x,temp_y;
unsigned char *temp_p;
//顯示哭笑符
if (ku_flag)temp_p=(&ku)+32;
else temp_p=&ku;
temp_x=0;
temp_y=16;
ku_flag=!ku_flag;
display(temp_p,temp_x,temp_y,2);
//顯示秒
temp=time.second;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=13;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=12;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示分
temp=time.minute;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=9;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=8;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示時
temp=time.hour;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=5;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=4;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示日
temp=day.day;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=13;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=12;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示月
temp=day.month;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=9;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=8;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示年
temp_year=day.year/100;
temp=day.year%100;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=5;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=4;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
//顯示年高位
temp=hex_bcd(temp_year);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=3;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=2;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);
}
/****************************************************************
**潤年判斷leap()子函數
**參數:unsigned int year
**返回字:潤年標志leap0為非潤年
**內部變量:bit leap1
****************************************************************/
bit leapf(unsigned int year){
bit bdata leap1;
if(year%4==0){
if(year%100==0){
if(year%400==0){
leap1=1;
}
else leap1=0;
}
else leap1=1;
}
else leap1=0;
return(leap1);
}
/****************************************************************
**hex_bcd()子函數
**參數:hex需要轉換的單字節16進制數
**返回字:轉換完成的單字節bcd碼,高4位為高位低4位為低位
**內部變量:bcd,temp為無符號字符型
****************************************************************/
unsigned char hex_bcd(unsigned char hex){
unsigned char bcd,temp;
bcd=hex%10;
temp=hex/10;
temp=temp<<4;
bcd=bcd|temp;
return (bcd);
}
/****************************************************************
** key()鍵盤子函數
** 鍵盤為兩鍵式一個鍵
** 參數:
****************************************************************/
/****************************************************************
** time0()定時器0中斷子函數,產生50ms中斷
**
****************************************************************/
void time0() interrupt 1 using 1{
TH0=0x3c; //time0 50ms interrupt
TL0=0xba;
TR0=1;
msecond++;
if (msecond==20){
second_flag=1;
msecond=0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -