EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: Simon on November 22, 2010, 08:22:25 am

Title: learning C for pic
Post by: Simon on November 22, 2010, 08:22:25 am
ok so people keep telling me that I should use C not Basic (still don't know the advantage but then I don't know any C). So what should I do ? I currently use the mikroe Basic compiler, is their C compiler recommended or are there better options that are free.

OK so should I learn C as a language or follow the manual for the compiler that explains the language assuming there is a such a manual ?
Title: Re: learning C for pic
Post by: jahonen on November 22, 2010, 08:27:06 am
I think both would be a good idea. I originally learned C on PC, and much later used it in embedded systems. Of course you must realize that embedded system, there is no operating system to do the housekeeping for you, and resources are scarce. Otherwise no problem learning the C in general sense.

I think it is best to develop computational algorithms on powerful PC environment, and only when it works properly on the PC, transfer it to embedded environment. Debugging in PC is much easier than in embedded system. Of course, not everything can be done this way, and less if the application is heavily dependent on the HW.

Regards,
Janne
Title: Re: learning C for pic
Post by: Kiriakos-GR on November 22, 2010, 08:31:41 am
I bet that "Basic" still haves some life in it.
Mostly because its old and backwards compatible.

In got my first training on "Basic" at 1988 , like the first class in college ( The Greek educational system are different) after high-school  we have other naming about schools.  
Title: Re: learning C for pic
Post by: Simon on November 22, 2010, 08:50:32 am
well all I care for is achieving what I want to achieve, but is C has more mileage in it best learn now than carry on with basic and then have to relearn it all in C
Title: Re: learning C for pic
Post by: DaveW on November 22, 2010, 08:55:25 am
The main advantage of C (at work anyway), is being able to reuse code and change processors-if you want to do this, its good to learn the basic C, most of the proprietary I've used has just been extra functions so its not too hard other versions. For the pure C this is quite a good book, a free download
http://publications.gbdirect.co.uk/c_book/ (http://publications.gbdirect.co.uk/c_book/)
Because its old it teaches C that also runs on embedded stuff, no GUI bits!
Oh, and a vote for MikroC, good bit of kit, although found it expensive when I bought it (as a student)
Title: Re: learning C for pic
Post by: alm on November 22, 2010, 09:01:28 am
Mostly because its old and backwards compatible.
Backwards compatible? Don't make me laugh. It would probably be hard to find two compilers/interpreters that can run the same non-trivial program, and many of the older compilers don't exist anymore (including the Microsoft one). Is there even a standard BASIC, like ANSI C, that most vendors implement?

For embedded work, it's nice that C is closer to hardware, for example bitwise operations, pointers, bit fields and fixed-width data types (eg. uint8_t). If BASIC compilers implement this it all, it will be (yet another) vendor-specific extension.

I believe the MikroE compilers translate it into some sort of intermediary language, which makes them produce worse code. Never verified this myself, though.
Title: Re: learning C for pic
Post by: Simon on November 22, 2010, 09:01:54 am
I thought mikroe products had free versions or limitations on the pro version, my projects are small. for the basic compiler they limit you to 2K of program, I doubt I used a micro yet with that much memory
Title: Re: learning C for pic
Post by: Mechatrommer on November 22, 2010, 11:40:33 am
basic and C is just like english and spanish or france or german language or whatever.... well.... i hate to say it long.... in short, if you already familiar with basic, step by step of translating yourself into competent C should be easier than if you know nothing of any programming language. both got if, loop, for, +, - etc.
Title: Re: learning C for pic
Post by: migsantiago on November 22, 2010, 11:48:31 am
Use C.

Eventually, it will let you jump to higher platforms such as C++, C# or Java.

Basic won't.
Title: Re: learning C for pic
Post by: TheDirty on November 22, 2010, 11:54:51 am
Like mentioned, C is be far and away the most popular language for microcontrollers.  There is usually a few C compilers for any popular architecture.  I'm currently using 3 different architectures and share basic code between them.  I've also stolen code from Linux drivers, Arduino libraries, and libraries for other microcontrollers.

