[General] Need help in MplabX and pic24f

Status
Not open for further replies.

begin_mplab

Newbie level 1
Joined
Oct 28, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
48
hello ,
I'm a beginer in MplabX and in PIC and i would like to begin with a simple example with pic24f and MplabX ,XC16 and a led (i like to understand the configuration of input and output of PIC)(langageC).
So please can you help me to send me a simple example or any link that can help me. (All example that i m found in google are wth MikroC or XC8)
thanks in advance
 

find attached ZIP file containing MPLAB and MPLABX project files
displays a rotating bit pattern on the the LEDs of a Microchip Explorer 16 development board using a PIC24FJ256GB110

program code is
Code:
// LEDblink.c  for Explorer 16 with a PIC24FJ256GB110
//     LEDs are connected to PORT A

#include "p24Fxxxx.h"

_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) 
_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON)

// main program code
int main(void)
{
    int i=1;
	long int j;
	TRISA =0;				//all A bits are output
    while (1)				// loop displaying shifting bit										
      {
       for(j=0;j<100000l;j++) 
	   PORTA=i; 		// output i to PORTA
       i<<=1;				// shift i one bit left				
       if(i>256)i=1;		// if i> 256 reset to 1
      }
}
 

Attachments

  • LEDblink.zip
    103.7 KB · Views: 112

i m trying this project with MplabX and Mplab and in buinlding he dont dissplay me any error
but iwould like to simulate my project in isis and he dont work and display me any error
im modify the project with this : and he dont work
my problem is with the configuration of input output
thnks in advance
 

Attachments

  • blink_led.rar
    35 KB · Views: 111

but i can simulate with isis. i m trying this example but he dont work also!!!
my problem is in the cnfiguration of bits in mplabX
Code:
#pragma config POSCMOD = HS             // Primary Oscillator Select (HS Oscillator mode selected)
#pragma config OSCIOFNC = OFF           // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRIPLL           // Oscillator Select (Primary Oscillator with PLL module (HSPLL, ECPLL))
#pragma config IESO = OFF               // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) disabled)

// CONFIG1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON              // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2               // Comm Channel Select (Emulator/debugger uses EMUC2/EMUD2)
#pragma config GWRP = OFF               // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF                // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG port is disabled)
because isis display me this errrs
 

but i m trying with the same circuit with pic18f and he have worked but in pic24f he dispaly me this errors
 

using your configuration I can simulate this program in MPLABX (it also runs OK on an Explorer 16 board)
Code:
// LEDblink.c  for Explorer 16 with a PIC24FJ256GB110
//     LEDs are connected to PORT A

#include "p24Fxxxx.h"

#pragma config POSCMOD = HS             // Primary Oscillator Select (HS Oscillator mode selected)
#pragma config OSCIOFNC = OFF           // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRIPLL           // Oscillator Select (Primary Oscillator with PLL module (HSPLL, ECPLL))
#pragma config IESO = OFF               // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) disabled)

// CONFIG1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON              // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2               // Comm Channel Select (Emulator/debugger uses EMUC2/EMUD2)
#pragma config GWRP = OFF               // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF                // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG port is disabled)
//_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) 
//_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON)
//_CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS)	

// main program code
int main(void)
{
    int i=1;
	long int j;
	TRISA =0;				//all A bits are output
    while (1)				// loop displaying shifting bit										
      {
       for(j=0;j<100000l;j++) 
			PORTA=i; 		// output i to PORTA
       i<<=1;				// shift i one bit left				
	   if(i>256)i=1;		// if i> 256 reset to 1
      }
}
 
Last edited:

with isis it dont work and if i choose frequency clock 20MHz he display me errir msg and if i choose 8Mhz he dont display me any error but the led not blink
 

plz you are using the explorer 16 in experience and the led are blinked with my configuration? or you are using the simultor of Mplabx not isis. Can you send me the link plz of just explorer 16 board to try with in my experience
thanks in advance
 

plz you are using the explorer 16 in experience and the led are blinked with my configuration? or you are using the simultor of Mplabx not isis. Can you send me the link plz of just explorer 16 board to try with in my experience
thanks in advance
I programmed the Exploer 16 with the code and it displayed the shifting bit on the LEDs
https://www.microchip.com/Developme...m_term=&utm_content=&utm_campaign=Explorer+16

I also ran it using the MPLAX similator and if I watched PORTA I could see the bit shifting
 
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
plz in your simulink file that your are using in the Mplabx simulator you are a pic24fj256ga010 and a led conected to port A or what is your architecture exactly?
thanks in advance
 

plz in your simulink file that your are using in the Mplabx simulator you are a pic24fj256ga010 and a led conected to port A or what is your architecture exactly?
thanks in advance
I am using a PIC24FJ256GB110 and the LEDs are on PORTA

when running MPLABX looks like (breakpoint on line 18 and watching PORTA and variable i)
 
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
i m trying with the Mplabx simulator. I'm doing this step :
1. Build a debug version of the open project by clicking on the Debug Project icon
2.Click “Step Into” to execute one line of source code. Notice the PC increment as the green line goes to the next line in code.
3.From the Window menu select Debugging ,then Watches
4.Highlight the radio button “SFR’s”
Select PORTA from the scrolling menu of Special Function Registers (SFR)
and i m founding this value of portA and i and i dont know if it is true or no
can you explain me please
can you explain me please this explication of this paramter and its hexadecimal value 0x044
thanks in advance
 

in the code
Code:
    while (1)				// loop displaying shifting bit										
      {
       for(j=0;j<100000l;j++) 
			PORTA=i; 		// output i to PORTA
       i<<=1;				// shift i one bit left				
       if(i>128)i=1;		// if i> 128 reset to 1
      }
