Embedded Systems Practical Guide: 8051 Microcontroller Programming, Lecture notes of Embedded Systems

embedded systems practical.pdf

Typology: Lecture notes

2019/2020

Uploaded on 02/27/2020

sancheet-walekar
sancheet-walekar 🇮🇳

4.8

(4)

3 documents

1 / 81

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
S.Y.B.Sc. (I.T) Semester IV Embedded Systems Practical Manual 2017-2018
1
Practical Manual
2017-2018
On
Embedded Systems
(Course Code-USIT4P5)
For
S.Y.B.Sc. I.T.
(Semester IV)
Prepared By
Mrs.Archana Bhide
R.J.College,Ghatkopar.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Embedded Systems Practical Guide: 8051 Microcontroller Programming and more Lecture notes Embedded Systems in PDF only on Docsity!

Practical Manual

On

Embedded Systems

(Course Code-USIT4P5)

For

S.Y.B.Sc. I.T.

(Semester IV)

Prepared By

Mrs.Archana Bhide

R.J.College,Ghatkopar.

Index

Sr No Title

Introduction Introduction to Embedded System Practical Introduction to 8051 Microcontroller Introduction to TKBase Trainer kit

List of Practical

  1. Design and develop a reprogrammable embedded computer using 8051 microcontrollers and to show the following aspects. a. Programming b. Execution c. Debugging
  2. a Configure timer control registers of 8051 and develop a program to generate given time delay. b To demonstrate use of general purpose port i.e. Input/ output port of two controllers for data transfer between them.
  3. a Port I / O: Use one of the four ports of 8051 for O/P interfaced to eight LED‟s. Simulate binary counter (8 bit) on LED‟s b To interface 8 LEDs at Input-output port and create different patterns. c To demonstrate timer working in timer mode and blink LED without using any loop delay routine.
  4. a Serial I / O: Configure 8051 serial port for asynchronous serial communication with serial port of PC exchange text messages to PC and display on PC screen. Signify end of message by carriage return. b To demonstrate interfacing of seven-segment LED display and generate counting from 0 to 99 with fixed time delay.
  5. c Interface 8051 with D/A converter and generate square wave of given frequency on oscilloscope.
  6. a Interface 8051 with D/A converter and generate triangular wave of given frequency on oscilloscope b Using D/A converter generate sine wave on oscilloscope with the help of lookup table stored in data area of 8051.
  7. Interface stepper motor with 8051 and write a program to move the motor through a given angle in clock wise or counter clock wise direction
  8. Generate traffic signal.
  9. Implement temperature control.
  10. Implement Elevator control.
  11. a To demonstrate the procedure for flash programming for reprogrammable embedded system board using Flash Magic b To demonstrate the procedure and connections for multiple controllers programming of same type of controller with same source code in one go, using flash magic.

Interrupt handler / controller: Interrupt handling mechanism handles multiple interrupts generated from various processes simultaneously. There can be number of interrupt sources or group of sources. The service to these sources can have priorities according to the system priorities. Certain sources of interrupts are non maskable and cannot be disabled.

There is a separate program and data memory for the controller. Internal and external RAM for registers, temporary data and stack, Internal and external ROM for program memory, internal flash memory, memory cards, memory buffers of ports, cache memories. Communication ports: several communication ports serial as well as parallel to communicate with various peripheral devices like keyboards touch screens, sensors, transducers etc. (input) or printers, LED / LCD display, network etc. (output).

Power supply, Reset and Oscillator Circuit: Many embedded systems have their own power supply; however fee systems use PC power by connecting to computer. Power supply has range of voltages in one of following range 5 ±0.25V, 3.3 ±0.3V, 2 ±0.2V and 1.5 ±0.2V Reset circuit helps the processor to begin processing of instructions from a starting address. This address is set by default in processor Program Counter (PC) on a power up. A program to be executed after reset is - a system program which executes from beginning, or a boot program, or a system initialization program. Reset circuit activates for a fixed period and then deactivates.

Software components of embedded system -

