Assembly Language Question, I/O ports

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
This instruction for 16F series:

Rich (BB code):
bsf     status,5
movlw   B'01001100'
movwf   trisb
Does this essentially mean:
RB0 = output
RB1 = input
RB2 = output
RB3 = output
RB4 = input
RB5 = input
RB6 = output
RB7 = output ???

Or, does reading B'xxxxxxx' from left to right go bit 7,6,5,4,3,2,1,0?

Another question: Say pin 4 is RA3/MCLR/Vpp and you want to use it as MCLR. Would you set that pin as input whenever you're specifying the literal value? What about pins that ultimately wont be connected to anything in the circuit, are those better set as inputs or outputs?


I'm sorry to be bothersome with questions like these, but books and online tutorials only go into so much detail... even those specified for "beginners" make too many assumptions of things "you should already know".
 
Last edited:

JDT

Joined Feb 12, 2009
657
Other way round. RB0 is the RH end (the Least Significant Bit).

I/O pins that are not used should be set as outputs.

An unused pin set as an input can "float" between the supply rails and can cause excessive current to flow in parts of the chip. Also, there is a risk of static damage with un-connected inputs. If set as an output, a transistor on the chip internally connects it to ground, shorting any static.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Thanks for the reply. Very helpful.

I/O pins that are being used as a special function, like MCLR, should be specified as inputs or outputs? Does it matter, or will setting that bit's SFR override any B'xxxxxxxx' command?
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Another question regarding the configuration word (bits).

I'm seeing different ways of doing it and am wondering if they are all practical or correct. They are:

1. Setting the configuration in the assembler during programming

2. (double underscore) __config B'xxxxxxxxxxxxxx' (x = 0, or 1)

3. _CONFIG_CP_OFF&_WDT_OFF&_PWRTE_ON&_XT_OSC


My preference seems to be with choice 2, which seems the easiest. Are all 3 methods correct though?
 

AlexR

Joined Jan 16, 2008
732
Setting the config bits during programming is not a good idea. You are likely to forget to do it and even if you do remember it leaves you no record of how the bits were set.
Of the other two methods I prefer 3 since it tells you how the various features are set without you having to dig through the data sheet to decode what the various bits mean. You do however have the syntax wrong. The 3 option should start with the __config command so it should read
Rich (BB code):
__config _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
 
Last edited:

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Thank you for the response. Option 3 that I gave I was quoting directly from one of the online books referenced in AAC's links forum Useful websites for electronics (Ver. 2) to This Page under the heading Example of How to Write a Program. There seems to be some other mistakes I've noticed in this ebook as well, so I'm grateful for the clarification on that. Following the example on this ebook for specifying the include file, the author says:

include "pic16f887inc", which returned an error when I tried it. I've since changed it to #include "p16f887.inc" which did not return an error.

Anyways, point being, thanks for clearing that up.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Thanks Tahmid, always helpful you are.

I need clarification on something else regarding I/O Ports.

When specifying direction for port A when PORTA is only 5 bits wide, using binary, would I use:

movlw B'10011' or...
movlw B'00010011' ?

The datasheet says those unimplemented bits are read as 0, so I assume I would specify all 8 bits, just leaving the 3 unimplemented bits as 0.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
When specifying direction, since PORTA is only 5 bits wide, B'10011' is the same as B'00010011', as the bits 5,6 and 7 are unimplemented. By the way B'10011' reads the same as B'00010011' in either hex or decimal. Even if you write B'11110011' it will still be the same as the higher 3 bits are unimplemented and will make no difference if you write 1 or 0 or nothing at all.
Thanks.
 
Top