VIEW:


Các chức năng của đồng hồ:




Các chức năng của đồng hồ:
Hiển thị thời gian
- Đếm ngược
- Báo thức
- Bấm giờ
Các nút bấm chức năng
S1: Ấn chọn từng 7seg
S2: Thay đổi chức năng đồng hồ
S3: Điều chỉnh

Cài đặt chức năng:
Đặt giờ cho đồng hồ: Ấn S1 môt lần, đồng hồ hiển thị nhấp nháy báo phần tử đang chọn, bấm S2 một lần để thêm 1 giờ, bấm S3 một lần để thêm 1 phút
Chức năng báo thức: Nhấn S1 hai lần, sẽ thấy các số chức năng thay đổi được nhấp nháy. Án S2 một lần để thêm 1 giờ, ấn S3 1 lần để thêm 1 phút. Sẽ tắt báo thức khi giá trị hơn 23h và tắt báo thức sau 3 giây
Cài đặt đếm ngược: bấm S1 ba lần, bạn sẽ thấy các số về không. Bấm S2 để chọn số từ thấp kết thúc ở số cao, sau đó ấn S3 để xác nhận. Nó sẽ bất đầu chạy khi nhấn 6 lần S2.
Bấm giờ: Ấn S1 bốn lần, bạn sẽ thấy đồng hồ hiện  00:00:00, và giữ tại đó, ấn S2 1 lần để bắt đầu bấm giờ và ấn S2 lần nữa để kết thúc bấm giờ, ấn S3 để reset đồng hồ bấm giờ.

Bước 1: Chọn linh kiện: 

1 AT89C2051 U2
2 78L05 U1
3 12MHz Oscillator X3
4  2 digit 7segment display LED1
5 2 digit 7segment display LED2
6  2 digit 7segment display LED3
7 LED D2
8 LED D3
9 LED D4
10 LED D5
11 Buzzer  U7
12 CAP 30pF  C1
13 CAP 30pF C2
14 CAP 0.1uF (104) C3
15 CAP 0.1uF (104) C4
16 CAP 10uF C5
17 CAP 100uF C6
18 PNP 9012 Q1
19 PNP 9012 Q2
20 PNP 9012 Q3
21 PNP 9012 Q4
22 PNP 9012 Q5
23 PNP 9012 Q6
24 PNP 9012 Q7
25 Button S1
26 Button S2
27 BUTTON S3
28 Resistor 220 Ohm R1
29 Resistor 220 Ohm R2
30 Resistor 220 Ohm R3
31 Resistor 220 Ohm R4
32 Resistor 220 Ohm R5
33 Resistor 220 Ohm R10
34 Resistor 220 Ohm R11
35 Resistor 1K Ohm R12
36 Resistor 1K Ohm R13
37 Resistor 1K Ohm R14
38 Resistor 1K Ohm R15
39 Resistor 1K Ohm R16
40 Resistor 1K Ohm R17
41 Resistor 1K Ohm R18
42 Resistor 5.1K Ohm R19
43 Resistor 2K Ohm R7
44 Resistor 2K Ohm R8
45 Resistor 10K Ohm R6
46 2 pin connector J1
47 2 pin connector J2
48 2 pin connector J3
49 20pin DIP socket  -
50 PCB 50mmx105mm  -

Bước 2: Sơ đồ mạch:  



Bước 3: Code C cho mạch: 


#include<REG2051.H>
code senen_seg[10]={0x81,0xe7,0x92,0xa2,0xe4,0xa8,0x88,0xe3,0x80,0xa0};
bit key1_enter=0,key2_enter=0,key3_enter=0,countdown_mark=0,stopwatch_mark=0,count_mark=0,bell_mark=0;
unsigned char program=0,program_variable=0,count_bit=0,count=0;
unsigned char hour=10,minute=10,second=0;
unsigned char delayed_hour=22,delayed_minute=10,delayed_second=0;
unsigned char count_hour=0,count_minute=0,count_second=0;
unsigned int count_time=0,count_count=0;
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
;
}
void time0_init(void){
EA=0;
TR0=0;
TMOD=0x02;
TH0=0x4;
TL0=0x4;
ET0=1;
TR0=1;
EA=1;
}

