1)



LAB #1 - RAM Memory

EET 211 - K. Dudeck

1) Connect a seven segment (common cathode) display to a 74LS48 decoder/driver. Use the pin information for the display as shown on the attached drawing (page 2).

2) Test the display by simulating a BCD input to the driver.

3) This RAM has the capacity to store 16 4-bit binary numbers. The pulser on the counter increments the address of the RAM and displays that address on the four LEDs. The seven segment display shows the value at that memory location.

__

4) When the negative pulser, connected to the WE (write enable), goes low, the value of the four DIP switches is written to the memory location. Try writing your 11 digit student number into the first 11 memory locations on the RAM.

5) Try reading back your lab partner's student number.

6) (Design)-- Using principles learned in this lab, design a memory system which will store and display (32) 8-bit numbers. Draw a block diagram of your design and explain how it operates, do not build.

LAB 2 - Using the 8051 Simulator Program

EET 211 - K. Dudeck, Penn State Hazleton

The 8051 Simulator is written by Steve Nolan and is a nice way to develop 8051 programs off line. The simulator is freeware. The Simulator will only read programs that have been assembled and converted into an Intel Hex format file. This processes begins with writing the 8051 assembly program using a text editor and saving it as an *.ASM file. The assembler produces a *.OBJ binary file. Then a utility called an Object to Hex converter “OH”is run and the result is a *.HEX file that is burned into the ROM of the 8051. This process is shown below.

prog.asm ((Assembler) ( proj.obj ( (OH ultility) ( prog.hex

The 8051 assembler used here is called “AS31” and is a free 8051 assembler originally written by Ken Stauffer. Versions of AS31 found here include important bug fixes and

added features, such as standard intel-hex output format that can be used for the Nolan Simulator as well as for use with PAULMON2 and EPROM programmers. AS31 is a good tool for building small 8051-based projects that are written in 100% 8051 assembly language.

All the files needed to test this out are on the course webpage.

Procedure

1) Download the file sim8051.zip from the course homepage into a directory you wish to work in. Extract all the files therein.

2) Using Note Pad, view the assembly text file “test1.asm”

You should see a program like this:

.ORG 0H ; Assembler directive to load program at 0000H

MOV R5,#99H

MOV R7,#69H

MOV A,#10H

ADD A,R7

ADD A,#01H

HERE: SJMP HERE

.END ; Assembler directive marking program end

3) Minimize note pad, do not close it. Then go into the DOS prompt. Unfortunately,

DOS always places you into the C:\windows directory. Using the CD command,

get into the directory you placed these files into. You will see the “a31.exe” file

which is the assembler.

4) Assemble the TEST1 program by typing > a31-l test1.asm

This produces a “test1.hex” file. The simulator will run this.

The “-l” (the letter L option) produces a list file.

5) Return to windows by typing > exit

6) View the test1.lst file using Notepad. You will see the machine code produced by the assembler.

7) Using Windows explorer, run the sim8051 application.

Then Load the test1.hex into the simulator. It will confirm it loaded 11 bytes from the hex file.

8) Then hit the “view code listing” button to see the 11 bytes of machine code and the corresponding assembly program. Also hit the “View Processor registers” button. This program will adjust the contents of the registers.

9) Run the program by hitting the “Execute Loaded File” button. This program should load a 99H into R5, a 69H into R7, and after loading a 10H into the accumulator, it adds the contents of R5 plus another 01H yielding a final result of 7A residing in the accumulator.

10) The program runs indefinitely because of the SJMP 9 command, but hit the “Stop” button. This stops and resets the processor. All the register values clear.

11) Single step through the program by hitting the “Single Step” button. You can observe what happens to the registers one instruction at a time in this manner.

12) For you to do: Modify the TEST1.asm so that it places your age into R0, your most comfortable temperature into R1 and adds 20 to your age and places that result into the accumulator.

13) Assemble and run your program on the simulator.

LAB 3 – Intro to “Paul” 8051 Microcontroller Board

EET 211 - K. Dudeck

Introduction

In this lab we will become familiar the “Paul” Stoffregen’s 8051 Microcontroller Board. This 8051 development board provides an easy and low-cost way to develop projects based on the 8051 microcontroller, without the need to purchase any other equipment, such as EPROM programmers or emulators. It accomplishes this by coming equipped with a FLASH ROM containing a boot-up program called “PAULMON2”.