in the while loop
1. the for() statement is a delay so we can see the bit shifting
2. i is written to PORTA
3. i is ahifted left 1 bit, i.e. its value goes 1 2 4 8 16 32 64 128
4. if i is greater than 128 it is resets to 1 to start the shift pattern again

in the watch window PORTA and i show the shifting bit pattern
0x0001 0x0002 0x0004 ..... 0x0020 0x0040 0x0080
then resets to 0x0001
 
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
Hello, Im trying to display a message in LCD so im begin with th project "_GettingStarted.X" in the link https://microchip.wikidot.com/tls0101:lab2 andi m modify and i m use ISIS to verify my code but he display me a warning in issis
Code:
Clock 4MHz specified in schamtic is ognired for oscillator mode 'FRC'
( (i m trying with pic18f XC8and he has working without any error )
So i m trying to work with the explorere 16 board and i dont know if my code it is true or no because i cant understand the simulator of MplabX because he don't lets me draw the circuit of my card board
my 2 pogramm code and my isis file are in this file.
Can you please verify with me this project
thanks in advance
 

Attachments

  • LCD_frm.rar
    112.7 KB · Views: 113

the LCD code looks OK

try comparing it with the LCD code for an Explorer 16 with a PIC24FJ256GB110 (so some of the pins will be different for other processors)

as far as I know it works (the LCD on both my Explorer 16's are dead so cannot check it)

Code:
// lcd.c -  Explorer 16 - functions for the PC1602-J lcd display 8-bit mode
//
// see http://www.repairfaq.org/filipg/LINK/F_LCD_progr.html

#include "hardware.h"
#include "timer.h"
#include "lcd.h"

// LCD display ports etc
#define LCDdata LATE					// data port
#define LCDdataEnable	TRISE
#define RS LATBbits.LATB15				// RS bit in LCDstatus
#define RW LATDbits.LATD5				// read/write bit in LCDstatus
#define E  LATDbits.LATD4   			// enable bit in LCDstatus
#define Eenable TRISDbits.TRISD4
#define ERSenable TRISDbits.TRISD5
#define RWenable TRISBbits.TRISB15

void lcd_delay() { mSecDelay(2); }  // if LCD does not work make this longer

// Write a nibble to the LCD
// may have to adjust delays to suit the processor and clock
void lcdNibble(int n)
{
    int lcd=LCDdata;
	lcd_delay();
    LCDdata=n;
	lcd_delay();
    E=1;					// take clock E high 
	lcd_delay();
    E=0;
	lcd_delay();
 }

// Write a Control Command to the LCD
// This is written as two nibbles
void lcdCmd(int c)
{
 	RS=0;			        // Take RS pin low for command
	lcdNibble(c);			        // Makeup Lower Nibble
}

// write a data byte to LCD
int lcdPutchar(int d)
{
//    printf("%c", d);
	RS=1; 				// Take RS pin high for data
	lcdNibble(d);		            // Makeup Lower Nibble
    return 1;
}

// Initialise the LCD in 4bit Mode
void lcdInit()
{
	E=0;				// take E low
 	RS=0;				// Take RS pin low for command
 	RW=0;				// Take RS pin low for command
    // set RS, RW and E bits as output
	Eenable =0;
	ERSenable =0;
	RWenable =0;
    LCDdataEnable &= 0x0;          // set bits 0-3 output for data
	lcdNibble(0x3);		// This put the LCD into Soft Reset 
	lcdNibble(0x3);
	lcdNibble(0x3);
	lcdNibble(0x2);
	lcd_delay();
//	lcdCmd(0x28);			// 2 line, 4 bit mode 
	lcdCmd(0x38);			// 2 line, 8 bit mode 
	lcd_delay();
    lcdCmd(0x6);			// increment cursor after each write
	lcd_delay();
    lcdCmd(0x1);			// clear display
	lcd_delay();
    lcdCmd(0x2);			// home
	lcd_delay();
    lcdCmd(0xF);			// turn disply on
	lcd_delay();
}

// move to line (1 or 2) at position >= 1
void lcdCursor(unsigned char line,unsigned char position)
{
   switch (line)
	{
	  case 1:lcdCmd (0x80 + position -1 );lcdCmd (0x80 + position -1 ); break;
	  case 2:lcdCmd (0xc0 + position -1 ); lcdCmd (0xc0 + position -1 ); break;
	  default : break;
  	}
  lcd_delay();
}

void lcdString(unsigned char line, unsigned char position, unsigned char *string)
{

	lcdCursor(line,position);
	while (*string)
	  lcdPutchar(*string++);

}

void lcdStringAtCursor(unsigned char *string)
{

	while (*string)
	  lcdPutchar(*string++);
}

void lcdClear(void)
{
	lcdCmd(0x01);
}

void lcdHome(void)
{
	lcdCmd(0x02);
}


// clear line 1 or line 2
void lcdClearLine(unsigned char line)
{
	unsigned char i;
	lcdCursor(line,1);
	for (i=0; i<16; i++) lcdPutchar(' ');
	lcdCursor(line,1);
}
 
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
my problem i dont have the explorer 16 board(next week i will have one) so i d lke to verify with ISIS because i can verify if my code is OK but i dont know why with pic18f it is OK and if i chanege with pic24f ; XC16 he don worked
another question please why in the code with explorere 16 he has choose to use PMP,
thanks in advance
 

the pic24f_lcd_test project is using the PMP (Parallel Master Slave Port (PMP/PSP)
my code uses the digital IO pins directly
 

i trying with this code but he display mean error in fucnction
Code:
void lcd_delay() { mSecDelay(2); }  // if LCD does not work make this longer
and i dont have this file .h
Code:
#include "hardware.h"
#include "lcd.h"
thanks in advance
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…