Sie sind auf Seite 1von 82

8051 and Embedded C

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Introduction
An embedded system
application
contains at least one programmable computer
(microcontroller, microprocessor or digital signal
processor chip)
used by individuals who are, in the main, unaware that
the system is computer-based.

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Examples of Embedded Applications
Mobile Phone Systems :customer handsets and base stations

Automotive Applications : braking systems, traction control, airbag release systems,


engine-management units, steer-by-wire systems

Domestic Appliances: dishwashers, televisions, washing machines, microwave ovens, video


recorders, security systems, garage door controllers

Aerospace Applications: flight control systems, engine controllers, autopilots and passenger
in-flight entertainment systems

Medical Equipment: anesthesia monitoring systems, ECG monitors, drug delivery systems
and MRI scanners).

Defense Systems: radar systems, fighter aircraft flight control systems, radio systems and
missile guidance systems

Embedded Systems excludes : personal digital assistants (PDAs) bcoz cut-down version of
a desktop computer system.
Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi
Step 1 : Which processor should you use?

Desktop Processors
cost more than US $100.00
requires : numerous external support chips to function: increases
cost.

Additional Components increase the physical size of the system,


and the power consumption
External chip support + Power consumption : Major
factors considered in battery-powered embedded devices

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


8051

Introduced by Intel in 1980.


prices of modern 8051 less than US $1.00.
Performance of around 1 million instructions per
second, and 256 bytes (not megabytes!) of on-chip
RAM.
32 port pins and a serial interface.
8051s profile (price, performance, available
memory, serial interface) match the needs of many
embedded systems very well.
8051 produced more 400 different forms : Philips,
Infineon, Atmel and Dallas
Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi
Standard 8051 : External interface (40 pin DIP Package)

Imp: 8051 requires minimum external components to


operate.
Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi
8051 : Circuit Diagram for Applications

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Small 8051 : 20 pins
Original 8051
32 I/O pins
connected 128 kbytes of external memory.
Small 8051
15 I/O pins,
do not support external memory.
Standard and Small 8051s aimed,
at low-performance
limited memory
Low product cost

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Extended 8051 : 80 pins

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Important Points : 8051 Architecture
If none of existing chips matches : your application,
build your own device.
Have
8051 cores,
additional area of field-programmable gate arrays
(FPGAs) :create own on chip hardware.
set of tools for the programming of blank FPGAs or
Application-Specific ICs (ASICs).

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Step 2 : Which programming language should u use?
First Step : Select Processor : Second Step : Select Programming Language
Computer
Accept Instruction : Machine Code
Machine Code
Language of Computer , Not Programmer Language
Difficult to understand By Programmer
Error Prone.
Assembly / HLL (C, C++, Java, Ada) are translated into machine code to be
executed by the computer.
No point in creating perfect source code, if translator generate executable code
that does not operate as we intended.

8051 : Embedded Processor : Limited Power and Memory : Selected Language


must be Efficient
Embedded System Program
Need low-level access of hardware
Need to able to read/write to a particular memory location using pointers or
equivalent mechanism.
Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi
Which programming language should you use?
Language Used :
Support creation of Flexible libraries
Making it easy to reuse a code components in wide range of projects.
Code Must adapt to new processor with minimal difficulty.
Good Code: Easy to Understand, now and even after due course of time also.
Language : Commonly Used
Recruit Experienced Developers
Existing Developers have access s to sources of information
For embedded system: language C
Efficient
High-Level L
a
Provide Low-Level Access to Hardware n
Well Defined. g
u
a
g
e
Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi
Features of C Language
C : Middle Level Language
C Supports
High Level Features (functions and modules)
Low Level Features (access to hardware via pointers )
Efficient
Popular and Understood
C syntax: easy to understand.
Well proven compliers for embedded systems.
Experienced Staff available
Books, training material and WWW sites material is available.

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Step 3 : Which operating system should you use?
First Step : Select Processor (8051 ) , Second Step : Select Programming Language
(C), Third Step : Select Operating System.

Desktop Application Embedded Application


User Programs: Runs Only One Program
- Loaded from disk on demand - Program runs : Microcontroller Powered On
- Along with required data - Program Stops : Microcontroller Powered OFF
- Desktop PC does not require OS - Sophiscated Graphics Screen, Printers and
- Desktop PC used to Run Multiple Disks are Unavailable.
Programs
- OS provide common code Used By
these programs.

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Architecture of Desktop OS

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Example of Embedded Systems
Develop : microcontroller-based control system to be used as part of
the central-heating system in a building.
System consist of a
gas-fired boiler (which we wish to control),
a sensor (measuring room temperature),
a temperature dial (through which the desired temperature is specified)
controller (to which boiler, sensor, temperature dial are connected by
appropriate ports)

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


