基于AT89C51的電子時(shí)鐘
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit MG=P1^0;
sbit MS=P1^1;
sbit MM=P1^2;
sbit HG=P1^3;
sbit HS=P1^4;
sbit SD=P1^5;
bit shan;
code uchar NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar sec,min,hour;
uchar hour1;
void delay(uint a)
{
while(a--);
}
void init0 ()
{
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
TR0=1;
EA=1;
ET0=1;
}
void display_time()
{
P0=NUM[min%10];
MG=1;
delay(300);
P1=0x00;
#include
#define uchar unsigned char
#define uint unsigned int
sbit MG=P1^0;
sbit MS=P1^1;
sbit MM=P1^2;
sbit HG=P1^3;
sbit HS=P1^4;
sbit SD=P1^5;
bit shan;
code uchar NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar sec,min,hour;
uchar hour1;
void delay(uint a)
{
while(a--);
}
void init0 ()
{
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
TR0=1;
EA=1;
ET0=1;
}
void display_time()
{
P0=NUM[min%10];
MG=1;
delay(300);
P1=0x00;
P0=NUM[min/10];
MS=1;
delay(300);
P1=0x00;
MS=1;
delay(300);
P1=0x00;
P0=0xbf;
MM=shan;
delay(300);
P1=0x00;
if(hour>12)
{
hour1=hour-12;
}
else
{
hour1=hour;
}
MM=shan;
delay(300);
P1=0x00;
if(hour>12)
{
hour1=hour-12;
}
else
{
hour1=hour;
}
P0=NUM[hour1%10];
HG=1;
delay(300);
P1=0x00;
HG=1;
delay(300);
P1=0x00;
P0=NUM[hour1/10];
HS=1;
delay(300);
P1=0x00;
HS=1;
delay(300);
P1=0x00;
if(hour>=12)
{
P0=0x8c;
SD=1;
delay(300) ;
P1=0x00;
}
{
P0=0x8c;
SD=1;
delay(300) ;
P1=0x00;
}
else
{
P0=0x88;
SD=1;
delay(300);
P1=0x00;
}
}
void FT()
{
while(P3==0xfe)
display_time();
sec=0;
min++;
if(min==60)
min=0;
}
void ST()
{
while(P3==0xfd)
display_time();
hour++;
if(hour==24)
hour=0;
}
main()
{
init0();
hour=1;
while(1)
{
display_time();
if(P3==0xfe) FT();
if(P3==0xfd) ST();
}
}
{
P0=0x88;
SD=1;
delay(300);
P1=0x00;
}
}
void FT()
{
while(P3==0xfe)
display_time();
sec=0;
min++;
if(min==60)
min=0;
}
void ST()
{
while(P3==0xfd)
display_time();
hour++;
if(hour==24)
hour=0;
}
main()
{
init0();
hour=1;
while(1)
{
display_time();
if(P3==0xfe) FT();
if(P3==0xfd) ST();
}
}
關(guān)鍵詞:
AT89C51電子時(shí)
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論