; OpenFire microcontroller migration test file * ; * ; Filename: 722Av1.asm * ; Date: 11/1/14 * ; File Version: * ; * ; Author: P Dack * ; * ; * ;****************************************************************************** ; * ; Files required: P16F722A.INC * ; * ;****************************************************************************** ; * ; Features of the 16F722: * ; * ; Precision Internal Oscillator (16 MHz or 500 kHz operation) * ; On Chip 3.2 V Regulator * ; Pinout compatible to other 28/40 pin PIC16CXXX and 16FXXX micros * ; Brownout reset with selectable trip points * ; 8 bit resolution and 14 channel A/D Converter * ; Wide operating voltage range (1.8-5.5V) * ; A/D converter with selectable 1.024, 2.048, 4.096 voltage reference * ; AUSART, SPI, and IIC * ; * ;****************************************************************************** ; * ; Notes: * ; * ; * ;****************************************************************************** ; * ; Revision History: * ; * ;****************************************************************************** ;------------------------------------------------------------------------------ ; PROCESSOR DECLARATION ;------------------------------------------------------------------------------ LIST p=16F722A ; list directive to define processor #INCLUDE ; processor specific variable definitions ;------------------------------------------------------------------------------ ; ; CONFIGURATION WORD SETUP ; ; The 'CONFIG' directive is used to embed the configuration word within the ; .asm file. The lables following the directive are located in the respective ; .inc file. See the data sheet for additional information on configuration ; word settings. ; ;------------------------------------------------------------------------------ __CONFIG _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_2_5 & _BOR_ON & _CP_OFF & _MCLR_DIS & _PWRT_DIS & _WDT_OFF & _INTOSCIO __CONFIG _CONFIG2, _VCAP_DIS ;------------------------------------------------------------------------------ ; VARIABLE DECLARATION ;------------------------------------------------------------------------------ COUNT1 equ 0x21 ;Counter variables for delays COUNT2 equ 0x22 COUNT3 equ 0x23 W_STORAGE equ 0x27 ;Storage for working reg SERVAL equ 0x28 ;SERIAL VALUE BYTE1 equ 0x29 ;3x storage registers for bytes received over serial BYTE2 equ 0x2A BYTE3 equ 0x2B BYTE2_COMP equ 0x2C ADDRESS_VAL equ 0x2D ;address - 1 to 128 available, set in Main ;------------------------------------------------------------------------------ ; RESET VECTOR ;------------------------------------------------------------------------------ ORG 0x0000 NOP ;get past interrupt vector address (interrupts unused) NOP NOP NOP NOP goto Main ;------------------------------------------------------------------------------ ; CONFIG ROUTINES ;------------------------------------------------------------------------------ ;---------------PIC initialization routine--------- InitChip ; Setup the oscillator BSF STATUS, RP0 ;Select memory bank 1 MOVLW B'00010000' ;setup the internal oscillator for 4Mhz MOVWF OSCCON ;load the value into the oscilator config register BANKSEL CCP1CON movlw 0x00 movwf CCP1CON ;turn comparators off MOVWF CCP2CON CLRF PORTA ;ensure all outputs are off CLRF PORTB CLRF PORTC BANKSEL TRISA MOVLW B'00010000' ;RA all output except RA4 MOVWF TRISA MOVLW B'00000000' ;RB all output MOVWF TRISB MOVLW B'10000000' ;RC all output except 7 (RX) MOVWF TRISC movlw B'00001111' movwf ADCON1 ; Make PortA digital BCF STATUS, RP0 ;Select memory bank 0 CLRF PORTA ;ensure all outputs are off CLRF PORTB CLRF PORTC CLRF INTCON RETURN ;---------------Firing Delay (30mS)------------------------ delay ;29993 cycles movlw 0x6E movwf COUNT1 movlw 0x18 movwf COUNT2 delay_0 decfsz COUNT1, f goto $+2 decfsz COUNT2, f goto delay_0 ;3 cycles goto $+1 nop ;4 cycles (including call) return ;---------------Serial initialisation routine--------- InitSER BANKSEL SPBRG MOVLW d'25' ;9k6Bd MOVWF SPBRG BANKSEL TXSTA MOVLW B'00100110' MOVWF TXSTA BANKSEL RCSTA MOVLW B'10010000' MOVWF RCSTA BANKSEL PORTA RETURN ;---------------Timer initialisation routine--------- InitTimer BANKSEL T1CON MOVLW B'00000000' ;1:1 PS, TIMER1 not running, internal clock. MOVWF T1CON RETURN ;------------------------------------------------------------------------------ ; MAIN PROGRAM ;------------------------------------------------------------------------------ Main ; Initialize PIC inputs and outputs CALL InitChip CALL InitSER CALL InitTimer BANKSEL ADDRESS_VAL MOVLW D'1' ;set address to '1' MOVWF ADDRESS_VAL GOTO MainLoop1 ;------------------------------------------------------------------------------ ; FIRING/TEST ROUTINES ;------------------------------------------------------------------------------ ;------------------firing------------------ cue1fire BSF PORTC,5 ;ARM BSF PORTA,0 ;Fire Cue 1 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue2fire BSF PORTC,5 ;ARM BSF PORTA,1 ;Fire Cue 2 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue3fire BSF PORTC,5 ;ARM BSF PORTA,2 ;Fire Cue 3 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue4fire BSF PORTC,5 ;ARM BSF PORTA,3 ;Fire Cue 4 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue5fire BSF PORTC,5 ;ARM BSF PORTA,5 ;Fire Cue 5 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue6fire BSF PORTC,5 ;ARM BSF PORTA,6 ;Fire Cue 6 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue7fire BSF PORTC,5 ;ARM BSF PORTA,7 ;Fire Cue 7 call delay ;30mS delay clrf PORTC clrf PORTA GOTO MainLoop1 cue8fire BSF PORTC,5 ;ARM BSF PORTB,0 ;Fire Cue 8 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue9fire BSF PORTC,5 ;ARM BSF PORTB,1 ;Fire Cue 9 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue10fire BSF PORTC,5 ;ARM BSF PORTB,2 ;Fire Cue 10 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue11fire BSF PORTC,5 ;ARM BSF PORTB,3 ;Fire Cue 11 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue12fire BSF PORTC,5 ;ARM BSF PORTB,4 ;Fire Cue 12 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue13fire BSF PORTC,5 ;ARM BSF PORTB,5 ;Fire Cue 13 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue14fire BSF PORTC,5 ;ARM BSF PORTB,6 ;Fire Cue 14 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue15fire BSF PORTC,5 ;ARM BSF PORTB,7 ;Fire Cue 15 call delay ;30mS delay clrf PORTC clrf PORTB GOTO MainLoop1 cue16fire BSF PORTC,5 ;ARM BSF PORTC,0 ;Fire Cue 16 call delay ;30mS delay clrf PORTC GOTO MainLoop1 cue17fire BSF PORTC,5 ;ARM BSF PORTC,1 ;Fire Cue 17 call delay ;30mS delay clrf PORTC GOTO MainLoop1 cue18fire BSF PORTC,5 ;ARM BSF PORTC,2 ;Fire Cue 18 call delay ;30mS delay clrf PORTC GOTO MainLoop1 cue19fire BSF PORTC,5 ;ARM BSF PORTC,3 ;Fire Cue 19 call delay ;30mS delay clrf PORTC GOTO MainLoop1 cue20fire BSF PORTC,5 ;ARM BSF PORTC,4 ;Fire Cue 20 call delay ;30mS delay clrf PORTC GOTO MainLoop1 ;------------------testing------------------ checkfb call delay BTFSS PORTA,4 ;test if continuity RETLW d'0' ;no cont. - return 0 RETLW d'1' ;OK - return 1 cue1test BSF PORTA,0 ;Cue 1 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue2test BSF PORTA,1 ;Cue 2 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue3test BSF PORTA,2 ;Cue 3 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue4test BSF PORTA,3 ;Cue 4 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue5test BSF PORTA,5 ;Cue 5 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue6test BSF PORTA,6 ;Cue 6 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue7test BSF PORTA,7 ;Cue 7 call checkfb ;check feedback line clrf PORTA call BYTESEND GOTO MainLoop1 cue8test BSF PORTB,0 ;Cue 8 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue9test BSF PORTB,1 ;Cue 9 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue10test BSF PORTB,2 ;Cue 10 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue11test BSF PORTB,3 ;Cue 11 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue12test BSF PORTB,4 ;Cue 12 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue13test BSF PORTB,5 ;Cue 13 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue14test BSF PORTB,6 ;Cue 14 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue15test BSF PORTB,7 ;Cue 15 call checkfb ;check feedback line clrf PORTB call BYTESEND GOTO MainLoop1 cue16test BSF PORTC,0 ;Cue 16 call checkfb ;check feedback line clrf PORTC call BYTESEND GOTO MainLoop1 cue17test BSF PORTC,1 ;Cue 17 call checkfb ;check feedback line clrf PORTC call BYTESEND GOTO MainLoop1 cue18test BSF PORTC,2 ;Cue 18 call checkfb ;check feedback line clrf PORTC call BYTESEND GOTO MainLoop1 cue19test BSF PORTC,3 ;Cue 19 call checkfb ;check feedback line clrf PORTC call BYTESEND GOTO MainLoop1 cue20test BSF PORTC,4 ;Cue 20 call checkfb ;check feedback line clrf PORTC call BYTESEND GOTO MainLoop1 respond ;respond option - reply with '1' MOVLW D'1' call BYTESEND GOTO MainLoop1 ;------------------------------------------------------------------------------ ; REGULARLY USED ROUTINES ;------------------------------------------------------------------------------ BYTESEND BANKSEL TXREG ;send byte MOVWF TXREG RETURN TIMERSTART BANKSEL TMR1L ;load timer1 with '20ms' BCF PIR1,0 ;clear overflow flag MOVLW 0xDF MOVWF TMR1L MOVLW 0xB1 MOVWF TMR1H BSF T1CON,0 ;TMR1 Enabled RETURN ERR_RESET BANKSEL RCREG ;Read byte to clear received flag MOVFW RCREG BANKSEL RCSTA BCF RCSTA,4 ;toggle CREN BSF RCSTA,4 GOTO MainLoop1 ;------------------------------------------------------------------------------ ; CONTINUAL LOOP ;------------------------------------------------------------------------------ MainLoop1 BANKSEL PIR1 ;check for byte received BTFSS PIR1,5 ;on PIR1 interrupt flag bit 5 GOTO MainLoop1 ;if nothing, repeat BCF PIR1,5 ;clear flag BANKSEL RCSTA ;go to receive status bank BTFSC RCSTA,2 ;test no framing error GOTO ERR_RESET ;if framing error, clear it and flush bad data BTFSC RCSTA,1 ;test no overrun error GOTO ERR_RESET ;if overrun error, clear it and flush bad data BANKSEL RCREG ;go to received data bank MOVFW RCREG ;retrieve it to 'W' MOVWF BYTE1 ;store it BANKSEL RCSTA ;toggle CREN, leave on BCF RCSTA,4 BSF RCSTA,4 CALL TIMERSTART ;Start 20ms timeout MainLoop2 BTFSC PIR1,0 ;check for timer overflow GOTO MainLoop1 ;if overflowed, restart from beginning BANKSEL PIR1 ;check for byte received BTFSS PIR1,5 ;on PIR1 interrupt flag bit 5 GOTO MainLoop2 ;if nothing, repeat BCF PIR1,5 ;clear flag BANKSEL RCSTA ;go to receive status bank BTFSC RCSTA,2 ;test no framing error GOTO ERR_RESET ;if framing error, clear it and flush bad data BTFSC RCSTA,1 ;test no overrun error GOTO ERR_RESET ;if overrun error, clear it and flush bad data BANKSEL RCREG ;go to received data bank MOVFW RCREG ;retrieve it to 'W' MOVWF BYTE2 ;store it BANKSEL RCSTA ;toggle CREN, leave on BCF RCSTA,4 BSF RCSTA,4 CALL TIMERSTART ;Start 20ms timeout MainLoop3 BTFSC PIR1,0 ;check for timer overflow GOTO MainLoop1 ;if overflowed, restart from beginning BANKSEL PIR1 ;check for byte received BTFSS PIR1,5 ;on PIR1 interrupt flag bit 5 GOTO MainLoop3 ;if nothing, repeat BCF PIR1,5 ;clear flag BANKSEL RCSTA ;go to receive status bank BTFSC RCSTA,2 ;test no framing error GOTO ERR_RESET ;if framing error, clear it and flush bad data BTFSC RCSTA,1 ;test no overrun error GOTO ERR_RESET ;if overrun error, clear it and flush bad data BANKSEL RCREG ;go to received data bank MOVFW RCREG ;retrieve it to 'W' MOVWF BYTE3 ;store it BANKSEL RCSTA ;toggle CREN, leave on BCF RCSTA,4 BSF RCSTA,4 VERIFY_DATA ;checksum COMF BYTE2,W ;check complement of byte2 against byte3 XORWF BYTE3,W BTFSS STATUS,Z ;if it matches, continue GOTO MainLoop1 ;if not, reset ADDRESS_CHECK MOVFW ADDRESS_VAL ;check received address vs module address XORWF BYTE1,W BTFSC STATUS,Z ;if it doesn't match, continue GOTO FIRE ;if it does, goto Fire MOVFW ADDRESS_VAL ADDLW D'128' ;add 128 to address XORWF BYTE1,W BTFSC STATUS,Z ;if it doesn't match, reset GOTO TEST ;if it does, goto TEST GOTO MainLoop1 FIRE MOVLW D'1' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue1fire ;go to corresponding fire routine ;else continue MOVLW D'2' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue2fire ;go to corresponding fire routine ;else continue MOVLW D'3' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue3fire ;go to corresponding fire routine ;else continue MOVLW D'4' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue4fire ;go to corresponding fire routine ;else continue MOVLW D'5' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue5fire ;go to corresponding fire routine ;else continue MOVLW D'6' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue6fire ;go to corresponding fire routine ;else continue MOVLW D'7' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue7fire ;go to corresponding fire routine ;else continue MOVLW D'8' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue8fire ;go to corresponding fire routine ;else continue MOVLW D'9' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue9fire ;go to corresponding fire routine ;else continue MOVLW D'10' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue10fire ;go to corresponding fire routine ;else continue MOVLW D'11' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue11fire ;go to corresponding fire routine ;else continue MOVLW D'12' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue12fire ;go to corresponding fire routine ;else continue MOVLW D'13' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue13fire ;go to corresponding fire routine ;else continue MOVLW D'14' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue14fire ;go to corresponding fire routine ;else continue MOVLW D'15' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue15fire ;go to corresponding fire routine ;else continue MOVLW D'16' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue16fire ;go to corresponding fire routine ;else continue MOVLW D'17' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue17fire ;go to corresponding fire routine ;else continue MOVLW D'18' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue18fire ;go to corresponding fire routine ;else continue MOVLW D'19' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue19fire ;go to corresponding fire routine ;else continue MOVLW D'20' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue20fire ;go to corresponding fire routine ;else continue MOVLW D'42' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO respond ;go to respond routine ;else continue GOTO MainLoop1 ;if not 1-20 or the meaning of life (42) then reset TEST MOVLW D'1' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue1test ;go to corresponding test routine ;else continue MOVLW D'2' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue2test ;go to corresponding test routine ;else continue MOVLW D'3' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue3test ;go to corresponding test routine ;else continue MOVLW D'4' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue4test ;go to corresponding test routine ;else continue MOVLW D'5' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue5test ;go to corresponding test routine ;else continue MOVLW D'6' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue6test ;go to corresponding test routine ;else continue MOVLW D'7' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue7test ;go to corresponding test routine ;else continue MOVLW D'8' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue8test ;go to corresponding test routine ;else continue MOVLW D'9' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue9test ;go to corresponding test routine ;else continue MOVLW D'10' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue10test ;go to corresponding test routine ;else continue MOVLW D'11' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue11test ;go to corresponding test routine ;else continue MOVLW D'12' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue12test ;go to corresponding test routine ;else continue MOVLW D'13' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue13test ;go to corresponding test routine ;else continue MOVLW D'14' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue14test ;go to corresponding test routine ;else continue MOVLW D'15' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue15test ;go to corresponding test routine ;else continue MOVLW D'16' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue16test ;go to corresponding test routine ;else continue MOVLW D'17' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue17test ;go to corresponding test routine ;else continue MOVLW D'18' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue18test ;go to corresponding test routine ;else continue MOVLW D'19' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue19test ;go to corresponding test routine ;else continue MOVLW D'20' ;check cue XORWF BYTE2,W ;against received byte BTFSC STATUS,Z ;if a match occurrs GOTO cue20test ;go to corresponding test routine ;else continue GOTO MainLoop1 ;if not 1-20 then reset END