How to Develop Embedded Software
8051 Devices
Do not have sufficient memory Resources : to allow compilation
Do not support: Keyboard and Graphics
Cross-Complied code is required
Step 1 : Cross-compiler on Desktop PC generates 8051
compatible machine code i.e. 8051 executable code
Step 2 : Test and Refine Executable machine code

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


How to Test and Refine: 8051 Executable Code
Build hardware for embedded system
Small embedded applications: BreadBoard Approach
BreadBoard
Microcontroller and Associated Components are connected together Without
Soldering
To Test and Refine: Hardware and Software design
Transfer Executable code to Embedded Hardware
requires
Flash Memory to Store program
flash Programmers to transfer code to Microcontroller

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Alternative Approach : 8051 Executable Code
Step 1: Create executable code for embedded systems using cross
compiler and appropriate tools
Step 2: Use a Software Simulator : e.g. Keil Software running on
Desktop PC to test code
Step 3: Repeat step 1 and 2

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Embedded Software
Flexible hardware platform in form of Embedded Software
Eliminates need of Hardware Soldering
Debugging facilities
Profiling Code : Measuring the duration of Particular function
Duration Measure imp bcoz timing is imp factor in Embedded Systems.

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


8051 Code
In Embedded Systems
No Output Screen : To Display Output
Code designed to flash an LED on for one second, off for one
second,

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Dissecting the code
8051 : 4 8bit Bidirectional Ports;
Port 0 , Port 1 , Port 2 , Port 3
Bidirectional Ports: Used for input / output
Ports are controlled using special function registers (SFRs).
SFR are 8-bit Latches
Port contain value in Latches
Until new value is not written on device
Until Device is not Reset
4 ports is represented by SFR: are named P0, P1, P2 and P3.
Physically, each SFR area of memory in the upper areas of internal RAM:
P0 is at address 0x80,
P1 at address 0x90,
P2 at address 0xA0
P3 at address 0xB0.

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Representation of Ports in SFR Areas of Memory

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Controlling Port Pins
Write to Ports : Write to above addresses
Writing to Addresses : Declaring SFR variable, Hidden header file.
#include ensure copy of Keil reg52 inserted in source file before compilation.
reg52 file
Matches 8052 register set.
Compatible with 8052 as Target hardware
Key Part of this file till now is as follows
Write to Ports as Follows

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating and Using Predefined Bit Variable
Complier Deal SFRs: Indirection (* Pointer) variable is optional.

Control
Complete Port
Individual Port Pin
Control of Pin 1.5 is achieved by LED_pin is a bit variable that contain
information of already defined port pin .
As port pin already exist hence declared
using sbit keyword.
sbit Keyword Port 1 oin 5 is assigned to it
Not ISO/ANSI C declaration but Keil Extension
Allows to Declare Bit Variables: Part of already defined (byte sized) variables
^ -- to access specific Pin

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating and Using Userdefined Bit Variable
Set status of individual pin
8051:BDATA area (16 bytes in size)

Creating and Using Bit variable


bit Keyword :stores data assigned
to variable in BDATA area
Variable declared using bit
keyword can store a single bit :0/1

LED_pin is a bit variable for already defined


port pin .
LED_state_G is user defined bit variable
decalred using bit keyword

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Delay Function
Accurate Delay: Requirement of many Embedded Systems.
Implemented Using Loop Delay as Follows

Default Delay Loop Longer Delay Loop : Additional layer

Delay of 1 second is achieved as follows

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Embedded C Software : Keil
Prepared By: Mrs. Reetu Gupta,
IT, DYPCOE, Akurdi
Need of Software
Flexible hardware platform in form of Embedded Software
Eliminates need of Hardware Soldering
Debugging facilities
Profiling Code : Measuring the duration of Particular function
Duration Measure imp bcoz timing is imp factor in Embedded Systems.

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Desktop Code vs Embedded Code
Desktop Systems : Peripheral Screen to show Output
Embedded Systems : LED Flash to show output

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Configuring Simulator

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Create New Project File
Project Menu- New Vision Project

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Create New Project File contd
Provide project name, save project

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Select Microprocessor/Microcontroller
Select the Target Processor: Atmel AT89S52

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Select Microprocessor/Microcontroller
Select the Target Processor: Atmel AT89S52

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Configure Target Device
Project Window Target Folder Right ClickOptions with Target --Set
Oscillator Frequency
e.g. Oscillator Frequency default 12 Mhz

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Build Target
Project Menu Build Target (Compile and Link Source Files)

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Running Simulation
Debug Menu Start/Stop Debug Session

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Configure Simulator to Display Port Activity
LED connected Port 1
Peripherals MenuI/O ports Port 1

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Port Activity

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Project Window Flag
Ensure Port Activity is Visible set Periodic window Update Flag

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Run Simulation

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Super Loop Architecture

void main(void)
{
LED_FLASH_Init();
while(1) //Infinite Loop
{
LED_FLASH_Change_State()
;
DELAY_LOOP_Wait(1000);
}
}

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Controlling Port Pin

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
8051 Ports
8051 : 4 8bit Bidirectional Ports;
Port 0 , Port 1 , Port 2 , Port 3
Bidirectional Ports: Used for input / output
Ports are controlled using special function registers (SFRs).
SFR are 8-bit Latches
Port contain value in Latches
Until new value is not written on device
Until Device is not Reset
4 ports is represented by SFR: are named P0, P1, P2 and P3.
Imp : Physically, each SFR area of memory in the upper areas of
internal RAM:
P0 is at address 0x80,
P1 at address 0x90,
P2 at address 0xA0
Prepared By: Mrs. Reetu Gupta,
P3 at address 0xB0. IT, DYPCOE, Akurdi
Declaring SFR Variable
Write to Ports : Write to Port addresses
Write to Addresses : Declaring SFR variable.
#include ensure copy of Keil reg52 inserted in source file before
compilation.
Declare SFR variable as Follows

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Assigning Value to Port
Declare SFR variable : SFR p1 =0x90
Declare char variable to store data : unsigned char port_data
Assign Data to Port as Follows

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Declaring Bit variables
Declaring Already Defined Variable
Using Sbit Keyword

LED_pin is a bit variable that contain


information of already defined port pin .
As port pin already exist hence declared
using sbit keyword.
Port 1 pin 5 is assigned to it

Set status of individual pin

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Declaring Bit variables
Declaring User Defined Variable
Using bit Keyword
8051:BDATA area (16 bytes in size)

Creating and Using Bit variable


bit Keyword :stores data assigned
to variable in BDATA area
Variable declared using bit
keyword can store a single bit :0/1

LED_pin is a bit variable for already defined


port pin .
LED_state_G is user defined bit variable
decalred using bit keyword

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Delay Function
Accurate Delay: Requirement of many Embedded Systems.
Implemented Using Loop Delay as Follows

Default Delay Loop Longer Delay Loop : Additional layer


Delay of 1 second is achieved as follows

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Performance Analyzer
Check Delay Duration: Performance Analyzer

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Measuring Loop Delay : Part 1

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Measuring Loop Delay : Part 2

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
Measuring Loop Delay : Part 3

Prepared By: Mrs. Reetu Gupta,


IT, DYPCOE, Akurdi
LED On-Off Embedded Program : Keil

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Default Screen

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Open Existing Project
Step 1 : Project Menu --- Open Project

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Open Existing Project
Step 2 : Select Project File: .uvprojx, .uvproj, .uvmpw, .uv2, .uv3, .mpw

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project
Step 1: Create .uvprojx file
Step 2: Select Device/ Target Processor: 8051
Select Processor
Step 3: Create .C Code File
Select programming for coding
Step 4: debug ,test and run application

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 1: Create .uvprojx file
Project Menu- New Vision Project

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 1: Create .uvprojx file
Provide project name, save project

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device
Select yes option

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device
Select yes option :Default Startup File

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device
Select yes option

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 2: Select Target Device
Select no option : No Startup File

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 3: Create .C Code File
Project FolderTarget1-Source Group 1-New Item

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 3: Create .C Code File
Select C file Give Name --Add

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 3: Create .C Code File
Write code .c file

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 4: Debug, Test and Run
After Code : Build Target

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 4: Debug, Test and Run
Successful Build -- 0 Errors / 0 Warnings -- Code Complied Successfully

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 4: Debug, Test and Run
After Build -- Debug Menu : Start/Stop Debug

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Creating New Project : Step 4: Debug, Test and Run
Start Debugging : Click OK

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Select Ports : Peripherals
After Debug Session : Peripheral I/OSelect Port
Flashing LED connected to Port 1

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Port Configuration
Port 1 with Pins and Pin status is Displayed

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Running Simulator
Debug Run

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


Running Simulator
Running : Port 1 pin 5 is on and off

Prepared By: Mrs. Reetu Gupta, IT, DYPCOE, Akurdi


UNIT-IV

Embedded

Sr. No. Question A B C D Ans


1 Which system software is used to convert a compiler Linker Cross Cross C
"C" language program in to language of compiler Linker
another processor?

2 Embedded C programming language support All Some Specific none A


________ instructions of normal "C"
language.

3 CCS C is ________________. compiler Linker Cross Cross C


