PDA

View Full Version : PortA , PortB



DiGGi
- 10th September 2006, 15:55
Hello,
I have a problem. I'm using PIC16F627A and PicBasic-Compiler (NOT PRO!!).
If I use e.g. the commands 'PINx' , 'Button' or 'High/Low' they all work only on PortB. Is there a possibility that they work on PortA ??

Dirk

BobK
- 10th September 2006, 16:18
Hi DiGG,

Did you remember to disable the analog and comparator features on PortA?

BobK

DiGGi
- 10th September 2006, 16:43
How can i disable them?

BobK
- 10th September 2006, 17:11
Hi DiGGi,

It usually depends on what's in the data sheet for the particular PIC you are using. These are something like: ADCON1 = 7 to disable the analog inputs and make the pins digital and CMCON = 7 to disable the comparators. There is a section in the PIC datasheet for each of these 2 items. Go to www.microchip.com and in the search field enter the part number you want a manual for. example: PIC16F628. This will give you selections on all the available documents for that part.

ADCON1 and CMCON are then placed in your initialization section of your program.

Please bear in mind that PICs that have analog ports don't necessarily have comparators. This is why you need to have the datasheet handy to refer to.

BobK

DiGGi
- 10th September 2006, 17:32
Hi,
fiorst ThX for your help, but in my data sheet there is no ADCON1 and CMCON.

is there an other solution , for PIC16F627A?

Diggi

paul borgmeier
- 10th September 2006, 17:41
...If I use e.g. the commands 'PINx' , 'Button' or 'High/Low' they all work only on PortB. Is there a possibility that they work on PortA ??
No - As I remember, PBC does not have predefined pins or directions for PORTA. You must do them directly (make sure you turn off any analog presets as Bob has noted – this requirement is PIC specific).

For example to make RA0 high,


poke $85, %00000000 ' make all PORTA outputs
poke $05, %00000001 ' set RA0 high

to turn off RA0 and turn on RA1, you could then do this


poke $05, %00000010
Ask if you need more and good luck

mister_e
- 10th September 2006, 17:43
Ok i do a try, PicBasic is far different from PBP...

try


POKE $1F,7 ' disable comparator


refer to figure 4-2 of the datasheet for the memory map, and section 10 for the comparator module

About 'Pin' Statement... i guess it's valid but i can't confirm how and why... time for me to purchase PBC. I hate to guess..

DiGGi
- 10th September 2006, 18:02
hi

Thank you both.

@paul borgmeier, yes i know but i want to read the pin states seperately

@mister_e the command you sent is working in PB but how can i controle the Pins on PortA with comands like Button/Pin ?

Dirk

paul borgmeier
- 10th September 2006, 18:03
i guess it's valid but i can't confirm how and why... time for me to purchase PBC. I hate to guess..
Hi Steve,
No need to buy PBC or guess - the manual is free online on MELABs site.

http://www.melabs.com/resources/index.htm#Manuals

paul borgmeier
- 10th September 2006, 18:22
@paul borgmeier, yes i know but i want to read the pin states seperately

Not tried but should work


poke $85, $04 ' make RA2 an input
...
peek $05, B0 ' read all of PORTA
B0=B0 & $04 ' isolate bit 2
IF B0 = 0 then TurnOFF
do something here if B0 = 1
goto IFEXIT
TurnOFF:
do something here if B0 = 0
IFEXIT:
...

DiGGi
- 10th September 2006, 18:27
hi

The text in '2.2. The Pins' chapter says that PIN, Button - Commands only work on PortB. That is annoying.

If I would use PEEK the stats of every pin would be written in a var.
E.G. Pin 4 and Pin 6 are high , tha var would look like %01010000.
Is that right?

paul borgmeier
- 10th September 2006, 18:30
If I would use PEEK the stats of every pin would be written in a var.
E.G. Pin 4 and Pin 6 are high , tha var would look like %01010000.
Is that right?

Yes - BITWISE operate to find what you want. See the LET command for more in the PBC manual and my example above your last post.

DiGGi
- 10th September 2006, 18:33
Thanks a lot @ all
I'll try this suggestion and i'll let you know the result.

Dirk

mister_e
- 10th September 2006, 18:34
Edit: nevermind... too late ;)

BobK
- 10th September 2006, 21:33
Hi DiGGi,

What has been said to you in the last few replies has been correct. If you want to get real basic here you can read porta like this:

Peek PortA, B0 Read PortA and put results in Variable B0
If Bit0 = 1 then task 1 'Reads PortA pin 0, if 1 then goto task 1
If Bit1 = 1 then task 2 'Reads PortA pin 1, if 1 then goto task 2
If Bit2 = 0 then task 3 'Reads PortA pin 2, if 1 then goto task 3

This is really the basic way I started. You can do the BITWISE operations like Paul was showing you also. Whatever you are comfortable with.

Variable B0 now represents a reading of the pins on PortA. you can now look at each pin individually.

Do you have a copy of the PBC manual? If not goto www.melabs.com and download a copy. There is a 2 page explanation on PEEK and a small explanation of POKE.

BobK

DiGGi
- 10th September 2006, 21:44
thx

i read that manual allready. And found the Bitx command. But i haven't time to test it yet. I'll tiy it later. And let you know if it works or not.

Dirk

paul borgmeier
- 10th September 2006, 22:00
...If you want to get real basic here you can read porta like this:

Peek PortA, B0 Read PortA and put results in Variable B0
If Bit0 = 1 then task 1 'Reads PortA pin 0, if 1 then goto task 1
If Bit1 = 1 then task 2 'Reads PortA pin 1, if 1 then goto task 2
If Bit2 = 0 then task 3 'Reads PortA pin 2, if 1 then goto task 3

...

Bob,
Nice addition - your approach is certainly easier and faster to write. Utilizing the fact that Bit0, Bit1, etc. are predifeined as the bits of B0 is the better approach for straightforward (i.e., normal) operations. Thanks for adding - now Dirk has lots of options. If it were me, I would skip the bitwise stuff and use what Bob has above.

DiGGi
- 14th September 2006, 08:07
hi,

my prog i working by using Peek and Bit0, Bit1 ...

Thanks for your help!

Diggi