Preview

C Programming for Embedded Microcontroller Systems

Good Essays
Open Document
Open Document
1596 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C Programming for Embedded Microcontroller Systems
C programming for embedded microcontroller systems.
Assumes experience with assembly language programming.

V. P. Nelson
Spring 2013

ELEC 3040/3050 Embedded Systems Lab –
V. P. Nelson

Outline
• Program organization and microcontroller memory • Data types, constants, variables
• Microcontroller register/port addresses
• Operators: arithmetic, logical, shift
• Control structures: if, while, for
• Functions
• Interrupt routines
Spring 2013

ELEC 3040/3050 Embedded Systems Lab –
V. P. Nelson

Basic C program structure
#include
#include

/* common defines and macros */
/* I/O port/register names/addresses for the MC9S12C32 microcontroller */

/* Global variables – accessible by all functions */ int count, bob;
//global (static) variables – placed in RAM
/* Function definitions*/ int function1(char x) { //parameter x passed to the function, function returns an integer value int i,j;
//local (automatic) variables – allocated to stack or registers
-- instructions to implement the function
}
/* Main program */ void main(void) { unsigned char sw1;
//local (automatic) variable (stack or registers) int k;
//local (automatic) variable (stack or registers)
/* Initialization section */
-- instructions to initialize variables, I/O ports, devices, function registers
/* Endless loop */ while (1) {
//Can also use: for(;;) {
-- instructions to be repeated
} /* repeat forever */
}
ELEC 3040/3050 Embedded Systems Lab –
Spring 2013

V. P. Nelson

Declare local variables
Initialize variables/devices
Body of the program

Address
0x0000
0x0400
0x0800
0x1000
0x4000

MC9S12C32 memory map
I/O Registers
Vacant
2KB RAM

16KB Flash
Memory
Vacant

0xFF00

Spring 2013

2K byte RAM [0x0800..0x0FFF] for variable & stack storage

Vacant

0x8000

0xC000

Control registers for I/O [0x0000..0x03FF]

16KB Flash
Memory

16K byte Flash EEPROM [0x4000..0x7FFF] for program code & constant data storage

