Microcontroller programming in C

Discussion in 'Embedded Systems and Microcontrollers' started by herc, Aug 26, 2009.

  1. herc

    Thread Starter New Member

    Aug 26, 2009
    2
    0
    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!
     
  2. walid el masry

    Active Member

    Mar 31, 2009
    132
    0
    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

    Code ( (Unknown Language)):
    1. [B]
    2. the main program
    3. void main()
    4. {
    5.  
    6. }
    7. -------------------------------------------------
    8. declare a variable
    9. int variable_name;
    10. int1 i; // i integer variable of 1 bit
    11. unsigned int8 i; // i positive integer variable of 8 bit
    12. signed int8 i; // i real integer(+ and -) variable of 8 bit
    13.  
    14. also there is int16 and int32
    15. -------------------------------------------------
    16. global variable
    17. int x;
    18. void main()
    19. {
    20. }
    21. -------------------------------------------------
    22. local variable
    23. void main()
    24. {
    25. int x;
    26. }
    27. -------------------------------------------------
    28. put value in variable or port
    29. variable_name = value;
    30. PORTB=value;
    31. -------------------------------------------------
    32. intialize a port
    33. TRISB=value;
    34. -------------------------------------------------
    35. make a loop
    36. name:
    37. goto name;
    38.  
    39. endless loop
    40. while(1)
    41. {
    42. }
    43. -------------------------------------------------
    44. delay
    45. delay_ms();
    46. -------------------------------------------------
    47. while statement
    48. while(condition)
    49. {
    50. statement
    51. }
    52. -------------------------------------------------
    53. do while statement
    54. do
    55. {
    56. statement
    57. } while (condition);
    58. -------------------------------------------------
    59. if statement
    60. if (condition)
    61. {
    62. statement
    63. }
    64. -------------------------------------------------
    65. if else statement
    66. if (condition)
    67. {statement1}
    68. else {statement2}
    69.  
    70. (expression1)? expression2 : expression3
    71. -------------------------------------------------
    72. if else if statement
    73. if (condition1)
    74. {statement1}
    75. else if(condition2)
    76. {statement2}
    77. -------------------------------------------------
    78. handle port pins
    79. PORTB.F0==>PORTB.F7
    80. PORTB.B0==>PORTB.B7
    81. -------------------------------------------------
    82. for statement
    83. for (start; stop; condition)
    84. {
    85. statement
    86. }
    87. -------------------------------------------------
    88. *Arithmetic and Logical Operations*
    89. Single operand:
    90. Increment ++
    91. Decrement --
    92. Complement ~
    93.  
    94. Arithmetic operation:
    95. Add +
    96. Subtract -
    97. Multiply *
    98. Divide /
    99. Reminder %
    100.  
    101. Logical operation:
    102. Logical AND &
    103. Logical OR |
    104. Exclusive OR ^
    105. NOT !
    106.  
    107. +=    a += 8    a = a + 8
    108. -=    a -= 8    a = a - 8
    109. *=     a *= 8    a = a * 8
    110. /=    a /= 8    a = a / 8
    111. %=    a %= 8    a = a % 8
    112. -------------------------------------------------
    113. *Conditional Operators*
    114. Equal to ==
    115. Not equal to !=
    116. Greater than >
    117. Less than <
    118. Greater than or equal to >=
    119. Less than or equal to <=
    120. &&
    121. ||
    122. ^^
    123. !
    124. *BITWISE OPERATORS*
    125. << Shift left    a = b << 2
    126. >> Shift right a = b >> 2
    127. --------------------------
    128. very important note [ after testing ]
    129. z = 0X12;
    130. x = z >> 4;
    131.  
    132. result is x = 0x01;
    133. --------------------------
    134. z = 0X12;
    135. x = z << 4;
    136.  
    137. result is x = 0x20;
    138. --------------------------
    139. ~ Bitwise complement a = ~b
    140. -------------------------------------------------
    141. break and continue
    142. int x;
    143. for(x=0,x<10,x++){
    144. if(x==5){break;}
    145. y=x;}
    146. //y or x never be 6 and loop ended at x=5 and y = 4
    147.  
    148. int x;
    149. for(x=0,x<10,x++){
    150. if(x==5){Continue;}
    151. y=x;}
    152. //y never be 5
    153. -------------------------------------------------
    154. switch statement
    155. int x;
    156. switch(x)
    157. {
    158. case 1: y=10;
    159. break;
    160. case 2: y=20;
    161. break;
    162. case 3: y=30;
    163. break;
    164. y=40;
    165. }
    166. -------------------------------------------------
    167. void
    168. void void_name()
    169. {
    170. statement
    171. }
    172. -------------------------------------------------
    173. function
    174. type_of_result function_name (formal parameters)
    175. {
    176.     description of formal parameters
    177.     definition and declaration
    178.     operators
    179.     ...
    180. }
    181. -------------------------------------------------
    182. constants
    183. number
    184. const constant_name = number;
    185.  
    186. character
    187. const constant_name = 'A';
    188.  
    189. string
    190. const constant_name = "string";
    191. -------------------------------------------------
    192. Assembly code
    193. asm
    194. {
    195. Assembly language instructions
    196. ...
    197. }
    198. -------------------------------------------------[/B]
    199.  
     
  3. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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..
     
  4. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Which microcontroller is the class using?
     
  5. herc

    Thread Starter New Member

    Aug 26, 2009
    2
    0
    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!
     
  6. rushi53

    Member

    May 8, 2009
    21
    0

    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
     
Loading...