morganlamprecht
Newbie level 2
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);
}
}
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);
}
}