If you are currently using PIC's and have no interest in moving to other platforms or doing larger scale development, stick with what you have, but not learning C is going to be a big hindrance to you if you want to move on.
Title: Re: learning C for pic
Post by: Mechatrommer on November 22, 2010, 12:15:04 pm
C is be far and away the most popular language for microcontrollers.
not just microcontroller, C is number one in any programming language, its the closest thing to assembly.
Title: Re: learning C for pic
Post by: TheDirty on November 22, 2010, 12:42:55 pm
not just microcontroller, C is number one in any programming language, its the closest thing to assembly.

I don't know of anyone that uses K&R or ANSI C for programming PC's now-a-days.  I was just going to say C is the most popular for embedded, but it's not for FPGA/CPLD.
Title: Re: learning C for pic
Post by: alm on November 22, 2010, 01:00:10 pm
I don't know of anyone that uses K&R or ANSI C for programming PC's now-a-days.
Assuming that includes current ANSI versions like C99: How many system programmers do you know? What language is the Win32 API written in? Many Windows components? The kernel of any current Unix-like OS? A significant part of Gnome? But you're right if you claim that many development is focused on higher level languages these days. The same will probably happen to MCU's once the hardware will exceed requirements, and development time starts to get more expensive than extra silicon.
Title: Re: learning C for pic
Post by: TheDirty on November 22, 2010, 01:08:48 pm
Quote
But you're right if you claim that many development is focused on higher level languages these days. The same will probably happen to MCU's once the hardware will exceed requirements, and development time starts to get more expensive than extra silicon.
This is were you should have started and ended your thread.  Yes, I'm right, the majority of software development for the PC would be higher level languages.  Because I don't know people that do Linux kernel development or write device drivers doesn't make that not true.

I mean technically I do know someone as I've done small linux throw away programs in C, but I did not claim that C is not used in PC development at all.
Title: Re: learning C for pic
Post by: Hypernova on November 22, 2010, 03:41:09 pm
not just microcontroller, C is number one in any programming language, its the closest thing to assembly.

I don't know of anyone that uses K&R or ANSI C for programming PC's now-a-days.  I was just going to say C is the most popular for embedded, but it's not for FPGA/CPLD.

Of course not for FPGA's, those take hardware descriptions not software instructions.
Title: Re: learning C for pic
Post by: joelby on November 22, 2010, 06:37:11 pm
Of course not for FPGA's, those take hardware descriptions not software instructions.

Actually there are translators for using (non-ANSI) C/C++/SystemC on FPGAs, though I'm not sure how popular this is.
Title: Re: learning C for pic
Post by: Simon on November 22, 2010, 06:48:27 pm
well I don't know what the future holds. currently my pic projects are small, basically replacing a number of IC's with one pic or doig some simple math function that conventional IC just would not do (unless I made my own mcu out of them  ;D). But with the future in mind and the rest of the programming world speaking C I guess I should too
Title: Re: learning C for pic
Post by: Mechatrommer on November 22, 2010, 10:55:19 pm
i was emphasizing TheDirty's point beyond mcu domain. that post should not be taken seriously, as it is clearly OT or OD (out of domain). and i cannot prove 100% of my statement, but i'm certain it will not be basic or delphi or others, non that i have heard. FPGA is not a true native programming, ie serial execution, its just connecting wires among gates in varying different manner, afaik.
Title: Re: learning C for pic
Post by: Simon on November 22, 2010, 11:35:29 pm
and i'm only talking basic versus c in pics
Title: Re: learning C for pic
Post by: Mechatrommer on November 23, 2010, 12:08:36 am
and i'm only talking basic versus c in pics
i'm trying to talk globally, to show the importance of C, so any newbies reading wont wander far off. if you know it earlier, you would have been a competent C programmer by now. and if you really get what i mean (my implicit semantics) you'll further rant just why not you have started opening the "bible of C" 10 yrs ago. But i would like to keep the option open as to not being marked as a funboy. Cheers ;)