Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INTRODUCTION:
While assemblers/compilers allow you to assemble a given program, you must run the program on an actual microcontroller to test its operation. The assembler creates an executable file with the .hex extension. This hex file must be downloaded into a microcontroller. In older systems, the microcontroller had to first be taken out of the system board and placed into an eraser to erase its contents. After the contents were erased, a PROM burner was used to burn the hex file into the chip. With the advent of Flash memory in recent years, microcontrollers are equipped with a loader that enables a program to be downloaded into the chip without removing it from the system board. The DS89C450 chip used in the 8051 Trainer has a built-in serial bootloader that allows the hex file to be downloaded into the chip with the use of a x86 PC serial port. Windows HyperTerminal software is used to access the chips contents via the serial port of the x86 PC. The HyperTerminal enables you to both delete and program the chips contents. This lab shows the process of accessing the Flash contents of the 8051 Trainer chip, deleting the old contents, and downloading a new hex file into it. You will use a simple program such as toggling bits to verify the operation of the 8051 Trainer. This will ensure the port is operating properly before you connect the port to devices such as an LCD or a stepper motor. Note: Before connecting a microcontroller to any device, first run a toggle program to make sure the CPU and ports are working properly.
OBJECTIVES:
To examine the flag bits of the PSW To examine the stack To learn the operation of the MDE 8051 Trainer To download a program that tests the 8051 ports
REFERENCE:
Mazidi, Muhammed Ali, Janice Mazidi, and Rolin McKinlay. The 8051 Microcontroller and Embedded Systems. Upper Saddle River, NJ: Pearson Prentice Hall, 2006. o Chapters 2, 3, and 4
MATERIALS:
8051 Assembler 8051 Trainer 1
;A=67H, CY=0, AC=1, P=1 ;A=00H, CY=1, AC=1, P=0 ;A=1bH, CY=1, AC=0, P=0 ;No operation- helps with debugging
2. Use the simulator to single-step and examine the registers, paying close attention to the PSW registers. Start Debug and make sure the Main Registers window and Bit window are opened. View > Main Registers, Main > Data Dump > Bit View. Locate Bank D0; this is the PSW. The LSB is to the left, MSB to the right as follows:
P -OV RS0 RS1 F0 AC CY
Initially, the PSW should read 01 because the ACC contains an odd number of ones. D0 will appear as follows: 01 00 00 00 00 00 00 00 because the P bit is high. Review Figure 2-1.
Figure 2-1 3. Step through the program while carefully examining the PSW and D0 registers. 4. Click on each bit in D0 and examine the message at the bottom of the Bit window. Repeat this activity until you understand the relationship between the contents of ACC, PSW, and D0.
2. Make and debug the program. View the Main Registers and the Data windows. 3. Step through the program while carefully examining the values of R0 through R7, SP, 00, and 08. 4. This program initially loads four values into registers. The values are placed on the stack in a random order. 5. Then the stack is emptied and the values are placed in a different set of registers. 6. SP increments when data is pushed onto the stack and decrements when data is pulled from the stack. 7. Notice the order of the values is different.
Figure 2-2 1. Examine the Trainer (Figure 2-2) carefully. You should observe the following features: POWER LED5on the left and PRG LED6 program mode on the right PRG / RUN switch to select run or program mode RESET button Bank of eight DIP switches Bank of eight LEDs 5VDC jack Two 9-pin DIN ports labeled Serial 0 and Serial 1 Two 20-pin male/female combination of connectors labeled from left to right: J1, J3, J4, J2 Two 8-pin male/female combinations of connectors, one set connected to the DIP switches and the other to the LEDs Two 2-pin jumpers labeled S1-RXD and S2-TXD (These are for serial communication and will be covered later.) Maxim DS89C450 microprocessor, 74HC244 tri-state buffer (to drive the LEDs), and MAX232 serial interface along with an 11-MHz crystal and various components
DELAY: MOV LOOP3: MOV LOOP2: MOV LOOP1: NOP NOP NOP DJNZ DJNZ DJNZ RET END
4. The 8051 requires executable code to be in hexadecimal format. Make sure the hex option in the linker is checked. See the last page of Appendix I, Basic ProView Software Tutorial, in the textbook. After making the project executable (Project > Make F9), verify that a hex file is created and saved in the appropriate project folder. You should find multiple files: .asm, .lst, .src, .hex and others. 5. Establish a connection to the Trainer and download the hex file to the Trainer.
Lab 2 Worksheet
Name: _____________________________ Date: ____________Class: _____________
1. Find the value of the CY flag after the execution of the following code. (a) MOV A,#85H ADD A,#92H
(b)
(c)
(d)
3. Upon pushing data onto the stack, the SP register is _______________________. (decremented, incremented)
4. Upon popping data from the stack, the SP register is _______________________. (decremented, incremented)
5. Can you change the value of the SP register? If yes, explain why you would want to do that. ____________________________________________________________
10
Lab 2 Worksheet
8. Which I/O ports were tested in this lab?
9. Name the pins of P3, I/O Port 3, that are alternatively used for TxD and RxD.
10. Which I/O ports of the 8051 have internal pull-up resistors?
11. Which of the 8051 I/O ports require the connection of external pull-up resistors in order to be used for I/O?
12. Upon reset, all of the 8051 I/O ports are configured as _____________. (output, input)
11