PLZ help with this code for project mplab ASAP :(

Thread Starter

goldfish300

Joined Mar 12, 2009
12
my project is about a game that turn leds on and off . i have 4 leds and 3 button . i need button one when pressed to turn led 1 and 3 on and when button 2 is pressed turn on led 2 and 4 and finally button 3 turn off the leds.

here i have the code , but when i use it it keep the first the third led on and nothing happen when i press on button 2 or the stop one .

the code :

Rich (BB code):
#INCLUDE	"P16F84A.INC"

#DEFINE		PB1	PORTB, 1
#DEFINE		PB2	PORTB, 2
#DEFINE		PB3	PORTA, 3


#DEFINE		LEDY		PORTA, 0
#DEFINE		LEDG		PORTA, 1
#DEFINE		LEDR		PORTA, 2
#DEFINE		LEDW		PORTA, 3

CBLOCK	0X0C
	A1, A2, A3
ENDC

ORG		0X000
GOTO		MAIN


MAIN
	CALL		SETUP
	

FUNCTION	
	BTFSC		PB1
	CALL		GAME1
	BTFSC		PB2
	CALL		GAME2
	BTFSC		PB3
	CALL		STOP
	GOTO		FUNCTION

STOP
	BCF		PORTA,0
	BCF		PORTA,1
	BCF		PORTA,2
	BCF		PORTA,3		

GAME1
	BSF	LEDW
	CALL	DELAY_1S
	BCF	LEDW
	BSF	LEDG
	CALL	DELAY_1S
	BCF	LEDG
	GOTO	GAME1

GAME2
	BSF	LEDR
	CALL	DELAY_1S
	BCF	LEDR
	BSF	LEDY
	CALL	DELAY_1S
	BCF	LEDY
	GOTO	GAME2

DELAY_1S
	MOVLW	D'46'	
	MOVWF	A1
	MOVLW	D'189'
	MOVWF	A2
	MOVLW	D'37'
	MOVWF	A3
	DECFSZ	A3
	GOTO		$-1
	DECFSZ	A2
	GOTO		$-5
	DECFSZ	A1
	GOTO		$-9
	RETURN

SETUP
	CLRF		PORTA
	CLRF		PORTB
	BSF		STATUS, RP0
	CLRF		TRISA
	MOVLW	B'00001110'
	MOVWF	TRISB
	BCF		STATUS, RP0
	RETURN

END
and the drawing here :


plz help im having it tomor :confused::confused::confused:
 

thatoneguy

Joined Feb 19, 2009
6,359
In GAME1 and GAME2 routines, you end up in an infinite loop.

You need to check for the button presses in each of the games, on each loop.

The code is doing exactly what you told it to, unlike object oriented/event oriented programming which runs multiple tasks, assembly is very literal.
 
Top