PDA

View Full Version : PortA as Inputs in PIC16F628A program



JackBauer2424
- 9th February 2006, 07:20
I'm working on the following simple piece of code that serouts the states (high or low) of its PortA and PortB pins. Right now it's successfully sending the PortB states but I'm not getting accurate PortA states. Please tell me what I'm doing wrong and feel free to comment if you think there's a better way to do this.
Thanks

SYMBOL PortA = 5
SYMBOL TrisA = $85
SYMBOL PortB = 6
SYMBOL TrisB = $86
SYMBOL CmCom = $1F
SYMBOL Ready = 2
SYMBOL Load = 1
SYMBOL Xmit = 3

POKE TrisA,%11111111 'only using PORTA.0-PORTA.3 in real application
POKE TrisB,%11110101
POKE CmCom,%00000111


Main:
IF Pin2 = 1 THEN Transmit

GOTO Main


Transmit:
HIGH Load
PEEK PortB,B0
PEEK PortA,B1

LOW Load

SEROUT Xmit, N9600, ("A","B",B0,B1) '"A" and "B" are qualifiers
GOTO Main

'End of Program

sougata
- 24th February 2006, 06:44
Hi,

Your chip has an onboard voltage comparator. You can turn this off by inserting:

CMCON = 7

This may solve your problem.

Regards

Sougata

mramos
- 31st May 2006, 00:01
The books shows

Symbol CMCON = $1f
Poke COCON ,7

or

poke $1f,7 (one line version)

mister_e
- 31st May 2006, 01:24
As i can't say how read from a pin in PBC and you have correctly POKE the CMCON register in your code example in the first post, my question is... how do you connect your switch to the PORT? Any pull-up/pull-down resistor?

I guess one day i'll buy PBC myself too just for fun :D

mister_e
- 31st May 2006, 01:32
let's do a try... sorry if i'm wrong.. i try


Main:
peek PORTA,B0
if Bit1=1 then transmit ' iF PORTA.1=1 then transmit
GOTO Main

mramos
- 31st May 2006, 03:05
Main:
peek PORTA,B0
if Bit1=1 then transmit ' iF PORTA.1=1 then transmit
GOTO Main


The peek reads porta into B0 (you did not include where you have porta defined (unless PB has it defined.. I doubt it, maybe PBP does, I made an include to drop in my code since BP is not a complete product). B0 is byte 0 in the chip.

Now that it is in B0, you need to IF against B0. So you can AND it (as it is a byte not a bit) with %00000010.

mister_e
- 31st May 2006, 04:23
i based my example on a PBC code example on the Melabs Website.
adcx.bas ==> http://www.melabs.com/resources/samples/x1/pbc/adcx.bas

Our friend already defined PORTA, TRISA and so on on his First post. Read back everything.

As far as i know B0 is a pre-define variable in PBC

BIT1... comes from the PBC code example ( ... ok ok it was BIT2) and nowhere it was pre-define. By their example it seems to return or set the Bit value of B0 variable.

As i said, i tried. I don't have and i don't use PBC.

Let's see what are the result of someone using PBC.

BobK
- 31st May 2006, 05:06
Hello,

If I recall correctly B0 is a byte variable that can be tested for its individual bits. So Mister E is correct. If you peek at a port and have the byte put into the variable B0, then you test the individual pins of the port by testing the bits. Bit0 would be the same as PortA.0 for example. This should also be able to be done with variable B1. It has been a few years since I worked with PBC.

It is a complete product. It serves a specific purpose. Is it the answer to programming with Basic, NO. But it does fill a need if you use it correctly. In my case it didn't fill my need because of what I was trying to accomplish so I bought the upgrade to PBP.

BobK

mister_e
- 31st May 2006, 05:11
BobK, i think our friend mramos is in a kind of PMS or bad mood anyway... http://www.picbasic.co.uk/forum/showpost.php?p=21305&postcount=3

timmoore47
- 31st May 2006, 08:21
Hello,

If I recall correctly B0 is a byte variable that can be tested for its individual bits. So Mister E is correct. If you peek at a port and have the byte put into the variable B0, then you test the individual pins of the port by testing the bits. Bit0 would be the same as PortA.0 for example. This should also be able to be done with variable B1. It has been a few years since I worked with PBC.

It is a complete product. It serves a specific purpose. Is it the answer to programming with Basic, NO. But it does fill a need if you use it correctly. In my case it didn't fill my need because of what I was trying to accomplish so I bought the upgrade to PBP.

BobK

What are PBC's limitations? I've just bought it and wondered what extra goodies which might be useful to me, might be in PBP?

:)

Tim

Melanie
- 31st May 2006, 09:44
Full comparison can be made from the MeLabs website and downloading and comparing the manuals from the two products, but as a (incomplete) summary...

Handy commands such as LCDOut (and others) that save a lot of hassle.

No restrictions on PIC pins and the ability in being able to alias them sensibly.

No restrictions on assigment of variables (RAM) and the ability to alias them.

Powerful IF THEN ELSE ENDIF structure permitting unrestricted nesting.

Easy and direct access to PICs Registers without convoluted PEEKs and POKES.

Ability to embed Programmer CONFIG directives.

The list goes on...

The paradox is that it is the Professional Programmers who have the knowledge and expertise to make PBC do anything they want, yet it is a product aimed at the bottom-end hobbyist. Whilst it is PBP that has all the easy to use features a novice needs, but it is aimed at the Professional. Time is money and life is short... how much of your life do you want to devote to your programming?

mramos
- 31st May 2006, 17:30
Full comparison can be made from the MeLabs website and downloading and comparing the manuals from the two products, but as a (incomplete) summary...

Handy commands such as LCDOut (and others) that save a lot of hassle.

No restrictions on PIC pins and the ability in being able to alias them sensibly.

No restrictions on assigment of variables (RAM) and the ability to alias them.

Powerful IF THEN ELSE ENDIF structure permitting unrestricted nesting.

Easy and direct access to PICs Registers without convoluted PEEKs and POKES.

Ability to embed Programmer CONFIG directives.

The list goes on...

The paradox is that it is the Professional Programmers who have the knowledge and expertise to make PBC do anything they want, yet it is a product aimed at the bottom-end hobbyist. Whilst it is PBP that has all the easy to use features a novice needs, but it is aimed at the Professional. Time is money and life is short... how much of your life do you want to devote to your programming?

No PMS, I feel IF and ENDIF are part of a good compiler (is one every on I have). And I will make PBC do all I need now that I know its limits.

timmoore47
- 1st June 2006, 09:34
IF THEN ELSE etc would be Brilliant but as I've got the Compiler version not Pro, I'll do it long hand.

I Just wanted to avoid assembler, due to ease of maintenance of Basic Programs. My needs are not too complex once I've mastered intputing and decisions.

Thanks everyone for your help!

:)

Tim