Home > other >  A (C) makes 51 single-chip electronic clock
A (C) makes 51 single-chip electronic clock

Time:09-30

/* a electronic clock procedures, the electronic clock is composed of four digital tube electronic clock, walking function respectively, ring, take time to adjust, the alarm clock time adjustment function! Adjust part consists of three key implementation respectively, a function key, a + (plus), another for - (minus) keys, other function keys are reusable function! */
Hard key introduction: digital tube bits. 10. One hundred. One thousand. The decimal point respectively by P0.0 P0.1 P0.2 P0.3 P0.4, buzzer P3.5 feet, the key of by P3.2 add key pick P3.3 minus P3.4
Here are two pictures!!!!!!

#include //the header file
# define uchar unsigned char//macro definition
# define uint unsigned int//macro definition
Uchar shi fen, nshi nfen, MAO, ding, ding1, ding3, Yin;//variable definition
Sbit ge=P0 ^ 0;//digital tube bits
Sbit shi4=P0 ^ 1;//digital tube 10
Sbit bai=P0 ^ 2;//digital tube one hundred
Sbit qian=P0 ^ 3;//digital tube one thousand
Sbit dian=P0 ^ 4;//two decimal place
Sbit BBT=P3 ^ 5;
//alarm clock outputSbit key=P3 ^ 2;//function keys defined
Sbit key1=P3 ^ 3;//+ + button definition
Sbit key2=P3 ^ 4;//definition button
Bit a=0;//the time when a user defined
Bit b=0;//callback hours a definition
Bit c=0;//the minute a definition
Bit d=0;//the clock little bit definition
Bit e=0;//callback defined alarm clock minutes
Bit g=0;//main program to define, it controls the display inside the main program subroutine
Uchar code table []={
Xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99,
0 x92, 0 x82, 0 xf8, 0 x80, 0 x90,
Xc6 x88 0, 0 x83, 0, 0 xa1, 0 x86,
0 x8e};//array, namely list
Void key11 ();//this sort of subroutine
Void delay (uint);//declare delay subroutine
Void disy (uchar, uchar);//declaration time display subroutine
Void ndisy (uchar, uchar);//declare callback, display subroutine 1
Void disy1 (uchar);//declare callback always shows hours subroutine
Void disy2 (uchar);//statement adjusted constantly according to molecular program
Void chushi ();//initialization program
Void BBBT ();//alarm subroutine
//////////////main program/////////////////
Void main ()//main program start
{
Chushi ();//initialize
While (1)
//circulation{
If (g!=1)//if g is not equal to 1, is executed next, otherwise, skip the next
Disy (fen, shi);//call when display subroutine
Key11 ();//subroutine call buttons
BBBT ();//call the alarm subroutine
}
}
/////////////button to perform subroutine/////////////
Void key11 ()//key sub function
{

If (a!=0)//if a is not equal to zero, then execute braces statement, otherwise skip
{
Dian=0;//open the middle two decimal point
Delay (10);//delay a moment
Dian=1;//will point to turn off the
Delay (10);//delay for a while, the above is the dynamic display
Disy (fen, shi);//call display subroutine
Delay (4000);//delay, to make it blink
}
If (b!=0)//if b is not equal to zero, then execute braces statement
{
Disy1 (shi);//display subroutine call hours, this program in the previous statement
Delay (2000);//delay, even if it is flashing
If (key1==0)//if there is a press the + button, execute braces content
{
Delay (10);//to shake
If (key1==0)//judgment again
{
Shi++;//will press the hour + 1
Disy1 (shi);//add 1 display subroutine call hours after
Delay (10);//delay a moment
If (shi==24)//if added to 24 for executing the next statement, or skip
Shi=0;//arrive 24 qing 0
}
}
If (key2==0)//if there is a press - button, execute braces content
{
Delay (10);//to jitter
If (key2==0)//reconfirm
{
Shi -;//press will indeed hours minus 1
Disy1 (shi);//call display program
Delay (10);//delay
If (shi==(0-1))//if the hours by the time (0-1), to 23
Shi=23;//to 23
}
}
}
If (c!=0)//if b is not equal to zero, then execute braces statement
{
Disy2 (fen);//call the component display subroutine
Delay (2000);//make it shine
If (key1==0)//whether + buttons have press
{
Delay (10);//delay
If (key1==0)//confirm again press condition
{
Fen++;//will add 1
Disy2 (fen);//call display subroutine
Delay (10);//delay a moment
If (fen==60)//if to about 60, execute the next statement
Fen=00;//clear 0
}
}
If (key2==0)//if the keys pressed the executing the next statement
{
Delay (10);//delay a moment
If (key2==0)//judgment again
{
Fen,;//will reduce 1
Disy2 (fen);//call display subroutine
Delay (10);//delay
If (fen==(0-1))//if the grading in (0-1), then to 59
Fen=59;//to 59
}

}

}
If (d!=0)//if b is not equal to zero, then execute braces statement
{
Ndisy (nshi nfen);//call the alarm clock display program
Delay (2000);//make it flash
If (key1==0)//if the + button pressed the statement execution braces
{
Delay (10);//to shake
If (key1==0)//judgment again
{
Nshi++;//will alarm when add 1
Ndisy (nshi nfen);//call display subroutine
Delay (10);//delay
If (nshi==24)//if 24 is executed under the word
Nshi=0;//to 24, clear 0
}
}
If (key2==0)//if the - button press, is the performance of the brackets
{
Delay (10);//to shake
If (key2==0)//judgment again
{
Nshi -;//since minus 1
Ndisy (nshi nfen);//call display program
Delay (10);//delay
If (nshi==(0-1))//if hours equals (0-1), is executed with the
Nshi=23;//to 23
}
}
}
If (e!=0)//if b is not equal to zero, then execute braces statement
{
Ndisy (nshi nfen);//call display subroutine
Delay (2000);//flashing
If (key1==0)//+ button press?
{
Delay (10);//to shake
If (key1==0)//reconfirm
{
Nfen++;//will add 1
Ndisy (nshi nfen);//call display subroutine
Delay (10);//delay
If (nfen==60)//to 60?
Nfen=00;//clear 0
}
}
If (key2==0)//- have to press the button?
{
Delay (10);//delay
If (key2==0)//reconfirm
{
Nfen -;//points minus 1
Disy (nfen, nshi);//call display
Delay (10);//delay
If (nfen==(0-1))//if the grading in (0-1), are performed with the
Nfen=59;//to 59
}

}
}
}

