Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Practical - 1 DAC CODE

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

MCOEP

Experiment -
Aim –
Assembly language Programming using 8051.
Apparatus –
8051 microcontroller kit by Dyna.
Theory –
DYNA-51 is designed to be an ideal introduction to rapidly expanding field of
Microcontrollers. It is an excellent tool for learning 8051 Micro controller and also for
development of 8051 based systems. The kit has LCD module interface and ASCII
keyboard interface. DYNA-51 has two modes of operation
1. Local mode
2. Remote Mode

POWER SUPPLY
The kit is used with the Dyna log's SMPS 03A Model Power Supply. The 6 pin
female connector can be plugged in 6 pin male connector soldered on-board.
The power requirement of Dyna-51 board is:
+5 V 3 Amps
+12 V 1 A
-12 V 0.5 A

CN2 and CN4 for 8255 I/O interface -


Two 26 pin FRC male connectors are provided on board for 8255's I/O Interface.
Connector can be used for interfacing DYNA-PIO cards. Centroids printer can be
interfaced through this connector.

Installation procedure -
1. First connect Power Supply (SMPS-03A) cable (6-pin female connector) to the
system supply connector (CN3) with proper orientation.
2. For Serial mode connect the serial cable to 9-pin DTM connector.
3. Switch on the Power Supply. LCD display will show
4. Press ‘S’ key for Remote (Serial) Mode or ‘CR’ for Local Mode.

P1 for system signals bus -


A 50 pin FRC male connector provided is for Bus expansion. All the address Data and
control lines along with interrupt lines are terminated on this connector. The same
connector is used to interface DYNA-51 with DYNA Study cards.

Memory map -
The memory map of DYNA-51 is shown in the following table:

00000-07FFF 32KB PROGRAM MEMORY EPROM 27256 contains firmware


8000-93FF Reserved
9400-FFFF PROG/DATA RAM

203149 - FMM
MCOEP

System I/O map -


The I/O devices are addressed using lower Data Memory space. The data memory
map for different chips is given below:

8255 (#1) PPI


BASE = 100H
BASE + 0 100H PORT A
BASE + 1 101H PORT B
BASE + 2 102H PORT C
BASE + 3 103H Control Word Register

Command set for DYNA_51:

D Display Memory
Syntax: D start end <CR>
D start Selected area of addressable memory may be accessed and displayed by the D
command. The D command produces a formatted listing of the memory contents
between start (starting address) and end (end address) inclusive on the display. Each
line of the listing begins with the address of the first memory location displayed on
that line, represented as 4 hexadecimal digits followed by contents of 8 memory
locations, each one represented by 2hexadecimal digits.

EX. D 1000 1020 <CR>


1000: 75 F0 0A E5 1B A4 25 1C

E Edit Memory
Syntax: E strt<CR>
The E command allows you to examine and modify memory locations individually.

EX. E 9400 <CR>


9400: 02.04 22.08

A Assemble Command
Syntax: A strt address <CR>
The A command accepts assembly language statements and assembles each statement
into executable machine code. These assembled machine codes are stored in a
specified memory on line-by-line basis at the time of entry.

EX. A 9400 <CR>


9400: MOV A,#04H <CR>
9402: INC A <CR>
9403: MOV R1,A<CR>
9404: <CR>

203149 - FMM
MCOEP

Disassemble Command
Syntax: U start end <CR>
The U command followed by the address disassembles the program from the specified
location. The U command translates machine instruction into assembly language
mnemonics.

EX. U 9400 9406 <CR>


9400: 7407 MOV A,#04h
9402: 04 INC A
9403: 02900A MOV R1, A

GO Run Program
Syntax: GO Addr<CR>
The GO command is used to execute user program from the address stated in this
command. To illustrate the operation of [GO] command the sample program is given
below.

C000: MOV A,#02h


C002: MOV R0,#02h
C004: ADDA, R0
C005: MOV DPTR, # C050H
C008: MOVX @ DPTR, A
C009: LJMP 6000H ; control is transferred to sign on prompt

R REGISTER DISPLAY

Syntax: R<CR>
This command is used to examine the contents of ACC, PSW, SP, DPTR, PC and
registers R0 to R7.

EX. R <CR>
R0- R7 : 02 04 05 06 07 09 01 00
Dyna-51 Local Mode
Dyna log 4-16

1. Press 'SPACE BAR' to toggle display.


Rno. EDIT REGISTER
Syntax: Rno.= DATA<CR>
This command is used to modify the contents of register R0 to R7, ACC, SP, PSW,
DPTR, PC individually.
EX. 1. R0=12<CR>
2. R4=09<CR>
3. PSW=40<CR>
4. DPTR=D000<CR>
5. PC=C009<CR>

203149 - FMM
MCOEP

Program –
1) Addition of two 8bit numbers
Two numbers at D200h and D201h
Result is at D400h