static void timer0_isr(void) interrupt TF0_VECTOR using 1
{
count_time++;
if(count_time>=4020){
count_time=0;
second++;
if(second>=60){
second=0;
minute++;
if(minute>=60){
minute=0;
hour++;
if(hour>=24)hour=0;
}
}
}
if(delayed_hour==hour && delayed_minute==minute && second<4) P3_7=0;
else P3_7=1;
if(countdown_mark==1){
count_count++;
if(count_count>=4000 && (count_second!=0|count_minute!=0|count_hour!=0)){
count_count=0;
count_second--;
if(count_second>=60){
count_second=59;
count_minute--;
if(count_minute>=60){
count_minute=59;
count_hour--;
if(count_hour>=100) count_hour=99;
}
}
}
if(count_second==0&&count_minute==0&&count_hour==0&&count_count<=12000) P3_7=0;
else P3_7=1;
if(count_count>=15000) count_count=14000;
}
if(stopwatch_mark==1){ count_count++;
if(count_count>=40){
count_count=0;
count_second++;
if(count_second>=100){
count_second=0;
count_minute++;
if(count_minute>=60){
count_minute=0;
count_hour++;
if(count_hour>=60) count_hour=0;
}
}
}
}
}
unsigned char show_key (void){
unsigned char x=0,y=0;
switch (program){
case 0: P1&=senen_seg[second%10];
break;
case 1: if(count_time>=2000) P1&=senen_seg[second%10];
break;
case 2: if(delayed_hour==24) P1=0xfe;
else P1&=senen_seg[delayed_second%10];
break;
case 3: if(count_bit>=0) P1&=senen_seg[count_second%10];
else P1=0xff;
break;
case 4: P1&=senen_seg[count_second%10];
break;
case 5: P1&=senen_seg[count_second%10];
break;
}
P3_3=0;
delay(10);
if(P3_5==0){
key1_enter=1;
if(count<=254)count++;
}
if(P3_4==0) key2_enter=1;
if(P3_2==0) key3_enter=1;
P3_3=1;
P1|=0xff;
switch (program){
case 0: P1&=senen_seg[second/10];
break;
case 1: if(count_time>=2000) P1&=senen_seg[second/10];
break;
case 2: if(delayed_hour==24) P1=0xfe;
else P1&=senen_seg[delayed_second/10];
break;
case 3: if(count_bit>=1) P1&=senen_seg[count_second/10];
else P1=0xff;
break;
case 4: P1&=senen_seg[count_second/10];
break;
case 5: P1&=senen_seg[count_second/10];
break;
}
P3_1=0;
delay(10);
P3_1=1;
P1|=0xff;
switch (program){
case 0: P1&=senen_seg[minute%10];
break;
case 1: if(count_time>=2000) P1&=senen_seg[minute%10];
break;
case 2: if(delayed_hour==24) P1=0xfe;
else P1&=senen_seg[delayed_minute%10];
break;
case 3: if(count_bit>=2) P1&=senen_seg[count_minute%10];
else P1=0xff;
break;
case 4: P1&=senen_seg[count_minute%10];
break;
case 5: P1&=senen_seg[count_minute%10];
break;
}
P3_2=0;
delay(10);
P3_2=1;
P1|=0xff;
switch (program){
case 0: P1&=senen_seg[minute/10];
break;
case 1: if(count_time>=2000) P1&=senen_seg[minute/10];
break;
case 2: if(delayed_hour==24) P1=0xfe;
else P1&=senen_seg[delayed_minute/10];
break;
case 3: if(count_bit>=3) P1&=senen_seg[count_minute/10];
else P1=0xff;
break;
case 4: P1&=senen_seg[count_minute/10];
break;
case 5: P1&=senen_seg[count_minute/10];
break;
}
P3_5=0;
delay(10);
P3_5=1;
P1|=0xff;
switch (program){
case 0: P1&=senen_seg[hour%10];
break;
case 1: if(count_time>=2000) P1&=senen_seg[hour%10];
break;
case 2: if(delayed_hour==24) P1=0xfe;
else P1&=senen_seg[delayed_hour%10];
break;
case 3: if(count_bit>=4) P1&=senen_seg[count_hour%10];
else P1=0xff;
break;
case 4: P1&=senen_seg[count_hour%10]; break;
case 5: P1&=senen_seg[count_hour%10];
break;
}
P3_0=0;
delay(10);
if(P3_4==1 && key2_enter==1){
x=3; key2_enter=0;
}
P3_0=1;
P1|=0xff;
switch (program){
case 0: P1&=senen_seg[hour/10]; break;
case 1: if(count_time>=2000) P1&=senen_seg[hour/10]; break;
case 2: if(delayed_hour==24) P1=0xfe; else P1&=senen_seg[delayed_hour/10];
break;
case 3: if(count_bit>=5)P1&=senen_seg[count_hour/10]; else P1=0xff;
break;
case 4: P1&=senen_seg[count_hour/10];
break;
case 5: P1&=senen_seg[count_hour/10]; break;
}
P3_4=0;
delay(10);
if(P3_5==1 && key1_enter==1){
if(count>=127) x=1; else x=2; key1_enter=0;
count=0;
}
if(P3_2==1 && key3_enter==1){
x=4;
key3_enter=0;
}
P3_4=1;
P1|=0xff;
if(program<=1 && count_time>=2000) P1&=0xff;
if(program<=1 && count_time<=2000) P1&=0x7f;
if(program==2) P1&=0x7f;
if(program==3) P1&=0xff;
if(program==4) P1&=0x7f;
if(program==5) P1&=0xff;
y=x;
x=0;
return y;
}
void main(){
P1=0xff;
P3=0xff;
time0_init();
while(1){
switch(program){
case 0: while(program==0){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=1;
break;
}
}
break;
case 1: while(program==1){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=2;
break;
case 3: hour++;
if(hour>=24)hour=0;
break;
case 4: minute++;
if(minute>=60)minute=0;
break;
}
}
break;
case 2: while(program==2){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=3;
break;
case 3: delayed_hour++;
if(delayed_hour>=25)delayed_hour=0;
break;
case 4: delayed_minute++;
if(delayed_minute>=60)delayed_minute=0;
break;
}
}
break;
case 3: while(program==3){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=4;
break;
case 3: count_bit++;
if(count_bit>=7)count_bit=0;
break;
case 4: switch(count_bit){
case 0: count_second+=1;
break;
case 1: count_second+=10;
break;
case 2: count_minute+=1;
break;
case 3: count_minute+=10;
break;
case 4: count_hour+=1;
break;
case 5: count_hour+=10;
break;
case 6: break;
}
if(count_hour>=100) count_hour-=100;
if(count_minute>=60) count_minute-=60;
if(count_second>=60) count_second-=60;
break;
}
if(count_bit==6) countdown_mark=1;
else countdown_mark=0;
}
break;
case 4: count_hour=0;
count_minute=0;
count_second=0;
while(program==4){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=5;
break;
case 3: stopwatch_mark=~stopwatch_mark;
break;
case 4: if(stopwatch_mark==0){
count_hour=0;
count_minute=0;
count_second=0;
}
break;
}
}
break;
case 5: count_hour=0;
count_minute=0;
count_second=0;
while(program==5){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=0;
break;
case 3: count_second++;
if(count_second>=100){
count_second=0;
count_minute++;
if(count_minute>=100){
count_minute=0;
count_hour++;
if(count_hour>=100)count_hour=0;
}
}
break;
case 4: count_hour=0;
count_minute=0;
count_second=0;
break;
}
if(P3_7==0){
while(P3_7==0) show_key();
count_second++;
if(count_second>=100){
count_second=0;
count_minute++;
if(count_minute>=100){
count_minute=0;



0 nhận xét Blogger 0

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click vào icon để xem code!
Để chèn biểu tượng cảm xúc, bạn cần để code sau một khoảng trắng.

 
ThangShare © 2016. All Rights Reserved. Design by: Thắng BME - Sitemap
Top