0% found this document useful (0 votes)
10 views1 page

Doanxem

This C code defines constants for an LED display and input pins. It includes a function to display hours, minutes, seconds on the LEDs by decoding the numeric values and turning on the correct LEDs. The main loop increments the seconds, displays the time, and rolls over the minutes and hours as needed.

Uploaded by

tranchiphong610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Doanxem

This C code defines constants for an LED display and input pins. It includes a function to display hours, minutes, seconds on the LEDs by decoding the numeric values and turning on the correct LEDs. The main loop increments the seconds, displays the time, and rolls over the minutes and hours as needed.

Uploaded by

tranchiphong610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <REGX51.

H>
#define hour P3_6
#define min P3_7
#define led1 P2_0
#define led2 P2_1
#define led3 P2_2
#define led4 P2_3
#define led5 P2_4
#define led6 P2_5
#define on 0
#define off 1

char so[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
void delay_ms(unsigned int x){
unsigned int TGIAN_TRE1;
while(x!=0)
{
TGIAN_TRE1=121;
while(TGIAN_TRE1!=0)
{
TGIAN_TRE1=TGIAN_TRE1-1;
}
x=x-1;
}
}
void hienthi (unsigned char gio, unsigned char phut, unsigned char giay)
{
unsigned char chuc0, chuc1, chuc2, donvi0, donvi1, donvi2 i;
chuc0=gio/10;
donvi0=gio%10;
chuc1=phut/10;
donvi1=phut%10;
chuc2=giay/10;
donvi2=giay%10;
for (i=0;i<17;i++)
{
led1=on; P0=so[chuc0]; delay_ms(10); led1=off;
led2=on; P0=so[donvi0]; delay_ms(10); led2=off;
led3=on; P0=so[chuc1]; delay_ms(10); led3=off;
led4=on; P0=so[donvi1]; delay_ms(10); led4=off;
led5=on; P0=so[chuc2]; delay_ms(10); led5=off;
led6=on; P0=so[donvi2]; delay_ms(10); led6=off;
}
}
void main()
{
unsigned char gio=0, phut=0, giay=0;
while(1)
{
giay++;
hienthi(gio, phut, giay);
if(giay==59) phut++;
if(phut==59) gio++;
if (phut>59) phut=0;
if(gio>23) gio=0;
}
}

You might also like