PC OPCODE LABEL INSTRUCTIONS REMARK

2) Addition of two 16bit numbers


Two numbers are at D300h and D302h,
Result is at D500h

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM
MCOEP

3) Addition of ten 8bit numbers


Data is at D500h onwards.
Result is at D600h

PC OPCODE LABEL INSTRUCTIONS REMARK

4) Find smallest number from given data


Data is at D600h onwards.
Result is at D60Ah.

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM
MCOEP

5) Arrange numbers in the descending order


Data is at D700h onwards.
Result is at D700h.

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM
MCOEP

Experiment -
Aim –
Control of stepper motor using 8051.
Apparatus –
8051 microcontroller kit by Dyna, PIO stepper motor card, CN4 cable, DB-9
connector, stepper motor.
Theory –
The stepper motor controller card has 12 pins connector out of which 1, 2, 3 are
connected to power supply (+12, +5, GND) respectively which is obtained from the
serial port connector which is at back of microcontroller kit. The pins 4,5,6,7 and 8
are PA1, PA2, PA3, PA4 and GND are connected to 8255 using CN4 connector.
While pins 9, 10, 11 and 12 are connected to motor windings B1, A1, B2, A2.
The connection block diagram is shown in figure

The pin connector arrangement for the CN4 connector is as follows


T3 connector 8255 signal 8255 pin T3 connector 8255 signal 8255 pin
pin number pin number
1 PA3 1 14 PC0 14
2 PA2 2 15 PC1 15
3 PA1 3 16 PC2 16
4 PA0 4 17 PC3 17
5 +5V 26 18 PB0 18
6 PA7 37 19 PB1 19
7 PA6 38 20 PB2 20
8 PA5 39 21 PB3 21
9 PA4 40 22 PB4 22
10 PC7 10 23 PB5 23
11 PC6 11 24 PB6 24
12 PC5 12 25 PB7 25
13 PC4 13 26 GND 7

203149 - FMM
MCOEP

The address of different ports of 8255 on CN4 connector are given in following
diagram

T
h
e

s
t
e
p
p
e
r motor is a 12V D.C motor with a current rating of 5A per phase. The step angle is
1.8 degree. The stepper motor has a winding which is shown below

Each phase winding is split into two equal section A1, A2 and B1, B2. The two
windings are differentially wound as shown in figure by polarity dots. The
significance of this is that a +ve current flowing through A1. This type of winding is
called bifilar winding. Thus with bifilar winding a unipolar supply with 4 on-off
switches as is sufficient.

203149 - FMM
MCOEP

The below switching sequence/logic will move the staff in one direction. To change
the direction the direction of sequence, execute the sequence form upwards. The
stepping action is caused by sequential switching supply to the two phases of the
motor as explained in the switching sequence table.
Position SW1 SW2 PH-1 PH-2 CODE
P3 P2 P1 P0
A 2 4 0 1 0 1 05H
B 1 4 1 0 0 1 09H
C 1 3 1 0 1 0 0AH
D 2 3 0 1 1 0 06H

