'Probado en la Pic EBasic ******************
Define CONF_WORD = 0x2f50
Define CONF_WORD_2 = 0x3ffd
Define CLOCK_FREQUENCY = 8
'*******
Symbol ledverde = RB0
Symbol ledamarillo = RA7
Const ledon = 0
Const ledoff = 1
'*******
Dim mseg As Word
Dim segundos As Byte
Dim seg_wait As Word
Dim minutos As Byte
Dim horas As Byte
Dim prog_e As Bit
'********
OSCCON = 0x7e 'set intrc To 8mhz, se usara reloj interno a 8Mhz
CMCON = 0x07 'comparador a off
AllDigital
TRISA = 0xff
TRISB = 0xff
TRISB.0 = 0 'Led verde, false
TRISA.7 = 0 'Led amarillo, false
'*******
OPTION_REG.T0CS = 0 'selecciona reloj interno
OPTION_REG.PSA = 0 'asigna el prescales al timer0
OPTION_REG.PS0 = 0 'bits de la seleccion del factor de division,prescaler 128
OPTION_REG.PS1 = 1 'bits de la seleccion del factor de division,prescaler 128
OPTION_REG.PS2 = 1 'bits de la seleccion del factor de division,prescaler 128
'*********
INTCON.TMR0IF = 0 'borra el flag de desbordamiento del timer0
TMR0 = 0xf0 'cargo el registro del tmr0 para que desborde cada 1mS
INTCON.TMR0IE = 1 'habilita las interrupciones del timer0
INTCON.PEIE = 1 'Habilitacion de interrupciones de perifericos
Enable 'INTCON.GIE habilita todas las interrupciones globales
'*******
mseg = 0
segundos = 0
seg_wait = 0
minutos = 0
horas = 0
prog_e = 0
ledverde = ledoff
ledamarillo = ledoff
'********
loop:
'SE CALCULAN LOS SEGUNDOS
If mseg >= 1000 Then
Toggle ledverde 'portb.4
segundos = segundos + 1
seg_wait = seg_wait + 1
mseg = 0
Endif
'SE CALCULAN LOS MINUTOS
If segundos >= 60 Then
minutos = minutos + 1
segundos = 0
Endif
'SE CALCULAN LAS HORAS
If minutos >= 60 Then
horas = horas + 1
minutos = 0
Endif
'SE COMPRUEBA SI HA LLEGADO AL LIMITE
If minutos = 1 And prog_e = 0 Then
mseg = 0
segundos = 0
seg_wait = 0
minutos = 0
horas = 0
ledamarillo = ledon 'portb.5 = 1
prog_e = 1
Endif
'COMPRUEBA SI HA PASADO EL TIEMPO EN ACTIVO
If prog_e = 1 Then
If seg_wait >= 20 Then
ledamarillo = ledoff 'portb.5 = 0
prog_e = 0
seg_wait = 0
'segundos = 0 '/* Si no se pone a cero este tiempo se acumula
'minutos = 0 ' y da la sensación de que se acortan los tiempos en 20seg.
'horas = 0 '*/
Endif
Endif
Goto loop
End
On Interrupt
Save System
mseg = mseg + 1
TMR0 = 0xf0
INTCON.TMR0IF = 0
Resume