;**************************************************************************** ;Filename: gridstart.asm ;Author: Pete Griffiths ;Date: 23/05/2008 ;Version: 1.0.6 ;Description: Race Track F1 style grid start controller ;Information: http://picprojects.org.uk/projects/ ;**************************************************************************** ;Revision History ;**************************************************************************** #include p16f684.inc ; processor specific variable definitions __CONFIG _CP_OFF & _CPD_OFF & _BOD_ON & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT errorlevel -302 ; suppress banksel warning messages ;**************************************************************************** ;Defines ;**************************************************************************** #define BANK0 bcf STATUS,RP0 ;Select BANK0 #define BANK1 bsf STATUS,RP0 ;Select BANK1 startSwitch equ 2 ; RA2 start switch input (schmitt trigger input) driveMode equ 0 ; RA0 drive mode 0=constant, 1= PWM (for LEDs) brightPot equ 1 ; AN1 analogue input for adjusting LED brightness by PWM distDrive equ 4 ; RA4 0 = PWM with constant outputs drive ; 1 = PWM with multiplexed output drive light1 equ 0 light2 equ 1 light3 equ 2 light4 equ 3 light5 equ 4 ; flag bits oneSecond equ 0 ; set every second in Int Handler, cleared by state code brightAdj equ 1 ; used by display driver code tmr2out equ 2 ; state machine runs each time this flag set (every 4mS) holdOut equ 3 ; random hold time out flag ;**************************************************************************** ; Variables in GPR ;**************************************************************************** cblock 0x70 ; This GPR range is common to all banks w_temp status_temp flags state tick countDown holdLo holdHi portMirror driveMask brightLevel endc ;**************************************************************************** ;Reset Vector ;**************************************************************************** org 0x000 ; reset vector nop ; goto Init ; run start up code ;**************************************************************************** ;Interrupt Vector ;**************************************************************************** org 0x004 ; interrupt vector location Isr movwf w_temp swapf STATUS,W clrf STATUS movwf status_temp clrwdt ; clear Watchdog timer btfsc PIR1, TMR2IF call _timer2IH btfsc INTCON, T0IF call _displayIH swapf status_temp,W movwf STATUS swapf w_temp,F swapf w_temp,W retfie ;----------------------------------------------------- _timer2IH bcf PIR1, TMR2IF bsf flags, tmr2out clrz btfss flags, holdOut decf holdLo,F skpnz decf holdHi,F skpnz bsf flags, holdOut decfsz tick,F return movlw .250 movwf tick bsf flags, oneSecond decf countDown,F return ;----------------------------------------------------- ; _displayIH bcf INTCON, T0IF ; clear TMR0 Interrupt Flag btfss PORTA, driveMode ; Test drive mode input goto _staticDrive ; if jumper set, do static drive nop movlw 1<