This action might not be possible to undo. Are you sure you want to continue?
Eng Electronic Engineering Yr 2 / Qualifiers ³Embedded Hardware´ Module Lecture 14
Presented by Mr. Fergal Henry I.T, Sligo Monday 24th January 2011
8051 Microcontroller Data Memory Map .
8051 Microcontroller Instruction Set .1 .
2 .8051 Microcontroller Instruction Set .
30h add a. The second number is stored at general-purpose RAM address 31h.31h mov 32h. The first number is stored at general-purpose RAM address 30h.a end .First 8051 Assembly Program Let¶s write an assembly program to add two numbers together & generate a result (sum). The result is to be stored at address 32h. The program is as follows: org 0 mov a.
The third & final instruction mov 32h.a copies the sum from the accumulator & pastes it into RAM address 32h. The assembler converts each instruction into an opcode. The assembler directive org 0 places the first opcode in the program at address 0000h in code memory. The first instruction mov a.30h copies (reads) the number from RAM address 30h & pastes (writes) it into the accumulator. The second instruction add a. Assembly programs terminate with end.Assembly Program Explained We will use the EdSim51 Simulator (developed by Jim Rogers) to assemble this program. .31h adds the number at address 31h to the number in the accumulator & places the result (sum) in the accumulator.
Code Memory in EdSim51 A screenshot of code memory is illustrated below. Questions: (i) What are the opcodes for each of the three instructions? (ii) How many bytes of code memory are added to each opcode for addresses? (iii) What are the respective addresses for each opcode? .
.Data Memory in EdSim51 A screenshot of data memory is illustrated below. Address 32h is updated with the result of the addition (01h + 02h = 03h) after the program is stepped through. In this example. By default. The final value in the accumulator can be viewed in binary & hex formats opposite. code memory addresses contain 00h. I have manually modified memory addresses 30h & 31h to contain the data 01h & 02h respectively.
0 when a switch SW0 is open? Q.p2 jmp start end .Echo Switches to LEDs Let¶s write a program to read the status of the switches & echo them to the LEDs.3 What port are the cathodes of the LEDs LED0 ± LED7 wired to? Q.2 What logic level is on a P2.4 What logic level on P1.1 What port are the switches SW0 ± SW7 wired to? Q.0 turns LED0 on? org 0 start: mov p1. Q.
P1 & P2 are the special function registers which keep track of the logic levels on the port pins. We will use jmp & let the assembler decide which is the appropriate one to use.asm Discussed There are 3 types of jump instruction (AJMP. The jump instruction in this program creates an infinite loop. . The binary pattern is first read from P2 & is then written to P1. LJMP & SJMP) where the range for jumping code memory addresses is medium. long & short respectively. We use a data transfer instruction where P2 is the source & P1 is the destination. which allows us to constantly read the switches to see if any change has occurred.echo. Hence the status of the switches is echoed to the LEDs.
the motor stops.c jmp start end .1 mov p3. The inputs to the driver. The motor runs clockwise / anti-clockwise if the voltage on these 2 pins are different.0 respectively. are connected to P3.1 & P3.p2.0 mov p3. A & B.p2.DC Motor Control The DC motor is interfaced to the 8051 via a bridge driver. org 0 start: mov c. If the voltage is the same on both pins.0.c mov c.1.
.motor. All reading & writing of bits is done through the carry flag. which is bit 7 (MSB) in the Program Status Word special function register. The instructions used here are in the Boolean Variable Manipulation category as we need to access bits rather than bytes. The status of SW0 is read into the carry flag & then written from the carry flag to the B input of the driver. The status of SW1 is read into the carry flag & then written from the carry flag to the A input of the driver. An infinite loop is used again here as the switches will have to be monitored in case they change.asm Discussed We will control the motor using switches SW0 & SW1.
Testing the Motor Program Set the Update Freq to 1. When neither switch 0 or 1 is pressed. the motor runs clockwise. When switch 0 is pressed only. the motor stops. the motor runs anti-clockwise. Ensure that the motor is enabled. Run the program rather than stepping it. When both switches are pressed. Adjust the slider for the motor to MAX. . Switch off the key/switch bounce i.e. When switch 1 is pressed only. This runs the simulator at its slowest speed. leave it un-checked. the motor is off.
A1 & A0 are the inputs of the decoder & are connected to P3.4 & P3. This is controlled using the 2-to-4 line decoder.3 respectively. The decoder works as follows: A1 A0 Q3 Q2 Q1 Q0 Display Activated 0 0 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 DISP 0 DISP 1 DISP 2 DISP 3 .Controlling the Seven Segment Displays (SSDs) Only one of the SSDs is turned on at any given time.
The displays are common anode. c. f. b.Displaying Digits on the SSDs There are 8 LEDs on each SSD. When a display is activated. d. g & dp. 5V is applied to the common anode of a display. The are labelled a. e. A LOW (0) on a cathode will light a particular segment while a HIGH (1) will turn it off. Question: What binary number is written to P1 to display the number 5 with decimal point turned off? . This means that all 8 anodes are tied together. The 8 cathodes are connected to P1 as shown below.
b specifies a binary number as opposed to h for hexadecimal. # differentiates a number from an address. org 0 start: setb p3. SSD code for 3. We will use the Boolean Variable Manipulation instructions for setting & clearing bits.4 clr p3.asm We will write a program to display the number 3 on DISP 2 with the decimal point off.#10110000b. A semicolon precedes a comment. end .3 mov p1. Ensure that the SSD is enabled rather than the LCD module.SSD.