Anda di halaman 1dari 59

TRANSLAM INSTITUTE OF TECHNOLOGY & MANAGEMENT

(MAWANA ROAD,MEERUT)

TRAINING REPORT
ON

EMBEDDED SYSTEM
B.TECH(2011)
(DEPARTMENT OF ELECTRONICS AND COMMUNICATION)

PERFACE
First of all it is our proud to express our heartfelt gratitude to supreme power. The almighty lord, the ultimate creator of the whole world, who always guards us on the right path of life. Without his grace, this task of work would have never been to a successful end. We are wishing to express our heartfelt gratitude to my guide, who has been helpful to me in completing this training. We intent our forthright thanks to staff of the cad arena who provide us the final tips that helped us to improve our performance. Finally, we are indwelled to my parents for their love and moral supports whose encouragement pushed us to achieve this goal, without which we should have been able to fight out all odds during my training.

ACKNOWLEDGEMENTS First and foremost, I would like to thank my respected parents, who always encouraged me and taught me to think and workout innovatively what so ever be the field of life. My sincere thanks goes to Mr. Taz (Cad Arena, Dehradun) for his prodigious guidance, persuasion, and painstaking attitude, reformative and prudential suggestion throughout my summer training schedule. Last but not the least, my sincere thanks to all the staff members and friends for instilling in me a sense of selfconfidence.

CONTENTS
1. Introduction to Embedded System
1.1-Introduction 1.2-What is an Embedded System 1.3-Three criteria choosing Microcontroller

2. Introduction to 8051 microcontroller


2.1-Block diagram of 8051 Microcontroller 2.2-Pin description of 8051 Microcontroller 2.3-Pins of I/O Port 2.4-Hardware structure of I/O Pin 2.5-Other Pins 2.6-Port 3 Alternate Function

3. 8051 Timers/Counter
3.1-Timer/Counter Programming 3.2-Timer 3.3-Timer Modes 3.4-Delay Length Factors 3.5-Timer Delay Calculation in sec 3.6-Findings THx and TLx when time is known 3.7-Counter

4. 8051 Interrupts
4.1-Interrupt Programming 4.2-Steps in Executing an Interrupt

5. Serial Communication in 8051


5.1-Basics of Serial Communication 5.2-Packaging data (Start and Stop bits) 5.3-Serial Control (SCON) Ragister 5.4-Modes of Operation 6. 8051 Registers 6.1-TMOD Register 6.2-TCON Register 6.3-Interrupt Enable Register 7. Programs Examples Using C 7.1-Write a program to toggle all pins of P1 continously 7.2-Write a program to toggle bit D0 of Port P1 (P1.0) 50,000 times 7.3-Write a program to get a byte data from P0,if it is less than 100,send it to Port1;otherwise send it to port2 7.4-Write a program to monitor a bit P1.5,if it is high send 55H to P0;otherwise send AAH to P2

8. Application Of Embedded System 9. Summary

Introduction to Embedded Systems

INTRODUCTION
The embedded systems is wide and varied, and it is difficult to exact definitions or descriptions. Chapter 1 introduces a useful model that can be applied to any embedded system. Chapter 2 introduces and defines the common standard components when building an embedded system.

What Is an Embedded System?


An embedded system is an applied computer system "embedded system", it constantly evolves with advances in technology and dramatic decreases in the cost of implementing various hardware and software components. In recent years, the field has outgrown many of its traditional descriptions. Following are a few of the more common descriptions of an embedded system:

Three criteria in Choosing a Microcontroller


1. meeting the computing needs of the task efficiently and cost effectively speed, the amount of ROM and RAM, the number of I/O ports and timers, size, packaging, power consumption easy to upgrade cost per unit 2. availability of software development tools assemblers, debuggers, C compilers, emulator, simulator, technical support 3. wide availability and reliable sources of the microcontrollers.

Introduction to 8051
Microcontroller

Block Diagram
External interrupts Interrupt Control CPU Bus Control Serial Port TxD RxD On-chip ROM for program code
Timer/Counter

On-chip RAM

Timer 1 Timer 0

C I

OSC

4 I/O Ports

P0 P1 P2 P3

Address/Data

Pin Description of the 8051


P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 RST (RXD)P3.0 (TXD)P3.1 (INT0)P3.2 (INT1)P3.3 (T0)P3.4 (T1)P3.5 (WR)P3.6 (RD)P3.7 XTAL2 XTAL1 GND 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 Vcc P0.0(AD0) P0.1(AD1) P0.2(AD2) P0.3(AD3) P0.4(AD4) P0.5(AD5) P0.6(AD6) P0.7(AD7) EA/VPP ALE/PROG PSEN P2.7(A15) P2.6(A14) P2.5(A13) P2.4(A12) P2.3(A11) P2.2(A10) P2.1(A9) P2.0(A8)

