Sie sind auf Seite 1von 32

Programming embedded systems

Seminar 1

INTRODUCTION


Dr. Tran Thanh Hung
Department of Automation Technology,
College of Engineering, Can Tho University
Email: tthung@ctu.edu.vn

Outline
Seminar objectives
Embedded system: What is it?
Course overview
Why C?
Why MSP430?
Hardware & Software required
Simple software architecture
Examples
Software delay

Seminar objectives
At the end of this seminar, by referring the lecture
notes, students will be able to:
know the course objectives
identify the requirements for an embedded system
explain why MSP430 and C are chosen for embedded
system development
explain the relationship between C, assembly, and
machine languages
know the basic features of MSP430
write a simple software to run a task

What is an embedded system?
An embedded system is a computer system
designed for one or few application.
Which components does an embedded
system consist of?

Core of embedded system

MCU = MicroController Unit
Applications of embedded system
Mobile phone systems
Automotive applications
Domestic appliances
Aerospace applications
Medical equipment
Defence systems
Course overview
This course will introduce the principles of
programming for embedded systems.
By the end of this course, you will be able to:
Know how to build an embedded system
Design embedded software for a simple
application
Implement and test designed software
Understand issues of reliability and safety
Textbooks
1. Embedded C by Michael J. Pont
2. MSP-EXP430G2 LaunchPad Experimenter
Users Guide
3. Code Composer Studio Users Guide
4. MSP430G2435 Datasheet
How computers were built?
Which programming language
should you use?
Remember:
CPU/MCU can only understand programs in machine
language
All programs need to be translated to machine code
Need a good translator software: translate correctly
what you write
Power and memory of MCU are limited: language must
be efficient
For programming embedded system, you need low-
level access to hardware



Why C?
A mid-level:
- support functions
- access hardware
Independent to device
High efficient
Popular
Easy to understand
Good compilers

Can we build CPU/MCUs that can
understand high-level language?
Can we build CPU/MCUs that can
understand high-level language?
Thats means:
Why MSP430?
How to chose MCU for an embedded system?
Some famous MCUs:
+ Z80 (8bit) designed by Zilog from 1976: needs too
many clock periods to run an instruction
+ 8051 (8bit) series (or MSC-51) developed by Intel
from1980: one of the first single chip microcontrollers,
needs 12 clock periods to run an instruction
+ AVR (8bit-RISC) developed by Atmel in 1996,
integrates ADC and many other components, most
instructions run in 1 clock period
+ MSP430 (16bit-RISC) developed by Texas Instrument
from 1990s



Why MSP430?
In this course, MSP430 family is chosen,
because:
- Price: very cheap
- Available: very famous, easy to find
- Performance: powerful, ultra low-power,
suitable for many embedded systems
- Wide range: many MCUs to chose
See http://www.ti.com/msp430


Hardware & Software required



MSP430 LaunchPad
Hardware & Software required
Software required:
- Code Composer Studio (CCS)
- Or IAR Embedded Workbench

See http://focus.ti.com/docs/toolsw/folders/print/msp-exp430g2.html#0

MSP430 Block Diagram
MSP430 Characteristics
16 bit RISC CPU, up to 25 Mhz Clock
Ultra low power consumption:
0.1 A for RAM data retention
0.8 A for real-time clock mode operation
250 A/MIPS during active operation
Low operation voltage: 1.8V 3.6 V
Up to 256K Bytes of In-System Programmable
(ISP) Flash Memory

MSP430 Characteristics
Pin-outs from 14 pins up to 100 pins
Most pins have multiple features (pin
multiplexing)
On-chip analogue devices: ADC, DAC
Embedded Debug/Emulation capability (JTAG)
Many 16-bit Timer/Counters
Many Interrupt Sources
Serial Interface: SPI, I2C

Simple software architecture
What is the minimum software environment
you need to run a task X()?

void main (void)
{
X_Init() ; //Prepare for Task X()
while(1) //super loop
{
X(); //Perform task X()
}
}

Simple software architecture
What are strengths of super loops ?
- Very simple, easy to build, debug, test, and maintain
- High efficient: use minimum hardware
- Highly portable
BUT: What are the weakness ?
- Not suitable for applications required accurate timing
- Full power consumption
Example 1.1: Flashing a LED
#include msp430g2452.h
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
while(1)
{
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
}
How to write a software to turn on/off a LED connected to P1.0?
Can you see the LED blink? Why?
Example 1.2: LED runs
#include msp430g2452.h
void main(void)
{ unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0xFF; // Set P1 to output direction
while(1)
{

for (i = 0;i<=7;i++)
P1OUT = 0x01 << i; // Shift left i bit
}
}
Can you see the LED run? Why?
Software delay
void loop_delay(void)
{
unsigned int x;
for (x = 0; x <10000; x++);
}
How to create a delay without using any hardware resource ?
void longer_loop_delay(void)
{
unsigned int x, y;
for (x = 0; x <10000; x++)
for (y = 0; y <10000; y++);
}
void delay(unsigned int ms)
{ unsigned int x, y;
for (x = 0; x <= ms; x++)
for (y = 0; y <= 120; y++);

}
How to create a useful delay?
Software delay
What are strengths of software delay ?
- Can be used to create very sort delays
- Require no hardware
- Will work on any microcontroller
BUT: What are the weakness ?
- Very difficult to create precisely time delays
- Need to be re-tuned if you change microcontroller, or
clock frequency, or compiler optimization settings
Conclusion
Seminar objectives
Embedded system: What is it?
Course overview
Why C?
Why MSP430?
Hardware & Software required
Simple software architecture
Examples: Central heating system; access input,output
Software delay




Bi tp 1.0
1. Ci t phn mm Code Composer Studio V.4
2. Tm hiu phn mm Code Composer Studio:
- Cc menu, ca s
- Cch to project, bin dch (build), debug (trong
help contents)
- Common Debug Actions


Bi tp 1.1
To project Baitap1_1
Chn thit b MSP430G2452 cho Device
Variant
To source file baitap1_1.c, nh li ni dung
trong Example 1.1
Bin dch v Debug chng trnh
Chy tng lnh chng trnh, quan st LED
Chy chng trnh lin tc, quan st LED
Thay i chng trnh LED chp tt 1
ln/giy


Bi tp 1.2
To project Baitap1_2
Chn thit b MSP430G2452 cho Device
Variant
To source file baitap1_2.c, nh li ni dung
trong Example 1.2
Bin dch v Debug chng trnh
Chy tng lnh chng trnh, quan st LED
Chy chng trnh lin tc, quan st LED
Thay i chng trnh thy c LED chy
ui


Bi kim tra 1.1
1. Lit k cc thnh phn chnh ca mt h thng nhng.
2. Ti sao MSP430 v C c chn pht trin h
thng nhng?
3. Mi quan h gia C, hp ng v ngn ng my th
no?
4. Dng Code Composer Studio, tm on m tng
ng bng hp ng v m my ca 1 vng for trong
hm delay.
5. Ti sao chng ta cn dng siu vng lp thc hin
mt cng vic?
T hc (5G)
Khm ph cc tnh nng cn li ca CCS
c file Code Composer Studio Users
Guide

Das könnte Ihnen auch gefallen