compiler Linker
4 Cross Compiler Program Program Program Both A C
converts______________________ of C of C in C &B
language language language
into into into
binary another program
language language of another
. processor
s
language.
5 Embedded system is designed to execute execute Both none A
single many
program program
repeatedl s
y
6 Embedded system is Reactive Real None both D
time
7 Software written for embedded system is Embedde system operating All A
called d program system
Software
8 Software for embedded system is written in Flash RAM EEPROM All C
___________________ . ROM
9 Embedded system has ___________. response strict dea Both C
time dlines
constraint
s
10 OS used in embedded systems is Single real time open All B
user OS OS source
11 Which feature of C language helps in pointers arrays Strings functio A
accessing the underlying hardware ns
12 Which feature of C language helps in bit arrays Strings functio A
accessing the underlying hardware manipula ns
tion
14 A cross compiler is a compiler whose purpose Compile Convert Combine All A
is code for high both high
a target level level lang.
CPU that language and
is code to assembler
different assemble into a
from the r code single
developm module
ent CPU
15 Execution of single program repeatedly is distribute
embedde Both none B
done by d system d system
16 Use of pointers in embedded systems is for bit calling Accessing All C
_______________ manipula functions underlyin
tion g
hardware
17 Embedded C requires compilers to create files microcon micropro operating A&B D
to be downloaded to the trollers cessors system
18 Embedded C is used for microcon desktop A&B none A
trollers compute
rs
19 Following s an embedded system digital mobile washing All D
camera phone machine
20 Embedded devices have following resource limited limited limited All D
constraints ROM RAM stack
space
21 Embedded system programming is to get minimum minimu Both none C
maximum features in space m time.
22 Embedded systems are programmed using Machine Low High All D
Code level level
language language
23 which language provides direct hardware C PASCA FORTRA All A
control without sacrificing benefits of high L N
level languages.

24 Compared to other high level languages, C C is structure supports All D


offers more flexibility because relatively d low-level
small language bit-wise
data
manipulat
ion.
25 A traffic-light sequencer is an example of desktop embedde distribute All B
d system d system
26 A remotely-controlled robot is an example of desktop embedde distribute none B
d system d system
27 A controller for a domestic washing machine desktop embedde distribute none B
is an example of d system d system
28 Numbers are stored and transmitted inside a binary ASCII decimal alphanu A
computer in ___________. form code form meric
form form
29 The 8051 microcontroller is of ___pin package as 30,1byte 20, 1byte 40,8 bit 40, 8 C
a ______ processor. byte
30 8051 series of micro controllers are made by a) Atmel b) c)intel d) both D
which of the following companies? Philips of the
mentio
ned
31 8051 is always a beneficial to use for Low cost Both A None c
embedded application because of : Sufficien and B
t
memory
32 Embedded System is an application that contains A micro B. C. D. None C
one programmable computer consist of ________ controller Microproc Both A and
essor B

33 8051 microcontroller access _____bytes of on chip A. 128 B. C. 256 D 8 Bit C


RAM Bytes 512bytes Bytes

34 8051 microcontroller is originally developed by A. M HP IBM Intel D


_____
ic
A. Microsoft
B. HP ro
C. IBM so
D. Intel ft

35 Small 8051 microcontroller is developed by Infineon Atmel & IBM HP B


Phillips
36 How many pis are thir for small 8051 20 30 40 80 A
controller
37 Which of the following is produced as small Infineon AF17RE Atmel All C
8051 microcontroller____ C515C G51 AT89C20
51
38 Which of the following is extended 8051 Infineon AF17RE Atmel All A
microcontroller____ C515C G51 AT89C20
51
39. Extended 8051 also supports additional CAN(Co Signal 8 bit Code A
feature of ntroller input instructio translati
Area output n set on
network) system system
40. CAN feature in Infineon C515C is ___ Controlle Signal Compiler Code A
r Area Area Area Area
network Network Network Networ
k
41. Which of the following language is most of Object Sequenti Java HTML B
the time efficient so as to use for embedded Oriented al
application ____
42. Which of the following is the example for Washing Oven LED light All D
embedded System. machine

1. Microwave oven is example of?


A. Electrical device b. Automatic application c. Embedded system** d. None

2. Which language is used in embedded programming?


A. C language** b. Java Language c. Dot net d.Python

3. Delay(200) is used to
A. pause for 200 sec b. pause for 200 millisecond** c. pause for 200 nanosecond

4. Toggle led(LED_GREEN) used to


A. . change state of LED to red b. Change state of LED to green** c. change state of light

5. Most programs in embedded system are


A. In finite loop b. In Infinite loop** c. Not in Loop

Das könnte Ihnen auch gefallen