'****************************************************************
'* Name : Persiana.BAS *
'* Author : Max Eduardo Reyes Vera Juárez *
'* Notice : Copyright (c) 2008 Protegido por leyes de autor *
'* : All Rights Reserved *
'* Date : 03/01/2008 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
device = 16f88
ansel = 0 ' Salidas Digitales
osctune = 0 ' Frecuencia Media
osccon = 126 ' %01111110 Oscilador Interno a 8MHZ
trisb = %00001100
trisa = %00100000
CLEAR PORTA
CLEAR PORTB
declare lcd_type alpha
declare lcd_interface 4 ' LCD a 4 Bits
declare lcd_lines 2 ' LCD 2 Filas
DECLARE LCD_DTPIN PORTB.4 ' PORTB4-7 Salidas del LCD
DECLARE LCD_ENPIN porta.2 ' RA6 Pin E LCD
declare lcd_rspin porta.3 ' RA7 PIN RS LCD
declare sda_pin porta.0 ' PIN SDA I2C RTC
declare scl_pin porta.1 ' Pin SCL I2C RTC
declare slow_bus true ' Bus Lento para I2C
symbol ctrl = 1 ' Constante para el flasheo de 1 segundo
dim ssec as byte ' Variables para la configuracion del RTC
dim smin as byte
dim shor as byte
dim swek as byte
dim smon as byte
dim sday as byte
dim sano as byte
dim rsec as byte
dim rmin as byte
dim rhor as byte
dim rwek as byte
dim rmon as byte
dim rday as byte
dim rano as byte
dim d2hex as byte
dim lsb as byte
dim msb as byte
dim i as byte ' Variable comodin
dim bt1 as portb.3 ' Botones de Configuracion
dim okk as portb.2
dim cfg as porta.4
dim izq as portb.1 ' Salidas a L293D
dim der as portb.0
delayms 1000 ' Pausa para LCD
If cfg=1 then
gosub ConfRTC
else
Gosub NormalOP
endif
ConfRTC:
shor=0
smin=0
ssec=0
sday=0
smon=0
sano=0
h:
print $FE,1, " Ingrese Hora"
print $FE,$C0, dec shor, " Hora"
if bt1=1 then ' Ingresamos Hora
gosub pausa
if bt1=1 then
shor=shor+1
print $FE,$C0, dec shor, " Hora"
endif
endif
IF SHOR>23 THEN SHOR=0 ENDIF
if okk=1 then
D2HEX=shor
gosub dec2hex
SHOR=d2hex
gosub save
goto m
endif
gosub P2
goto h
m:
print $FE,1, "Ingrese minutos"
print $FE,$C0, dec smin, " mins"
if bt1=1 then ' Ingresamos Minutos
gosub pausa
if bt1=1 then
smin=smin+1
print $FE,$C0, dec smin, " mins"
endif
endif
IF SMIN>59 THEN SMIN=0 ENDIF
if okk=1 then
D2HEX=sMIN
gosub dec2hex
SMIN=d2hex
gosub save
goto S1
endif
gosub P2
goto m
S1:
print $FE,1, "Ingrese Segundos"
print $FE,$C0, dec ssec, " segs"
if bt1=1 then ' Ingresamos Segundos
gosub pausa
if bt1=1 then
ssec=ssec+1
print $FE,$C0, dec ssec, " segs"
endif
endif
IF SSEC>59 THEN SSEC=0 ENDIF
if okk=1 then
D2HEX=sSEC
gosub dec2hex
SSEC=d2hex
gosub save
gosub d1
endif
gosub p2
GOSUB S1
d1:
print $FE,1, "Ingrese Dia"
print $FE,$C0, dec sday
if bt1=1 then ' Ingresamos Dia
gosub pausa
if bt1=1 then
sday=sday+1
print $FE,$C0, dec sday
endif
endif
IF Sday>31 THEN Sday=1 ENDIF
if okk=1 then
D2HEX=sday
gosub dec2hex
Sday=d2hex
gosub save
gosub m1
endif
gosub p2
GOSUB d1
m1:
print $FE,1, "Ingrese mes"
print $FE,$C0, dec smon
if bt1=1 then ' Ingresamos Mes
gosub pausa
if bt1=1 then
smon=smon+1
print $FE,$C0, dec smon
endif
endif
IF Smon>12 THEN Smon=1 ENDIF
if okk=1 then
D2HEX=smon
gosub dec2hex
Smon=d2hex
gosub save
gosub w1
endif
gosub p2
GOSUB m1
w1:
print $FE,1, "Ingrese Año"
print $FE,$C0, dec sano
if bt1=1 then ' Ingresamos Año
gosub pausa
if bt1=1 then
sano=sano+1
print $FE,$C0, dec sano
endif
endif
IF Sano>99 THEN Sano=0 ENDIF
if okk=1 then
D2HEX=sano
gosub dec2hex
Sano=d2hex
gosub save
gosub writertc
endif
gosub p2
GOSUB w1
WriteRTC: '*************Escribimos el RTC*******************
busout $D0,$00,[ ssec, smin, shor,swek, sday, smon, sano,ctrl]
print $FE,1, "Configurando..."
delayms 750
Date:
Print $FE,1, " Hora/Fecha ok? "
busin $D0,$00,[rsec,rmin,rhor,rwek,rday,rmon,rano]
' Fecha y Hora OK? si NormalOP no repetimos configuracion
print $FE,$C0, hex rhor,":", hex RMIN,":", hex RSEC
gosub Pausa
if okk=1 then NormalOP
if bt1=1 then confrtc
goto date
Save:
Print $FE,1, "Guardado" ' subrutina de msj guardado
delayms 750
return
Pausa: ' pausa 50mS
delayms 50
return
P2: ' Pausa 300mS
delayms 300
return
Dec2Hex:
lsb=d2hex//10 'obtener lsb
msb=d2hex/10 'obtener msb
d2hex=msb*16 'convertir msb a bcd
d2hex=d2hex+lsb 'juntar msb hex y lsb
return
NormalOP:
busin $D0,$00,[rsec,rmin,rhor,rwek,rday,rmon,rano]
print $FE,1, shex2 rhor,":", shex2 RMIN,":", shex2 RSEC
print $FE,$C3, shex2 rday,"/", shex2 rmon,"/20", shex2 Rano
IF RHOR=$03 AND RMIN=$06 AND RSEC=$10 THEN
GOSUB BLINK
ENDIF
delayms 100
goto normalop
BLINK:
FOR I=0 TO 10
HIGH PORTB.0:HIGH PORTB.1
GOSUB P2
LOW PORTB.0: LOW PORTB.1
GOSUB P2
NEXT
RETURN