?? main.c
字號:
#include<reg51.h>
#include<stdio.h>
#include<absacc.h>
#include"key.h"
#include"lcd1602.h"
#define uint unsigned int
#define uchar unsigned char
#define DIGPORT P2
#define WORDPORT P0
bit int0_flag=0; ///中斷申請標(biāo)記位
/*數(shù)碼管顯示編碼0-----9*/
uchar data CLOCK[4]={0,0,0,0};
//主函數(shù)
void main(void){
uchar temp[16];
uchar key;
EA=1;
TR0=1;ET0=1;TR0=1;
TMOD=0X01;
TH0=0Xdc;TL0=0x88; //T0定時(shí)
IT0=1;TR1=0;EX0=1;IE0=1;
LCD_init();
while(1)
{
if(int0_flag)
{
if(CLOCK[2]>35&&CLOCK[2]<60)
{CLOCK[3]=CLOCK[3]+1;
CLOCK[1]=0;
CLOCK[2]=0;
sprintf(temp,"TIME:%2bu:%2bu:%2bu",CLOCK[3],CLOCK[2],CLOCK[1]);
LCD_setxy(1,1);
LCD_string(temp);
}
if(CLOCK[2]>0&&CLOCK[2]<25)
{CLOCK[3]=CLOCK[3];
CLOCK[2]=0;
CLOCK[1]=0;
sprintf(temp,"TIME:%2bu:%2bu:%2bu",CLOCK[3],CLOCK[2],CLOCK[1]);
LCD_setxy(1,1);
LCD_string(temp);
}
int0_flag=0;
}
//小時(shí)
key=keyscan();
sprintf(temp,"TIME:%2bu:%2bu:%2bu",CLOCK[3],CLOCK[2],CLOCK[1]);
LCD_setxy(1,1);
LCD_string(temp);
switch(key)
{
case 1:
{TR0=0;
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60)CLOCK[2]=0;
delay_10ms();
}TR0=1;
break;
case 2:
{TR0=0;
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)CLOCK[3]=0;
delay_10ms();
}TR0=1;
break;
case 3:
{TR0=0;
CLOCK[1]=CLOCK[1]+1;
if(CLOCK[1]==60)CLOCK[1]=0;
delay_10ms();
}TR0=1;
break;
case 4:
CLOCK[2]=0;
CLOCK[1]=0;
CLOCK[3]=0;
break;
}
}
}
//子函數(shù)24小時(shí)時(shí)鐘
void timer0(void) interrupt 1 using 1
{
TH0=0xdc;
TL0=0x88;
//時(shí)鐘處理
CLOCK[0]=CLOCK[0]+1;
if (CLOCK[0]==100)
{
CLOCK[0]=0;
CLOCK[1]=CLOCK[1]+1;
if(CLOCK[1]==60)
{
CLOCK[1]=0;
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60)
{
CLOCK[2]=0;
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)
{
CLOCK[3]=0;
}
}
}
}
}
/************外部中斷函數(shù)*****************/
void intflag() interrupt 0
{
int0_flag=1;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -