; TITLE 'IRcoder.asm' ; ; I included the "include" file for the 508 for reference while programming ; LIST P = 12C508, F = INHX8M ; P12C508.INC Standard Header File, Version 1.02 Microchip Technology, Inc. ;========================================================================== ; Verify Processor ;========================================================================== IFNDEF __12C508 MESSG "Processor-header file mismatch. Verify selected processor." ENDIF ;========================================================================== ; Register Definitions ;========================================================================== W EQU H'0000' F EQU H'0001' ;----- Register Files ----------------------------------------------------- INDF EQU H'0000' ; Uses FSR to address data mem. TMR0 EQU H'0001' ; 8 bit real time clock/counter PCL EQU H'0002' ; Low order 8 bits of PC STATUS EQU H'0003' ; STATUS FSR EQU H'0004' ; Indirect data memory addr pointer OSCCAL EQU H'0005' ; Calibration data for osc. GPIO EQU H'0006' ; General Purpose I/O ;----- STATUS Bits -----------Page 14-------------------------------------- GPWUF EQU H'0007' ; GPIO reset bit PA0 EQU H'0005' ; Program Page preselect NOT_TO EQU H'0004' ; Time Out bit NOT_PD EQU H'0003' ; Power Down bit Z EQU H'0002' ; Zero bit DC EQU H'0001' ; Digit carry/*borrow bit CARRY EQU H'0000' ; carry/*borrow bit ;----- OPTION Bits -----------Page 15-------------------------------------- NOT_GPWU EQU H'0007' ; Enable wake-up on pin change NOT_GPPU EQU H'0006' ; Enable weak pull-ups T0CS EQU H'0005' ; Timer0 clock source select T0SE EQU H'0004' ; Timer0 sources edge select PSA EQU H'0003' ; Prescalar assignment bit PS2 EQU H'0002' ;\ PS1 EQU H'0001' ; > Prescalar rate select bits PS0 EQU H'0000' ;/ ;========================================================================== ; RAM Definition ;========================================================================== __MAXRAM H'3F' ;========================================================================== ; Configuration Bits ;========================================================================== _MCLRE_ON EQU H'0FFF' _MCLRE_OFF EQU H'0FEF' _CP_ON EQU H'0FF7' _CP_OFF EQU H'0FFF' _WDT_ON EQU H'0FFF' _WDT_OFF EQU H'0FFB' _LP_OSC EQU H'0FFC' _XT_OSC EQU H'0FFD' _IntRC_OSC EQU H'0FFE' _ExtRC_OSC EQU H'0FFF' __CONFIG ( _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC ) ;========================================================================== ; Program Variables ;========================================================================== ;Port definitions and other constants or macros #define REV buttons,5 ; Pin 2 = GP5 = Bit 5 I #define FWD buttons,4 ; Pin 3 = GP4 = Bit 4 I #define LEFT buttons,3 ; Pin 4 = GP3 = Bit 3 I #define RIGHT buttons,2 ; Pin 5 = GP2 = Bit 2 I #define GUNS buttons,1 ; Pin 6 = GP1 = Bit 1 I #define DATA GPIO,0 ; Pin 7 = GP0 = Serial output #define SENDIT B'11111110' ; GP0 sends data out #define DELAY D'16' ; 2400 BAUD delay amount (416us) #define BIT dout,0 ; bit 0 of the output, what data to send #define Go D'64' #define Rev D'133' #define Fwd D'134' #define Left D'135' #define Right D'132' #define Guns D'141' #define Motors D'137' #define Stop D'0' LIST ;Register locations for important stuff,only 9-15 are available before table delay1 EQU D'8' ; First counter for time delays delay2 EQU D'9' Sdelay EQU D'10' ; seria loop counter dout EQU D'11' ; Bit notation register bcount EQU D'12' ; bit count register buttons EQU D'13' ; button data ;================================ ; Main Code = ;================================ ORG 0x1FF ; MOVLW 0x50 ; My EPROM calibration value,remove for OTPs start ORG 0x000 MOVWF OSCCAL ; Store the factory osc. calibration value MOVLW SENDIT ; Set GPIO 0 as output, rest as inputs TRIS GPIO ; Configure pins as either I or O MOVLW B'10000111' ; Set OPTION bits (Weak pullups enabled) OPTION ; Implement OPTION bits CLRF dout ; set bit = 0 BCF DATA ; turn LED off main ;=========================================================================== ; This program will read GPIO 1-5 for button press status and send the byte ;out in inverted serial that that button corressponds to. ;This is designed to go with my revB calc program for Tony's chip which has ;two servo ports and three binary output ports with time delays attached. ;The data goes out at 2400 baud inverted with one start and one stop bit. ;Copyright Revision 8/2/00 Dennis Clark and TTT Enterprises ;=========================================================================== wloop BCF DATA ; make sure that data line starts Low MOVF GPIO,W ; get button data MOVWF buttons ; save data BTFSS REV ; check for reverse GOTO doRev ; do reverse BTFSS FWD ; check for forward GOTO doFwd ; do forward BTFSS LEFT GOTO doLeft BTFSS RIGHT GOTO doRight BTFSS GUNS GOTO doGuns MOVLW Stop ; send stops out MOVWF buttons CALL sendbyte ; transmit the data back CALL mdelay ; short delay GOTO wloop doTime MOVLW Go MOVWF buttons CALL sendbyte ; turn motors on CALL longdelay ; wait a bit GOTO wloop ; and wait for the next request doRev MOVLW Rev ; get reverse byte MOVWF buttons CALL sendbyte CALL mdelay ; short delay MOVLW Motors MOVWF buttons CALL sendbyte GOTO doTime doFwd MOVLW Fwd ; get Forward byte MOVWF buttons CALL sendbyte CALL mdelay ; short delay MOVLW Motors MOVWF buttons CALL sendbyte GOTO doTime doLeft MOVLW Left MOVWF buttons CALL sendbyte CALL mdelay ; short delay MOVLW Motors MOVWF buttons CALL sendbyte GOTO doTime doRight MOVLW Right ; turn right MOVWF buttons CALL sendbyte CALL mdelay ; short delay MOVLW Motors MOVWF buttons CALL sendbyte GOTO doTime doGuns MOVLW Guns ; do gun sounds MOVWF buttons CALL sendbyte CALL mdelay ; short delay GOTO wloop ;================================ ;SUBROUTINES ;================================ longdelay ;This will delay 333ms (256*23us*56) MOVLW 0x00 MOVWF delay1 ; inner loop MOVLW 0x00 ; 333ms delay MOVWF delay2 ; outer loop oloop ; outer loop iloop ; inner loop NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP DECFSZ delay1,F ;decrement the inner loop GOTO iloop ;and repeat inner loop DECFSZ delay2,F ;decrement outer loop GOTO oloop ; and repeat outer loop RETLW 0 ; we are done here mdelay ;This will delay 3ms MOVLW 0x00 MOVWF delay1 ; inner loop mloop NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP DECFSZ delay1,F ;decrement the inner loop GOTO mloop ;and repeat inner loop RETLW 0 sendbyte ;This will send the data back via 2400 baud RS232 BCF DATA ; Keep data line Low right now MOVLW 8 ; 8bit data byte MOVWF bcount ; save this number here BCF BIT ; send start bit snext CALL sdelay ; 417us delay (416.7 is perfect) RRF buttons,F ; start sending the data BTFSC STATUS,CARRY ; Test for bit to be transmitted BSF BIT ; Bit is a 1 BTFSS STATUS,CARRY BCF BIT ; Bit is a 0 DECFSZ bcount,F ; if = 0 then we are done GOTO snext ; send the next bit otherwise CALL sdelay BSF BIT ; sending stop bit CALL sdelay RETLW 0 ; sdelay ;Short 2400 BAUD delay 8*1E-6*51(+3)=417us (416.7 is perfect) MOVLW DELAY MOVWF Sdelay ; Pulses the left IR led at 40 KHz MOVF dout,F ; check for == 0 BTFSS STATUS,Z GOTO nfloop ; =1, inverse is to do nothing floop BSF DATA ; =0, inverse is to flash LED NOP ; NOP NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; BCF DATA ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; DECFSZ Sdelay,F GOTO floop NOP RETLW 0 nfloop BCF DATA ; =1, inverse is to not flash LED NOP ; NOP ; NOP NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; BCF DATA ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; NOP ; DECFSZ Sdelay,F GOTO nfloop NOP RETLW 0 END ; directive 'end of program'