Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MPLAB Sim Debugger watch window PORTA and PORTE not showing values

Status
Not open for further replies.

morganlamprecht

Newbie level 2
Joined
Aug 24, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
I am writing a simple code to test a PIC18F4520 digital output operation...just sending bytes to the ports to light LEDs...while debugging my code with MPLAB Sim, in the watch window PORTA shows a value of 0xD0 loaded into it and PORTE shows 0x00...all other ports are showing correct values...i know that some config bits disable certain port pins but i have searched the net and think i have it configured correctly...here is the code...thanks in advance for the help

btw...ive tried simply addressing both ports with PORTA and PORTE, LATA and LATE, sending binary instead of hex numbers, and using BSF...still yields same results

#include <p18f4520.h>
#include "portb.h"
#include "delays.h"

/* CHANGE HARDWARE VARIABLE TO MEANINGFUL VARIABLE */
/* Define LED0 as LATDbits.LAT0 */
//#define LED0 LATDbits.LAT0
#define LED0_7 LATA
#define LED8_15 LATB
#define LED16_23 LATC
#define LED24_31 LATD
#define LED32_39 LATE


//Config bits currently not set in code
#pragma config OSC = INTIO67 /* Sets the oscillator mode to INTIO2 */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#pragma config DEBUG = ON /* Compiles with extra debug code */

/* Define values for ON and OFF states */
#define ON 0xFF
#define OFF 0x00

void Config(void);
void LEDByteTest(void);
void LEDBitTest(void);

void main()
{
for(;;){
Config(); //calls Config function to set up port configurations
LEDByteTest(); //runs through LED test to test DO Ports
}
}

void Config(void){
/* Set PORT A as digital outputs */
LATA = 0x00;
TRISA = 0x00;
/* Set PORT B as digital outputs */
LATB = 0x00;
TRISB = 0x00;
/* Set PORT C as digital outputs */
LATC = 0x00;
TRISC = 0x00;
/* Set PORT D as digital outputs */
LATD = 0x00;
TRISD = 0x00;
/* Set PORT E as digital outputs */
LATE = 0x00;
TRISE = 0x00;

return;
}

void LEDByteTest(void){

/****************** TURN ON *********************/

/* Turn on LED, A0-A7 */

LED0_7 = ON; //Turns ON PORTA (LATA)

Delay1KTCYx(10000);

/* Turn on LED, B0-B7 */

LED8_15 = ON; //Turns ON PORTB (LATB)

Delay1KTCYx(10000);

/* Turn on LED, C0-C7 */

LED16_23 = ON; //Turns ON PORTC (LATC)

Delay1KTCYx(10000);

/* Turn on LED, D0-D7 */

LED24_31 = ON; //Turns ON PORTD (LATD)

Delay1KTCYx(10000);

/* Turn on LED, E0-E7 */

LED32_39 = ON; //Turns ON PORTE (LATE)

Delay1KTCYx(10000);
}

}
 

You do not appear to have disabled any other peripherals which share the ports you are using.

PORTA Reference: PIC18F2420/2520/4420/4520 Data Sheet, pg 105, Section: 10.1 PORTA, TRISA and LATA Registers



The other PORTA pins are multiplexed with analog
inputs, the analog VREF+ and VREF- inputs and the comparator
voltage reference output. The operation of pins
RA3:RA0 and RA5 as A/D converter inputs is selected
by clearing or setting the control bits in the ADCON1
register (A/D Control Register 1).
Pins RA0 through RA5 may also be used as comparator
inputs or outputs by setting the appropriate bits in the
CMCON register. To use RA3:RA0 as digital inputs, it is
also necessary to turn off the comparators.

The TRISA register controls the direction of the PORTA
pins, even when they are being used as analog inputs.
The user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs.

Note: On a Power-on Reset, RA5 and
RA3:RA0 are configured as analog inputs and
read as ‘0’. RA4 is configured as a digital input.

Example for Port A:
Code:
LATAB = 0;   Alternate method to clear output data latches
ADCON1 = 7; Disable  ADC module
CMCON = 7; Disable Comparator Module
TRISA = X, Set direction of I/O (input or output)

PORTE depending on its peripheral configuration, may have a similar initialization procedure, check the datasheet for details.

BigDog
 
Last edited:
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
thanks bigdog...pointed me in the right direction...had to configure

ADCON0 = 0x00
ADCON1 = 0x0F

everything is working now
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top