Program –
Write program to rotate motor continuously in clockwise direction

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM
MCOEP

203149 - FMM
MCOEP

Experiment -
Aim –
Interfacing of 8 bit A/D converter with 8051.
Apparatus –
8051 microcontroller kit by Dyna, PIO ADC card, CN4 cable, DB-9 connector.
Theory –
The DMS-ADC-01 Analog to Digital Converter card interfaces with the DYNA-51 or
any other DMS Microprocessor kits. It is used to develop digital signal processing and
real time process control applications.
DMS-ADC-01 card incorporates monolithic CMOS 8 bit successive approximation
analog to digital converter ADC-0809. This converter features a high impedance
chopper stabilized comparator, its resolution is 8 bits and conversion time is
100microseconds. It has a programmable clock oscillator that generates 100 KHz
clock signal. The reference voltage for the ADC is 5.12 V and is generated by
dividing 6.8 V Zener voltage .The instructions are written considering DYNA-51
Microcontroller kit. In case this card is interfaced to any kit, then care has to be taken
regarding the port an RAM addresses of the kit.
V REF +

CLOCK

START
GND

EOC
VCC

IN 7
IN 6

IN 5

IN 4
IN 3
OE

D3
D1

14 13 12 11 10 9 8 7 6 5 4 3 2 1

15 16 17 18 19 20 21 22 23 24 25 26 27 28
IN 0
IN 1
IN 2
V REF -

ALE
D2

D0

D4

D5

D6

D7

A
B
C

PIN DIAGRAM OF IC 0809

General Procedure -
1: Before switching ON the power supply, check the direction of the 26 pin flat
connector cable connector at both ends. All the supply connections+5 V, +12 V and -
12V must be applied simultaneously the ADC -01A card. ADC 0809 chip will get
damaged if +5V is absent +/ -12V supply is applied.
2: Defined 8255 PIO in mode00, Port A as input port, Port B as output port and Port
C as input port. Do not define the 8255 in any other mode except as mentioned above,
to avoid damage to the 8255 IC.
3: The maximum positive analog input voltage to be applied to the ADC-01A is less
than or equal to 5.120V dc (+ or -) or 3.5 V RMS ac (frequency less than 60 hertz).

203149 - FMM
MCOEP

4: The reference voltage on the ADC -01A is factory calibrated at 5.12V and do not
change this setting, because if excessive voltage is applied, ADC-0809 may get
damaged.

Block diagram description:


Since only one channel is used of the analog multiplexer, the channel select address of
ADC-0809 are not interfaced with the 8255 IC. The 8255 are defined in mode O
(Simple I/O). Port A is used for reading the ADC data, is defined in output mode and
Port C is used to read the status and it is defined in input mode.
When analog voltage AC/DC is applied at input, oscillator is enabled (bit PB2 of
8255 is set to logic 1), and then the start conversion pulse of short duration is applied
from pin PBO. OE pin is kept low during this goes high. After the conversion is over
the EOC pin goes high. The status of this pin is polled through bit PCO or PC7 of Port
C. After conversion is over, clock oscillator is disabled and data output pins of ADC
0809 are read through Port A of 8085.
With 5.12 V at full scale reference, for 5.12 V the minimum voltage step is 5120
mV/256=20 mV. Thus using a precision reference, voltages can be applied from 20
mV to 5.12V in various steps. The user can also study the linearity, repeat accuracy
and accuracy of the A/D converter and its stability for low voltages.

203149 - FMM
MCOEP

