(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
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
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.
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
8051 (8031)
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.
8051 timer/counter
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.
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.
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)
IE1
(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)
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
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
SM0
SM1
SM2
REN
SM0 0 0 1 1 SM1 0 1 0 1
TB8
RB8
TI
RI
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
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.
IE1
(LSB) IT0
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