Вы находитесь на странице: 1из 6

D.R.L.

RELOJ - ALARMA CON LCD

CÓDIGO FUENTE DEL PROGRAMA DE PRUEBA.


'Reloj digital con horas, minutos y segundos mostrado en LCD
AllDigital
TRISB = 0
TRISC = 0
TRISA = 255
TRISD = 0

'configuracion del timer para interrupciones cada 0,01seg


INTCON = 0x00
INTCON.GIE = True 'habilitacion general de interrupcioes
INTCON.T0IE = True 'habilita la interrupcion timer 0
TMR0 = 100 'se carga al tmr0 100
OPTION_REG = 0x00
OPTION_REG = %11010101
'-----------------------
'configuraciòn del LCD
Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTC
Define LCD_RWBIT = 1
Define LCD_EREG = PORTC
Define LCD_EBIT = 2
D.R.L.

Define LCD_COMMANDUS = 3000


Define LCD_DATAUS = 50
Define LCD_INITMS = 10
Lcdinit
'-----------------------
Dim segundos As Byte
segundos = 0
Dim minutos As Byte
minutos = 0
Dim horas As Byte
horas = 12

Dim segundos_al As Byte


segundos_al = 0
Dim minutos_al As Byte
minutos_al = 0
Dim horas_al As Byte
horas_al = 0

Dim flanco_seg As Bit


flanco_seg = 0
Dim flanco_min As Bit
flanco_min = 0
Dim flanco_horas As Bit
flanco_horas = 0
Dim flanco_al As Bit
flanco_al = 0

Symbol ajustar = PORTA.1


Symbol aj_horas = PORTA.2
Symbol aj_minutos = PORTA.3
Symbol aj_segundos = PORTA.4
Symbol parar_alarma = PORTE.0
Symbol alarma = PORTD.0

Dim conti As Byte


conti = 0

Dim control_seg As Bit


control_seg = 0

PORTD = 0

inicio:
Gosub tiempo
Gosub mostrar
Gosub ajustar_tiempo
Gosub comparar
Gosub resetear
D.R.L.

Goto inicio
End

tiempo:
If control_seg = True Then
control_seg = False

If segundos < 59 Then


segundos = segundos + 1
Else
segundos = 0
If minutos < 59 Then
minutos = minutos + 1
Else
minutos = 0
If horas < 23 Then
horas = horas + 1
Else
horas = 0
Endif
Endif
Endif
Endif
Return

mostrar:
Lcdcmdout LcdClear
Lcdout "Hora ", #horas, ":", #minutos, ":", #segundos
Lcdcmdout LcdLine2Home
Lcdout "Alarma ", #horas_al, ":", #minutos_al, ":", #segundos_al
WaitMs 50
Return

ajustar_tiempo:
If ajustar = True Then
If aj_segundos = True Then

If flanco_seg = 0 Then
flanco_seg = 1
If segundos < 59 Then
segundos = segundos + 1
Else
segundos = 0
Endif
Endif
Else
flanco_seg = 0
Endif

If aj_minutos = True Then


D.R.L.

If flanco_min = 0 Then
flanco_min = 1
If minutos < 59 Then
minutos = minutos + 1
Else
minutos = 0
Endif
Endif
Else
flanco_min = 0
Endif

If aj_horas = True Then

If flanco_horas = 0 Then
flanco_horas = 1
If horas < 23 Then
horas = horas + 1
Else
horas = 0
Endif
Endif
Else
flanco_horas = 0
Endif
Else
If aj_segundos = True Then

If flanco_seg = 0 Then
flanco_seg = 1
If segundos_al < 59 Then
segundos_al = segundos_al + 1
Else
segundos_al = 0
Endif
Endif
Else
flanco_seg = 0
Endif

If aj_minutos = True Then

If flanco_min = 0 Then
flanco_min = 1
If minutos_al < 59 Then
minutos_al = minutos_al + 1
Else
minutos_al = 0
Endif
D.R.L.

Endif
Else
flanco_min = 0
Endif

If aj_horas = True Then

If flanco_horas = 0 Then
flanco_horas = 1
If horas_al < 23 Then
horas_al = horas_al + 1
Else
horas_al = 0
Endif
Endif
Else
flanco_horas = 0
Endif
Endif
Return

comparar:
If horas = horas_al Then
If minutos = minutos_al Then
If segundos = segundos_al Then
alarma = True
Endif
Endif
Endif
Return

resetear:
If parar_alarma = 1 Then
If flanco_al = 0 Then
flanco_al = 1
alarma = False
Endif
Else
flanco_al = 0
Endif
Return

On Interrupt

If INTCON.T0IF = True Then


INTCON.T0IF = False
TMR0 = 100
conti = conti + 1
If conti = 100 Then
control_seg = True
D.R.L.

conti = 0
Endif
Endif
Resume

Вам также может понравиться