Program –
PC OPCODE LABEL INSTRUCTIONS REMARK
C100 900103 MOV DPTR,#0103H
C103 7489 MOV A,#89H
C105 F0 MOVX @DPTR,A
C106 900101 MOV DPTR,#0101H
C109 7401 MOV A,#01H
C10B F0 MOVX @DPTR,A
C10C 900100 L3 MOV DPTR,#0100H
C10F 7400 MOV A,#00H
C111 F0 L1 MOVX @DPTR,A
C112 04 INC A
C113 B4FFFB CJNE A,#FFH,L1
C116 900100 L2 MOV DPTR,#0100H
C119 14 DEC A
C11A F0 MOVX @DPTR,A
C11B B400F8 CJNE A,#00H,L2
C11E 80EC SJMP L3

203149 - FMM
MCOEP

Experiment -
Aim –
Interfacing of 8 bit D/A converter with 8051.
Apparatus –
8051 microcontroller kit by Dyna, PIO DAC card, CN4 cable, DB-9 connector.
Theory –
The DMS-DAC -01A Digital to Analog Convertor interfaces with the DYNA -51
Microcontroller kit or any other Microcontroller and Microprocessor kits. It is used to
implement analog and digital signal processing and real time process control
application on DAC-01A interface card.
DAC-01A is designed around DAC-0800 monolithic 8bit high speed current output
digital converter featuring 100 n seconds settling time (typical). DAC-01A has
adjustable voltage reference which permits full scale voltage. The Vref to full scale
current matching of better than +/- 1 LSB gives +/- full scale error.
Precision OP-AMP based current to voltage converter has 20 mA output load driving
capacity. Analog input is polarity protected and buffered and has 10 ohms input
impedance. Analog comparator has medium switching speeds (in milliseconds)and
its outputs converted to TTL level and latched to avoid oscillating comparator status
reading which occurs when 2 analog inputs of the comparator are nearly equal .
The PCB track design is shielded to keep low noise level in the analog paths and this
card gives stable readings of the analog input. The DAC-01 card is also protected for
reverse supply polarity. The instructions are written considering DYNA-51 kit. If this
card is interfaced to any other kit, then care has to be taken regarding the port and
RAM addresses of the kit.
General Procedure -
1: Before switching ON the power supply, check the direction of the 26 pin flat cable
connector at both ends. All supply connections +5V, +12V and -12Vmust be applied
simultaneously to the DAC -01A cart. DAC 0800 and 8255 chips will get damaged if
only +5Vis applied to the cart.
2: Defined Port A of 8255 in the output mode (as a data output port).Port B is also in
the output mode for applying control signals to the DAC and define Port C as input
mode to read the status of DAC. Do not define the 8255 in other mode except as
mentioned above, to avoid damage to the 8255 IC
3: The DAC analog voltage at output socket supplies for 20 mA load (maximum), no
attempt should be made to draw more current from this output.
4: The maximum + analog input voltage to be applied to the analog voltage input
socket are less than or equal to +6V.

203149 - FMM
MCOEP

Description -
DMS-DAC-01A Interface card is designed around the DAC 0800 monolithic 8 bit
high speed current output digital to analog convertor and it is plugged into 8255 chip
through a 26 pin flat cable connector on the DYNA-51 kit. Ports A and B of the 8255
are defined in the output mode and Port C in the input mode. The 8 bit data input for
DAC 0800 is written into the Port A output register by the CPU. This data is latched
into LS373 by applying a software generated positive going latching pulse through bit
PBO of Port B (used to control port) of 8255. A logic high state at bit PBO keeps the
latch in LS373 in flow through condition. When the RESET key of DYNA-51 is
pressed, the address and data buses of the system as well as the 8255 ports go into
tristate condition, and logic 1's by LS373 remains in flow through condition and DAC
gets FF Hex as input data and gives fullscale output.
Port C of the 8255 is used as an input status port and it must not be defined in the
output mode when the DAC-01A card is connected to DYNA51. The DAC 0800
gives complementary sinking current outputs IO and IO* proportional to the digital
data input and reference voltage. The full scale output currents IFS for all logic states
is given by:
IFS = IO + IO* = (VRFF/RREF) x (255/256)
DAC0800 will give full scale output current.
NOTE: *indicated active low signal.
IFS = IO = = (VRFF/RREF) x (255/256)
Precision metal film resistors with high temperature stability are provided for positive
and negative references and the reference voltage is variable (adjusted by pot)
between 0 to +VCC and are buffered. The output current IO of DAC 0800 is converted
into voltage Vo by precision OPAMP based current to voltage converter as shown
below

