• 0
Sign in to follow this  
Tawachi

Enabling Input / Output ports on Digilent ChiKit WiFire

Question

Hi,

I adapted an MPLAB X program from Dogan Ibrahim's book based on PIC18 microcontroller for my PIC32 WiFire ChipKit. However the following two configuration statements generated errors during building (the syntax is unknown to the compiler) and I therefore commented them out.

//Configuration: Ext reset, Watchdog OFF, HS oscillator
//#pragma config MCLRE = ON, WDT = OFF, OSC = HS

//MEMCONbits.EBDIS = 1; //Enable input / output functions

The program was able to build, however it could not do as programmed (the LED 4 did not switch on when button 1 was pressed). I think this is related to the statements I commented out, Kindly assist to troubleshoot and for the correct syntax. Below is the full program.

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

//Configuration: Ext reset, Watchdog OFF, HS oscillator
//#pragma config MCLRE = ON, WDT = OFF, OSC = HS
//
//Define switch and LED connections
#define BTN1 PORTAbits.RA5
#define LED4 PORTGbits.RG15
//
//Define clock frequency
#define _XTAL_FREQ 10000000
//
//Start of main program


int main(int argc, char** argv) {

    TRISAbits.TRISA5 = 1; //Configure RA05 as input
    TRISGbits.TRISG15 = 0; //Configure RG15 as output
    //MEMCONbits.EBDIS = 1; //Enable input / output functions
    
    for (;;) { //do forever
        if (BTN1 == 0) //If BTN1 is pressed
            LED4 =1; // LED 4 is turned ON
        else
            LED4 =0;
    }
  }

 

Edited by KaitlynFranz

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hey Tawachi,

Have you tried using the "Set Configuration Bits" feature in MPLAB? As the compiler gave you an error saying the syntax was unknown, I would think the current config bit naming is different than what was used for this particular PIC18 project.

Hit the Run drop-down menu and select "Set Configuration Bits". From the window that opens you can fiddle with your configuration bits as you see fit, then just hit the "Generate Source Code to Output" button at the bottom. This generates configuration code you can just copy and paste into your own which should resolve any syntax issues from occurring in your configs. Let me know if this helped or if you run into other issues.

Regards

Share this post


Link to post
Share on other sites
  • 0

Hi NAEastland,

Thank you so much. I have found the 'Set Configuration bit' tool very useful indeed. I however have another issue. I have set LATA to 0xAAAA in a programme, but when debugging I get LATA = 0x000082AA in the Watches window. Similarly when I set LATA to 0xFFFF, I get a different value. I have no clue where this discrepancy is originating from. I am using a PIC32MZ2048ECG100.

Regards

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this