Upload
kt8815
View
214
Download
0
Embed Size (px)
Citation preview
Programming embedded systems
Seminar 1
INTRODUCTION
Dr. Tran Thanh Hung Department of Automation Technology,
College of Engineering, Can Tho UniversityEmail: [email protected]
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
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
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 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
Textbooks
1. Embedded C by Michael J. Pont
2. AT89S52 datasheet
How computers were built?
Hardware (CPU/MCU)
Software 00001111ADD R1, R2Word, Excel,...
x = x + y
BIOS
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?
Hardware (CPU/MCU)
Software 00001111ADD R1, R2Word, Excel,...
x = x + y
BIOS
Can we build CPU/MCUs that can understand high-level language?
Hardware (CPU/MCU)
Software x = x + y
That’s means:
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
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
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
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
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
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
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(); }}
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?
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+
+);}
}
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 8051?
• Hardware & Software required
• Simple software architecture
• Examples: Central heating system; access input,output
• Software delay
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
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?