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
  • Good Essays

    Set a breakpoint to pause execution of the program at a given line number. It can also print the value of a variable during execution also run a single line of program code, pausing after it completes.…

    • 567 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Programming fundamentals

    • 299 Words
    • 2 Pages

    Note. This assignment is cumulative and the information and results will be used in the following weeks.…

    • 299 Words
    • 2 Pages
    Satisfactory 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
  • 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
  • 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
  • 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
  • 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
  • Powerful Essays

    The parallel input-output port chip 8255 is also called as programmable peripheral input-output port. The Intel’s 8255 is designed for use with Intel’s 8-bit, 16-bit and higher capability microprocessors. It has 24 input/output lines which may be individually programmed in two groups of twelve lines each, or three groups of eight lines. The two groups of I/O pins are named as Group A and Group B. Each of these two groups contains a subgroup of eight I/O lines called as 8-bit port and another subgroup of four lines or a 4-bit port. Thus Group A contains an 8-bit port A along with a 4-bit port. C upper.…

    • 3402 Words
    • 14 Pages
    Powerful 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
  • 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