# Let's learn MPLAB X

Status
Not open for further replies.

#### be80be

##### Well-Known Member
Ok this sounds fun I order a microstick2 it come's with some good chips.
Ok I find a sample code I pick up the paper with how to setup MPLABX and load the tool setting before the project.
Bad ideal I just spent 5 hours reinstalling MPLAB X and the whole ball of wax just to find I can't set tools because I haven't loaded the project.
The paper with My microstick showed just enough to get me in trouble LOL

#### Nigel Goodwin

##### Super Moderator
I will try my hardest NOT to use MPLAB X.... If I can use MPLAB IDE V8.xx for the rest of my career... Good!!!
I moved to it a while back, once you get used to it it's OK - but initially it's a bit of a shock

#### Nigel Goodwin

##### Super Moderator
Ok this sounds fun I order a microstick2 it come's with some good chips.
I ordered one of those, pretty useful (and a bargain), particularly as it has a built-in programmer.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
I moved to it a while back, once you get used to it it's OK - but initially it's a bit of a shock
Don't get me wrong.. I have had to use it several times... It's very buggy.. It creates faulty coff files and missreports where files are.... As I use Proteus a lot I rely on these files being where they're suppossed to.

#### be80be

##### Well-Known Member
It's probably great after you figure it all out. The microstick works great but I'll post some of the code I can for the life of me figure how it's setting the port pin it's using a .h file that's not showing in the window.

#### be80be

##### Well-Known Member
I sit and look and look some more I finally fine out how its doing what it dose but dang this is a hard way to toggle a led.
C:
#include <stdint.h>
#include <xc.h>
#include "main.h"

int main()
{

// Initialize the LED. This symbol is defined in system_config.h
LED_TRIS = 0;

/* Initialize Timer 1
* Each configuration sets the MCU's oscillator to 32MHz (see the respective
* "system.c" for configuration bits).  For the LED to blink
* at a rate of 1Hz, it must be toggled at 2Hz.
*
* Calculation:
* Fcy = Fosc / 2 = 16E6 [Hz]
* T1CONbits.TCKPS = 3 divides the input clock by 256.
* PR1 = Fcy[Hz] / 256 / 2[Hz] = 0x7A12;
*/
_T1IF = 0;
_T1IE = 0;
TMR1 = 0x0000;
PR1 = 0x7A12;
T1CONbits.TCKPS = 3;
T1CONbits.TON = 1;

enum
{
} demoState;

while (1)
{
switch (demoState)
{
case IDLE:
if (_T1IF == 1)
{
_T1IF = 0;
}
break;

LED ^= 1; // Toggle the LED
demoState = IDLE;
break;

// Add other case states here...
default:
demoState = IDLE;
break;
}
}
return 0;
}

/*******************************************************************************
End of File
*/

#### be80be

##### Well-Known Member
Here for the pic 32
I'm trying to understand how there doing the portbit's
C:
#include <plib.h>

#define SYS_FREQ         (40000000L)

main() {
SYSTEMConfig(SYS_FREQ, 0);

mPORTAClearBits(BIT_0);                    //Clear bits to ensure light is off.
mPORTASetPinsDigitalOut(BIT_0);            //Set port as output

int i;
int j;

while(1) {                                //This loop determines the initial time between blinks.

j = 100000;

while (j){                            //This loop controlls how quickely blinking speeds up.
mPORTAToggleBits(BIT_0);        //Toggle light status. (Can be viewed in LATA SFR)

i = j;                            //Time to wait in between toggle.
while(i--) {}                    //Kill time.

j = j - 1000;                    //Increase constant to increas blinking speed faster.
}
}
}
Where are they coming up with this
C:
 mPORTAToggleBits(BIT_0);

#### Pommie

##### Well-Known Member
I'm guessing that the lower case m starting the name represents a macro. Check the includes.

Mike.

#### large_ghostman

##### Well-Known Member
Why would you do it like that? How exactly does that save time or effort? Or make it easier to understand? What the hell was wrong with simply using ~ !

The first code looks almost like part of a RTOS, only without any of the useful bits in it.

