Paso 3: Una muestra del código fuente (lenguaje C)
#include < REG2051. H >código senen_seg [10] = {0x81, 0xe7, 0x92, 0xa2, 0xe4, 0xa8, 0x88, 0xe3, 0 x 80, 0xa0};
bit key1_enter = 0, key2_enter = 0, key3_enter = 0, countdown_mark = 0, stopwatch_mark = 0, count_mark = 0, bell_mark = 0;
Programa char sin signo = 0, program_variable = 0, count_bit = 0, cuenta = 0;
hora de unsigned char = 10, minutos = 10, segundo = 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;
retardo de vacío (unsigned int t)
{
unsigned int i, j;
para (i = 0; i < t; i ++)
para (j = 0; j < 10; j ++)
;
}
void time0_init(void) {}
EA = 0;
TR0 = 0;
TMOD = 0 X 02;
TH0 = 0X4;
TL0 = 0X4;
ET0 = 1;
TR0 = 1;
EA = 1;
}
Static void timer0_isr(void) interrupción TF0_VECTOR con 1
{
count_time ++;
Si (count_time > = 4020) {}
count_time = 0;
segundo ++;
Si (segundo > = 60) {}
segundo = 0;
minuto ++;
Si (minuto > = 60) {}
minuto = 0;
hora ++;
Si (hora > = 24) hora = 0;
}
}
}
Si (delayed_hour == hora & & delayed_minute == minuto & & segundo < 4) P3_7 = 0;
Else P3_7 = 1;
{if(countdown_mark==1)}
count_count ++;
Si (count_count > = 4000 & & (count_second! = 0|count_minute! = 0|count_hour! = 0)) {}
count_count = 0;
count_second--;
Si (count_second > = 60) {}
count_second = 59;
count_minute--;
Si (count_minute > = 60) {}
count_minute = 59;
count_hour--;
Si (count_hour > = 100) count_hour = 99;
}
}
}
Si (count_second == 0 & & count_minute == 0 & & count_hour == 0 & & count_count < = 12000) P3_7 = 0;
Else P3_7 = 1;
Si (count_count > = 15000) count_count = 14000;
}
if(stopwatch_mark==1) {count_count ++;
Si (count_count > = 40) {}
count_count = 0;
count_second ++;
Si (count_second > = 100) {}
count_second = 0;
count_minute ++;
Si (count_minute > = 60) {}
count_minute = 0;
count_hour ++;
Si (count_hour > = 60) count_hour = 0;
}
}
}
}
}
unsigned char show_key (void) {}
sin firmar char x = 0, y = 0;
interruptor (programa) {}
caso 0: P1 & = senen_seg [segunda % 10];
rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [segunda % 10];
rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe;
persona P1 & = senen_seg [delayed_second % 10];
rotura;
caso 3: Si (count_bit > = 0) P1 & = senen_seg [count_second % 10];
persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_second % 10];
rotura;
caso 5: P1 & = senen_seg [count_second % 10];
rotura;
}
P3_3 = 0;
Delay(10);
{if(P3_5==0)}
key1_enter = 1;
Si (cuenta < = 254) count ++;
}
if(P3_4==0) key2_enter = 1;
if(P3_2==0) key3_enter = 1;
P3_3 = 1;
P1| = 0XFF;
interruptor (programa) {}
caso 0: P1 & = senen_seg [segundo/10];
rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [segundo/10];
rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe;
persona P1 & = senen_seg [delayed_second/10];
rotura;
caso 3: Si (count_bit > = 1) P1 & = senen_seg [count_second/10];
persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_second/10];
rotura;
caso 5: P1 & = senen_seg [count_second/10];
rotura;
}
P3_1 = 0;
Delay(10);
P3_1 = 1;
P1| = 0XFF;
interruptor (programa) {}
caso 0: P1 & = senen_seg [minuto % 10];
rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [minuto % 10];
rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe;
persona P1 & = senen_seg [delayed_minute % 10];
rotura;
caso 3: Si (count_bit > = 2) P1 & = senen_seg [count_minute % 10];
persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_minute % 10];
rotura;
caso 5: P1 & = senen_seg [count_minute % 10];
rotura;
}
P3_2 = 0;
Delay(10);
P3_2 = 1;
P1| = 0XFF;
interruptor (programa) {}
caso 0: P1 & = senen_seg [minuto/10];
rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [minuto/10];
rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe;
persona P1 & = senen_seg [delayed_minute/10];
rotura;
caso 3: Si (count_bit > = 3) P1 & = senen_seg [count_minute/10];
persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_minute/10];
rotura;
caso 5: P1 & = senen_seg [count_minute/10];
rotura;
}
P3_5 = 0;
Delay(10);
P3_5 = 1;
P1| = 0XFF;
interruptor (programa) {}
caso 0: P1 & = senen_seg [hora % 10];
rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [hora % 10];
rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe;
persona P1 & = senen_seg [delayed_hour % 10];
rotura;
caso 3: Si (count_bit > = 4) P1 & = senen_seg [count_hour % 10];
persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_hour % 10]; rotura;
caso 5: P1 & = senen_seg [count_hour % 10];
rotura;
}
P3_0 = 0;
Delay(10);
Si (P3_4 == 1 & & key2_enter == 1) {}
x = 3; key2_enter = 0;
}
P3_0 = 1;
P1| = 0XFF;
interruptor (programa) {}
caso 0: P1 & = senen_seg [horas/10]; rotura;
caso 1: Si (count_time > = 2000) P1 & = senen_seg [horas/10]; rotura;
caso 2: if(delayed_hour==24) P1 = 0xfe; persona P1 & = senen_seg [delayed_hour/10];
rotura;
caso 3: Si (count_bit > = 5) P1 & = senen_seg [count_hour/10]; persona P1 = 0xff;
rotura;
caso 4: P1 & = senen_seg [count_hour/10];
rotura;
caso 5: P1 & = senen_seg [count_hour/10]; rotura;
}
P3_4 = 0;
Delay(10);
Si (P3_5 == 1 & & key1_enter == 1) {}
Si (cuenta > = 127) x = 1; Else x = 2; key1_enter = 0;
cuenta = 0;
}
Si (P3_2 == 1 & & key3_enter == 1) {}
x = 4;
key3_enter = 0;
}
P3_4 = 1;
P1| = 0XFF;
Si (programa < = 1 & & count_time > = 2000) P1 & = 0xff;
Si (programa < = 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;
volver y;
}
void main() {}
P1 = 0XFF;
P3 = 0XFF;
time0_init();
{while(1)}
{Switch(Program)}
caso 0: {while(program==0)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 1;
rotura;
}
}
rotura;
caso 1: {while(program==1)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 2;
rotura;
caso 3: hora ++;
Si (hora > = 24) hora = 0;
rotura;
caso 4: minuto ++;
Si (minuto > = 60) minuto = 0;
rotura;
}
}
rotura;
caso 2: {while(program==2)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 3;
rotura;
caso 3: delayed_hour ++;
Si (delayed_hour > = 25) delayed_hour = 0;
rotura;
caso 4: delayed_minute ++;
Si (delayed_minute > = 60) delayed_minute = 0;
rotura;
}
}
rotura;
caso 3: {while(program==3)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 4;
rotura;
caso 3: count_bit ++;
Si (count_bit > = 7) count_bit = 0;
rotura;
caso 4: {switch(count_bit)}
caso 0: count_second += 1;
rotura;
caso 1: count_second += 10;
rotura;
caso 2: count_minute += 1;
rotura;
caso 3: count_minute += 10;
rotura;
caso 4: count_hour += 1;
rotura;
caso 5: count_hour += 10;
rotura;
caso 6: romper;
}
Si (count_hour > = 100) count_hour-= 100;
Si (count_minute > = 60) count_minute-= 60;
Si (count_second > = 60) count_second-= 60;
rotura;
}
if(count_bit==6) countdown_mark = 1;
Else countdown_mark = 0;
}
rotura;
caso 4: count_hour = 0;
count_minute = 0;
count_second = 0;
{while(Program==4)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 5;
rotura;
caso 3: stopwatch_mark = ~ stopwatch_mark;
rotura;
caso 4: {if(stopwatch_mark==0)}
count_hour = 0;
count_minute = 0;
count_second = 0;
}
rotura;
}
}
rotura;
caso 5: count_hour = 0;
count_minute = 0;
count_second = 0;
{while(Program==5)}
{Switch(show_key())}
caso 0: romper;
caso 1: programa = 0;
rotura;
caso 2: programa = 0;
rotura;
caso 3: count_second ++;
Si (count_second > = 100) {}
count_second = 0;
count_minute ++;
Si (count_minute > = 100) {}
count_minute = 0;
count_hour ++;
Si (count_hour > = 100) count_hour = 0;
}
}
rotura;
caso 4: count_hour = 0;
count_minute = 0;
count_second = 0;
rotura;
}
{if(P3_7==0)}
show_key() de while(P3_7==0);
count_second ++;
Si (count_second > = 100) {}
count_second = 0;
count_minute ++;
Si (count_minute > = 100) {}
count_minute = 0;