Código:
DEVICE 16F877
ON INTERRUPT GOTO actrb0 'Enable software interrupts,
'and point to interrupt handler
INTCON = %11010010 'Se habililta a GIE ,PEIE Y INTF
pie1=%00000010 'se habilita TMR2IF (flag de interr. de RB2)
DECLARE XTAL=4
'****************************************************************
'DEFINOICION PARA EL LCD
'******************************************************
declare lCD_DTPIN = PORTd.4 'PARA 4 LINEAS DE DATOS EN EL LCD
declare LCD_RSPIN = PORTb.2 'asigna portd.2 a RS
declare LCD_ENPIN = PORTb.1 'Asigna portd.3 a E
declare LCD_LINES = 2 'LCD de dos filas
declare LCD_INTERFACE = 4 'un bus de 4 líneas
declare LCD_TYPE =0
'******************************************************
' DEFINICION de las variables
****************************************************************
dim n as word
dim ini as bit
dim rmin as byte
dim rseg as byte
dim ovflow as BYTE
dim rmin0 as byte
dim i as byte
dim sel As byte
dim k as bit
dim sw as bit
'****************************************************************
'CONDICIONES INICIALES
'****************************************************************
trisb=%00000001
trisc=%11110000
TRISd=%00001111
option_reg=%11000111
PR2=250 'Genera 1000 p/s con un cristal de 4Mhz
t2con=01010110 'se trbaja con TMR2, , prescalesr=16, postscaler=011
rmin=0
rseg=0
ovfLOw=0
rmin0=0
n=6 'periodo de un semiciclo en useg
i=1
ini=0
PORTB=%00000000
sel=1
sw=0
k=0
INTCON.1=0
'****************************************************************
'rutina que conrola el tiempo de encendido
'****************************************************************
ret1: call lee_tem
PRINT AT 1,1,"V=",DEC N," ","TPO=",dec I," "
if portC.7=0 then goto RET1 'pregunata si se pulso ini
ini=1 'se inicia el proceso
Print $fe,1 'borra pantalla
sigue: if pir1.1 =1 then call cont2
if portD.2=1 then n=n+1 'n controla el instante de disparo del TRIAC
aa: if portD.2=1 then goto aa
IF N>6 THEN n=0
if portD.3=1 then n=n-1 'n conrola el instante de disparo del TRIAC
bb: if portD.3=1 then goto bb
IF N<1 THEN n=6
pr2=250
goto sigue
disable
'****************************************************************
'rutina que atiende el pulso de referencia que entra por RB0
'****************************************************************
actrb0:
INTCON.1=0 'se desactiva los flags de intrrupciones
IF Portb.0=0 then goto sale1
if ini=0 then goto sale1
delayms n 'retarda el disparo del TRIAC n mSeg
portB=%10100000
delayus 500 'con una ancho de pulso de 500 uSeg
portB=%00000000
ENDIF
sale1: intcon=%11010010 'se activa los flags de interrupciones
RESUME ' salir de la rutina
ENABLE
return
'*******'****************************************************************
'cont2 'rutina que activa al cont2
'*******'*********************************************************
cont2: 'activa el idicador
PIR1.1=0 'desactiva el flag de TMR2
if ini=0 then goto sale2
ovflow=ovflow+1
if ovflow=2 then goto uno 'controla el reloj
PRINT AT 1,1,"V=",DEC N," ","TPO=",dec I," ","SEL=",DEC sel
print at 2,1,"min=",dec rmin," ","seg=",dec rseg," ","INI=",DEC ini," ","PER=",DEC RMIN0," "
goto sale2
uno: ovflow=0
rseg=rseg+1
if rseg=60 then goto dos
goto sale2
dos: rseg=0
rmin=rmin+1
rmin0=rmin0+1
endif
if rmin=60 then sale2
if rmin=i then
ini=0
rmin=0
rseg=0
ovflow=0
endif
sale2: pie1.1=1
intcon=%1001000
RESUME ' salir de la rutina
ENABLE
return
'****************************************************************
'rutina que conrola el tiempo de encendido
'****************************************************************
lee_TEM:
if portD.1=1 then i=i+1 'se establece el tiempo
m0: if portD.1=1 then goto m0
if i>60 then i=1
return
'****************************************************************
end
Última edición por un moderador: