Lab-Report Microprocessors

Similar documents
Microcontroller Intel [Instruction Set]

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

8051 Overview and Instruction Set

8051 Microcontroller

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Embedded Controller Programming

Digital Blocks Semiconductor IP

Programming of 8085 microprocessor and 8051 micro controller Study material

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

~: Simple Programs in 8051 assembly language :~

SN8F5000 Family Instruction Set

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

Instruction Set Of 8051

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Module Contents of the Module Hours COs

Dodatak. Skup instrukcija

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

DR bit RISC Microcontroller. Instructions set details ver 3.10


Contents. Join the Technical Community Today!

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

Microcontroller. Instruction set of 8051

Highlights. FP51 (FPGA based 1T 8051 core)

8051 Core Specification

Subroutines & Software Delay Routines

8051 Microcontroller Assembly Programming

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

Microcontroller and Applications

Introduction to uc & Embedded Systems

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Application Brief D-005

Question Bank Microprocessor and Microcontroller

1. Write A Program to move a block of data within the internal RAM

Assembly Language programming (3)

C51 Family. Architectural Overview of the C51 Family. Summary

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

Figure Programming model

Chapter Family Microcontrollers Instruction Set

MODEL ANSWER WINTER 17 EXAMINATION Subject Title: Microcontroller and applications

Report Title: Digital Voltmeter using 89C51

TUTORIAL Assembly Language programming (2)

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

Timers and interrupts

Dragonchip. Instruction Set Manual

Assembly Language programming (2)

Principle and Interface Techniques of Microcontroller

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

MCS -51 Programmer s Guide and Instruction Set

MODULE-1. Short Answer Questions

Principle and Interface Techniques of Microcontroller

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

S.J.P.N Trust's. Hirasugar Institute of Technology, Nidasoshi.

8051 I/O and 8051 Interrupts

D: arc SRC KUT51 KUT51LCD.LST KUT51LCD PAGE 1

AL8051S 8-BIT MICROCONTROLLER Application Notes

FACULTY OF ENGINEERING LAB SHEET

8051 Microcontroller

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

To Produce a Bidirectional, Speed Regulated Moving Message Display by Using the SAB80515/SAB80535's Timer 2 & 8-Bit Converter

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

UNIT MICROCONTROLLER AND ITS PROGRAMMING

ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

LCD AND KEYBOARD INTERFACING

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

8051 Microcontrollers

8051 Microcontrollers

Lecture 5. EEE3410 Microcontroller Applications Department of Electrical Engineering Assembly Language Programming (1)

80C451 operation of port 6

System & Program Developments of 8051

CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

build_char macro P1,P2,P3,P4,P5,P6,P7,P8 ;Macro for building a custom character

Y51 Microcontroller. Technical Manual

Chapter 09. Programming in Assembly

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

CPEG300 Embedded System Design. Lecture 6 Interrupt System

ENSC E-123: Final Exam: Digital Electronics. Spring 2014

;~~~~~~~~~~~~ ;P4-6-1.ASM ~ ;~~~~~~~~~~~~ SYMBOLS RS REG P2.0 EN REG P2.1 PICK REG P3.0 RELAY0 REG P3.1 RELAY1 REG P3.6 RELAY2 REG P3.

A Facilitated Learning Environment for Mentally Disabled Children

MICROPROCESSOR LABORATORY MANUAL

CPEG300 Embedded System Design. Lecture 8 Timer

Microcontroller and Embedded Systems:

The 8000 Series Swiss Army Knife Manual

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

Interrupt Programming: Interrupts vs. Polling Method:

EE6502- MICROPROCESSOR AND MICROCONTROLLER

EE 354 Sept. 2, 2016 A51 Sample Programs

Vector-based Pong on an Oscilloscope

Introduction To MCS-51

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Application Brief D-002

MicroConverter Technical Note - uc007 User Download (ULOAD) Mode

Transcription:

Lab-Report Microprocessors Digital Voltage Meter (DVM) NO YES Name: Dirk Becker Course: BEng 2 Group: A Student No.: 9801351 Date: 05/May/1999

1. Contents 1. CONTENTS... 2 2. INTRODUCTION... 3 3. THE PROJECT... 3 4. THE MAIN PROGRAM... 4 5. THE LAB... 5 A) MILESTONE 1 READ FROM ADC AND WRITE TO DAC... 5 i. Read from A/D converter... 5 ii. Write to D/A converter... 6 iii. AD and DA converter characteristics... 6 B) MILESTONE 2 500MS TIMING LOOP... 7 C) MILESTONE 3 SCALING TO 3 DIGIT ASCII... 9 D) MILESTONE 4 OUTPUT TO LC DISPLAY... 10 6. CONCLUSION... 11 7. APPENDIX... 12 E) THE COMPLETE CODE... 12 Page 2 of 15

2. Introduction Microelectronics is increasingly pervading all aspects of industry, education and the home. A leading example of microelectronic techniques is the microprocessor, and as its use increases the need for knowledge and understanding will also grow. The microprocessor lab was designed to give an overview over the programming of such a microprocessor system. Therefor a Digital Voltage Meter was to implement on the UELMON 51. 3. The Project With the UELMON system a digital voltmeter with the following specifications was to implement: Input Voltage Range: Display: Refresh Rate: 0..5 Volts 2½ digits 500ms +/- 1ms The project was divided into 5 different sections (Milestones). These sections were as follows: Section 1 Read data from AD converter and write it to DA for determination of dynamic range and I/P - O/P relationship of the DA and AD. Section 2 Implement a 500ms timing loop, for reducing the sample rate to s 2 (2 samples per second). Section 3 Convert the hexadecimal data from the AD converter to 3 ASCII digits. Section 4 Write the converted ASCII data to the LCD. Section 5 Refinements. Page 3 of 15

4. The Main program First an overall flowchart of the voltmeter program was developed. It puts the different task into a chronological order. First the applied voltage has to be converted to a digital value and written to the DAC. Then the hexadecimal ADC value has to be converted to a 3 digit ASCII, which can be written to the LC-Display. Then the program has to wait until the 500ms are finished. Therefore the timer has to be started before reading from the ADC. Figure 1 shows the resulting flowchart. Init / Start Get ADC Input lcall getadc Write to DAC lcall wrtdac Convert Hex ADC I/P to Decimal (Scaling) lcall convert Display Voltage on LC-Display lcall display Wait until timer has reached 500ms lcall waitfiv figure 1 - The main program (Overall flowchart) Page 4 of 15

5. The Lab a) Milestone 1 Read from ADC and write to DAC First section of the Lab was to implement a short program, which was able to read the content of the Analogue to Digital Converter and write it to the Digital to Analogue Converter. The I/P value was always printed on the screen via the pint8u function of the UELMON. Pint8u prints automatically the actual content of the Accumulator to the serial interface as a decimal number (0..255). Later the program was divided into the subroutines GETADC and WRTDAC, which are called from the main program. i. Read from A/D converter Subroutine GetADC Initialise AD- Converter MOV DPTR, #A_D MOV a, #0 MOVX @DPTR, a NO EOC? WAIT: JB P3.2, WAIT YES Load converted value to Accu MOVX a, @DPTR Return to main RET figure 2 - Subroutine GetADC Figure 2 shows the flowchart for the subroutine, which reads from the ADC and writes it to the Accumulator. The resulting code is shown on the right hand side of the flowchart. The A/D has to be started by writing a dummy value to it, and then the program wait until the conversion is done and writes the resulting value to the Accu. Page 5 of 15

ii. Write to D/A converter As a next part of the first section the read value of the A/D had to be written to the D/A converter and the characteristics of both were to be obtained. Subroutine WRTDAC Write Accu to DAC MOV DPTR, #D_A MOVX @DPTR, a Return to main RET figure 3 Subroutine Writ to DAC iii. AD and DA converter characteristics Input to ADC/V Screen Out (Dec - Output of DA/V 0..255) 0 0 0 0.1 1 0.01 0.3 16 0.16 1 52 0.52 2 104 1.04 3 156 1.56 4 207/208 2.07 4.90 254 2.54 4.91 254/255 2.55 4.92 255 2.55 From this table the characteristics of the ADC and DAC can be obtained: ADC: Resolution = Quantisation error = (4.90V 254dec. - 4.92V = 20mV) 255dec. max.voltage stepsize = 20mV Resolution 2 = 10mV Range : 0..4.92V Page 6 of 15

DAC: 0..255 (Range :0..2.55V) 2.55V 0..2.55V Resolution = 10mV 255 Res Q Err = = 5mV 2 b) Milestone 2 500ms timing loop For sampling the incoming voltage with a sampling rate of ½ second the program must provide a timer, which is started before reading from the ADC and halts the program, until 500ms are done and the next input value can be read. The 500ms timing loop consists of a) The ISR (Figure 4) and b) an external counter routine (Figure 5). The timer is started before the ADC starts to work and is preloaded with a defined value. If the timer overflows the 8051 generates an interrupt, which forces the program to continue at the address of the interrupt vector (UELMON=080b). With every overflow a second variable (n) is decremented and the timer again set to the defined value. When the helping counter n has reached 0, the program starts continuing at the beginning. ISR (Interrupt Service Routine) Set new Timer value mov th0, #prehigh mov tl0, #prelow Start timer again setb tr0 Decrement overflow counter (n) dec n Return to main RETI figure 4 - ISR Page 7 of 15

Subroutine Waitfiv NO Overfglow counter n=0? waitfiv: mov a, n cjne a, #0, waitfiv YES Return to main RET figure 5 - Overflow counter routine The overflow counter routine is called at the end of the main program in order to secure a proper timing. Calculation of the Timer preset-value: The Timer counts without preset from 0 up to 65535 and generates then an interrupt. For these 65535 counts the timer needs about 65ms, which means for a delay of 500ms the timer 500ms has to be restarted = 7. 69 times to provide 500ms delay. 65ms Also the timer can be restarted 8 times, but then it must be presetted by a value, to do the same timing (500ms). Therefore the timer has not to start with 0, because the timing loop would increase 500ms (8*65ms= 520ms). 7.6923 65536 Hence the counter only should count = 63015 turns. 8 Proof: 8 63.015ms = 504ms 8 62.5ms = 500ms TMR0 : 0..62500 counting but TMR0 counts up Hence 65536-62500=(3036) 10 (3036) 10 =$0BDC $0B=Highbyte and $DC=Lowbyte of TMR0 Page 8 of 15

c) Milestone 3 Scaling to 3 digit ASCII The LC-Display needs a 3 digit value in ASCII format to work correct. So the HEX value coming from the ADC must be converted (scaled) in an appropriate way. Subroutine CONVERT (Hex already in Accu) Calculate MSD by dividing accu 50 mov b, #50 div ab Convert to ASCII and store in R1 add a, #30 mov r1, a Calculate 1/10 Volts by dividing remainder by 5 mov a, b mov b, #5 div ab Convert to ASCII and store in R2 add a, #30 mov r2, a Calculate 1/100 Volts by multiplying remainder by 2 mov a, b rl a Convert to ASCII and store in R3 add a, #30 mov r3, a Return to main RET figure 6 Figure 6 shows the flowchart of the scaling procedure. The different digits are stored in the registers R1..R3. Page 9 of 15

d) Milestone 4 Output to LC Display The last part of the lab (Milestone 4) was to display the contents of the internal register R1..R3 of the 8051 in a Voltage meter appropriate form. The initialisation routine for the display was copied from the Lab-examples, because of the lack of documentation on the LCD. The LC-Display is controlled serial by port 3 of the 8255 and the LCD data are applied via port 2 of the 8355. To obtain a proper work of the display it has to be initialised in a special way (subroutine INITL). Subroutine Display Move cursor to mid position, line 2 mov a, #$C5 lcall lcset Display Volts mov a, r1 Display '.' (Dot) mov a, '.' Display 1/10 Volts mov a, r2 Display 1/100 Volts mov a, r3 Display 'V' for Volts mov a, 'V' Return to main RET figure 7 - Subroutine Display Page 10 of 15

Figure 7 shows the subroutine to display the stored data on the LC-Display. First the cursor is moved to a mid position in the second row via the LCSET function, and then the registers are output in the format #.##V, like on a usual DVM. 6. Conclusion The UELMON is a mighty tool to develop and test programs for the Intel 8051 processor. After assembling and simulating the code it can be direct downloaded and tested on the UELMON. With its implemented routines for accessing the serial port debugging and error searching is made very easy. It is very important to use a simulator for developing assembler code, because otherwise some errors can t be found. In a time, where microprocessors become more and more important and are in use in every day s life every engineer should be able to use them, because of their high flexibility. Dirk Becker, dirk.becker@gmx.de, www.oldradio.home.pages.de Page 11 of 15