PAULMON2 is a user-friendly 8051 family monitor, intended for use in a single board computer like the development board used in this course.

By placing PAULMON2 in the board's EPROM, the board will "boot-up" to a friendly menu-driven monitor which allows you to download your programs to RAM and run them, which is much faster and easier than reprogramming the EPROM.

PAULMON2 also provides several features to help you debug your programs, including a de-assembler and single-step program execution.

It is very easy to use and together with an 8051 family assembler, such as the one above, it provides a very low-cost 8051 development system. PAULMON2 is in the public domain. You may use pieces of the code in your own programs and even

incorporate the code into your own commercial products, if you wish.

For more information on the board and software details, visit:



The memory map for the board is shown below.

Memory Map of Paul 8051 Microcontroller Board

0000H – 1FFFH 8K ROM with PAULMON2

permanently stored.

00H – FFH Internal RAM Amtel AT89C52 Chip

Port 0 –Port 3 Internal I/O Ports (port 1 direct)

2000H – 2FFFH 8K External RAM (user programs) 6264 Chip

4000H – 4003H Port Expansion 82C55 Chip

4000H -Port A

4001H – Port B

4002H – Port C (on board LED’s)

4003H –Port Program Byte

8000H – 81FFH 8K External Flash ROM SST39F512

The procedure for running a program on the 8051 board is as follows. First the assembly program is written using a text editor, such as “notepad”. The program is stored as a text file with a *.asm file extension. Then an 8051 assembler utility, such as as31.exe, is used to generate the machine code in the Intel hex-file format. The board is capable of downloading this hex file into its memory. Normally the program is downloaded into the board’s external RAM location, 2000H. The first couple of lines of the original assembly program contains a 64 byte “header” file. Two of the lines, shown below, cause the program to be downloaded beginning at RAM location 2000H.

.equ locat, 0x2000 ;Location for this program

.org locat

To cause it to be loaded into the flash memory, set the location between 0x8000 to 0xFF00 (the last two digits must be zero for PAULMON2 to recognize the header). To program the flash memory, download your program in the same way as loading it

into RAM, and PAULMON2 will automatically handle the flash programming as it receives the data. The portion of flash memory where you're downloading must be erased, otherwise the download will not work and you'll see errors reported.

Because the RAM doesn't need to be erased before it is written, it's easier to develop your code by downloading it into the RAM, and then setting it to the flash when it's working.

If you want to make the board run your program immediately upon power up of the board, as in a dedication system application, you must have the board bypass the running of the PAULMON2 startup program. This is accomplished by editing a line in the 64 byte assembly “header” file. The appropriate line is shown below:

.db 35,255,0,0 ;id (35=prog)

To do this, change the "35" to "249" in the header. More details can be found in

the PAULMON2 manual. Once you've done this, the board will boot up and run your program, stored in Flash ROM, instead of PAULMON2.

Once this program has been downloaded into memory, the PAULMON2 program will never again to be able to be run. You would never be able to download another program to board unless there were a way to erase the Flash ROM without using the PAULMON2 software.

To manually erase the flash ROM and get back to PAULMON2, short the "ERASE FLASH" jumper and press the reset button. The board will now boot-up to PAULMON2 as before.

Procedure

There is a very good detailed description of “Using the board for the first time” on Paul Stoffregen’s web page listed below.



1) Connect the serial cable from the COM1 port of the PC to the upper D connector

on the 8051 board.

2) Run the Hyperterminal application named “8051 Board”. This session has been already been created with the proper communication settings the for the 8051 board, as described in the web site.

3) Apply 12 - 15VDC power to the board. Hit Enter on the keyboard and the welcome message should appear.

4) Type a “?” to see a list of functions the Monitor Program has performs.

5) Try editing the External RAM using the “E” command. Once there, change the contents of memory locations (using control-E and control-X) 2000H to 200EH to the following:

2000: 45 45 54 20 32 31 31 20 69 73 20 66 75 6E 21 24

Notice how the corresponding ASCII are displayed. What is the text message

you just programmed?

6) Clear the Hyperterminal screen, turn off the power supply and hit the Enter.

Notice how the RAM contents are gone.

7) We will now download our first assembly program to the Board. This program is

called “Blink.asm” and it is an assembly text file. In order for this program to be

transferred to the board’s RAM, it must be assembled and converted into an Intel

hex file, named Blink.hex. To do this, we must run the DOS-based assembler

program, as31.exe . This assembler is available from the sim8051.zip file

downloaded from the course homepage.

8) Go into DOS and using the CD command, change the directory to the one that

contains the unzipped files that you downloaded. Then to assemble the blink

program type:

as31 blink.asm

Notice how a file called blink.hex is generated. This is the HEX text file that will

be sent to the 8051 board at RAM location 2000H.

Return to windows by typing exit

9) From the hyperteminal window, select Transfer –Send text file. You will need to

set the “all file type” option in notepad to list the blink.hex file. Send the

BLINK.HEX file to the board.

10) From PAULMON2 issue the “R” command. All programs written for

PAULMON2 contain a 64 byte header. In this header are the program names and

download locations. The “R” command recognizes that header and names. Run

the blink program. The LED’s will blink. To end the program, press ESC on the

keyboard.

11) Cycle the power on the board. Try to run the program again. You will notice that PAULMON2 states that there are no program headers found in memory.

12) We will next download the blink program directory into flash ROM. To do this,

edit the “blink.asm” and change the first line to read:

.equ locat, 0x8000 ;Location for this program

13) Save the changes to the assembly program and compile and download the new

version to the board by repeating steps 8 and 9. But before doing this you must

make sure that the FLASH ROM is erased. This is done by issuing the

PAULMON2 “Z” command.

14) Run the program again. Cycle the power on the board, and try to run the program

again. This time it is there.

15) There is a way to examine the assembly code of a program that is in RAM

or ROM. To view the code of this program, do the following PAULMON2

commands.

1) Edit external RAM “E”

2) Goto to Memory loactaion 8040 “^G 8040” (where our program begins

after the 64 (40H) byte header file).

3) You see only the machine code. Quit this “^Q”

4) Now notice PAULMON2 set to this location, 8040H.

5) Issue the program list command “L”

6) Notice the assembly and machine code.

7) Run the program again using the “R” command.

16) We will now modify the blink program so that it will be a self starting program.

This is mentioned in the introduction. First, we MUST erase the Flash ROM

using the “Z” command.

17) Edit the “blink.asm” file and locate the line :

.db 35,255,0,0 ;id (35=prog)

Change the “35” to “249”, and re-assemble and download to the board, as

described previously.

18) Cycle the power to the board, and notice the program runs automatically. Cycle

the power again. This board will forever more run the dedicated blink program.

19) In order to get PAULMON2 to run again in order to download any future

programs, the Flash ROM must be erased by shorting the “Erase Flash” jumper

located on the board, and pressing the reset button. The board boots up as before.

20) Edit the blink.asm so that it will be downloaded into RAM again by changing

back the location to 0x2000 and the program id back to 35.

You can also make the LED’s blink faster by changing the number of times the

delay loop runs from 250 to 100 in the following portion of the program.

delay:

mov r0, a

dly2: mov r1, #250

dly3: nop

You can also change LED pattern by editing the LED look up table. The 0’s indicate where the LED is ON. Change the values in the look up table so that only one LED is on at a time. The decimal number that follows is a second delay. Change all of them to 50. The first couple of line should look like:

table:

.db 01111111b, 50

.db 10111111b, 50

.db 11011111b, 50

.db 11101111b, 50

Finish with the rest of the data table.

Assemble, download and run this new modified blink program.

This is the end of this lab.

LAB 4 – Simple I/O Programming for the 8051 Microcontroller Board

EET 211 K. Dudeck

Introduction

In this lab we see how to we will be able to we will see how to read data from 8 switches into the 8051 and also be able to send a 8-bit binary number from the 8051 out to 8 LEDs.

The 8051 controller board makes use of an 8255 I/O chip. This chip is located all the on the right side of the board. The chip uses a technique called “Mapped Memory I/O.” This means that the I/O chip appears to the processor as simply a group of memory locations. Moving data to these memory locations causes the chip to send data out of one of its output ports, while moving data from these memory locations causes data to be read from one of chips input ports.

The 8255 I/O has four addressable ports. Three are actual ports, and one is a port programming register that is used to configure how each of the other ports acts, input or output. The following address show how these ports are assigned on the 8051 board.

|Port name |Address |Comments |

|Port_a |4000H |Input (Switches) |

|Port_b |4001H | |

|Port_c |4002H |Output (LED’s) |

|Port_abc_pgm |4003H |Port Program Register |

It is important to note that the each of the 8255 ports can be programmed as input or output ports, but the selections listed here reflect the actual hardware configuration on the 8051 microcontroller board. Additionally, Port C can be split programmed, half input half output.

The configuration for the Port Program register is as follows:

|I/O=1 |Mode |Mode |Port A |Port C h |Mode |Port B |Port C l |

|BSR=0 |= 0 |= 0 |In = 1 |Out = 0 |= 0 |Out = 0 |Out = 0 |

We must therefore send the value 1001000 or 90H to memory location 4003 before any attempt to read the switches or write to the LED’s is made.

The following code must be placed in the beginning of your assembly program to accomplish this:

.equ port_abc_pgm, 0x4003

mov dptr, #port_abc_pgm

mov a, #90H

movx @dptr, a ;Port A in, B and C out

In order to read the switches at Port A into the Accumulator, the following assembly code must be entered into your program:

.equ port_a, 0x4000

mov dptr, #port_a ;Read Port A

clr a

movc a, @a+dptr

In order to send to contents of the Accumulator to the LED’s on Port C, the following code must be entered into your program:

.equ port_c, 0x4002

mov dptr, #port_c ; Write to Port C

cpl a ; complement A because a 0 turns on a LED

movx @dptr,a

The entire program that will continuously read the value of the switches into the Accumulator and send that value to the LED’s is shown on the page.

Notice some key elements of this assembly program.

1) The program location where is will be downloaded is 2000H, the beginning of

RAM.

2) The 64 byte header file required by PAULMON2 is first defined, and the real program code will be located 64 bytes later, or at address 2040H.

3) This program also utilizes a subroutine called “esc” at ROM location 003EH in PAULMON2. When this subroutine is called, it goes out to the computer keyboard and checks to see is the escape key was pressed. If it was, the C flag is set, and our program will break out of the continuous loop and return to PAULMON2. This is a useful way to do break out of a continuous loop and return to PAULMON2. This can be done for any future programs we write for the 8051 board.

4) The program itself first configures the 8255 chip correctly by sending 90H to the

Port Program register. Then the loop is set up and the program first reads Port A

and then sends the value to Port C and repeats until the escape key is press on the

keyboard.

5) The accumulator must be complemented prior to sending the value to Port C because the LED’s are connected so that a “0” turns on the corresponding LED.

[pic]

Procedure

1) Using Notepad, enter the assembly program listed above and save it as “simio.asm”. There is a file called “Blank.asm” contained in the zip file that contains the basic structure for a PAULMON2 program. This is a good starting point for all your programs. Be sure to the save your modified program as another name and also change the listed program name in the 64 byte header file. You must save using the “ALL FILES” option.

2) Assemble the program using the “as31” assembler as demonstrated in the previous lab.

3) Download the “simio.hex” file to the board using Hyperterminal.

4) Run the program and see how it works.

5) *Program Challenge*

Write another program that will continuously (until escape is pressed) display the contents, as a binary number on the LED’s, of any of the first 256 RAM locations beginning with 2000H. This means that the highest address is 20FFH. Therefore, the high byte of the address will ALWAYS be 20H, and the low byte of the address will be 00-FF. The actual memory location that will be displayed on the LED’s will be 20xx, where xx is 8-bit byte obtained by reading the switch positions on Port A.

Address of memory location to be displayed :

DPTR = 2000H + (Port A)

The program you have written functions like the “E” command in PAULMON2, without actually running PAULMON2.

6) Assemble and run this program.

7) Verify that when all the switches on Port A are off, the LED display shows :

On Off On Off Off On Off On This value could have been anticipated, why?

Turn on the least significant switch, the one closest to the end of the board. The LED display should show:

On On On Off Off On Off On Again, why?

8) Modify this program so that is runs automatically when the board is powered up.

This is the end of this lab.

LAB 5 - Loops and Decision Making

EET 211 - K. Dudeck

Introduction

In this lab we will explore the use of conditional jumps, such as CJNE .

This instruction compares two bytes and jumps to a label if they are not equal.

For example, CJNE A, #43H, HERE

jumps to the label “HERE” if the accumulator is NOT equal to the value 43H. If the value is equal then the next program line is executed.

The concept of nested loops will be used to illustrate how to generate time delays.