An embedded system processor executes software that is specific to a given application system. Software components include editor, assembler, linker, and loader. The steps involved in executing an embedded assembly program are as followed –

  1. An assembler translates the assembly software into machine codes.
  2. The code is linked with other required codes. As there are several codes required to linked together for the final binary file. Linker produces binary file. This binary file can directly be run on a computer and is called as an executable file.
  3. Loader program performs task of reallocating the codes after finding the physical memory address available at a given instant. The loader is part of operating system and places the codes into its memory after reading the „exe‟ file.
  4. These codes are to be then located as ROM image.
  1. Lastly, this ROM image file is either burned into PROM or flash memory using a device programmer tool, or it is masked for the PROM from the ROM image file.

Fig 2 Process of converting assembly language program into the machine codes and obtaining the ROM image

Software is developed in higher level languages to save efforts instead of using assembly language. Following are different program layers in embedded C

Processor commands Main Function Interrupt service Routines Tasks 1 ….. N Kernel and scheduler Standard Library functions

Fig 3 Program Layers in embedded C

Machine specific Assembly language program

From library needed machine codes

Machine codes for the programs at various addresses

Bytes for linked programs

Data Bytes

Machine codes ready for locating at various addresses

Device (ROM) programmer (burner)

Embedded System ROM Memory

Assembler

Linker Loader

Re allocating addresses

Introduction to 8051 Microcontroller

8051 architecture

8051 architecture consists of 8 bit CPU with processing capability, oscillator driver unit, 4k on chip program memory, 128 bytes internal data memory, 128 bytes of SFR, 32 general purpose I/O lines organized into 4 8-bit bidirectional ports, two 16 bit timer units and a full duplex programmable UART (Universal Asynchronous Receiver Transmitter) for serial data transmission.

Fig below shows the internal architecture of 8051 microcontroller

Fig 5 (A) Pin configuration and (B) Internal architecture of 8051 microcontroller

8051 memory organization

8051 is build around Harvard architecture. Program and data memory is separated logically. Separate address spaces are assigned for program and data memory. 8051‟s address bus is 16 bit wide and it can address up to 64KB memory.

Program or code memory is lowest 4K bytes of program memory as on chip memory (built in chip memory). Internal and external program memory is switched

between using changing logic levels of pin External Access ( EA ). 1 on this pin

means instructions are to be executed from the program memory up to 4K and logic 0 on this pin means that chip is in external program execution mode. The

control signal for external program memory execution is PSEN (program Strobe

Enable). This is not activated for internal program memory.

Basic 8051 architecture supports 128 bytes of internal data memory and 128 bytes of special function register memory. SFR is not available for the user for general data memory operation. The address range of internal user data memory is 00 H to 7F H. SFR reside at memory area 80 H to FF H. control signals used for external

data memory address are RD and WR. 16 bit register holding the address to be

accessed is Data Pointer (DPTR). DPTR is made up of two 8 bit registers DPH and DPL. This register is accessible to the user and its contents can be modified. In external data memory operations port 0 emits the contents of DPL and port2 emits the contents of DPH.

Internal data memory addresses are always one byte long. It can accommodate up to 256 bytes of internal data memory (Ranging from 0 to 255). 8051 uses Direct addressing of data memory greater than 7F H

Fig 6 Memory organization of 8051

8051 registers: 8051 registers can be broadly classified as CPU registers and scratchpad registers. CPU registers: Accumulator B register Program Status word

The 13-bit register consists of all 8 bits of TH1 and the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored. Setting the run flag (TR1) does not clear the registers. Mode 0 operation is the same for the Timer 0 as for Timer 1. Substitute TR0, TF0, and INT0 for the corresponding Timer 1 signals in Figure 2. There are two different GATE bits, one for Timer1 (TMOD.7) and one for Timer 0 (TMOD.3).

Figure 8. Timer/Counter 0/1 Control (TCON) Register

Mode 1 Mode 1 is the same as Mode 0, except that the Timer register is being run with all 16 bits.

Mode 2 Mode 2 configures the Timer register as an 8-bit Counter (TL1) with automatic reload.

Overflow from TL1 not only sets TF1, but also reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged. Mode 2 operation is the same for Timer/Counter 0.

Mode 3 Timer 1 in Mode 3 simply holds its count. The effect is the same as setting TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate counters. The logic for Mode 3 on Timer 0 is shown in Figure 7. TL0 uses the Timer 0 control bits: C/T, GATE, TR0, and TF0, as well as the INT0 pin. TH0 is locked into a timer function (counting machine cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the “Timer 1” interrupt. Mode 3 is provided for applications requiring an extra 8-bit timer on the counter. With Timer 0 in Mode 3, an 80C51 can look like it has three Timer/Counters. When Timer 0 is in Mode 3, Timer 1 can be turned on and off by switching it out of and into its own Mode 3, or can still be used by the serial port as a baud rate generator, or in fact, in any application not requiring an interrupt

Fig 10 Four 7 segment display characters.

Fig 11 using 7 segment to display output Hex Keypad

8051RD2 signal pins from pin 1 through 40 are made available to the users from IO header CN5 from pin marked 1 through 40. The first 8 pins of CN5 are mapped to first 8 pins of 8051RD2. 16 hex keypad is interfaced to 8051RD2 as matrix of 4 scan signals and 4 return signals. Pressing a key switch push button generates a logic Low on the associated RD2 pin.

Fig 12 Hex Keypad Thus, 4 X 4 keyboard matrix, giving a total of 16 keys with each key representing a single hexadecimal value as shown in Fig 12. The 8051RD2 microcontroller program scans keyboard matrix to detect which key was pressed. After detection, corresponding hex code is displayed on the 4 character 7 segment display. P1.0 to P1.3 are assigned as output (key scan) and P1.4 to P1.7 are assigned as inputs (key returns). User program detects which key has been pressed while a lookup table defines the value of each key.

RS232C Serial Port

RS232 signals are used to implement the interface (RD and TD signals). RS transmit and receive signals appear on the male DB9 connector labeled SER-D9. The user provides RS232 UART code. A standard serial cable can be used to connect the 8051RD2 with the PC. A standard MAX232 RS232 is used to drive RX and TX signals. Fig 13 shows the connection between the Serial port and DB9connector, including the MAX232 RS-232 voltage converter. A jumper is placed between RX TX pin for an easy loopback test.

Fig 13 Connection using the DB9 connector.

Introduction to Development Environment

Software Used Execution of Embedded C program is done in two steps. First step is performed at the host machine. Here, a C program is compiled and built to generate a hex file, which is assembly code generated by a tool. Several compilers are available for compiling and linking program. Following are few examples –

 Crossware Tools for Embedded Development  μVision 5

1. Crossware Tool

Steps to be followed – Generation of hex file in crossware

  1. Boot the Crossware Embedded Development studio.
  2. IDE of the software looks as given in fig below –

Fig 15 Crossware C compiler IDE

  1. Cancel the demonstration project window and start with a new program. New opens the following dialog box.

Fig 16 new dialog box.

  1. Select an executable program. This will allow the user to select the target. Here, we need to select the target family as 8051, group NXP and family member as NXP89C51RD2, configured for normal operation as shown in fig below –

Fig 17 Target Selection

  1. Chose the directory to be used to store the file and give a suitable name to the project without any extension.

Fig 20 Program file format

  1. In the next dialog box, cancel creation of startup file. And select C as the programming language.

Fig 21 Final step in creation of project

  1. After creation of project IDE will look as follows –

Fig 22 Crossware IDE

10.Write the embedded c program in the main.c, which is open in the editor window. Save the file. Compile to create object file.

  1. To create the hex file, build the complied main.c file. This will create the required hex file. We can use the hex file to burn the flash memory of the microcontroller.
  2. To create a new crossware project, first close the existing project then open a new workspace. We can now create a new project or open existing one. Note that a project cannot be compiled or saved without having a workspace.

Simulation of the program

  1. Compile and build the file main.c. Chose the Simulate menu and a. Go to „Step Info‟ to see the result at every step, „Go‟ to directly see the output directly. b. „step to cursor‟ option can be used to see the results at a desired location. c. To see the register contents at every execution step, go to window – registers.

Project / workspace window

Editor window

Output Window