7. Appendix e) The complete code ; Read ADC Input ; Write it to serial and DAC, with a sampling rate of 1/2 second ; and convert it to decimals ; ; Dirk Becker, 9801351, >= 1-MAR-1999 ; ;.EQU A_D,$E000 ; Set address of AD Converter.EQU D_A,$C000 ; Set address of DA Converter.EQU pint8u,$004d ; Set address of print ACC to serial.equ newline,$0048 ; Set address off serial CR/LF.equ prelow, $dc ; Preload TMR0 LowByte.equ prehigh, $0b ; Preload TME0 HighByte.equ n, $30 ; Overflow counter.equ p8255, $4000 ; Address of the Port-Interface 8255.org $8000 ljmp init.org $800b ; ISR Start vector isr: mov th0, #prehigh ; Presets TMR0 High mov tl0, #prelow ; and low byte setb tr0 ; Starts TMR0 again dec n ; Decrement helping counter i ; back and wait for next interrupt init: setb ea ; Enable interupts setb et0 ; with TMR0 overflow interrupt mov a, tmod ; ( TMR1 must anl a,#$f0 ; not be orl a,#$01 ; changed ) mov tmod, a ; and set to 16-Bit Counter mode lcall initl ; Call LCD - Init START: mov th0, #prehigh ; Presets TMR0 High mov tl0, #prelow ; and low byte setb tr0 ; Starts TMR0 mov n, #8 ; Set helping counter n to 8 lcall getadc ; Read ADC lcall wrtdac ; write it to DAC lcall convert ; convert it to ascii lcall display ; and print it on the LCD lcall waitfiv ; wait until 500ms are done LJMP start ; Goto Start forever Page 12 of 15

; ****************************************************************** ; * Subroutine GETADC * ; * Reads content from ADC and writes it to the accu * ; ****************************************************************** getadc: MOV DPTR, #A_D ; Set Datapointer to Adress of ADC MOV A, #0 ; Load #0 to Acc MOVX @DPTR, A ; load Acc to Address of ADC WAIT: JB P3.2, WAIT ; Wait until End of Conversion (Port3, Pin2) MOVX A, @DPTR ; Load Result to Acc ; LCALL pint8u ; Print content of ACC to serial ; LCALL newline ; Send CR/LF to serial ; ******************************************************************** ; * Subroutine WRTDAC * ; * Reads content from accu and writes it to the DAC * ; ******************************************************************** wrtdac: MOV DPTR, #D_A ; Set Datapointer to Address of DAC MOVX @DPTR, A ; Move Content of Acc to DAC for Output ; ******************************************************************** ; * Subroutine WAIT * ; * Waits until 500ms are done * ; ******************************************************************** waitfiv: mov a, n cjne a, #0, waitfiv ; are 500ms ; done? - go back ; ******************************************************************** ; * Subroutine Convert * ; * Converts the accu into decimals and stores the * ; * results int r1, r2 and r3 (MSB... LSB) * ; ******************************************************************** convert: mov b, #50 ; divide Accu div ab ; by 50 - Remainder to register B add a, #$30 ; convert accu to ASCII mov r1, a ; and store it to R1 --> Volts ;LCALL pint8u ; Print content of ACC to serial mov a, b ; divide remainder mov b, #5 ; by 5 div ab add a, #$30 ; convert accu to ASCII mov r2, a ; store it in R2 --> 1/10 Volts ;LCALL pint8u ; Print content of ACC to serial mov a, b rl a add a, #$30 mov r3, a ;LCALL pint8u ;lcall newline ; Multiply remainder ; by 2 --> 1/100 Volts ; convert accu to ASCII ; Print content of ACC to serial ; done? - go back Page 13 of 15

; ******************************************************************** ; * Subroutine Display * ; * Prints the content or R1.. R3 to the LCD * ; ******************************************************************** display: mov a, #$C5 lcall lcset mov a, r1 mov a,#'.' mov a, r2 mov a, r3 mov a,#'v' ;*********************************************** ; initialisation of LCD * ;*********************************************** initl: mov dptr,#p8255+3 mov a,#80h movx @dptr,a mov dptr,#setlcd init1: mov a,#0 movc a,@a+dptr CJNE A,#0,init2 init2: inc dptr lcall LCset ljmp init1 ;8255 setup register ;port C is o/p Page 14 of 15

;******************************************************************** ; LCD write routines. LCdisp sends the (ASCII) char contained in A. * ; LCset sends the command contained in A * ; Note - The DPTR is preserved * ;******************************************************************** lcdisp: LCset: sendit: setb p1.5 ajmp sendit clr p1.5 ;setup for data ;setup for command push dpl push dph mov dptr,#p8255+2 ;address of 8255 port c movx @dptr,a ;send data to 8255 clr p1.6 ;write enabled nop nop nop setb p1.7 ;clock the data nop nop nop acall delay clr p1.7 setb p1.6 acall delay pop dph ;restore dptr, Note: last in pop dpl ;is first out when using the stack delay: mov r0,#0ffh djnz r0,* ;*************************************************************** setlcd:.db $3C,$06,$0E,$01,$81,$81,$00.end Page 15 of 15