[SOLVED] 16F84A Transmission controller

Status
Not open for further replies.

shifteh

Newbie level 6
Joined
Jun 28, 2011
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,400
16f84A, 20Mhz,

hello basically transmission has 2 wires
wire1 wire 2
First 1 1
Second 0 1
Third 0 0
Forth 1 0

as you can see above depending on which wire has 12v+ the gear is selected

i have 2 inputs porta's pin 0 and 1
2 outputs portb's 0 and 1

this is my code so far, im pretty much a noob so im ready to get flamed lol, mplab brings up all thease errors when i try and quick build any advice would be awsome

thanks chris

;**************************************************************************
;
;Sequential gear selector for Ford falcons running the 4 speed Btr gearbox
;
;1.0ver
;
;**************************************************************************
errorlevel -207
#define portb 06h
#define PORTB 06h
#define PORTA 05h
#define porta 05h
;--------------------------------------------------------------------------
; Program Code
;--------------------------------------------------------------------------

ORG 0 ;reset vector
temp1 res 1
Start call init

init
BSF 03h,5 ;Go to Bank 1
MOVLW b'00011' ;Put 00011 into W
MOVWF 85h ;Move 00011 onto TRISA
BCF 03h,5 ;Come back to Bank 0

BSF 03h,5 ;go to bank 1
MOVLW b'00000' ; put 00000 into W
MOVWF 86h ; Set TrisB to output by mooving 00000 into it
BCF 03h,5 ;Come back to bank 1


MOVLW b'00011' ; MOVE FIRST GEAR INTO MEMORY
MOVWF 06h ;LOAD FIRST GEAR INTO PINS




;--------------------------------------------------------------------------------------------
;MAIN PROGRAM LOOP
;------------------------------------------------------------------------------------------

main

btfss PORTA, 0 ;Is "UP" button pressed?
CALL GEARUP ;Higher gear selection has been made

btfss PORTA, 1 ;Is "DOWN" button pressed?
CALL GEARDOWN ;Lower gear selection has been made

goto main



;--------------------------------------------------------------------------
; Subroutines
;--------------------------------------------------------------------------

;--------------------------------------------------------------------------
; GEAR UP SUBROUTINE
;--------------------------------------------------------------------------

GEARUP

_IF
movf portb,w ; CHECKS IF ITS IN FIRST IS SO SELECTS SECOND
sublw .11
bnz _FALSE

_TRUE
call gear2
_FALSE ;FAILED IF TEST ;
call checkforg2


checkforg2
_IF movf portb,w ; CHECKS IF ITS IN SECOND IF SO SELECTS THIRD
sublw .1
bnz _FALSE

_TRUE ;CODE BODY HERE!
call gear3
_FALSE ;FAILED IF TEST
call checkforg3

checkforg3
_IF movf portb,f ; CHECKS IF ITS IN THIRD IF SO SELECTS FORTH
bnz _FALSE

_TRUE ;CODE BODY HERE!
call gear4
_FALSE ;FAILED IF TEST
call checkfortop

checkfortop
_IF movf portb,w
sublw .10
bnz _FALSE

_TRUE ;CODE BODY HERE!

_FALSE ;FAILED IF TEST

goto main

;--------------------------------------------------------------------------
; GEAR DOWN SUBROUTINE
;--------------------------------------------------------------------------

GEARDOWN
_IF movf PORTB,w ; IF IN FORTH GO TO THIRD
sublw .10
bnz _FALSE

_TRUE ;CODE BODY HERE!
call gear3
_FALSE ;FAILED IF TEST
call thirdtosecond

thirdtosecond
_IF movf portb,f ; IF IN THIRD GO TO SECOND
bnz _FALSE

_TRUE ;CODE BODY HERE!
call gear2
_FALSE ;FAILED IF TEST
call secondtofirst

secondtofirst
_IF movf portb,w
sublw .1
bnz _FALSE

_TRUE ;CODE BODY HERE!
call gear1
_FALSE ;FAILED IF TEST

return

;--------------------------------------------------------------------------
; GEAR OUTPUT SELECTIONS
;--------------------------------------------------------------------------

gear1
MOVLW b'00011' ; MOVE FIRST GEAR INTO MEMORY
MOVWF 06h ;LOAD FIRST GEAR INTO PINS FROM MEMORY
goto main

gear2
MOVLW b'00001' ; MOVE SECOND GEAR INTO MEMORY
MOVWF 06h ;LOAD SECOND GEAR INTO PINS FROM MEMORY
goto main

gear3
MOVLW b'00000' ; MOVE THIRD GEAR INTO MEMORY
MOVWF 06h ;LOAD THIRD GEAR INTO PINS FROM MEMORY
goto main

gear4
MOVLW b'00010' ; MOVE FORTH GEAR INTO MEMORY
MOVWF 06h ;LOAD FORTH GEAR INTO PINS FROM MEMORY
goto main

end
 
Last edited:

well ive revised it a bit fixing the
goto xxxx
to
(TAB)goto xxxx

the problem im having now is the _if statements seems to go through the first one ok then gets stuck on the second one with an error 116
read up someware to use LOCAL

how would i use LOCAL in the _IF statements ?


thanks guys
 

ok so basically after reading a fair few things on the net regarding IF statements in asm i understand now that i have NFI lol

can somebody write a quick == for example look at portb , ok so we now have 00011 at portb , subtract 00010 if not left with 00000 then subtract 00001 if not left with etc etc , even a few lines just to pint me in the right direction would be all i need, thanks guys
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…