Created
April 24, 2019 16:41
-
-
Save itolosa/f9a4259dc6db1b7ae0b18696216995fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <16F628.h> | |
//defino funciones | |
void calc_day(void); | |
void tick_clock(void); | |
void zeller(void); | |
void check_on(void); | |
void check_off(void); | |
void bell(int); | |
//defino variables | |
char zell=0, seg=0, min=0, hr=8, day=27, month=4; | |
char monthday[]={31,0,31,30,31,30,31,31,30,31,30,31}; | |
int year=2011; | |
//funcion main | |
void main() | |
{ | |
//inicia el calculo del dia | |
calc_day(); | |
//corre el reloj | |
tick_clock(); | |
} | |
void calc_day(void){ | |
//calcula el dia del mes de febrero; util para años bisiestos | |
if(year%400==0||(year%4==0&&year%100!=0)){ | |
monthday[1]=29; | |
} else { | |
monthday[1]=28; | |
} | |
} | |
void tick_clock(void){ | |
//se inicia el reloj perpetuo | |
while(true){ | |
//si el mes es menor a 13, osea 12, sino termina el 'while' | |
while(month<13){ | |
//mientras el dia sea menor al limite de dias que permite el mes | |
while(day<monthday[month-1]){ | |
//inicia el calculo del dia de la semana con el algoritmo de zeller | |
zeller(); | |
//mientras la hora sea menor o igual a 23, osea un maximo de 23:59 | |
while(hr<=23){ | |
//mientras los minutos sean menor a 60 osea 59 min con 59 ms | |
while(min<60){ | |
//mientras los segundos sean menor a 60, osea 5999 ms | |
while(seg<60){ | |
//enciende el timbre si el tiempo es correcto | |
check_on(); | |
delay_ms(1000); | |
seg++; | |
//apaga el timbre si el tiempo es correcto | |
check_off(); | |
} | |
seg=0; | |
min++; | |
} | |
min=0; | |
hr++; | |
} | |
hr=0; | |
day++; | |
} | |
day=1; | |
month++; | |
calc_day(); | |
} | |
month=1; | |
year++; | |
calc_day(); | |
} | |
} | |
void zeller(){ | |
//algoritmo de zeller | |
int a, b, c; | |
if(month<=2) { | |
a=month+10; | |
b=(year-1)%100; | |
c=(year-1)/100; | |
} else { | |
a=month-2; | |
b=year%100; | |
c=year/100; | |
} | |
//calcula el día y lo guarda en la variable zell | |
zell = (700 + (26 * a - 2) / 10 + day + b + b / 4 + c / 4 - 2 * c) % 7; | |
} | |
void check_on(){ | |
//todos los timbres optimizados por 'task' | |
switch(task){ | |
case 1: //entrada y salida | |
if((hr==8&&min==0&&seg==0)||(hr==2&&min==45&&seg==0)){ | |
bell(30); | |
task=2; | |
if((hr==1||hr==6)&&min==0&&seg==0){ | |
task=0; | |
} break; | |
case 2: //timbres recreos | |
if((hr==8||hr==9)&&(min==00&&seg==00)){ | |
bell(30); | |
task=1; | |
} break; | |
case 3: //cambio de hora | |
if((hr==8||hr==9)&&(min==00&&seg==00)){ | |
bell(30); | |
task=2; | |
} break; | |
case 4: //timbre profesores | |
if((hr==8||hr==9)&&(min==00&&seg==00)){ | |
bell(30); | |
task=2; | |
} break; | |
default: | |
//en el caso de que la 'task' sea '0' o cualquier otro numero, esta seccion comprobara si se debe cambiar la 'task' | |
if(zell!=0||zell!=1){ | |
task=1; | |
} break; | |
} | |
} | |
void check_off(){ | |
//revisa si pin_b0 es 'true' y si el tiempo es el adecuado para apagarlo | |
if((input(pin_b0)==1)&&seg==t_off){ | |
output_low(pin_b0); | |
} | |
} | |
void bell(xy){ | |
//declara el tiempo para ser apagado en 't_off' y enciende el 'pin_b0' | |
t_off=xy+seg; | |
output_high(pin_b0); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment