LIST p=16F628a ;tell assembler what chip we are using include ;include the defaults for the chip __config 0x3D18 ;sets the configuration settings (oscillator type etc.) cblock 0x20 ;start of general purpose registers counta countb countc endc #define fwrd PORTB,3 #define bwrd PORTB,2 #define left PORTB,1 #define right PORTB,0 org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running movlw 0x00 movwf CMCON ;turn comparators off (make it like a 16F84) bsf STATUS, RP0 ;go to bank 1 movlw b'11110000' ;set PortA 4 inputs, 4 outputs movwf TRISA bcf STATUS, RP0 ;go to bank 0 clrf PORTA clrf PORTB begin btfsc fwrd ;check if forward switch is pressed call Table1 ;go to Table1 if yes; skip this step if not pressed btfsc bwrd ;check if backward switch is pressed call Table2 ;go to Table2 if yes; skip this step if not pressed btfsc left ;check if left switch is pressed call Table3 ;go to Table3 if yes; skip this step if not pressed btfsc right ;check if right switch is pressed call Table4 ;go to Table4 if yes; skip this step if not pressed goto begin Table1 btfsc bwrd ;safety check if BACKWARD switch is released return ;if yes, skip this step ; if no return to main btfsc left ;safety check if LEFT switch is released return ;if yes, skip this step ; if no return to main btfsc right ;safety check if RIGHT switch is released return ;if yes, skip this step ; if no return to main btfss fwrd ;check if FORWARD switch is still pressed return ;if yes, skip this step ; if no return to main call FOON call FOOFF FOON bsf PORTA,3 ;turn forward relays ON btfsc bwrd ;check if BACKWARD switch is pressed return ;if pressed return to main ; if not skip this step btfsc left ;check if LEFT switch is pressed return ;if pressed return to main ; if not skip this step btfsc right ;check if RIGHT switch is pressed return ;if pressed return to main ; if not skip this step btfss fwrd ;check if FORWARD switch is still pressed return ;if yes, skip this step; if no return to main goto FOON FOOFF bcf PORTA,3 ;turn FORWARD relays OFF call delay call delay call delay goto begin Table2 btfsc fwrd ;safety check if FORWARD switch is released return ;if yes, skip this step ; if no return to main btfsc left ;safety check if LEFT switch is released return ;if yes, skip this step ; if no return to main btfsc right ;safety check if RIGHT switch is released return ;if yes, skip this step ; if no return to main btfss bwrd ;check if BACKWARD switch is still pressed return ;if yes, skip this step ; if no return to main call BAON call BAOFF BAON bsf PORTA,2 ;turn BACKWARD relays ON btfsc fwrd ;check if FORWARD switch is pressed return ;if pressed return to main ; if not skip this step btfsc left ;check if LEFT switch is pressed return ;if pressed return to main ; if not skip this step btfsc right ;check if RIGHT switch is pressed return ;if pressed return to main ; if not skip this step btfss bwrd ;check if BACKWARD switch is still pressed return ;if yes, skip this step ; if no return to main goto BAON BAOFF bcf PORTA,2 ;turn BACKWARD relays OFF call delay call delay call delay goto begin Table3 btfsc right ;safety check if RIGHT switch is released return ;if yes, skip this step ; if no return to main call LEON call LEOFF LEON bsf PORTA,1 ;turn LEFT relays ON btfss left ;wait until LEFT button is released return goto LEON LEOFF bcf PORTA,1 ;turn LEFT relays OFF call delay call delay call delay goto begin Table4 btfsc left ;safety check if LEFT switch is released return ;if yes, skip this step ; if no return to main call RION call RIOFF RION bsf PORTA,0 ;turn RIGHT relays ON btfss right ;wait until RIGHT button is released return goto RION RIOFF bcf PORTA,0 ;turn RIGHT relays OFF call delay call delay call delay goto begin delay movlw d'255' movwf counta again_a decfsz counta, 1 goto again_a movlw d'255' movwf countb again_b decfsz countb, 1 goto again_b movlw d'255' movwf countc again_c decfsz countc, 1 goto again_c return end