Burt I might join in with this, what chip is on the board? I dont want to buy the board but I might have the chip. I got to get back into pics and pic 24. I also want to start learning the XC compilers as I like the 18K parts, and some of the 16f's that C18 dosnt support .

One other thing...........Reading the XC8 compiler manual, it makes a point of saying they have ditched the extended instruction set for the pic18F in the compiler!!! And yet the data sheets make a big this about the extended instruction set??? Also while the ISR might be easier they have mashed up inline ASM!!! What a faff compared to C18

I am tempted to have a look at CCS compiler, last time I looked it wasnt great, but XC seems a right bodge seeing as it is what 4-5 years old now? Same with mplab X 4-5 years old and little bettr than alpha stage software.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Why would you do it like that? How exactly does that save time or effort? Or make it easier to understand? What the hell was wrong with simply using ~ !
I'm with you!!! As I am a lone programmer I'll continue doing the same... BUT!! Microchip continue to service all the numpties who program like this.. It'slike they want a wrapper function for everything... Going down the road of Arduino and C++...

You should be more at home with XC8 than you ever did with C18... Create a large array in C18 say 2k const array for a font!! Only to find out that at a page break we gain a byte so the font is offset... How crap is that.. I never get that with XC8... Remember though... I have the Pro version so I get all memory for me... So my experience with XC8 might be better than yours.. Mind you!! It just cost me £162 for a new HPA subscription!! Bah Humbug!!!

#### Pommie

##### Well-Known Member
The pro version doesn't allow more memory, just less optimisation. However, I've never found the code too slow, yet.

Mike.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
The pro version doesn't allow more memory, just less optimisation. However, I've never found the code too slow, yet.

Mike.
I compile with pro.... Say 12% code used.... I compile free 17.5% code used Pro data used 18%... free 19.6%
More memory used in Free... Or should I say more wasted memory!!

#### large_ghostman

##### Well-Known Member
I'm with you!!! As I am a lone programmer I'll continue doing the same... BUT!! Microchip continue to service all the numpties who program like this.. It'slike they want a wrapper function for everything... Going down the road of Arduino and C++...

You should be more at home with XC8 than you ever did with C18... Create a large array in C18 say 2k const array for a font!! Only to find out that at a page break we gain a byte so the font is offset... How crap is that.. I never get that with XC8... Remember though... I have the Pro version so I get all memory for me... So my experience with XC8 might be better than yours.. Mind you!! It just cost me £162 for a new HPA subscription!! Bah Humbug!!!

Maybe you just hit the nail on the head, they have Atmel now, so just maybe the are going to attempt to mash it all into a single compiler!!! GOD HELP US ALL! man the lifeboats .

The memory thing was never an issue for me, ages ago on here you showed me how to do the MY BIG DATA thing, plenty good enough for me. But all this nonsense with inline ASM etc just makes the code longer to write and read. more errors creep in. I cant see how much the student pro version is. maybe they dont have one.

if you dont mind me asking how much is a pro license and is it yearly?

#### Nigel Goodwin

##### Super Moderator
I compile with pro.... Say 12% code used.... I compile free 17.5% code used Pro data used 18%... free 19.6%
More memory used in Free... Or should I say more wasted memory!!
I don't think the waste of memory is as important as the massive waste of speed - lot's of things run incredibly slowly, particularly loops.

#### be80be

##### Well-Known Member
The new cloud MPLAB lets you pay by the month.

#### large_ghostman

##### Well-Known Member
The new cloud MPLAB lets you pay by the month.
Thats nice of them.

Time to look for a man with a eye patch and parrot on his shoulder lol

#### large_ghostman

##### Well-Known Member
I don't think the waste of memory is as important as the massive waste of speed - lot's of things run incredibly slowly, particularly loops.
Are you saying simple loops take more cycles now? Sorry its a dumb question.

I finally got mplab (old version) and the old C18 installed, time to test loops

#### Nigel Goodwin

##### Super Moderator
Are you saying simple loops take more cycles now? Sorry its a dumb question.
Yes, the free version of the C compilers aren't just 'poorly optimised', they also deliberately insert lot's of extra spurious code to make them look bad.

I tried my IR tutorial, which Ian had converted to C - and it didn't work at all. I looked into why, and the loops take too long to read the IR pulses.