/////////////alarm clock son subroutine/////////////
Void BBBT ()//alarm subroutine
{
If (ding1==2)//if the counter ding1 arrived two interrupt? Is the performance of the brackets
{
Ding1=0;//clear 0 counter
If (shi==nshi)//walking hours time and alarm time are equal?
{
If (fen==nfen)/walking/minutes time and alarm time are equal?
{
BBT=~ BBT.//will be buzzing, invert, makes it sound
}
}

}
The else
BBT=1;//will be buzzing, turn off the
}

/////////////, anti-fuzzy initial program/////////////
Void chushi anti-fuzzy ()//initial function
{
TMOD=0 x11;//two timers work under way 1
EA=1;//always interrupt
ET0=1;//0 timer interrupt allows
ET1=1;//timer interrupt allow 1
TR0=1;//timer 0
TR1=1;//timer 0
TH0=(65536-50000)/256;//timer 0 high assignment
TL0=(65536-50000)%256;//timer 0 low assignment
TH1=(65536-10000)/256;//timer 1 high assignment
TL1=(65536-10000) % 256;//timer 1 low assignment
Shi=23;//boot hours 23
Fen=59;//boot 59 minutes show
Nshi=12;//boot display alarm clock hour 12
Nfen=00;//boot alarm clock minutes show 00
}

/////////////walking display subroutine/////////////
Void disy (uchar shi, uchar fen)/walking/display subroutine
{
P1=table [10] shi %;//hour bits assignment
Ge=0;//open end in a selected
Delay (5);//delay
General electric (ge)=1; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related