Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 22nd August 2004, 04:24 PM   #1
Default Help with pic code

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
hantto is offline  
Old 22nd August 2004, 06:31 PM   #2
Default

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
Kingpin094 is offline  
Old 22nd August 2004, 07:03 PM   #3
Default

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 is offline  
Old 22nd August 2004, 09:27 PM   #4
Default

Quote:
Originally Posted by hantto

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 23rd August 2004, 12:22 PM   #5
Default

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.
Attached Files
File Type: txt code.txt (1.4 KB, 32 views)
hantto is offline  
Old 23rd August 2004, 01:10 PM   #6
Default

Quote:
Originally Posted by hantto
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply

Tags
code, pic

Thread Tools
Display Modes




All times are GMT. The time now is 08:26 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker