org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
goto Start ;this is where the program starts running
org 0x005
Start movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
clrf IR_PORT ;make PortB outputs low
bsf STATUS, RP0 ;select bank 1
movlw b'11111101' ;set PortB all inputs, except RB1
movwf IR_TRIS
movlw 0xff
movwf PORTA
bcf STATUS, RP0 ;select bank 0
Read_Sw
btfss PORTA, SW1
call Switch1
btfss PORTA, SW2
call Switch2
btfss PORTA, SW3
call Switch3
btfss PORTA, SW4
call Switch4
btfss PORTA, SW5
call Switch5
btfss PORTA, SW6
call Switch6
btfss PORTA, SW7
call Switch7
btfss PORTA, SW8
call Switch8
call Delay27 ;is this delay still correct with
goto Read_Sw ;extra switches in? Perhaps doubled?
Switch1 movlw But1 ;will this work? I have replaced
call Xmit_RS232 ;progup etc with the relevant BUT”x”
retlw 0x00 ; ID’s?
Switch2 movlw But2
call Xmit_RS232
retlw 0x00
Switch3 movlw But3
call Xmit_RS232
retlw 0x00
Switch4 movlw But4
call Xmit_RS232
retlw 0x00
Switch5 movlw But5
call Xmit_RS232
retlw 0x00
Switch6 movlw But6
call Xmit_RS232
retlw 0x00
Switch7 movlw But7
call Xmit_RS232
retlw 0x00
Switch8 movlw But8
call Xmit_RS232
retlw 0x00
TX_Start movlw d'92'
call IR_pulse
movlw d'23'
call NO_pulse
retlw 0x00
TX_One movlw d'46'
call IR_pulse
movlw d'23'
call NO_pulse
retlw 0x00
TX_Zero movlw d'23'
call IR_pulse
movlw d'23'
call NO_pulse
retlw 0x00
IR_pulse
MOVWF count ; Pulses the IR led at 38KHz
irloop BSF IR_PORT, IR_Out
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
BCF IR_PORT, IR_Out
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP
NOP
NOP ;
NOP ;
DECFSZ count,F
GOTO irloop
RETLW 0
NO_pulse
MOVWF count ; Doesn't pulse the IR led irloop2
BCF IR_PORT, IR_Out
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
BCF IR_PORT, IR_Out
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP
NOP
NOP ;
NOP ;
DECFSZ count,F
GOTO irloop2
RETLW 0
Xmit_RS232 MOVWF Data_Byte ;move W to Data_Byte
MOVLW 0x07 ;set 7 DATA bits out
MOVWF Bit_Cntr
call TX_Start ;send start bit
Ser_Loop RRF Data_Byte , f ;send one bit
BTFSC STATUS, C
call TX_One
BTFSS STATUS, C
call TX_Zero
DECFSZ Bit_Cntr, f ;test if all done
GOTO Ser_Loop ;now send device data
movlw D'1'
movwf Dev_Byte ;set device to TV
MOVLW 0x05 ;set 5 device bits out
MOVWF Bit_Cntr
Ser_Loop2 RRF Dev_Byte, f ;send one bit
BTFSC STATUS, C
call TX_One
BTFSS STATUS, C
call TX_Zero
DECFSZ Bit_Cntr, f ;test if all done
GOTO Ser_Loop2
retlw 0x00
;Delay routines
Delay255 movlw 0xff ;delay 255 mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay27 movlw d'27' ;delay 27mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0 decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
;end of Delay routines
end