8051 (8031)

Pins of 8051 (1/4)


Vcc pin 40 Vcc provides supply voltage to the chip. The voltage source is +5V. GND pin 20 ground XTAL1 and XTAL2 pins 19,18

Pins of 8051 2/4


RST pin 9 reset It is an input pin and is active high normally low . The high pulse must be high at least 2 machine cycles. It is a power-on reset. Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost. Reset values of some 8051 registers

Pins of 8051 3/4


/EA pin 31
external access There is no on-chip ROM in 8031 and 8032 . The /EA pin is connected to GND to indicate the code is stored externally. /PSEN ALE are used for external ROM. For 8051, /EA pin is connected to Vcc. / means active low. /PSEN pin 29 program store enable This is an output pin and is connected to the OE pin of the ROM.

Pins of 8051 4/4


ALE pin 30 address latch enable It is an output pin and is active high. 8051 port 0 provides both address and data. The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch. I/O port pins The four ports P0, P1, P2, and P3. Each port uses 8 pins. All I/O pins are bi-directional. .

Pins of I/O Port


The 8051 has four I/O ports Port 0 pins 32-39 P0 P0.0 P0.7 Port 1 pins 1-8 P1 P1.0 P1.7 Port 2 pins 21-28 P2 P2.0 P2.7 Port 3 pins 10-17 P3 P3.0 P3.7 Each port has 8 pins. Named P0.X X=0,1,...,7 , P1.X, P2.X, P3.X Ex P0.0 is the bit 0 LSB of P0 Ex P0.7 is the bit 7 MSB of P0 These 8 bits form a byte. Each port can be used as input or output (bi-direction).

Hardware Structure of I/O Pin


Each pin of I/O ports Internal CPU bus communicate with CPU A D latch store the value of this pin D latch is controlled by Write to latch Write to latch 1 write data into the D latch 2 Tri-state buffer TB1: controlled by Read pin Read pin 1 really read the data present at the pin TB2: controlled by Read latch Read latch 1 read value from internal latch A transistor M1 gate Gate=0: open Gate=1: close

Other Pins
P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain. P0 has no internal pull-up resistors and does not connects to Vcc inside the 8051. P0 is open drain. Compare the figures of P1.X and P0.X. However, for a programmer, it is the same to program P0, P1, P2 and P3. All the ports upon RESET are configured as output.

Port 3 Alternate Functions


P3 Bit P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 Function RxD TxD INT0 INT1 T0 T1 WR RD Pin 10 11 12 13 14 15 16 17

8051 timer/counter

Timers /Counters Programming


The 8051 has 2 timers/counters:
timer/counter 0 timer/counter 1

They can be used as 1. The timer is used as a time delay generator.


The clock source is the internal crystal frequency of the 8051.

2. An event counter.
External input from input pin to count the number of events on registers. These clock pulses cold represent the number of people passing through an entrance, or the number of wheel rotations, or any other event that can be converted to pulses.

Timer
Set the initial value of registers Start the timer and then the 8051 counts up. Input from internal system clock (machine cycle) When the registers equal to 0 and the 8051 sets a bit to denote time out
8051

P2 Set Timer 0

P1 TH0 TL0

to LCD

Timer Mode 1
In following, we all use timer 0 as an example. 16-bit timer (TH0 and TL0) TH0-TL0 is incremented continuously when TR0 is set to 1. And the 8051 stops to increment TH0-TL0 when TR0 is cleared. The timer works with the internal system clock. In other words, the timer counts up each machine cycle. When the timer (TH0-TL0) reaches its maximum of FFFFH, it rolls over to 0000, and TF0 is raised. Programmer should check TF0 and stop the timer 0.

Delay length factors


Timer freq.or Machine cycle frequency= 1/12 clock frequency (when timer is used for generating delays) AT89C51 : 12 clocks per machine cycle DS89C4x0 : 1 clock per machine cycle Delay length depends upon Crystal frequency No. Of clocks per machine cycle C-compiler

Timer delay calculation in sec.


When the values of Thx and TLx are known :
Suppose hex value is YYXX = TH + TL Calculation in HEX : Step1 : [ FFFF-YYXX+1 ] x 1.085uS Calculation in decimal : Step1 : Convert YYXX into decimal NNNN. Step2 : [ 65,536 NNNN ] x 1.085 uS

Finding THx and TLx when time is known :


For 11.0592 MHz XTAL frequency : Step 1 : Desired time delay / 1.085 uS = n in decimal Step 2 : 65,536 n = M Step 3 : Convert M into hex value YYXX Step 4 : THx = YY Step 5 : Tlx = XX

