DEFINE OSC 20
CMCON = %00000111 'comparators off
ADCON1=6 'PORTA DIGITAL TODO
Sincro var Byte
B1 Var byte[3]
BS Var byte
J Var Byte
J=0
' Initialize hardware USART
RCSTA = %10010000' Enable serial port and continuous receive
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h' "BRGH a 0 para 2400,-->20, para 9600 ponerlo a 24
DEFINE HSER_BAUD 9600' "Velocidad de transmision 9600
ON INTERRUPT GOTO myint
INTCON = %11000000 ' Enable interrupts
PIE1.5 = 1 ' Enable interrupt on USART
OPTION_REG.7=0 'PULL UPS PORTB
TRISB = %00000001
mainloop:
IF PORTB.0 = 1 then ' Sincronismo con AC Paso por 0
Sincro = 255
PORTA = 0
PORTB = 0
endif
DISABLE INTERRUPT
IF Sincro = B1(1) then High PORTA.0
IF Sincro = B1(2) then HIGH PORTA.3
ENABLE INTERRUPT
pauseUS 25
Sincro=Sincro-1
Goto mainloop' Do it forever
''''''''''''Interrupcion
DISABLE
Myint:
if RCSTA.1 then ' Overrun error?
RCSTA.4=0 ' clear it
RCSTA.4=1
endif
Hserin [BS]
If BS=0 then J=0
B1(J)= BS
If J=2 then J=0
J=J+1
RESUME ' vuelve al programa principal
ENABLE
''''''''''''Interrupcion