Each 8051 instruction takes a number of machine cycles to operate. The time for one machine cycle to execute, tm, is related to the board’s crystal frequency, fxtal .

[pic]

For the Paul 8051 boards, the crystal frequency is 11.0592MHz, which has the machine cycle time, tm = 1.085μs.

To calculate the total delay time for a program or subroutine, simply add the number machine cycles for each instructor and multiply that total by 1.085μs.

The program below uses to nested loop to count down the inner loop 255 times, and repeat that process “num” times in the outer loop.

[pic]

The total number of machine cycles for this subroutine is calculated:

Delay time = (#machine cycles) · tm = (1025 · num + 11) · 1.085μs

For num=100, the delay time is 111.2ms, which is a little under 1/8th of a second.

Procedure:

1) Using the CJNE command, write a program that reads the switches at Port A and turns on the LED’s at Port C continuously until ALL the switches are on, then the program should end and return to PAULMON. This is a variation of a program already written in the previous lab. Assemble, download, and run this program.

2) Write a program that sends the number 00H to the LED’s and then the number 01H to the LED’s and repeats until the key is pressed. Analyzing the total number machine cycles in between the light ON then off. When this program is running, place an oscilloscope on the LED. See if you can experimentally verify the board’s crystal frequency. Show how you measured and calculated this.

3) Calculate the num value needed to make the delay subroutine to generate a delay of exactly ¼ of a second. Then add that subroutine so that the light blinks on for half a second and then off for half and repeats until the is pressed.

4) Write another program that causes the LED’s to be an 8-bit binary counter that counts up by one every quarter of a second until the value on the LED’s matches the pattern set on the switches.

5) Write a program that will produce a 1 kHz Square wave that comes of the least

significant bit of Port C. Using an Oscilloscope, see that it is working.

LAB 6 – Subroutines and Structured Programming

EET 211 - K. Dudeck

Introduction:

In this lab, we will learn how to use subroutines. A subroutine is a group of instructions that are written to be “called” at various points of a main program. A subroutine can be appended to the end of a main program, as the “delay” subroutine was in the previous lab, or accessed from code already written in ROM if the starting address is known.

The program below will print to the terminal two ASCII text strings. It uses two subroutines “pstr” and “newline”. These subroutines have already been written for you and exist in the PAULMON program. To use them, you simply need to know the ROM address that they begin at, how they work, and include a equate declaration at the top of your program with this information.

“pstr” is stored at ROM location 0038H and will print a string stored at the beginning address pointed to by the DPTR register. It will print each character, found in consecutive memory location to the terminal until it finds a ASCII value of 0 which is used to denote the end of the string. The subroutine will then terminate.

“newline” is stored at ROM location 0048H and will essentially send a carriage return and a line feed. This is the same thing that happens when you hit the ENTER key on your keyboard. Using this subroutine enables you print the second message on a newline.

Notice how the .equ statements contain the information for the assembler to link these subroutines into your program.

.equ locat, 0x2000 ;Location for this program

.equ esc, 0x003E ;paulmon2's check for esc key

.equ pstr,0x0038 ;prints a string pointed to by DPTR and ending with 0.

.equ newline,0x0048 ;prints a new line

;[Paul’s header file must be here]

do_msg: mov dptr, #mesg1

lcall pstr

lcall newline

mov dptr, #mesg2

lcall pstr

loop: lcall esc

jc exit

sjmp loop

exit: ret

mesg1: .db "EET 211 is a great course!",0

mesg2: .db "Ken Dudeck is the instructor.",0

Procedure:

1) Assemble, download, and run this program on the Microcontroller board.

2) Modify this program so that it first prints a message asking the person if he feels well today. The program should then get a character from the keyboard by using an existing subroutine in PALUMON called cin stored at ROM location 0032H.

If the person answers “Y” your program should then say “Great!”, if the person says anything else, your program should say “Too Bad!”.

Do not forget to include the equate declaration for the cin subroutine in the top of your program.

3) Assemble, download and run this program.

This is the end of this lab.

LAB 7 - Arithmetic and Logical Instructions

EET 211 - K. Dudeck

The following program, “get2bcd.asm”, reads a two digit decimal number from the keyboard and then sends that two-digit decimal number to a LED’s as two digit BCD number.

