Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Learning to Program in C!

Status
Not open for further replies.

cowana

New Member
Hi All

I've been using PICs for a while programming with PICAXE (BASIC), and I'd like to start learning to program in C (as seems to be the standard in industry).

I've just ordered a PicKit 2 plus demo board, plus I have some PIC boards with LEDs lying around.

Here's my question: What should I use to program?

I've heard I will need a C compiler - is this what MPLab is? Or is MPLab for actually downloading to the chip?

Can anyone recommend any tutorials or books for starting in C?

Waht steps do I need to take to get started?

Many thanks

Andrew
 
MLAB is the PC interface for working with PICs. There is a C compiler available for it, see **broken link removed**.

But first you need to learn the basics of C, as Hero999 stated.
 
Many thanks for your replies.

I've read a bit on C programming, but I think that the best way to learn is to start trying it out on hardware. I think LED on/off control, then flashing, then responding to switch(es), then using ADC and so on is the best route to go down - learning more commands/code at each step. Any other suggestions on how to learn C?

Thanks again.

Andrew
 
cowana,

I was a machinist for 40+ years and I was always fascinated with CNC control machines. Each machine had features that I like and those that I did not like. One day I decided that I would build my own CNC controlled machine starting with operating system software. I went to eBay and searched for Microsoft Visual Studio 6.0 which has VB6, C and C++. I purchase the software, installed it on my PC and began to do the lessons. First two times I got frusterated and quit. That presented a problem because I had also purchased some expensive electronics and servo drive systems. I gave it a rest for six months and then I made another charge at the project and while it took me a little over a year I wrote the software. What I lacked in the first two attempts was the DETERMINATION to accomplish the task. I wrote all of my own DLLs and drivers and this was my first experience with programming.

With a good programming package and the proper amount of DETERMINATION you can learn to program anything that you want.

You can download a free copy of the latest VB, C, C# or C++ for free from Microsoft's web sight. It is referred to as the Express Edition which has some limitations, but it's more than capable of anything that you want to do.

Microsoft Visual Studio Express - Build cutting edge Windows applications

Yep,
I'mClueless
 
Thanks I'mClueless. Does anyone know what the lessons in MPLab are like - and whether that would be suffient material? I'm going to be taught all of this at University next year, but I want to get a head start and learn it before I go.

Thanks again,

Andrew
 
OK - a really stupid question now. I've just received my PICkit 2, and am going through the tutorials. However, the code seems to be more like assember than C. Does microchip have any tutorials for coding in C?

#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &
_MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)
org 0
Start
BSF STATUS,RP0 ;select Register Page 1
BCF TRISC,0 ;make I/O Pin C0 an output
BCF STATUS,RP0 ;back to Register Page 0
BSF PORTC,0 ;turn on LED C0
GOTO $ ;wait here
end
 
Last edited:
**broken link removed** talks about PIC 2 and writing C code.
 
Good book

If you don't care which microcontroller the following book is quite good:

"C Programming for Microcontrollers"
Joe Pardue SmileyMicros.com
It uses an AVR 'Butterfly' demo board which is fairly cheap.

An excellent 16-bit PIC book:
"Programming 16 bit microcontrollers in C"
Lucio Di Jasio

I'm not aware of anything for the older PIC chips.
 
Last edited:
OK - a really stupid question now. I've just received my PICkit 2, and am going through the tutorials. However, the code seems to be more like assember than C. Does microchip have any tutorials for coding in C?

#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &
_MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)
org 0
Start
BSF STATUS,RP0 ;select Register Page 1
BCF TRISC,0 ;make I/O Pin C0 an output
BCF STATUS,RP0 ;back to Register Page 0
BSF PORTC,0 ;turn on LED C0
GOTO $ ;wait here
end

That is indeed assembly. The equivalent Hi-Tech C program would be,
Code:
#include <pic.h>
  
 __CONFIG(WDTDIS & INTIO & PWRTDIS & MCLRDIS & UNPROTECT & BORDIS); 

main(){
    TRISC0=0;       //make PORTC bit 0 output
    RC0=1;          //and drive it low to turn on LED
    while(1);       //loop forever
}

Edit, HiTech C comes with MPLAB.

Mike.
 
Last edited:
...
You can download a free copy of the latest VB, C, C# or C++ for free from Microsoft's web sight. It is referred to as the Express Edition which has some limitations, but it's more than capable of anything that you want to do.

Microsoft Visual Studio Express - Build cutting edge Windows applications

Yep,
I'mClueless

Hey clueless,

Is this free VB any better/different from VB6 (for hardware projects through the parallel port) under Windoz XP? (I dont need the .net functionallity).
 
You can use VBA for many applications that is included with any of the Microsoft Office products (Word, Excel, etc.)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top