Counter
Count the number of events
Show the number of events on registers External input from T0 input pin (P3.4) for Counter 0 External input from T1 input pin (P3.5) for Counter 1 8051 External input from Tx input pin. We use Tx to denote T0 or T1. TH0
P1 TL0 P3.4 a switch T0 to LCD

8051 Interrupts

Interrupts Programming
An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. Interrupts vs. Polling A single microcontroller can serve several devices. There are two ways to do that:
interrupts polling.

The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt
handler.

Steps in executing an interrupt


Finish current instruction and saves the PC on stack. Jumps to a fixed location in memory depend on type of interrupt Starts to execute the interrupt service routine until RETI (return from interrupt) Upon executing the RETI the microcontroller returns to the place where it was interrupted. Get pop PC from stack

Interrupt Sources
Original 8051 has 6 sources of interrupts
Reset Timer 0 overflow Timer 1 overflow External Interrupt 0 External Interrupt 1 Serial Port events (buffer full, buffer empty, etc)

Enhanced version has 22 sources


More timers, programmable counter array, ADC, more external interrupts, another serial port (UART)

Interrupt Enable (IE) register


All interrupt are disabled after reset We can enable and disable them bye IE

External interrupt type control


By low nibble of Timer control register TCON IE0 (IE1): External interrupt 0(1) edge flag.
set by CPU when external interrupt edge (H-to-L) is detected. Does not affected by H-to-L while ISR is executed(no int on int) Cleared by CPU when RETI executed. does not latch low-level triggered interrupt

IT0 (IT1): interrupt 0 (1) type control bit.


Set/cleared by software IT=1 edge trigger IT=0 low-level trigger

(MSB) TF1 TR1 Timer 1

TF0 TR0 Timer0

IE1

IT1 IE0 for Interrupt

(LSB) IT0

Interrupt Priorities
What if two interrupt sources interrupt at the same time? The interrupt with the highest PRIORITY gets serviced first. All interrupts have a power on default priority order.
1. External interrupt 0 (INT0) 2. Timer interrupt0 (TF0) 3. External interrupt 1 (INT1) 4. Timer interrupt1 (TF1) 5. Serial communication (RI+TI)

Priority can also be set to high or low by IP reg.

Interrupt Priorities (IP) Register


----PT2 PS PT1 PX1 PT0 PX0

IP.7: reserved IP.6: reserved IP.5: timer 2 interrupt priority bit(8052 only) IP.4: serial port interrupt priority bit IP.3: timer 1 interrupt priority bit IP.2: external interrupt 1 priority bit IP.1: timer 0 interrupt priority bit IP.0: external interrupt 0 priority bit

Serial
Communication

Basics of serial communication


Parallel: expensive - short distance fast no modulation Serial :cheaper long (two different cities by modem)-slow

Basics of serial communication

Packaging Data
Start and stop bits

In asynchronous transmission When there is no transfer the signal is high Transmission begins with a start (low) bit LSB first Finally 1 stop bit (high) Data transfer rate (baud rate) is stated in bps

Serial control (SCON) Register:7 6 5 4 3 2 1 0

SM0

SM1

SM2

REN
SM0 0 0 1 1 SM1 0 1 0 1

TB8

RB8

TI

RI

SM0 : mode specifier SM1 : mode specifier

MODE operation 0 shift register 1 8 bit UART 2 9 bit UART 3 9 bit UART

transmit rate fixed (xtal/12) variable (timer1) fixed (xtal/32 or xtal/64) variable (timer1)

SM2 : used for multi processor communication REN : receive enable (by software enable/disable) TB8 : transmit bit8 RB8 : receive bit 8 TI : transmit interrupt flag set by HW after send , clear by SW RI : receive interrupt flag set by HW after received ,clear by SW

Mode of operation
Mode 0 : Serial data enters and exits through RxD TxD outputs the shift clock. 8 bits are transmitted/received(LSB first) The baud rate is fixed a 1/12 the oscillator frequency.

Application
Port expansion
8051
TXD RXD

clk Shift register data

Mode of operation
Mode 1
Ten bits are transmitted (through TxD) or received (through RxD)
(A start bit (0), 8 data bits (LSB first), and a stop bit (1) )

On receive, the stop bit goes into RB8 in SCON the baud rate is determined by the Timer 1 overflow rate. Timer1 clock is 1/32 machine cycle (MC=1/12 XTAL)

Timer clock can be programmed as 1/16 of machine cycle Transmission is initiated by any instruction that uses SBUF as a destination register.

