Microcontroller programming in C

Thread Starter

herc

Joined Aug 26, 2009
2
I'm signed up to take an embedded systems class. The class will be programming microcontrollers using C and Assembly language. I have not use either of these languages, but I have used VHDL, MATLAB, and touched on C++ and JAVA.

Can anyone recommend a good tutorial type website that is specifically geared towards programming microcontrollers in C? None of those "hello world
" examples please.
Thanks!
 

walid el masry

Joined Mar 31, 2009
133
hi herc
try this
http://www.mikroe.com/en/books/pic-books/mikroc/

its tutorial made by mikroelektronica for the compiler
mikroc
and by coincidence iam learing programming pic using c so this what i achieve for now and note that the
tutorial is about programming PIC microcontroller made by MICROCHIP company

Rich (BB code):

the main program
void main()
{

}
-------------------------------------------------
declare a variable
int variable_name;
int1 i; // i integer variable of 1 bit
unsigned int8 i; // i positive integer variable of 8 bit
signed int8 i; // i real integer(+ and -) variable of 8 bit

also there is int16 and int32
-------------------------------------------------
global variable
int x;
void main()
{
}
-------------------------------------------------
local variable
void main()
{
int x;
}
-------------------------------------------------
put value in variable or port
variable_name = value;
PORTB=value;
-------------------------------------------------
intialize a port
TRISB=value;
-------------------------------------------------
make a loop
name:
goto name;

endless loop
while(1)
{
}
-------------------------------------------------
delay
delay_ms();
-------------------------------------------------
while statement
while(condition)
{
statement
}
-------------------------------------------------
do while statement
do
{
statement
} while (condition);
-------------------------------------------------
if statement
if (condition)
{
statement
}
-------------------------------------------------
if else statement
if (condition)
{statement1}
else {statement2}

(expression1)? expression2 : expression3
-------------------------------------------------
if else if statement
if (condition1)
{statement1}
else if(condition2)
{statement2}
-------------------------------------------------
handle port pins
PORTB.F0==>PORTB.F7
PORTB.B0==>PORTB.B7
-------------------------------------------------
for statement
for (start; stop; condition)
{
statement
}
-------------------------------------------------
*Arithmetic and Logical Operations*
Single operand:
Increment ++
Decrement --
Complement ~

Arithmetic operation:
Add +
Subtract -
Multiply *
Divide /
Reminder %

Logical operation:
Logical AND &
Logical OR |
Exclusive OR ^
NOT !

+=    a += 8    a = a + 8 
-=    a -= 8    a = a - 8 
*=     a *= 8    a = a * 8 
/=    a /= 8    a = a / 8 
%=    a %= 8    a = a % 8
-------------------------------------------------
*Conditional Operators*
Equal to ==
Not equal to !=
Greater than >
Less than <
Greater than or equal to >=
Less than or equal to <=
&&
||
^^
!
*BITWISE OPERATORS*
<< Shift left    a = b << 2
>> Shift right a = b >> 2
--------------------------
very important note [ after testing ]
z = 0X12;
x = z >> 4;

result is x = 0x01;
--------------------------
z = 0X12;
x = z << 4;

result is x = 0x20;
--------------------------
~ Bitwise complement a = ~b 
-------------------------------------------------
break and continue
int x;
for(x=0,x<10,x++){
if(x==5){break;}
y=x;}
//y or x never be 6 and loop ended at x=5 and y = 4 

int x;
for(x=0,x<10,x++){
if(x==5){Continue;}
y=x;}
//y never be 5
-------------------------------------------------
switch statement
int x;
switch(x)
{
case 1: y=10;
break;
case 2: y=20;
break;
case 3: y=30;
break;
y=40;
}
-------------------------------------------------
void
void void_name()
{
statement
}
-------------------------------------------------
function
type_of_result function_name (formal parameters)
{
    description of formal parameters
    definition and declaration
    operators
    ...
}
-------------------------------------------------
constants
number
const constant_name = number;

character
const constant_name = 'A';

string
const constant_name = "string";
-------------------------------------------------
Assembly code
asm
{
Assembly language instructions
...
}
-------------------------------------------------
 

rjenkins

Joined Nov 6, 2005
1,013
Hi,
get the free trial version of the CCS C Compiler (from www.ccsinfo.com)

This is an excellent compiler, and comes with many library / demo source files, also the help docs are prety good. (Well, the full version does - I expect the same is in the trial).

'C' is pretty much 'C', so the K&R book is always a good general reference.

The specifics for microcontrollers vary from compiler to compiler, as they are custom extensions each company tends to do their own thing..
 

Thread Starter

herc

Joined Aug 26, 2009
2
Thanks for the tips everyone. It seems that hardware programming won't be too different then C++.

The class I'll be taking will begin next week, so I don't know which microcontroller it will be yet.

Thanks again!
 

rushi53

Joined May 8, 2009
21
I'm signed up to take an embedded systems class. The class will be programming microcontrollers using C and Assembly language. I have not use either of these languages, but I have used VHDL, MATLAB, and touched on C++ and JAVA.

Can anyone recommend a good tutorial type website that is specifically geared towards programming microcontrollers in C? None of those "hello world
" examples please.
Thanks!

I would suggest a book rather than online tutorials.

Refer to a book on Microcontrollers by Mazidi.
That is a best book for beginers

--------------------------------------------------------
Thanks,
Rushikesh
www.projectsof8051.com
 
Top