The current drawn by the inverting and non-inverting terminal of Op-amp is very
small and the current IO sink by DAC 0800 develops a voltage Vo = -IO -RF at the
output of the Op-amp.

203149 - FMM
MCOEP

The output current IO of the DAC 0800 is given by


IO = VRFF/RREF (DO/2 + D1/4 + D2/8 + ….. + D7/256)
DN = 1 if Nth data bit is at high state, DN = 0 if Nth data bit is at low state
N = 0 to 7 because DAC is 8 bit
Since IO is sinking current, it is negative so that DAC output voltage is given by:
Vo = VREF x RF/RREF (DO/2 + D1/4 + D2/8 + ….. + D7/256)
Since IFS is known (from VRFF), the value of RREF can be calculated.
RREF = VFS (desired full scale output voltage)
IFS (the full scale output current)
Therefore RREF = VFS / IO
The DAC voltage output is connected to the non-inverting pin of the analog input
coming from the input socket it is polarity protected, buffered unity gain follower to
provide high input impedance (greater than 10 M-ohm). Of the existing hardware only
+ve input voltage less than 10 V can be applied at the analog input the buffered
analog input is fed to non-inverting terminal of an Op-amp and it is compared with
the DAC voltage. The comparator output is made TTL compatible by using a register
5 V zener. The comparator gives oscillating or intermediate level output when it’s to
analog input are exactly equal.
Program –

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM
MCOEP

Experiment -
Aim –
Interfacing of LCD with 8051.
Apparatus –
8051 microcontroller kit by Dyna, 16by2 LCD display.
Theory –
LCD display is used to display the messages for more interactive way to operate the
system or displaying error messages etc. interfacing LCD to microcontroller is very
easy if you understanding the working of LCD. In recent years, the LCD is finding
widespread use replacing LED’s this is due to following reasons:-
1. The declining prices of LED’s.
2. The ability to display numbers, characters and graphics. This is in contrast to
LED’s which are limited to no. Of few characters.
3. Incorporation of a refreshing controller into the LCD thereby relieving the CPU of
the task of refreshing the LCD. In contrast the led must be refreshed by the CPU
to keep displaying the data.
4. Ease of programming for characters and graphics.
16×2 Liquid Crystal Display which will display the 32 characters at a time in two
rows (16 characters in one row). Each character in the display of size 5×7 pixel
matrix, although this matrix differs for different 16×2 LCD modules if you take
JHD162A this matrix goes to 5×8. This matrix will not be same for all the 16×2 LCD
modules. There are 16 pins in the LCD module, the pin configuration us given below

LCD Pin diagram and description –

PIN
NAME FUNCTION
NO

203149 - FMM
MCOEP

PIN
NAME FUNCTION
NO
1 VSS Ground pin
2 VCC Power supply pin of 5V
3 VEE Used for adjusting the contrast commonly attached to the potentiometer.
RS is the register select pin used to write display data to the LCD
(characters), this pin has to be high when writing the data to the LCD.
4 RS
During the initializing sequence and other commands this pin should
low.
Reading and writing data to the LCD for reading the data R/W pin
5 R/W should be high (R/W=1) to write the data to LCD R/W pin should be
low (R/W=0)
Enable pin is for starting or enabling the module. A high to low pulse of
6 E
about 450ns pulse is given to this pin.
7 DB0
8 DB1
9 DB2
10 DB3
8 bit Data bus
11 DB4
12 DB5
13 DB6
14 DB7
15 LED+ Back light of the LCD which should be connected to Vcc
16 LED- Back light of LCD which should be connected to ground.