The program uses an appended subroutine, “getnum” that will read a ASCII character from the keyboard but ensure that it is a valid decimal number 0-9 (ASCII values 30H-39H). The subroutine will not terminate until one of those valid codes is received from the keyboard. The subroutine then converts the ASCII the corresponding BCD code by clearing the upper four bits of the code and returns the BCD number in the accumulator.

; “get2bcd.asm”

.equ locat, 0x2000 ;Location for this program

.equ cin,0x0032

.equ esc, 0x003E

[Paul’s Header File here]

startup:

mov dptr, #port_abc_pgm

mov a, #90H

movx @dptr, a ;Port A in, B and C out

begin: lcall getnum

swap a

mov r5,a

lcall getnum

orl a,r5

cpl a

mov dptr,#port_c

movx @dptr,a

lcall esc

jc exit

sjmp begin

exit: ret

getnum: lcall cin

cjne a,#2FH,cnt1

sjmp getnum

cnt1: jc getnum

cjne a,#3AH,cnt2

sjmp getnum

cnt2: jnc getnum

anl a,#0FH

ret

.end

Procedure

1) Enter, assemble, download, and Run this program to the Micro-controller board.

2) Write a program that requests the user to enter the number of seconds for a count down timer to count down from. Once that value is entered, the program counts down from that value and sends the value to LED’s as a BCD number. Once the number reaches zero, the program sends a “BANG!!” to the display and then ends.

3) Write a program that counts how many switches are closed at the Switches Port and continually lights the LED that corresponds to how many. For example, if no switches on LED #0 is on. If three switches are on LED#3 is on. When any more than six switches are on, the program terminates.

LAB #8- Analog to Digital Conversion

EET 211 -K. Dudeck

Microprocessors have the ability to interface to the external world via I/O ports. These I/O ports allow the microprocessor to read input bits (8 in the case of the 8085) from an external source (i.e. switches, sensor) into the microprocessor, or write the contents of a memory location out to an external destination (i.e. LEDs, control surfaces). In either case, the I/O information is DIGITAL, on/off.

Some applications require that the microprocessor deal with analog information. For example, reading the voltage off some circuit element which can range from 0 to 24V. In that case the voltage is not simply on or off, but rather a range of possibilities. An Analog to Digital Converter (ADC) is used to digitize the voltage level to an 8-bit binary

number that is proportional to the voltage. Another application may require the microprocessor to drive a voltage signal into a circuit ranging from 0 to 10V. A Digital to Analog Converter (DAC) is needed to accomplish this task.

In this lab you will use an ADC0809 to convert an analog signal from a function generator into an 8-bit binary number. You will also use a DAC08CP to convert an 8-bit binary number into an analog signal that will be displayed on the o-scope. Although in this lab you will not be interfacing the ADC and DAC directly to the microprocessor, future labs will illustrate how digital interfacing is accomplished, which when combined with the concepts learned here, make analog interfacing possible.

Equipment Needed Components Needed

(1) Function generator (1) ADC0809 ADC

(1) O-scope with probes (1) DAC08CP DAC

(1) TTL designer console (1) LM741 Op Amp

(1) +15 -15V power supply (1) 74LS163 4-bit Counter

PART I. Analog to Digital Conversion.

Study the circuit containing the ADC0809, Figure 1, which is found on the next page. Also review the data sheet for the ADC0809, found at the end of this lab write up on page 6. The ADC0809 has the potential of converting 8 different analog channels (pins IN 0 to IN 7) one at a time. The channel that is selected to be converted is determined by the three-bit address input (AD C, AD B, AD A -where AD A is least significant). Figure 1 shows the address selections all grounded and therefore IN 0 is selected.

The reference voltage establishes the lowest (VR-) and highest (VR+) voltages that the input voltage will be compared to. This voltage range is divided into 256 segments. The value that the input voltage nearest compares to will be placed on the data outputs, D7->D0 (or 2-1 -> 2-8).

Figure 1 shows the VR- connected to ground, and the VR+ connected to 5V. This means that 0V will be represented as $00 while 5V is represented as $FF on the data outputs. The resolution of this eight bit ADC is:

Resolution = (VR+ - VR-)/256 = (5-0)/256 = 19.5mV .

If the output is $2C, what's the input voltage?

solution: $2C = 2 x 16 +12 = 4410 (Convert to Decimal)

Vin = Output x Resolution = 44 x 0.0195 = 0.858 V

