PORTA register won't bit set (MPLAB)

Nov 22, 2006 5 Replies

When I execute my simple program in MPLAB the PORTA filer register bit 0 is not being set, but I can easily set bit 0 of the FSR register that sits right next to PORTA in the micro. In fact, nothing I do to PORTA works. Has anyone seen this before?



Start BSF STATUS, RP0 MOVLW B'11111110' BCF STATUS, RP0



BSF PORTA, 0 ;doesn't work BSF FSR, 0 ;works



Thanks, Thomas


is

as

porta is analoge by default, you need to set it to digital.

What is the purpose of the first three lines? And why do you change RP0 before and after the MOVLW? Doesn't make sense...

Maybe you meant to do this:

START BSF STATUS,RP0 MOVLW B'11111110' MOVWF TRISA BCF STATUS,RP0

BSF PORTA,0 ...

Some PICs have analogue inputs (for comparator/ADC modules) multiplexed with port A, in which case you need to disable these modules to use port A for general I/O. See the PIC's data sheet.

Regards, Costas _________________________________________________ Costas Vlachos Email: c-X-vlachos@hot-X-mail.com SPAM-TRAPPED: Please remove "-X-" before replying

porta is analoge by default, you need to set it to digital.

Thanks! That was it.

Hi Thomas,

Also ideally you need to be writing to LATB instead of PORTB. Of course you

*can* write to PORTB but it's a bad practice to get into. It can create headaches and quite mysterious behaviour as you become more advanced.

Remember.. Writes to the latch, Reads from the port.

There's alot of information regarding this topic;

formatting link
Lots of good info on the Microchip Forum too. Be concise with them on there because if you give the impression that you're not trying at all or haven't read the manual, well, you'll get the hang on it. :)

Good luck :)

Is RP1 = 0? PortA is only in bank 0 and you may be switching between banks 2 and 3 with your code.

Mike.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required