Design of digital clock system based on single chip microcomputer

Publisher:糖果龙猫Latest update time:2022-04-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include 

#define uint unsigned int

#define uchar unsigned char

uchar code table[]={ //Digital tube encoding without decimal point

0xc0,0xf9,0xa4,0xb0,

0x99,0x92,0x82,0xf8,

0x80,0x90};

uchar code table1[]={ //digital tube code with decimal point

0x40,0x79,0x24,0x30,

0x19,0x12,0x02,0x78,

0x00,0x10};

uchar shi=12,second,minute;

uint num,num1,num2,num3;

sbit k1=P1^4;

sbit k2=P1^5;

void display();

void keyscan();

void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

void init()

{

TMOD=0x01;

 

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

EA=1;

ET0=1;

TR0=1;

}

void main()

{

init();

while(1)

{

keyscan();

display();

 

}

}

 

void timer0() interrupt 1

{

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

num++;

if(num==20)

{

num=0;

second++;

if(second==60)

{

second=0;

minute++;

}

if(minute>=60)

{

minute=0;

shi++;

}

if(shi>=24)

shi=0;

}

}

void display()

{

P2=0xdf;

P0=table[second];

delay(2);

P2=0xff;

P2=0xef;

P0=table[second/10];

delay(2);

P2=0xff;

P2=0xf7;

P0=table1[minute];

delay(2);

P2=0xff;

P2=0xfb;

P0=table[minute/10];

delay(2);

P2=0xff;

P2=0xfd;

P0=table1[shi];

delay(2);

P2=0xff;

 

P2=0xfe;

P0=table[shi/10];

delay(2);

P2=0xff;

}

void keyscan()

{

if(k1==0)

{

delay(10);

if(k1==0)

{

shi++;

while(!k1);

}

}

if(k2==0)

{

delay(10);

if(k2==0)

{

minute++;

while(!k2);

}

 

}

 

}


Reference address:Design of digital clock system based on single chip microcomputer

Previous article:Design of timing electric fan based on single chip microcomputer
Next article:Design of high-precision thickness measurement system based on single-chip microcomputer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号