In order for the ADC to operate, the OE must be high, and the ALE and START must pulsed to start a conversion.

Figure 1 - Analog to Digital Conversion

Procedure:

1) Connect the circuit of figure 1. Connect the four most significant data outputs, D4 -> D7 to the four LEDs. Verify that grounding the IN 0 produces a $0 output, and connecting IN 0 to 5V produces a $F output. The pulser switch must be pulsed to take a new reading.

2) Using the o-scope, set the function generator to a 1Hz sine wave with 5V peak to peak output and a 2.5V DC offset. Connect this signal to the IN 0 pin. While observing the o-scope, sample the voltage at various times along the sine wave.

3) To achieve continuous sampling, disconnect the pulser switch and connect the EOC (End of Convert) output to the START and ALE inputs.

PART II. Digital to Analog Conversion.

Study the circuit shown in Figure 2. This circuit uses a DAC08CP Digital to Analog converter chip. The chip takes an 8-bit binary input (B8 -> B1) and converts it to an analog voltage that is in the range of VREF- to VREF+ (in this case, 0 -> +15V). The chip requires the standard power of 5V and GND and additionally a negative supply rail of approximately -15V. In order for the DAC to supply an external analog voltage, it is common practice to use an operational amplifier, such as a LM741 or equivalent, to buffer the DAC output. This is shown in Figure 2. The circuit in Figure 2 will convert any 8-bit binary number to an analog voltage ranging from 0 -> +15V.

Pin diagrams for the DAC08CP and the LM741 are found at the end of this lab, on page 6.

Figure 2 - Digital to Analog Conversion

[pic]

Procedure

1) Connect the circuit shown in figure 2. Use a 74LS163 counter to drive the four most significant input bits of the DAC. Set the clock input to 10kHz square wave. Connect the output of the LM741 to the o-scope and observe a digitally generated saw-tooth wave. If you expand the time base of the o-scope you will notice that the saw-tooth wave is generated in 16 distinct steps that correspond to the 16 count states of the counter. The voltage steps (resolution) should be approximately 0.93V (15V/16) apart. Sketch carefully what you see taking note to the o-scope sensitivity settings.

2) Measure the frequency of the saw-tooth wave. It should be 1/16th of the clock frequency.

3) See if you can make the waveform smoother by designing an 8-bit counter to drive all 8 data inputs of the DAC, and thus generate 256 steps in the saw-tooth wave. An 8-bit counter can be designed by using the RCO (ripple carry output) of the least significant 4-bit counter into the clock input of the most significant 4-bit counter.

-----------------------

.equ locat, 0x2000 ;Location for this program

;82C55 memory locations

.equ port_a, 0x4000

.equ port_b, 0x4001

.equ port_c, 0x4002

.equ port_abc_pgm, 0x4003

.equ esc, 0x003E ;paulmon2's check for esc key

.org locat

.db 0xA5,0xE5,0xE0,0xA5 ;signiture bytes

.db 35,255,0,0 ;id (35=prog)

.db 0,0,0,0 ;prompt code vector

.db 0,0,0,0 ;reserved

.db 0,0,0,0 ;reserved

.db 0,0,0,0 ;reserved

.db 0,0,0,0 ;user defined

.db 255,255,255,255 ;length and checksum (255=unused)

.db "Simple I/O",0 ;max 31 characters, plus the zero

,-©

ª

¬

­

ý

*

+

F

G

`

d

e

Œ

ç

ë

ö

÷

-(¬­ÚÛL\

üõïàÔàÔàÔàïÄïÄïÄïÀüÀ¹À³¥š¥š¥š¥š³Ž„Ž„z³q³qhö¬6?CJ]?hö¬OJQJ^J[?]hö¬OJQJ^J[?].org locat+64 ;executable code begins here

startup:

mov dptr, #port_abc_pgm

mov a, #90H

movx @dptr, a ;Port A in, B and C out

loop:

lcall esc ;Checks for escape key

jc exit

mov dptr, #port_a ;Read Port A

clr a

movc a, @a+dptr

mov dptr, #port_c ; Write to Port C

cpl a

movx @dptr,a

sjmp loop

exit: ret

.equ num,100

delay: push 4

push 5

mov r4,#num

outer: nop

mov r5,#255

inner: nop

djnz r5,inner

djnz r4,outer

pop 5

pop 4

ret

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download