; -------------------------------------------------------- ; -- AIR COMMAND - Water Rocket Flight Software V1.2 -- ; -- Copyright (c) 2006 GKDesign Engineering -- ; -- Author: George Katz 6/10/06 -- ; -- -- ; -- This code may be used and modified freely for -- ; -- personal use. For commercial use please contact -- ; -- the author at: Katz.George@gmail.com -- ; -------------------------------------------------------- ; PORT A ; desig. bit dir pin function ; RA0 0 in 17 'Arm' button. Arms flight computer ready for launch. ; RA1 1 in 18 'Launch Detect' button. Activated when the rocket experiences +ve Gs. ; RA2 2 in 1 'Program' button. When in standby mode, a new program sequence can be selected. ; RA3 3 out 2 - reserved for analog apogee sensor - not used in this version. ; RA4 4 out 3 - not used ; RA5 5 in 4 - used as master reset ; RA6 6 out 15 - not used ; RA7 7 out 16 - parachute deploy actuator. ; PORT B ; desig. bit dir pin function ; RB0 0 out 6 7 segment LED display - 'c' segment ; RB1 1 out 7 7 segment LED display - 'b' segment ; RB2 2 out 8 7 segment LED display - 'a' segment ; RB3 3 out 9 7 segment LED display - 'f' segment ; RB4 4 out 10 7 segment LED display - 'g' segment ; RB5 5 out 11 7 segment LED display - 'e' segment ; RB6 6 out 12 7 segment LED display - 'd' segment ; RB7 7 out 13 7 segment LED display - 'dp' segment LIST P=16F628A, R=DEC ; Use the PIC16F628 and decimal system #include "P16F628A.INC" ; Include header file errorlevel -302 __config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON CBLOCK 0x20 ; Declare variable addresses starting at 0x20 Loop1 Loop2 Loop3 Program ; The program index - which program to run. (The delay index) Armed ; bit 7 of this byte represents whether the FC is armed or not. (all other bits should be 0) 1 = armed. 0 = standby Message ; Used for displaying other status information on the display ENDC ; defines ARM_BTN EQU 0 LAUNCH_DETECT_BTN EQU 1 PROGRAM_BTN EQU 2 ; ; ----------- ; INITIALIZE ; ----------- ; ORG 0x000 ; Program starts at 0x000 CLRF PORTA ; Initialize port A CLRF PORTB ; Initialize port B BSF STATUS,RP0 ; switch to RAM bank 1 MOVLW 07h ; set bits RA0, RA1 and RA2 as inputs, the rest outputs MOVWF TRISA CLRF TRISB ; All pins port B output BCF STATUS,RP0 ; switch to RAM bank 0 ; ; ------------------------ ; FUNCTION OF PORT A PINS ; ------------------------ ; MOVLW 7 MOVWF CMCON ; Comparators off, all pins digital I/O GOTO Start ; jump over the table ; ; ----------------------- ; LED conversion table ; ----------------------- ; dec2led ADDWF PCL,1 ; dpdegfabc RETLW b'01101111' ; 0 RETLW b'00000011' ; 1 RETLW b'01110110' ; 2 RETLW b'01010111' ; 3 RETLW b'00011011' ; 4 RETLW b'01011101' ; 5 RETLW b'01111101' ; 6 RETLW b'00000111' ; 7 RETLW b'01111111' ; 8 RETLW b'01011111' ; 9 RETLW b'00111111' ; A RETLW b'01111001' ; b RETLW b'01101100' ; C RETLW b'01110011' ; d RETLW b'01111100' ; E RETLW b'00111100' ; F RETLW b'01101000' ; L - Launch delay RETLW b'00111110' ; P - Parachute deploy ; ; ---------- ; MAIN LOOP ; ---------- ; Start CLRF Program ; initialise the Program variable to be 0 CLRF Message ; initialise the Message variable to 0 CLRF Armed CALL LEDOut ; output current Program setting to display prgbtn_up BTFSS PORTA, ARM_BTN ; check if the ARM button is down (normally high) GOTO LaunchArmed ; ARM button was pressed BTFSC PORTA, PROGRAM_BTN ; check if we are pressing the program change button (normally high) GOTO prgbtn_up ; no we are not so check buttons again prgbtn_down BTFSS PORTA, ARM_BTN ; check if the launch button is down (normally high) GOTO LaunchArmed ; ARM button was pressed BTFSS PORTA, PROGRAM_BTN ; check if we are letting go of the program change button GOTO prgbtn_down ; nope still holding it down INCF Program,1 ; Program button has been down and now up, so we increment the Program variable MOVLW 16 ; check for overflow and wrap after 16 SUBWF Program,w SKPNC CLRF Program CALL LEDOut ; output the new program index to the display GOTO prgbtn_up ; go back to listening for keys LaunchArmed BSF Armed,7 ; Turn on the Armed flag. CALL LEDOut ; Turn on 'Armed' LED to indicate system is armed. ; Rocket waits for the launch detect event LnchDetect BTFSC PORTA, LAUNCH_DETECT_BTN ; See if launch detect button goes low since it is normally high. GOTO LnchDetect ; loop endlesly until launch detect is triggered ; launch was detected ; display the fact the computer is in the chute deploy delay MOVLW 16 ; 16 is the 'L' symbol MOVWF Message ; store that value in the message variable CALL LEDOut2 ; display it on screen ; Wait the appropriate delay to fire the chute setting the correct delay of 3 seconds + delay index (Program) MOVLW 12 ; We wait a minimum of 3 seconds 4 x 3 since we increment in 1/4 seconds ADDWF Program,0 ; Add the program offset to the 3 seconds already in the W register MOVWF Loop3 ; store the total number of loops we have to go through Inhibit CALL dly250 DECFSZ Loop3,F GOTO Inhibit ; Finished our delay so now we should deploy CLRF Armed ; Turn off the 'Armed' LED MOVLW 17 ; 17 is the 'P' symbol MOVWF Message ; store that value in the message variable CALL LEDOut2 ; display it on screen ; deploy the parachute by driving the output for a fixed period to give the motor ; enough time to run properly. deploy BSF PORTA,7 ; drive the motor CALL MotorDly ; Allow the motor to rotate for this delay BCF PORTA,7 ; stop the motor GOTO Start ; go back and await instruction to start again ; --------------- ; DELAY 250 MSEC ; --------------- dly250 MOVLW 250 MOVWF Loop1 Outer MOVLW 200 MOVWF Loop2 Inner NOP NOP DECFSZ Loop2,F GOTO Inner ; Inner loop = 5 usec. DECFSZ Loop1,F GOTO Outer RETURN ; --------------- ; Motor driving DELAY 250 MSEC ; --------------- MotorDly MOVLW 250 MOVWF Loop1 MOuter MOVLW 200 MOVWF Loop2 MInner NOP NOP DECFSZ Loop2,F GOTO MInner ; Inner loop = 5 usec. DECFSZ Loop1,F GOTO MOuter RETURN ; --------------- ; LED output sub routine. Calling this routine displays ; the status of the Program index as well as the Armed bit status ; --------------- LEDOut MOVF Program,0 ; load the Program index into W CALL dec2led ; convert the Program index to LED bits IORWF Armed,0 ; OR with the Armed bit (dp) MOVWF PORTB ; write value out to port B RETURN ; --------------- ; LED output sub routine. Calling this routine displays ; the status of the Message index as well as the Armed bit status ; --------------- LEDOut2 MOVF Message,0 ; load the Message index into W CALL dec2led ; convert the Program index to LED bits IORWF Armed,0 ; OR with the Armed bit (dp) MOVWF PORTB ; write value out to port B RETURN END