You May Also Find These Documents Helpful

  • Better Essays

    Nt1310 Unit 4

    • 3614 Words
    • 15 Pages

    The program is trying to collect the value of a "void" function into an integer variable.…

    • 3614 Words
    • 15 Pages
    Better Essays
  • Satisfactory Essays

    Cs Programming Chapter 1

    • 2450 Words
    • 10 Pages

    ____ data items may involve organizing or sorting them, checking them for accuracy, or performing calculations with them.…

    • 2450 Words
    • 10 Pages
    Satisfactory Essays
  • Satisfactory Essays

    E4.10: Draw the stack frame and enter the value of each stack slot (if it is…

    • 900 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    Embedded Systems 2 marks

    • 760 Words
    • 4 Pages

    The stack is used to keep track of the current and all suspended execution contexts. Thus, the stack contains all “live” local or automatic variables and all function and interrupt “return addresses.” When a program calls a function.…

    • 760 Words
    • 4 Pages
    Powerful Essays
  • Satisfactory Essays

    Lab Quiz 5

    • 708 Words
    • 3 Pages

    2. A value from memory is placed in this register by the FETCH sequence and DECODED as an instruction.…

    • 708 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    HW2 C

    • 142 Words
    • 1 Page

    Q2: Write a function that takes an integer m as a parameter then return the following…

    • 142 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    2- Write a program converts a temperature from Celsius to Fahrenheit. Use the following formula: F = 1.8 x C + 32 .…

    • 1616 Words
    • 7 Pages
    Good Essays
  • Powerful Essays

    1 Introduction 1.1 1.2 How important are programming languages? . . . . . . . . . . . . . . . . . . . . . . Features of the Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 2 3 7 7 7 8 8 9…

    • 31229 Words
    • 125 Pages
    Powerful Essays
  • Good Essays

    SSVEP: The corresponding signals of visual stimulus at particular frequency (ranging from 3.5 Hz to 75 Hz) is used to generate electrical activity of brain is treated as Steady state visual evoked potentials [9], [10].…

    • 1314 Words
    • 6 Pages
    Good Essays
  • Good Essays

    With the increasing pace of innovations and technology people are trying to add technology into things which are not even required which in turn is just complicates things for individuals . The greater down side to this is that there is no progress due to technology in the greater picture. When technology first came in we thought it help reduce pollution , improve the environment conditions . However that is not the case, global warming is increasing at an accelerated speed rate with the weather being extremely in-stable. The 32 megabytes microchip requires 1.7 kilograms of materials to make it and gives out thousands of potential toxic chemicals while manufacturing.…

    • 775 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    In this task we will be listing different types of hardware and software that will be suitable in order to set up the computer lab.…

    • 5447 Words
    • 22 Pages
    Powerful Essays
  • Powerful Essays

    Microcontrollers

    • 1522 Words
    • 7 Pages

    A simple ultrasonic range finder using 8051 microcontroller is presented in this project. This ultrasonic rangefinder can measure distances up to 2.5 meters at an accuracy of 1 centi meter. AT89s51 microcontroller and the ultrasonic transducer module HC-SR04 forms the basis of this circuit. The ultrasonic module sends a signal to the object, then picks up its echo and outputs a wave form whose time period is proportional to the distance. The microcontroller accepts this signal, performs necessary processing and displays the corresponding distance on the 3 digit seven segment display. This circuit finds a lot of application in projects like automotive parking sensors, obstacle warning systems, terrain monitoring robots, industrial distance measurements etc.…

    • 1522 Words
    • 7 Pages
    Powerful Essays
  • Good Essays

    C Programms

    • 1942 Words
    • 8 Pages

    1. Program to print text 2.Program To Read Two Numbers And Print The Sum Of Given Two Numbers. 3.Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and Print it. 4.Program To Read Three Numbers And Print The Biggest Of Given Three Numbers 5.Program To Read A Number And Find Whether The Given Number Is Even Or Odd. 6.Program to accept a year and check whether the given year IS leap year or not. 7.Individual Digits 8. Program to accept a three digit number and print the sum of individual digits. 9. Program to accept a number and check the given number is Armstrong or not. 10. Program to print ODD numbers from 1 to 10 11. Program to print natural numbers from 1 to 10 in Reverse 12. Program to print sum of the natural numbers from 1 to 10. 13. Program to accept a number and print mathematical table of the given no. 14. Program to print 1 to 10 mathematical tables . 15. Program to print fibonacci series . 16. Program to print numeric pyramid 17. Program to print numerical pyramid. 18. Program to print numerical diamond. 19. Program to print character pyramid. 20. Program to print character diamond. 21. Program to find biggest of two no by using ternary numbers 22. Program to find biggest of four no by using ternary numbers 23. Program to print smallest of four no by using ternary operators 24. Program to accept a year and check the given year is leap or not by using ternary 25. Program to accept a character in the uppercase and print in lower case. 26. Program to accept a character in any case and print in another case. 27. Program to natural number from 1 to 10 by using while loop. 28. Program to accept a string and print it by using the while loop. 29. Program to accept a string in upper case and print it by lower case. 30. Program to accept a string in any case and print it by another case . 31. Program to accept a string print each word in new line. 32. Program to accept a string and count no of capital letters, no. of…

    • 1942 Words
    • 8 Pages
    Good Essays
  • Satisfactory Essays

    13.a) What is the difference between an algorithm and pseudocode? Also write an Algorithm and pseudocode for solving a quadratic equation. (16)…

    • 2874 Words
    • 12 Pages
    Satisfactory Essays
  • Better Essays

    death penalty

    • 798 Words
    • 9 Pages

    #include void main() { clrscr(); printf("%d",printf("CQUESTIONBANK")); getch(); } What will output when you compile and run the above code? (a)13CQUESTIONBANK (b)CQUESTIONBANK13 (c)Garbage CQUESTIONBANK (d)Compiler error 4. #include #include void main() { short int a=5; clrscr(); printf("%d"+1,a); getch(); } What will output when you compile and run the above code?…

    • 798 Words
    • 9 Pages
    Better Essays