Is C++ good for pic micros,,?

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,579
I am wanting to get into C programming for pics, and the only courses available at my local college is C++ for begginers,,,is this worth doing for pic Microcontrollers,,?

I normally use assembley language which i've been used to for 20yrs and
using the Mplab compiler..
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,579
I just want to know is it worth learning C++ to be able to understand how to programme in C or C++, or just stick with assembley code..
 

WBahn

Joined Mar 31, 2012
24,973
I just want to know is it worth learning C++ to be able to understand how to programme in C or C++, or just stick with assembley code..
Higher end microcontrollers are at the point where programming in Java or C++ is now a viable option. But for a lot of micros they are simply too resource starved to handle the overhead. If you learn C++ then you will also be learning C, you just need to be aware of what aspects are C++ only. Anything that has anything to do with objects -- don't do it since that's C++.

There are LOTS of free online C courses out there, including ones that are specific to the version of C used by different microcontroller families.
 

hexreader

Joined Apr 16, 2011
382
My opinion - for what it is worth....

Learn C.

If you want to learn C++ in the future, you already have a good start.

Writing ASM is a good learning exercise and gives a good grounding, but C is the sensible way to go for PICs.
 

OBW0549

Joined Mar 2, 2015
3,092
I just want to know is it worth learning C++ to be able to understand how to programme in C or C++, ...
My opinion: for programming low-end microcontrollers, C++ isn't worth bothering with. Learning C, on the other hand, is not especially hard to do and may be worthwhile.

...or just stick with assembley code..
I do nearly all of my programming ( the 8- and 16-bit PICs) in assembly language. While I can program in C if I have to, I'm clumsy with it and it is not my first choice.
 

hexreader

Joined Apr 16, 2011
382
My opinion: for programming low-end microcontrollers, C++ isn't worth bothering with. Learning C, on the other hand, is not especially hard to do and may be worthwhile.


I do nearly all of my programming ( the 8- and 16-bit PICs) in assembly language. While I can program in C if I have to, I'm clumsy with it and it is not my first choice.
C++ for 8-bit and 16-bit PICs is a poor choice IMHO. For PIC32, C++ just might be sensible (not that I ever tried it)

As for ASM... I like it for PIC18 and (ds)PIC24/30/33, but I think (IMHO) that ASM becomes an insane choice for PIC32 (MIPS).

I still say (IMHO) learn C for all current PICs (except maybe PIC10 and some PIC12s). The knowledge will not be wasted.
 

OBW0549

Joined Mar 2, 2015
3,092
As for ASM... I like it for PIC18 and (ds)PIC24/30/33, but I think (IMHO) that ASM becomes an insane choice for PIC32 (MIPS).
Does MPLAB even support assembly language programming for the PIC32? I could be wrong, but I don't think it does.

It may seem counterintuitive, but I've found assembly language for the 16-bit PIC24/dsPIC families a lot easier than for the "lesser" PICs, for many reasons.

The 16-bit PICs are much less user-hostile.
 

AlbertHall

Joined Jun 4, 2014
8,783
Does MPLAB even support assembly language programming for the PIC32? I could be wrong, but I don't think it does.

It may seem counterintuitive, but I've found assembly language for the 16-bit PIC24/dsPIC families a lot easier than for the "lesser" PICs, for many reasons.

The 16-bit PICs are much less user-hostile.
The problem with ASM is the memory paging. It is a real pain which disappears with C. Do the 16 bit PICs not have memory paging?
 

OBW0549

Joined Mar 2, 2015
3,092
The problem with ASM is the memory paging. It is a real pain which disappears with C. Do the 16 bit PICs not have memory paging?
I believe they do, but I've never had to deal with it because the pages are large (8 KB I think?) and I rarely use more than a couple of hundred bytes.
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,579
No, No!

If you want to learn ASM, try something like Atmel AVR, TI MSP430, or Motorla/Freescale/NXP HCS08.

Then move on to C. You will not regret it!
I can already programme in Asm, been doing it for 20yrs, i want to learn C but there are no courses at any colleges locally,, only C++,,

looks like I'm going to learn it from a book, ideally i want face to face tuition..
 
Last edited:

MrChips

Joined Oct 2, 2009
19,747
Learning C is not that difficult. You don't need to sit in a college classroom.
There are numerous books and websites that will get you going.

Find a C compiler for your PC and type:
C:
#include<stdio.h>
void main(void)
{
  printf("Hello, World!");
}
Simply ask questions here when you are stuck.

I want to see your ASM code for doing this.
 

MaxHeadRoom

Joined Jul 18, 2013
19,414
I have never had any issue or need for memory paging the 16 bit Pic's I use with Assembly.
Just a quirk I guess, but I find assembly more intuitive than C!:confused:
On the ones I use, anyway.
As for routines, a library of .INC files can be formulated over time for large standard routines.
Max.
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,579
Learning C is not that difficult. You don't need to sit in a college classroom.
There are numerous books and websites that will get you going.

Find a C compiler for your PC and type:
C:
#include<stdio.h>
void main(void)
{
  printf("Hello, World!");
}
Simply ask questions here when you are stuck.

I want to see your ASM code for doing this.
I have no idea what that 'C' code means, if you can reccomend any books to learn from ( good ones that explain everything) that's a start..
 

MrChips

Joined Oct 2, 2009
19,747
Here is a start.

All C programs have a main( ) function;
C:
main( )
{
}
Name of the function is main, of course.
Inside the braces ( ) you will place input parameters which we can leave for later.
All your code goes inside the { }. This is called a compound statement vs a simple statement.

Got that so far?
 

OBW0549

Joined Mar 2, 2015
3,092
As for routines, a library of .INC files can be formulated over time for large standard routines.
I do that as well, for code that I frequently use in different projects. (I don't keep them in .inc files, but in separately-assembled source (.s) files that I list in the MPLAB project window.)

Also, FWIW, the functions in Microchip's C30 Compact Math Library can be called from assembly language and can be used license-free. (At least it could be as of MPLAB 8.92 and earlier; I don't know if that's changed since MPLAB-X and XC16.) This gives assembly language applications access to the full suite of C30's IEEE-754-compliant floating point math routines, both single and double precision.

I've attached the "poop sheet" for the library and the README file which details the calling conventions for the library functions.
 

Attachments

Thread Starter

Dodgydave

Joined Jun 22, 2012
8,579
Can you recommend any Good Books to learn C programming, as there are loads on Amazon, ideally that explain everything from scratch, with working routine examples...

This is why i prefer a tuition course i hate books for learning..
 
Last edited:
Top