;Nigel Goodwin 2003
;SkyDigital 'Backup' IR transmitter
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D1C ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb
count
Delay_Count
Bit_Cntr
Data_Byte
Dev_Byte
WDT_Count
Pulse
endc
IR_PORT Equ PORTB
IR_TRIS Equ TRISB
IR_Out Equ 0x01
IR_In Equ 0x02
Ser_Out Equ 0x01
Ser_In Equ 0x02
SW1 Equ 7 ;set constants for the switches
SW2 Equ 6
SW3 Equ 5
SW4 Equ 4
TV_ID Equ 0x01 ;TV device ID
But1 Equ 0x00 ;numeric button ID's
But2 Equ 0x01
But3 Equ 0x02
But4 Equ 0x03
But5 Equ 0x04
But6 Equ 0x05
But7 Equ 0x06
But8 Equ 0x07
But9 Equ 0x08
ProgUp Equ d'16'
ProgDn Equ d'17'
VolUp Equ d'18'
VolDn Equ d'19'
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
goto Start ;this is where the program starts running
org 0x005
Start BTFSC STATUS , NOT_PD
clrf WDT_Count
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
clrf IR_PORT ;make PortB outputs low
clrf TMR0
clrwdt
bsf STATUS, RP0 ;select bank 1
movlw b'11111101' ;set PortB all inputs, except RB1
movwf IR_TRIS
movlw 0xff
movwf PORTA
movlw b'00101111'
movwf OPTION_REG
bcf STATUS, RP0 ;select bank 0
incf WDT_Count, f
btfss WDT_Count, 0x04
sleep
Transmit
MOVLW 0x0F ;send preamble
call Xmit_RS232
MOVLW 0xCA
call Xmit_RS232
MOVLW 0x93
call Xmit_RS232
MOVLW 0x55
call Xmit_RS232
MOVLW 0x55
call Xmit_RS232
MOVLW 0x55
call Xmit_RS232
;end of preamble
MOVLW 0x95 ;send backup codes
call Xmit_RS232
MOVLW 0x5A
call Xmit_RS232
sleep
movlw d'40' ;delay approx 10 secs (40x255mS)
call Delay255
goto Transmit
TX_One movlw d'16'
call IR_pulse
retlw 0x00
TX_Zero movlw d'16'
call NO_pulse
retlw 0x00
IR_pulse
MOVWF count ; Pulses the IR led at 40KHz
irloop BSF IR_PORT, IR_Out
NOP ;
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 ;
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 ;
NOP ;
BCF IR_PORT, IR_Out
NOP ;
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 0x08 ;set 7 DATA bits out
MOVWF Bit_Cntr
Ser_Loop RLF 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
retlw 0x00
;Delay routines
LDelay MOVWF count
ldloop call Delay255
DECFSZ count,F
GOTO ldloop
retlw 0x00
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