;********************************************************************** ; Filename: tvcontrol.asm * ; Date: 26 February 2007 * ; File Version: 1.0 * ; Author: Paul R. Kucher IV * ;********************************************************************** list p=16f627A ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _EXTCLK_OSC ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x71 ; variable used for context saving status_temp EQU 0x72 ; variable used for context saving ; Variables loopval0 EQU 0x20 loopval1 EQU 0x21 TVCODE EQU 0x22 ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt main BCF STATUS,RP1 ; Make sure we're pointing to page 0 at first BSF STATUS,RP0 ; Point to page 1 CALL delay_50ms ; Delay if we are programming so pins don't short MOVLW B'11110011' ; PORTA data direction register MOVWF TRISA MOVLW B'11111111' ; PORTB data direction register MOVWF TRISB BCF STATUS,RP0 ; Point to page 0 MOVLW B'00000000' ; PORTA output data MOVWF PORTA MOVLW B'00000000' ; PORTB output data MOVWF PORTB ; Setup RS-232 BSF STATUS,RP0 ; Point to page 1 MOVLW D'32' ; 9600 baud MOVWF SPBRG BCF TXSTA,SYNC ; Clear SYNC BCF STATUS,RP0 ; Point to page 0 BSF RCSTA,SPEN ; Set SPEN BSF RCSTA,CREN ; Enable reception BSF STATUS,RP0 ; Point to page 1 BSF TXSTA,TXEN ; Enable TXEN BCF STATUS,RP0 ; Point to page 0 ; Setup Timer1 MOVLW B'00110000' MOVWF T1CON MOVLW B'00000000' MOVWF TMR1H MOVWF TMR1L CALL delay_50ms CALL delay_50ms CALL delay_50ms CALL delay_50ms mainloop: CALL checkserialerror BTFSS PIR1,RCIF GOTO mainloop CALL readserial GOTO mainloop readserial: MOVF RCREG,W MOVWF TVCODE MOVWF TXREG CALL sendir RETURN checkserialerror: BTFSC RCSTA,OERR GOTO clearserialerror RETURN clearserialerror: BCF RCSTA,CREN BSF RCSTA,CREN RETURN sendir CALL sendcode CALL sendcode CALL sendcode RETURN sendcode: MOVLW B'00100011' ; 65536 - 28125 = 37411 MOVWF TMR1L ; Initialize Timer MOVLW B'10010010' MOVWF TMR1H BSF T1CON,TMR1ON ; Enable Timer CALL startbit ; Send Remote Code BTFSS TVCODE,0 GOTO sendbit0value0 CALL sendone GOTO sendbit1 sendbit0value0 CALL sendzero sendbit1 BTFSS TVCODE,1 GOTO sendbit1value0 CALL sendone GOTO sendbit2 sendbit1value0 CALL sendzero sendbit2 BTFSS TVCODE,2 GOTO sendbit2value0 CALL sendone GOTO sendbit3 sendbit2value0 CALL sendzero sendbit3 BTFSS TVCODE,3 GOTO sendbit3value0 CALL sendone GOTO sendbit4 sendbit3value0 CALL sendzero sendbit4 BTFSS TVCODE,4 GOTO sendbit4value0 CALL sendone GOTO sendbit5 sendbit4value0 CALL sendzero sendbit5 BTFSS TVCODE,5 GOTO sendbit5value0 CALL sendone GOTO sendbit6 sendbit5value0 CALL sendzero sendbit6 BTFSS TVCODE,6 GOTO sendbit6value0 CALL sendone GOTO senddevicecode sendbit6value0 CALL sendzero senddevicecode CALL sendone ; TV 5-bit Code = 1 CALL sendzero CALL sendzero CALL sendzero CALL sendzero framespace: BTFSC TMR1H,7 GOTO framespace BCF T1CON,TMR1ON ; Disable Timer RETURN startbit: BSF PORTA,2 CALL delay_2dot4ms BCF PORTA,2 CALL delay_0dot6ms RETURN sendone: BSF PORTA,2 CALL delay_1dot2ms BCF PORTA,2 CALL delay_0dot6ms RETURN sendzero: BSF PORTA,2 CALL delay_0dot6ms BCF PORTA,2 CALL delay_0dot6ms RETURN delay_100us: MOVLW D'99' ; Our cycles are 0.2us long (20MHz/4) MOVWF loopval0 here_100us: NOP ; These make it 5 cycles total NOP DECFSZ loopval0,F GOTO here_100us RETURN delay_0dot6ms: MOVLW D'6' ; 100us*6=0.6ms MOVWF loopval1 here_0dot6ms: CALL delay_100us DECFSZ loopval1,F GOTO here_0dot6ms RETURN delay_1dot2ms: MOVLW D'12' ; 100us*12=1.2ms MOVWF loopval1 here_1dot2ms: CALL delay_100us DECFSZ loopval1,F GOTO here_1dot2ms RETURN delay_2dot4ms: MOVLW D'24' ; 100us*24=2.4ms MOVWF loopval1 here_2dot4ms: CALL delay_100us DECFSZ loopval1,F GOTO here_2dot4ms RETURN delay_5ms: MOVLW D'50' ; 100us*50=5ms MOVWF loopval1 here_5ms: CALL delay_100us DECFSZ loopval1,F GOTO here_5ms RETURN delay_50ms: MOVLW D'250' ; 200us*250=50ms MOVWF loopval1 here_50ms: CALL delay_100us CALL delay_100us DECFSZ loopval1,F GOTO here_50ms RETURN ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program'