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.

Odd issue with PORTA on PIC24

Status
Not open for further replies.

Shipton

New Member
So I'm trying to work through "Learning to Fly the PIC24." The author uses a PIC24FJ128GA010 but I have a 24HJ32GP202.

Currently, I'm using the following C30 program:

//
// Test
//

#include <p24hj32gp202.h>

int main()
{
TRISA = 0;
PORTA = 0xff;

return 0;
}

However, after execution in the MPLAB SIM, the watchlist claims that PORTA is 0x0014.

I have no idea why this is happening. I've tried a range of numbers and they all come out wrong. I realize that There are only pins RA0-RA4 on the HJ32GP202, so I even tried PORTA = 0x01, and it still comes out wrong.

Any help would be greatly appreciated
 
Bump:
Can anyone help?

Similar things happen with PORTB as well. For instance

#include <p24hj32gp202.h>

int main()
{
TRISB = 0;
PORTB = 0b10100;




return 0;
}

FOr some reason incurs PORTB to have the value "10000" afterwards. I don't understand why this is happening - and this in the simulator in MPLAB.
 
Last edited:
So I figured out it has to do with the default configuration of the pins as being analog.

However, I still can't get port A to completely work:

#include <p24hj32gp202.h>
//#include <p24FJ128GA010.h>

int main()
{
AD1PCFGL = 0xFFFF;
TRISA = 0;
PORTA = 0xFF;




return 0;
}

PORTA has 5 pins; sure enough, LATA is 00011111; but PORTA is still 10111. I can't figure out why - in this case RA3 - won't get HI.
 
All ODCx are at their default setting - just to note this is the simulator. I haven't touched the ODCs so I assume that it isn't. RA3 is also CLKO and OSC2, but those control bits also appear to be off. I'm baffled.
 
You could try writing to the LATA and LATB registers. Most new PICs have separate read and write registers for the ports, to get over the read-modify-write problem.

It is normal to write to the LAT registers and read from the PORT registers.
 
Yeah, I tried to write 0b11111 to the LATA register - but PORTA still reads 10111. Still can't seem to get RA3 to go HI.
 
Don't know what's going on, but on quick glance of the datasheet https://www.electro-tech-online.com/custompdfs/2010/01/70289F.pdf
I noticed page 104 there's a note saying: Note: Pull-ups on change notification pins should always be disabled when the port pin is configured as a digital output.
RA3 is CN29, a change notification pin, something where it can listen for an interrupt that needs to perhaps be turned off?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top