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.

Help with pic code

Status
Not open for further replies.

hantto

Member
Hello, i have coded a bit of code. It should read the portb inputs and hold the porta 2 low for 100ms if the b port was high, or high for 100ms if the portb was low. And it should continue and check every potb pin. Put for some reason it just switches on porta 2 if portb 4 is low. It doesn't continue to other ports.

Any help is mostly welcome!

Code:
Send
	bcf	portA,	LedSend
	movf	Bit_temp,	w
	xorlw	d'8'
	btfsc	status, z
	clrf	Bit_temp	
	
	btfss	portB,	Bit_temp
	goto	SendBit
	call	del100
	incf	Bit_temp,	f
	goto	Send
	
SendBit
	bsf	portA,	LedSend
	call	del100
	incf	Bit_temp,	f
	return
 
Just a few things here.

1) the btfss f,d (from the any pic data sheet) stores f as a seven bit adderss and b as a three bit
constant. Not knowing what uC you are using you should get a warning about truncation when you compile it.

2) You are using a goto SendBit and then a return from that. Need to use a call or you are going to get
stack overflow and the program will not work correctly.

try that sould fix it.
kingpin094
 
I'm using a pic16f628. I fixed the call/goto issue. But I don't cuite understand your first point. Do you mean that I can't use

Code:
incf	Bit_temp,	f

because it stores it in a wrong format? So i have to approach the problem from a different view and rewrite that part of the code?

This is the warning i get:

74 : Argument out of range. Least significant bits used.

As I understand this it shouldn't have any difference as long as the value doesn't exced 7. And it "doesn't" because it's reseting it to zero before it can read it with an 8 stored.
 
hantto said:
This is the warning i get:

74 : Argument out of range. Least significant bits used.

As I understand this it shouldn't have any difference as long as the value doesn't exced 7. And it "doesn't" because it's reseting it to zero before it can read it with an 8 stored.

You're looking at the wrong line, that one was fine - this is the one which is wrong!.

Code:
btfss   portB,   Bit_temp

You don't give any indication of what Bit_Temp is, but I'm presuming it's a variable - you can't use a variable in this way - BTFSS requires a constant, between 0 and 7.
 
Yes Bit_temp is a variable. So it is not possible to use a loop to read all the pins? I have to read all the pinns independently. So much for my attempt to do a bit of a 'better' code :)

Ok thanks for the help. Much appreciated!

Ofcourse if it is possible to do this in a loop, i'd be glad to know how.

Here's the whole code, if intrested.
 

Attachments

  • code.txt
    1.4 KB · Views: 215
hantto said:
Yes Bit_temp is a variable. So it is not possible to use a loop to read all the pins? I have to read all the pinns independently. So much for my attempt to do a bit of a 'better' code :)

Ok thanks for the help. Much appreciated!

Ofcourse if it is possible to do this in a loop, i'd be glad to know how.

You can do it in a loop by reading the port to a register, then shifting the register bit by bit in to CARRY, and checking that. If you check my tutorial RS232 transmit routines they do this same procedure to transmit a byte in W.

However, checking each pin with a BTFSS would only take 16 lines, and execute considerably faster (if that was a concern?) - plus it gives the added advantage of easily allowing seperate routines for each pin.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top