VCC, VSS AND VEE – Vcc, vss provide +5v & ground resp. VEE used for controlling
LCD contrast.

RS (Register select) – There are two very important registers inside the LCD. The RS
pin is used for their selection as follows. If RS =0 the instruction command code
register is selected, allowing the user to send a command such as clear display cursor,
at home, etc. If RS =1 the data register is selected allowing the user to send data to be
displayed on the LCD.

R/W (Read - write) - R/w input allows the user to write information to the LCD or
read information. From it R/w=1 when reading
R/w=0 when writing

E (Enable) - The enable pin is used by LCD to latch information presented to its data
pins, when data is supplied to data pins a high to low pulse must be applied to this pin
in order for the LCD to latch in the data present at the data pins. This pulse must be
minimum of 450ns wide.

203149 - FMM
MCOEP

D0-D7 (8 bit data bus) - The 8-bit data pins d0-d7are used to send information to the
LCD or read the contents of LCD’s internal registers. To display letters and no’s we
send ASCII codes a-z, a-z and 0-9 to these pins while making RS=1. There are also
instruction command codes that can be sent to the LCD to clear the display to force
the cursor to the home position or blink the cursor. We also uses RS=0 to check flag
bit to see if the LCD is ready to receive information. The busy flag is d7 and can be
read when R/W=1 and RS=0 as follows if R/W=1 and RS=0 when d7=1(busy flag=1)
the LCD is busy taking care of internal operations and will not accept any new
information when d7=0 the LCD is ready to receive the new information. It is
recommended to check the busy flag before writing any data to LCD.

16×2 LCD module commands.


16×2 LCD module has a set of preset command instructions. Each command will
make the module to do a particular task. The commonly used commands and their
function are given in the table below.

Command Function
0F LCD ON, Cursor ON, Cursor blinking
ON
01 Clear screen
2 Return home
4 Decrement cursor
06 Increment cursor
E Display ON ,Cursor ON
80 Force cursor to the beginning of 1st line
C0 Force cursor to the beginning of 2nd line
38 Use 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
0C3 Jump to second line, position3
OC1 Jump to second line, position1

LCD initialization.

The steps that has to be done for initializing the LCD display is given below and these
steps are common for almost all applications.

 Send 38H to the 8 bit data line for initialization


 Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
 Send 06H for incrementing cursor position.
 Send 01H for clearing the display and return the cursor.

Sending data to the LCD.

The steps for sending data to the LCD module is given below. I have already said that
the LCD module has pins namely RS, R/W and E. It is the logic state of these pins

203149 - FMM
MCOEP

that make the module to determine whether a given data input is a command or data to
be displayed.

 Make R/W low.


 Make RS=0 if data byte is a command and make RS=1 if the data byte is a
data to be displayed.
 Place data byte on the data register.
 Pulse E from high to low.
 Repeat above steps for sending another data.

The circuit diagram shows how to interface a 16×2 LCD module with
microcontroller. Capacitor C3, resistor R3 and push button switch S1 forms the reset
circuitry. Ceramic capacitors C1, C2 and crystal X1 is related to the clock circuitry
which produces the system clock frequency. P1.0 to P1.7 pins of the microcontroller
is connected to the DB0 to DB7 pins of the module respectively and through this
route the data goes to the LCD module. P3.3, P3.4 and P3.5 are connected to the E,
R/W, RS pins of the microcontroller and through this route the control signals are
transferred to the LCD module. Resistor R1 limits the current through the back light
LED and so do the back light intensity. POT R2 is used for adjusting the contrast of
the display.

203149 - FMM
MCOEP

PC OPCODE LABEL INSTRUCTIONS REMARK

203149 - FMM

You might also like