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.

How to use 16F628A's PortA.5 as an input ?

Status
Not open for further replies.

Bracer

New Member
My PortA.5 is current connected to +5V by a 4.7k resistor.

Everything works.

Port I would like to use PortA.5 as an input.

I proceed to remove the 4.7K resistor that connects PortA.5 to +5V.

And then connect it to a switch, and also to a 10K to keep it low unless switch turn on.

The whole system fails to work now, the chips internal timing no longer work in a stable fashion.

Must I add in one of those:
@ DEVICE pic16F628A ~~~
stuff ?

Or there's a different wiring for 16F628A PortA.5 ? Thanks :)
 
I'm not sure how to do it within a BASIC environment but just about every bit of programming software I've seen has a place to set the config bits. Check through the menus or mention what IDE you're using or what you're using to burn the HEX to the chip with.
 
In PIC 16F628, all pins in both Ports A and B can be configured as input/output by setting the corresponding bit in TRISA/B registers to 0 for OUT and 1 for IN, except PortA.5 that is input only. So your question is how to configure it as output ?
 
I am very glad you raise this question aljamri.
The thing is: I am unable to set PortA.4 as an output at all.

Even AFTER I have placed these two lines of codes in:
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT 'Use Internal Clock
CMCON = 7 ' Comparators off

It seems PortA.4 can ONLY be use as an input.

I am starting to accept that as a fact.

The question here is, since all PortA are by default inputs after I've placed these two codes in [I suppose...]:
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT 'Use Internal Clock
CMCON = 7 ' Comparators off

WHY couldn't I get PortA.5 to behave as an input ? [PortA.6 is ok...so why not PortA.5 ?] :(
It seems PortA.5 MUST be connect to +5V via a 4.7K just for the chip to work properly.

Remove that 4.7K and configure this pin as a normal input [10K to ground and a switch to +5V] and it not only didn't execute whatever it should execute when PortA.5 is high, the whole chip seems to lost a sense of timing !

What is that one line of code I have to put in PICBasic Microstudio to get PortA.5 to work as input correctly ?
Why does it desperately needs to connect to positive via a 4.7K in the first place ?

Help me :)
 
Last edited:
PortA4 can only sink current, not source it, check the datasheet. PortA5 CAN be used as an input or output but MCLR must be disabled in the config word as mentioned above. Have you also set the TrisA register(s) appropriately? A one in the bit posistion for input and a zero for an output.
 
We've alread explained why you can't use RA5, because you're not setting it in the config fuses. RA5 can be an input ONLY, but you must set the config fuses to use internal reset, and not leave RA5 as the MCLR pin.

I don't know if you meant to mention RA4 above?, but RA4 can be either input or output, although as an output it's an open-drain pin, so requires an external pullup for general use.

So:
RA5 can be input only.
RA4 can be either.

As others have suggested, you need to consult the PICBASIC instructions for how to set the config fuses.
 
So is there a way to "disable" the MCLR ?
It's something "like" these two lines of codes right ?

@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT 'Use Internal Clock
CMCON = 7 ' Comparators off

What is that line of code that can disable the MCLR ?
 
Last edited:
So is there a way to "disable" the MCLR ?
It's something "like" these two lines of codes right ?

@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT 'Use Internal Clock
CMCON = 7 ' Comparators off

What is that line of code that can disable the MCLR ?

It's specific to PICBASIC, I've no idea what it might be in other than assembler.

There should be a number of include files, which refer to the individual PIC's, check the one for the PIC you're using and you should be able to spot the required line, the section of the asembler file looks like this.

Code:
;==========================================================================
;
;       Configuration Bits
;
;==========================================================================

_BODEN_ON                    EQU     H'3FFF' ;Backwards compatability to 16F62X
_BODEN_OFF                   EQU     H'3FBF' ;Backwards compatability to 16F62X
_BOREN_ON                    EQU     H'3FFF'
_BOREN_OFF                   EQU     H'3FBF'
_CP_ON                       EQU     H'1FFF'
_CP_OFF                      EQU     H'3FFF'
_DATA_CP_ON                  EQU     H'3EFF'
_DATA_CP_OFF                 EQU     H'3FFF'
_PWRTE_OFF                   EQU     H'3FFF'
_PWRTE_ON                    EQU     H'3FF7'
_WDT_ON                      EQU     H'3FFF'
_WDT_OFF                     EQU     H'3FFB'
_LVP_ON                      EQU     H'3FFF'
_LVP_OFF                     EQU     H'3F7F'
_MCLRE_ON                    EQU     H'3FFF'
_MCLRE_OFF                   EQU     H'3FDF'
_RC_OSC_CLKOUT               EQU     H'3FFF'
_RC_OSC_NOCLKOUT             EQU     H'3FFE'
_ER_OSC_CLKOUT               EQU     H'3FFF' ;Backwards compatability to 16F62X
_ER_OSC_NOCLKOUT             EQU     H'3FFE' ;Backwards compatability to 16F62X
_INTOSC_OSC_CLKOUT   	     EQU     H'3FFD'
_INTOSC_OSC_NOCLKOUT         EQU     H'3FFC'    
_INTRC_OSC_CLKOUT   	     EQU     H'3FFD' ;Backwards compatability to 16F62X
_INTRC_OSC_NOCLKOUT	     EQU     H'3FFC' ;Backwards compatability to 16F62X
_EXTCLK_OSC                  EQU     H'3FEF'
_HS_OSC                      EQU     H'3FEE'
_XT_OSC                      EQU     H'3FED'
_LP_OSC                      EQU     H'3FEC'
 
All these talks about opening the include file/fuses to disable the MCLR is freaking the hell out of me, I don't understand why one have to mess with the internal files to make this work.

But thanks to everyone's hinting [TURN OFF MCLR !]
I have finally Found that ONE LINE OF CODE that will make it work.
Thanks to:
16F628A and RA5 (MCLR pin)
Post Number 1

For anyone in the future that is having trouble with using 16F628A PortA.5,
copy and copy this single line in top of your code:
@ DEVICE pic16F628A, MCLR_OFF

That's all, no need for scary opening include files and stuff, just this one line :)
 
Last edited:
All these talks about opening the include file/fuses to disable the MCLR is freaking the hell out of me, I don't understand why one have to mess with the internal files to make this work.

But thanks to everyone's hinting [TURN OFF MCLR !]
I have finally Found that ONE LINE OF CODE that will make it work.
Thanks to:
16F628A and RA5 (MCLR pin)
Post Number 1

For anyone in the future that is having trouble with using 16F628A PortA.5,
copy and copy this single line in top of your code:
@ DEVICE pic16F628A, MCLR_OFF

That's all, no need for scary opening include files and stuff, just this one line :)

We all knew you only needed one line, but the 'one line' is PICBASIC specific - we were making suggestions as to how you could find what it needed to be.
 
Code:
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT, MCLR_OFF
CMCON = 7

Counter var Byte
Counter = 0

Routine:

For Counter = 0 to 6
High PortB.Counter
Next Counter

pause 500

For Counter = 0 to 6
Low PortB.Counter
Next Counter

pause 500

GoTo Routine


Apparently:
Code:
High PortB.Counter
and
Code:
Low PortB.Counter
is giving me errors, I could have done this with no errors:
Code:
For Counter = 0 to 6
High Counter
Next Counter
but this will be a PICBasic command and I will not be able to control PortA.

How do I use the For Next Loop to handle PortA too ?
 
Last edited:
Have you tried searching the picbasic forum? Just seems logical since you found the answer to your first question there.
 
Status
Not open for further replies.

Latest threads

Back
Top