27
Programming embedded systems Seminar 1 INTRODUCTION Dr. Tran Thanh Hung Department of Automation Technology, College of Engineering, Can Tho University Email: [email protected]

Seminar 1

  • Upload
    kt8815

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Seminar 1

Programming embedded systems

Seminar 1

INTRODUCTION

Dr. Tran Thanh Hung Department of Automation Technology,

College of Engineering, Can Tho UniversityEmail: [email protected]

Page 2: Seminar 1

Outline

• Seminar objectives

• Embedded system: What is it?

• Course overview

• Why C?

• Why 8051?

• Hardware & Software required

• Simple software architecture

• Example: Central heating system

• Software delay

Page 3: Seminar 1

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 8051 and C are chosen for embedded

system development • explain the relationship between C, assembly, and

machine languages• know the basic features of AT89S52• write a simple software to run a task

Page 4: Seminar 1

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?

Page 5: Seminar 1

Core of embedded system

MCU = MicroController Unit

Page 6: Seminar 1

Applications of embedded system

• Mobile phone systems• Automotive applications• Domestic appliances• Aerospace applications• Medical equipment• Defence systems

Page 7: Seminar 1

Course overview

This course will introduce the principles of programming embedded system.

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

Page 8: Seminar 1

Textbooks

1. Embedded C by Michael J. Pont

2. AT89S52 datasheet

Page 9: Seminar 1

How computers were built?

Hardware (CPU/MCU)

Software 00001111ADD R1, R2Word, Excel,...

x = x + y

BIOS

Page 10: Seminar 1

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

Page 11: Seminar 1

Why C?

• A “mid-level”: - support functions- access hardware

• Independent to device • High efficient• Popular • Easy to understand• Good compilers

Page 12: Seminar 1

Can we build CPU/MCUs that can understand high-level language?

Hardware (CPU/MCU)

Software 00001111ADD R1, R2Word, Excel,...

x = x + y

BIOS

Page 13: Seminar 1

Can we build CPU/MCUs that can understand high-level language?

Hardware (CPU/MCU)

Software x = x + y

That’s means:

Page 14: Seminar 1

Why 8051?

• How to chose MCU for an embedded system?Some famous MCUs: + Z80 (8bit) designed by Zilog from1976: 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

Page 15: Seminar 1

Why 8051?

• In this course, 8051 family is chosen, because:

- Price: very cheap- Available: very famous, easy to find- Performance: suitable for many

embedded systems- Wide range: many MCUs to choseSee http://www.atmel.com/dyn/products/datasheets.asp?family_id=604

Page 16: Seminar 1

Hardware & Software required

• Hardware required: - Experimental kit with AT89S52 (Mua ở Trung tâm Điện-Điện tử, khoa Công nghệ)

• Software required:- Keil C version 3: programming environment

and assembler compiler

Page 17: Seminar 1

AT89S52

Low-voltage, high-performance microcontroller:

• 32 programmable I/O lines (in 4 ports)• 8K Bytes of In-System Programmable (ISP)

Flash Memory (10,000 Write/Erase Cycles )• 256 x 8-bit Internal RAM • Up to 64K Bytes optional external memory

Page 18: Seminar 1

AT89S52

• Three 16-bit Timer/Counters • Eight Interrupt Sources • Full Duplex UART Serial Channel • Low-power Idle and Power-down Modes • 4.0V to 5.5V Operating Range • Fully Static Operation: 0 Hz to 33 MHz • Watchdog Timer

Page 19: Seminar 1

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() }}

Page 20: Seminar 1

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

Page 21: Seminar 1

Example1.1: Central heating system

void main(void){ C_HEAT_Init(); // Init the system while(1) // 'for ever' (Super Loop) { // Find out what temperature the user requires C_HEAT_Get_Required_Temperature(); // Find out what the current room temperature is C_HEAT_Get_Actual_Temperature(); // Adjust the gas burner, as required C_HEAT_Control_Boiler(); }}

Page 22: Seminar 1

Example 1.2: Reading and writing ports

#include <Reg52.H>void main (void){unsigned char Port1_value;P1 = 0xFF; // set Port1 as inputwhile(1) { Port1_value = P1; // Read the value of P1 P2 = Port1_value; // Copy the value to P2 }}

How to write a software to access to port pins?

Page 23: Seminar 1

Software delay

void loop_delay(void){unsigned int x; for (x = 0; x <65535; x++);}

How to create a delay without using any hardware resource ?

void longer_loop_delay(void){unsigned int x, y;for (x = 0; x <65535; x++)

{for (y = 0; y <65535; y+

+);}

}

Page 24: Seminar 1

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

Page 25: Seminar 1

Conclusion

• Seminar objectives

• Embedded system: What is it?

• Course overview

• Why C?

• Why 8051?

• Hardware & Software required

• Simple software architecture

• Examples: Central heating system; access input,output

• Software delay

Page 26: Seminar 1

Exercise 1.1

1. Run Keil C2. Create a new project3. Type the program in example 24. Build the project5. Start debugging6. Click Run 7. Chose PeripheralI/O-PortsPort1, Port2 8. Change Port1 pins, observe Port29. Toggle disassembler window, find out the relationship

between instructions in C, assembly and machine languages

Page 27: Seminar 1

Test 1.1

1. List of components needed to build a core of an embedded system.

2. Why 8051 and C are chosen for embedded system development?

3. What is relationship between C, assembly, and machine languages?

4. Use Keil C, find the program in assembly and machine code corresponding to a loop delay

for (unsigned int x = 0; x <65535; x++);

5. Why do we use a “super loop” to run a task?