Mode of operation
Mode 2 :
Eleven bits are transmitted (through TxD), received (through RxD) A start bit (0) 8 data bits (LSB first) A programmable 9th data bit and a stop bit (1) On transmit, the 9th bit (TB8) can be assigned 0 or 1. On receive, the 9the data bit goes into RB8 in SCON. the 9th can be parity bit The baud rate is programmable to 1/32 or 1/64 the oscillator frequency in Mode 2 by SMOD bit in PCON register

Mode 3
Same as mode 2 But may have a variable baud rate generated from Timer 1.

The 8051

Ragisters

TMOD Register:

Gate : When set, timer only runs while INT(0,1) is C/T : Counter/Timer select bit. M1 : Mode bit 1. M0 : Mode bit 0.

high.

Gate
Every timer has a mean of starting and stopping.
GATE=0 Internal control The start and stop of the timer are controlled by way of software. Set/clear the TR for start/stop timer. SETB TR0 CLR TR0 GATE=1 External control The hardware way of starting and stopping the timer by software and an external source. Timer/counter is enabled only while the INT pin is high and the TR control pin is set (TR).

(MSB)
GATE

C/T M1 Timer 1

M0

GATE

C/T M1 Timer 0

(LSB) M0

TCON Register:

TF1: Timer 1 overflow flag. TR1: Timer 1 run control bit. TF0: Timer 0 overflag. TR0: Timer 0 run control bit. IE1: External interrupt 1 edge flag. IT1: External interrupt 1 type flag. IE0: External interrupt 0 edge flag. IT0: External interrupt 0 type flag.

TCON Register (1/2)


Timer control register: TMOD
Upper nibble for timer/counter, lower nibble for interrupts

TR (run control bit)


TR0 for Timer/counter 0; TR1 for Timer/counter 1. TR is set by programmer to turn timer/counter on/off. TR=0: off (stop) TR=1: on (start)
(MSB) TF1 TR1 Timer 1 TF0 TR0 Timer0 IE1 IT1 IE0 for Interrupt (LSB) IT0

TCON Register (2/2)


TF (timer flag, control flag)
TF0 for timer/counter 0; TF1 for timer/counter 1. TF is like a carry. Originally, TF=0. When TH-TL roll over to 0000 from FFFFH, the TF is set to 1.
TF=0 : not reach TF=1: reach If we enable interrupt, TF=1 will trigger ISR.

(MSB) TF1 TR1 Timer 1

TF0 TR0 Timer0

IE1

IT1 IE0 for Interrupt

(LSB) IT0

Interrupt Enable Register :

EA : Global enable/disable.
--: Undefined.

ET2 :Enable Timer 2 interrupt. ES :Enable Serial port interrupt. ET1 :Enable Timer 1 interrupt. EX1 :Enable External 1 interrupt. ET0 : Enable Timer 0 interrupt. EX0 : Enable External 0 interrupt.

Programs Examples

Using C

//Write an 8051 C program to toggle all the bits of P1 continuously. Solution: #include <reg51.h> void main(void) { for (;;) //Toggle P1 forever { p1=0x55; p1=0xAA; } }

//Write an 8051 C program to toggle bit D0 of the port P1 (P1.0) 50,000 times. Solution: #include <reg51.h> sbit MYBIT=P1^0; void main(void) { unsigned int z; for (z=0;z<=50000;z++) { MYBIT=0; MYBIT=1; }

//Write an 8051 C program to get a byte of data form P0. If it is less than 100, send it to P1; otherwise, send it to P2.
Solution:

#include <reg51.h> void main(void) { unsigned char mybyte; P0=0xFF; while (1) { mybyte=P0; if (mybyte<100) P1=mybyte; else P2=mybyte;

//Write an 8051 C program to monitor bit P1.5. If it is high, send 55H to P0; otherwise, send AAH to P2.
Solution:

#include <reg51.h> sbit mybit=P1^5; void main(void) { mybit=1; //make mybit an input while (1) { if (mybit==1) P0=0x55; else P2=0xAA; }

Application Of
Embedded System

Applicaton Of Embedded System: Consumer Electronics Medical. Industrial Automation and Control Networking and Communications Automotive. Aerospace and Defense Commercial Office/Home Office Automation

Summary
An embedded system is a product that has one or more computers embedded within it, which exercise primarily a control function. The embedded computer is usually a microcontroller: a microprocessor adapted for embedded control applications. Microcontrollers are designed according to accepted electronic and computer principles, and are fundamentally made up of microprocessor core, memory and peripherals. Microchip offers a wide range of microcontrollers, divided into a number of different families. Each family has identical central architecture and instruction set. However, common features also appear across all their microcontrollers. The Microchip 12F508 is a good microcontroller to introduce a range of features of microcontrollers in general and of PIC microcontrollers in particular.
Dr. Gheith Abandah 59

Anda mungkin juga menyukai