Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

My first code ever, will it work?

Status
Not open for further replies.

Lac

New Member
Ok, this is my first pic assembly code i have ever written, so there are surly some errors in there. But what I want to to is this:

I have two buttons, one connected to pin 1 and the other to pin 2. When one of the buttons are pushed, it will drag the pin it is onnected to low, the pic will then detect wich button is pushed (or both at once) and send the correct output to 2 output pins.

I'm not able to test this myself cause I haven't got my pic yet.

Cheers!
Lac.

Code:
		LIST	P=16F628, F=INHX8M
		include	"P16F628.inc"
		__CONFIG	0x3DED
		ORG	0x0000

STATUS		equ	03h
TRISA		equ	85h
PORTA		equ	86h
COUNT1		equ	08h
COUNT2		equ	09h

		bsf	STATUS,5
		movlw	00011
		movwf	TRISA
		bcf

check1		BTFSC	PORTA,0
		goto	check4
		goto	check2

check2		call	delay
		BTFSC	PORTA,1
		goto	BANK1
		goto	BANK3

check3		call	delay
		BTFSC	PORTA,0
		goto	BANK2
		goto	BANK3

check4		BTFSC	PORTA,1
		goto	check1
		goto	check3

BANK1
		MOVLW	00000
		MOVWF	PORTA
		call	delay	
		call	delay
		call	delay
		end

BANK2		MOVLW	00100
		MOVWF	PORTA
		call	delay	
		call	delay
		call	delay
		end

BANK3		MOVLW	01000
		MOVWF	PORTA
		call	delay	
		call	delay
		call	delay
		end

Delay

Loop1
		decfsz	COUNT1,1
		goto	Loop1
		decfsz	COUNT2,1
		goto	Loop1
return

end
 
im not gonna comb through it but your one line is just "bcf" i suppose you mean "bcf STATUS, 5" but i would recommend getting rid of that STATUS bit stuff and just use the standard microchip includes so you can just use RP0...
also "movlw 00011" should be movlw 0x03, or movlw b'00000011'
also you cant use "end" in the code, it will cause the compiler to stop assembling and ignore everything after it, use return to end a call
also you cant do those decfsz's at the end because COUNT1 and COUNT2 are literal values, they are not file registers. You need to use the cblock command to allocate ram for them

see the tutorials posted here they should be a good help...

Good Luck!
 
Your delay will work fine, but you must remove the end's from bank1.2.3.
Code:
loop	goto	loop
or
Code:
goto $
make the pic to start endless loop in the same address !


Turn off the comparator otherwise you can't use the porta
Code:
movlw	0x07
movwf	CMCOM

USE some kind of simulator/emulator to debug your code !
MPLAB SIM
PROTEL's DEMO
Picsimulator
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top