Professional Documents
Culture Documents
:Introduction to emu8086
EDITOR
PROGRAM
<filename>.asm
ASSEMBLER
PROGRAM
<filename>.lst
other .obj files
<filename>.obj
LINKER
PROGRAM
<filename>..exe
3. Using EMU8086:
To run this example in the emulator, click emulate (or press F5). The
program then attempts to assemble and save the executable to
c:\emu8086\MyBuild. If the assembler succeeds in creating the file, the emulator
will also automatically load it into memory.
You can then click single step (or press F8) to step through the code
one instruction at a time, observing changes in registers and the emulator screen.
You can also click step back (or press F6) to see what happens when
reversing those changes.
(or)
You can click run (or press F9) for burst execution.
Results can be verified either in registers or memory by view → memory.
Table 1: Registers
Assemble Description
r
Directive
DB define byte
DW define word (2 bytes)
DD define double word (4 bytes)
DQ define quad word (8 bytes)
DT define ten bytes
EQU Equate, assign numeric expression or
constant to a name.
1. b. ADDRESSING MODES
Aim: To transfer the 10h bytes from location 2000h: 0100h to 3000h: 0100h using different
addressing modes.
Equipment Required:
1. A PC with
a. Emu 8086 Installed
Program:
Flowchart:
START
DS 2000H
ES 3000H
SI 0100H
DI 0100H
CX 10H
AL [SI]
[DI] AL
SI SI + 1
DI DI + 1
CX CX - 1
NO (ZF = 1)?
YES
STOP
Result:
View memory contents.
First fill the source contents from 20100h to 20110h with some value 'FF'
Destination:
View es:0100 0110
3000:0100 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………
3000:0110 00 -
Destination:
View es:0100 0110
3000:0100 FF FF FF FF FF FF FF FF – FF FF FF FF FF FF FF FF …………
3000:0110 00 -
Exercise:
Aim: Assembly Language program to perform multiplication and division on the given
signed numbers.
Equipment required:
1. A PC with
a. Emu 8086 Installed
Program:
;MULTIPLICATION
MOV AX, OPR1 ;copy the first number in AX
MOV BX, OPR2 ;copy the second number in BX
IMUL BX ;multiply the contents of AX and BX
MOV PROD, AX ;save the lower word of result
MOV [PROD+2], DX ;save the higher word of result
;DIVISION
MOV AX, OPR1 ;copy the first operand in AX
CWD ;convert word in AX to double word
; i.e., DX =0, hence becomes DX:AX
IDIV BX ;divide the contents of DX:AX by BX
MOV QUO, AX ;save the Quotient
MOV REM, DX ;save the Remainder
HLT ;Exit to DOS mode
CODE ENDS ;End of code segment
END START ;End Program
Flowchart:
START
AX OPR1
BX OPR2
AX OPR1
AX AX * BX
PROD AX
[PROD+2] DX
AX OPR1
AX DX: AX / BX
QUO AX
REM DX
STOP
Result:
Data Input:
OPR1 = 4349H
OPR2 = 1298H
Expected Output:
PROD = 4E31558H
QUO (QUOTIENT) = 3H
REM (REMAINDER) = B81H
View Memory contents
Before execution:
View ds:0000 000B
0B52:0000 49 43 98 12 00 00 00 00 – 00 00 00 00
After execution:
View ds:0000 000B
0B52:0000 49 43 98 12 58 15 E3 04 – 03 00 81 0B
Exercise:
1. Write an ALP
a. To perform Multiplication and division on the given set of unsigned operands.
i. opr1 =7698H, opr2 =1234H
ii. opr1 =1234H, opr2 =7698H
iii. opr1 =9182H, opr2 =189H
iv. opr1 =6FH, opr2 =24H
v. opr1 =B4H, opr2= 19H and comment on the result.
b. To perform
i. -21 x 4
ii. -21 x -4
iii. -3/2
iv. 3/-2.
v. -3/-2 and comment on the result.
Aim: Assembly Language program to perform binary addition and subtraction on the given
numbers.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:
;SUBTRACTION
NEXT: MOV AL, NUM1 ;get the first number
SUB AL, NUM2 ;subtract the second number from the first
MOV DIFF, AL ;store the result of subtraction
JNC NEXT1
DEC BYTE PTR BORROW ;decrement borrow if CF is set
NEXT1 HLT ;Exit to DOS mode
:
CODE ENDS ;code segment ends here
END START ;end of the program
Flowchart:
START
AL NUM1
AL AL+ NUM2
SUM AL
NO (CF=1)?
YES
CARRY CARRY +1
AL NUM1
AL AL – NUM2
DIFF AL
NO (CF=1)?
YES
BORROW BORROW – 1
STOP
Result:
Data Input:
Num1 = E8H
Num2 = 43H
Expected Output:
Sum = 2BH
Carry =1
Diff = A5H
Borrow =0
After execution:
View ds:0 5
0B52:0000 E8 43 2B 01 A5 00
Exercise:
1. Write an ALP
a. To perform addition and subtraction on the given set of numbers.
i. NUM1 = B4H, NUM2 = 19H
ii. NUM1 = D182H, NUM2 = 179H
Observe the flag status.
2. Write an ALP
a. To find the result of (P+(Q*R)/S-T, If P=5, Q=-1,R=3, S=2, T=1.
b. To find GCD of two given numbers.
c. To find LCM of two given numbers.
d. To find Celsius for the given Fahrenheit temperature.
e. To perform addition, subtraction of the numbers E2ABC198H and
931EF125H.
f. To perform the addition of the following binary numbers, Result should also
be in binary.
5AH, 46H, 89H, 27H, 22H, ABH,D7H,87H,FH,19H.
Aim: Assembly Language program to perform BCD addition and subtraction on the given
BCD numbers.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:
DATA SEGMENT ;start of data segment
NUM1 DB 98H ;BCD Number 1
NUM2 DB 43H ;BCD Number 2
SUM DB 0 ;memory for result of BCD summation
CARRY DB 0
DIFF DB 0 ;memory for result of BCD subtraction
BORROW DB 0
DATA ENDS ;end of data segment
Flowchart:
START
AL NUM1
AL AL+ NUM2
DECIMAL ADJUST
AFTER ADDITION
SUM AL
NO (CF=1)?
YES
CARRY CARRY +1
AL NUM1
AL AL – NUM2
DECIMAL ADJUST
AFTER SUBTRACTION
DIFF AL
NO (CF=1)?
YES
BORROW BORROW – 1
STOP
Result:
Data Input:
NUM1 = 98
NUM2 = 43
Expected Output:
SUM = 41
CARRY =1
DIFF = 55
BORROW =0
After execution:
- ds:0 5 98 43 41 01 55 00
Exercise:
1. Write an ALP
a. To perform addition and subtraction on the given set of numbers.
i. Num1 =89, Num2= 14
ii. Num1 =88, Num2 = 98
iii. Num1 =347834, Num2 = 189754
b. To perform addition of the following BCD numbers.
89, 80, 9, 27, 73, 45, 67, 36
4. CODE CONVERSION
Aim: Assembly Language program to perform the code conversion from BCD to 7-segment.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Look – up table for BCD to 7-segment:
7-segments
Decima
BCD 7-segmant d 7-segment
l
code Display p g f e d c b a code (hex)
0 0000 0 0 1 1 1 1 1 1 3F
1 0001 0 0 0 0 0 1 1 0 06
2 0010 0 1 0 1 1 0 1 1 5B
3 0011 0 1 0 0 1 1 1 1 4F
4 0100 0 1 1 0 0 1 1 0 66
5 0101 0 1 1 0 1 1 0 1 6D
6 0110 0 1 1 1 1 1 0 1 7D
7 0111 0 0 1 0 0 1 1 1 27
8 1000 0 1 1 1 1 1 1 1 7F
9 1001 0 1 1 0 1 1 1 1 6F
Program:
Flowchart:
START
BX OFFSET CODELIST
AL CHAR (BCD code)
XLAT (Translate)
(AL [AL+BX])
CODEC AL
(7-segment code)
STOP
Result:
Data Input:
BCD input = 05
Expected Output:
7-segment output = 6DH
After execution:
View ds:0000 000b
0B56:0000 3F 06 5B 4F 66 6D 7D 27 – 7F 6F 05 6D
Exercise:
1. Write an ALP
a. To perform Binary to gray code conversion.
b. To perform Binary to ASCII code conversion.
Aim: Assembly Language program to search for a character in the given string.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:
Flowchart:
START
CX COUNT
DI OFFSET STRING
BX 0
AL BYTE1
(ZF=1)? NO
DI DI +1
DI DI +1 CX CX – 1
(CX =0)? NO
YES
(ZF =1)? NO
YES
BX DI
STOP
Result:
Character to be
Position (HEX)
searched
AL BX
'c' 3
'M' 1
'r' 4
'6' 12
'a' 0
Exercise:
1. Write an ALP
a. To count the number of times that the letter ‘S’ is present in the string
‘MICROPROCESSORS’.
b. To delete the character ‘S’ in the given string ‘MICROPROCESSORS’.
c. To replace the character ‘S’ by ‘$’ in the given string
‘MICROPROCESSORS’.
d. To find the number of times that the string “he” occurs in the string “He was
playing in the garden” and also the position at which it occurs.
Aim: Assembly Language program to sort the given set of unsigned numbers in ascending
order.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:
Flowchart:
START
DX COUNT-1
SI OFFSET LIST
CX DX
AL [SI]
COMPARE AL AND [SI+1]
(CF = 1)?
YES
EXCHANGE AL AND
[SI+1]NO
SI SI + 1
CX CX – 1
(ZF = 1)? NO
YES
DX DX – 1
NO (ZF = 1)?
YES
STOP
Result:
Data Input:
Given unordered numbers:
36H, 2FH, 38H, 1AH, 46H, 57H, 58H, 2DH, 76H, 37H, 87H, 45H
Expected Output:
Ascending order:
1AH, 2DH, 2FH, 36H, 37H, 38H, 45H, 46H, 57H, 58H, 76H, 87H
After execution:
View ds:0000 000b
0B56:0000 1A 2D 2F 36 37 38 45 46 – 57 58 76 87
Exercise:
1. Write an ALP
a. To sort the given set of unsigned numbers in descending order.
b. To sort the given set of signed numbers in ascending order.
c. To sort the given set of signed numbers in descending order.
d. To sort the word ‘MICROPROCESSOR8086’
i. In Ascending order
ii. In descending order
HARDWARE:
1. IBM PC with
a. Emu 8086 Installed
DESCRIPTION:
The emu8086 has virtual traffic lights shown in below figure. There are 12 LEDs
arranged in a 'X' junction form. These 12 LEDs are interface to 8086 in IO Mapped method at
an address 0004H of 16bits (of which most significant 4 bits are unused).
Out of 12 LEDs,
3 are Red LEDs corresponds to bit positions 0,3,6 and 9;
3 are Yellow LEDs corresponds to bit positions 1,4,7 and A;
3 are Green LEDs corresponds to bit positions 2,5,8 and B;
INTERFACE DIAGRAM
PROGRAM:
RESULT:
FLOWCHART:
START
GLOW ALL
RED LEDS
CALL DELAY
GLOW ALL
YELLOW LEDS
CALL DELAY
GLOW ALL
GREEN LEDS
CALL DELAY
Assignment:
1. Write an ALP
1. Overview
Using this programmer with your application board will enable you to program AT89Sxx
based microcontrollers In-circuit. You shall not need of any external programmer or do not
need to remove the chip from your hardware to update its firmware (embedded system
software inside microcontroller). The programmer communicates through a serial port to PC
which has “Proload” programming software installed. The process of reprogramming thus
becomes totally touch less. Proload software is used with this hardware to provide all the
necessary read, write, lock, and fuse functions.
2. Features
3. Supported Chips
· AT89S51
· AT89LS51
· AT89S52
· AT89LS52
4. Proload V5.2
Aim: Program to copy the value 55H into RAM memory locations 30H to 35H using
a. Direct Addressing mode.
b. Register Indirect Addressing mode without a Loop.
c. Register Indirect Addressing mode with a Loop.
Hardware:
1. IBM PC with
a. Keil Compiler
Program:
a.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H
Flowchart:
START
A 55H
[30H] A
[31H] A
[32H] A
[33H] A
[34H] A
STOP
Program:
b.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H
Flowchart:
START
A 55H
R0 30H
[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1
STOP
Program:
c.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H
MOV R2, #05 ; Load counter, R2 = 5
Flowchart:
START
A 55H
R0 30H
R2 05
[R0] A
R0 R0+1
R2 R2-1
NO (R2=0)?
YES
STOP
Result:
Aim: Program to generate a square wave of frequency 100Hz on P2.3 pin using time delay.
Assume that XTAL = 11.0592 MHz.
Hardware:
1. IBM PC with
a. Keil Compiler
Program:
Polling method:
AGAIN: JNB TF0, AGAIN ; monitor flag 0, stay until timer rolls
over
CPL P2.3 ; complement P2.3 to get hi, lo
CLR TR0 ; stop the timer 0
CLR TF0 ; clear timer 0 flag for next round
SJMP HERE
END
Interrupt method:
Result:
Connect 8051 pin P2.3 to Oscilloscope View square wave from in CRO.
Flowchart:
START
NO TF0 =1
YES
COMPLEMENT P2.3
P2.3 !P2.3
CLEAR TF0
TF 0
10.
Hardware:
1. AT89S51
2. LED
3. 500 ohms & 1k Resistor’s
4. SL100 Transistor
Circuit Diagram:
Fundamentals:
A current limiting resistor in series
should always be included in the circuit to protect not only the LED, but also the driver circuitry from
high current flow.
Resistance value is calculated as follows:
According to Ohm’s Law
V = IR
V = supply voltage = 5V
To blink an LED with 50% duty cycle continuously; The time delay between ON and OFF state should
be equal.
For better view of ON and OFF states, there is a need to implement minimum time delay of 100 ms.
Between ON and OFF states.
Port Map:
Flow Chart:
START
P1.0 = HIGH
TRANSISTOR ON
(LED ON)
DELAY = 1000 ms
P1.0 = LOW
TRANSISTOR OFF
(LED OFF)
DELAY = 1000 ms
STOP
Program:
/****Program to interface a LED with a 8051 micro controller***/
#include<reg51.h>
void delay_ms(unsigned int);
sbit LED = P1^0; /*equating P1^0 pin to a constant(LED)*/
void main(void)
{
P1= 0x00;
while(1)
{
LED = 1;
delay_ms(1000);
LED = 0;
delay_ms(1000);
}
}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}
Result:
Observe the LED’s status.
Exercise:
1. Write a C Program to generate the given pattern by interfacing 8 LEDs to 8051.
a. Blink all LEDs at a frequency of 1Hz.
b. Blink alternate LEDs at a frequency of 2Hz.
(Hint: use #define LED P1 to equate P1 port to a constant (LEDS)*/
AT89S51
Fundamentals:
Switch: A device, which opens or closes the circuit.
Switch State: Port Pin status
ON (close) = Logic high
OFF (open) = Logic low
What will happen if resistor (1OK) is not present?
Anytime you press the switch, P1.0 is directly connected to ground. P1.0 would try to deliver a
+5 logic level through a direct short to ground. It may cause damage to the internal circuitry of
micro controller.
About Circuit:
Fig1: Normal position of the switch is open. In this case logic high = 1 is port pin status. When
switch is pushed, P1.0 is connected to ground resulting logic low = 0 on port pin.
Fig2: Normal position of the switch is open. In this case logic low = 0 is port pin status. When
switch is pushed, P1.0 is connected to Vcc resulting logic high = 1 on port pin.
Need of delay: Switches suffer from a condition known as switch bounce. When switch is
closed at first, it won’t provide permanent connection instantaneously. It results in multiple logic
level transitions on port pin. If micro controller checks the port pin at this instance it may not get
a true current state of the switch.
Fig.1 Fig.2
1) When the switch is closed, the port pin gets shorted to the Vcc directly. It causes the damage
to the circuit.
2) When the switch is closed, the port pin gets shorted to the ground. It causes the damage to the
circuit.
3) It is an open circuit. P1.0 will be in the toggle state. So, the output will not be reliable.
4) Same for fig. 4.
Port Map:
Flowchart:
START
NO (SW=0)?
YES
COMPLEMENT
P2.0
DELAY
STOP
Program:
/*********Program to interface a led and a switch*********/
#include<reg51.h>
#include<delay.h>
void main(void)
{
LED = 0;
while (1) /*toggling a switch results in a led coming on and off*/
{
if ( SWITCH == 0)
{
LED = 1 – LED;
delay(200);
}
}
}
Result:
Observe the LED status when the switch toggles.
Exercise:
1. Write a C Program to Interface Switch and LED using an Interrupt.
2. Interface a LED in such a way that it should be ON only when the switch is closed. When
the switch is open LED should be OFF.
Fundamentals:
LS1
5
3
4
1
2
Also by using a transistor to provide a switching, any high voltage is isolated from low
voltage digital circuit that the micro controller operates in.
Circuit Diagram:
A logic high signal on port pin P2.0 cases the transistor to conduct and sink the relay to
ground. The magnetic field energizes, and relay contacts to activate. (Relay is closed).
A logic signal on port pin P2.0 cases the transistor to push into OFF state. Hence there is no
current flow from collector to ground; the relay will be in OFF state.
Whenever relay comes from ON state to OFF state, the coil generates a reverse voltage spike
due to the collapsing magnetic field around it. This voltage can destroy the transistor. Hence,
some protection is needed for transistor. This is the reason behind the diode being connected
across the relay coil. When the high voltage is produced, the diode conducts and shunts this
voltage back through the relay coil.
Flow Chart:
START
CONNECT P0 TO RELAYS
AND P2 TO LEDS
DELAY
DELAY
DELAY
STOP
Port Map:
P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
X X RELAY RELAY RELAY RELAY RELAY RELAY
Program:
/******Program for interfacing a relay with a bulb******/
void main(void)
{
while(1) //infinite loop
{
relay=0x15; //relay1, 3, 5 are on
led=0x15; //led1, 3, 5 are on
delay_ms(1000); //delay 1000 milli seconds
1
B1
BUZZER
2
R1
3
P0.0 2 Q1A
SL100
330 ohms
1
AT89c51
Port Map :
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P1.0
X X X X X X X BUZZE
R
Program:
/******program for interfacing a buzzer with 8051 microcontroller****/
#include<reg51.h>
#include<spectro_delay.h>
sbit BUZZER = P1^0;
void main(void)
{
BUZZER = 0;
while(1)
{
BUZZER = 1;
delay(1000);
BUZZER = 0;
delay(1000);
}
}
Flowchart:
START
P1.0 = HIGH
(BUZZER IS ON)
DELAY = 1000
P1.0 = LOW
(BUZZER IS OFF)
DELAY = 1000 ms
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 52
STOP
Exp 9: Interface applications using LED, Switch, Relay and Buzzer
Result:
Observe the sound coming from Buzzer.
Exercise:
1. Interface 6 relays and one buzzer to 8051; and write a program to on the buzzer when
6th relay is on.
Fundamentals:
The ADC0808 data acquisition component is a monolithic CMOS device with an 8 bit
Analog –to –Digital converter 8 channel multiplexer & microprocessor compatible control
logic. The 8 bit A/D converter uses successive approximation as the conversion technique.
The converter features a high impedance chopper stabilized comparator, a 256R voltage
divider with analog switch tree and a successive approximation register. The 8 channel
multiplexer can directly access any of 8 –single-ended analog signals. Easy interfacing to
microprocessor is provided by the latched & decoded multiplexer address input as latched
TTL TRI-STATE outputs.
The ADC0808 offers high speed, high accuracy minimal temperature dependence,
excellent long-term accuracy & repeatability & consumes minimal power.
Features:
Easy interface to all microprocessors
Operates ratio metrically or with 5V DC or analog span adjusted voltage reference.
Table:
Address Lines
IN0 L L L
IN1 L L H
IN2 L H L
IN3 L H H
IN4 H L L
IN5 H L H
IN6 H H L
IN7 H H H
Converter Characteristics:
The Converter
The heart of this single chip data acquisition system is its 8-bit analog-to-digital
converter. The converter is designed to give fast, accurate & repeatable conversions over a
wide range of temperatures.
Functional Description:
The A/D converter’s successive approximation register (SAR) is reset on the positive
edge of the start conversion (SC) pulse. The conversion begins on falling edge of the start
conversion pulse. The continuous conversion may be accomplished by tying the end-of-
conversion (EOC) output to the SC input. If used in this mode an external start conversion
pulse should be applied after power up. End-of-conversion will go low between 0 & 8 clock
pulses after the rising edge of start conversion. The most important section of A/D converter
is the comparator. It is this section which is responsible for the ultimate accuracy of the entire
converter. It is also the comparator drift which has the greatest influence on the repeatability
of the device. A chopper stabilized comparator provides the most effective method of
satisfying all converter requirements.
Pin diagram:
START
START CONVERSION
(EOC = 1)? NO
YES
DISPLAY ADC DATA
ON LCD
RETURN
Program:
//program to implement analog to digital conversion using ADC0808
#include<reg51.h>
#define LCD P2
#define ADC P0 //acquires analog to digital converted data
sbit A0=P1^0; //A0 A1 & A2 are analog input channel selection bits
sbit A1=P1^1;
sbit A2=P1^2;
sbit START=P1^3; //start conversion bit
sbit ALE=P1^4; //Select channel according to A0 A1& A2
sbit EOC=P1^5; //end of conversion bit
void init_lcd(void);
void cmd_lcd(unsigned char);
void write_lcd(unsigned char);
void display_lcd(unsigned char *);
void integer_lcd(int);
void float_lcd(float);
void delay_ms(unsigned int);
void main(void)
{
init_lcd();
ALE =0;
void init_lcd(void)
{
delay_ms(10);
cmd_lcd(0x28);
cmd_lcd(0x0e);
cmd_lcd(0x06);
cmd_lcd(0x01);
}
LCD=0;
LCD=c<<4|0x02;
LCD=0;
delay_ms(2);
}
void integer_lcd(int n)
{
unsigned char c[6];
unsigned int i=0;
if(n<0)
{
write_lcd('-');
n=-n;
}
if(n==0)
write_lcd('0');
while(n>0)
{
c[i++]=(n%10)+48;
n/=10;
}
while(i-->=1)
write_lcd(c[i]);
}
void float_lcd(float f)
{
int n;
float temp;
n=f;
integer_lcd(n);
write_lcd('.');
temp=f-n;
if(temp>=0.00&&temp<=0.09)
write_lcd('0');
f=temp*100;
n=f;
integer_lcd(n);
}
Result:
Connect POT between JP6.1 and JP6.4 and apply the outline of POT to IN0 of ADC0808.
Then vary the POT and observe the display on LCD.
(We can view amount of voltage that is applied to IN0)
Exercise:
1. Interface ADC0800 to 8051 and display the digital converted data in hex format after
applying analog input to it.
Hardware: AT89c51
DAC0808
Circuit diagram:
Fundamentals:
The DAC-0808 series is an 8-bit monolithic digital to analog converter(DAC) featuring the a
full scale output current setting time of 150ns while dissipating only 33mw with +/-
5vsupplies.No reference current(Iref) trimming is required for most applications since the full
scale output current is typically +/-1LSB of 255 Iref/256. Relative accuracies of better than
+/-0.19% assure 8-bit monotonicity and linearity while zero level output current of less than
4ua provides zero accuracy for Iref >=2ma. The power supply contents of the DAC-0808
series are independent of bit codes, and exhibits essentially constant device characteristics
over the entire supply voltage range. The DAC-0808 will interface directly with popular
TTL,DTL or CMOS logic levels.
PIN DIAGRAM
NC 1 16
COMPENSATION
2 15
GND -VREF
3 14
VEE +VREF
4 13
IO DAC0808 VCC
5 12
MSB A1 A8 LSB
6 11
A2 A7
7 10
A3 A6
8 9
A4 A5
FEATURES:
The reference amplifier provides a voltage at pin 14 for converting the reference voltage to a
current, and a turn around circuit or current mirror for feeding the ladder. The reference
amplifier input current, I14, must always flow into pin 14,regardless of the setup method or
reference voltage priority.Connections for a positive voltage are shown in fig 1. The
reference voltage source supplies the full current !14. for bipolar reference signals, as in the
multiplying mode,R15 can be tied to a negative voltage corresponding to the minimum input
level. It is possible to eliminate R15 with only a small sacrifice in accuracy and temperature
drift. The compensation capacitor value must be increased with increases in R14 to maintain
proper phase margin; for R14 values of 1, 2.5 &5Kohms, minimum capacitor values are
15,37 & 75pF. The capacitor may be tied to either VEE or ground, but using VEE increases
negative supply rejection.
A negative reference voltage may be used if R14 is grounded and the reference voltage is
applied R15 as shown in fig 2 a high input impedance is the main advantage of this method.
Compensation involves a capacitor to VEE on pin 16, using the same values as used before.
The negative reference voltage must be at least 4V above VEE supply. Bipolar input signals
may be handled by connecting R14 to a positive reference voltage equal to the peak positive
input level at pin 15.
The voltage on pin 4 is restricted to a range of -0.55 to 0.4V when VEE=-5V due to the
current switching methods employed in the DAC0808.The negative output voltage
compliance of the DAC0808 is extended to -5V where the negative supply voltage is more
negative than -10V. Using a full scale current of 1.992mA and load resistor of 2.5 K ohm
between pin 4 and ground will yield a voltage output of 256 levels between 0 and -4.980V.
Floating pin 1 does not effect the converter speed or power dissipation. However the value of
the load resistor determines the switching time due to increased voltage swing. Values of RL
up to 500ohm do not significantly affect performance , but a 2.5Kohm load increases worst-
case settling time to 1.2us.
The output current maximum rating of 4.2mA may be used only for negative supply voltages
more negative than -8V, due to the increased voltage drop across the resistors in the reference
current amplifier.
ACCURACY
Absolute accuracy is the measure of each output current level with respect to its intended
value, and is dependent upon relative accuracy and full scale current drift. Relative accuracy
is the measure of each output current level as a fraction of the full scale current. The relative
accuracy of the DAC0808 is essentially constant with temperature due to the excellent
temperature tracking of the monolithic resistor ladder.
FLOWCHART:
Program:
#include<reg51.h>
#include<delay.h>
#include<lcd.h>
#include<int.h>
#include<float.h>
#define DAC P1 //8 bit data is transmitted to DAC0808 for digital to analog conversion
void main(void)
{
init_lcd(4);
display_lcd("Digital-Analog");
cmd_lcd(0xc0);
display_lcd("Conversion");
while(1)
{
for(c=0;c<=255;c++)
{
cmd_lcd(0xcd);
integer_lcd(c); //display digital data
write_lcd(' ');
write_lcd(' ');
START=1; //enable latch
DAC=c; //transmit digital data to dac0808
START=0; //disable latch
delay_ms(500);
display_float(DAC);
}
}
}
Exercise:
Hardware : AT89s51
BDX33 Transistor
1N4007 Diodes
Resistors
Unipolar & Bi Polar Stepper motor’s
Circuit Diagram :
Fundamentals :
Whenever there is a need to rotate the shaft with precise angle, it can be easily achieved by
using a stepper motor. For example if you need to rotate the shaft with an angle of 1.8
degrees, a stepper motor can do it. Stepper motors are driven by pulse. Each pulse drives the
shaft through a step angle. Stepper motors are devices, which convert electrical impulses into
discrete mechanical rotations.
Stepper motors instead of being powered by a continuous flow of current as with DC motors
they are directly driven by the pulse.
Stepper Motor :
Unipolar : The Unipolar Stepper motor has 2 coils, simple lengths of wound wire. The coils
are identical and are not electrically connected.
In unipolar stepper motor there are 2 coils and 2 directions that gives us a possible 4-phase
sequence. All we need to do is get the sequencing right and the motor will turn continuously.
Bipolar : The Bipolar Stepper motor has 2 coils. The coils are identical and are not
electrically connected. The Bipolar Controller must be able to reverse the polarity of the
voltage across either coil, so current can flow in both directions. And, it must be able to
Energize these coils in sequence.
In the chart bellow, + indicates the coil is conducting in the forward Direction with one end
being positive with respect to ground. The indicates that the coil is conducting in the opposite
direction. Continuing the sequence as outlined above causes the rotor to rotate in a forward
direction.
Reversing this sequence causes the motor to rotate in the reverse direction. The coils only are
required to be energized long enough for the rotor to move to its' next position.
Flowchart :
Program:
#include<reg51.h>
#include<delay.h>
void main(void)
{
while(1) /*Clockwise Movement (9a65)*/
{
P1 = 0x09;
delay(3);
P1 = 0x0a;
delay(3);
P1 = 0x06;
delay(3);
P1 = 0x05;
delay(3);
}
}
//for Counter Clockwise Movement, reverse the stepping sequence(56a9)
#include<reg51.h>
#include<delay.h>
void main(void)
{
while(1) /*Counter Clockwise Movement (56a9)*/
{
P1 = 0x05;
delay(3);
P1 = 0x06;
delay(3);
P1 = 0x0a;
delay(3);
P1 = 0x09;
delay(3);
}
}
Result:
Observe the rotation of stepper motor.
Exercise:
3. Write a program to rotate the stepper motor by an angle 270 degrees in clockwise
direction by applying above different sequences.
Aim: Interfacing MAX 7219 driver to drive 7 segment led display’s with a at89c51
microcontroller using a SPI bus.
Hardware:
1. AT89c51
2. MAX 7219(SPI) SEVEN SEGMENT DISPLAY DRIVER
3. EIGHT 7 SEGMENT LED DISPLAYS
Circuit Diagram:
Description:
The Max7219 is compact, serial input/output common cathode display driver that interface
microcontrollers to 7 segment numeric led displays of up to 8 digits, bar graph displays, or 64
individual leds Included on chip are a BCD code-B decoder, multiplex scan circuitry,
segment and digit drivers, and an 8*8 static RAM that stores each digit. Only one external
resister is required to set the segment current for all led’s. The MAX7219 is compatible with
SPI, QSPI and Microwire, and has slew rate limited segment drivers to reduce EMI.
A convenient 3 wire serial interface connects to all common microcontrollers. Individual
digits may be addressed and updated without rewriting the entire display. The Max7219 also
allow the user to select code-B decoding or no-decode for each digit.
The devices include a 150 micro ampere low power shutdown mode, analog and digital
brightness control, a scan limit register that allows the user to display from 1 to 8 digits, and a
test mode that forces all led’s on.
Applications:
Features:
Program:
//program to interface seven segment display driver using software implemented SPI protocol
void init_7seg(void);
void write_7seg(unsigned char,unsigned char);
void send_byte(unsigned char);
void clear_7seg(void);
void delay_ms(unsigned int);
for(l=10;l>0;l--)
{
write_7seg(4,s[l-1]);
for(m=10;m>0;m--)
{
write_7seg(5,s[m-1]);
for(n=10;n>0;n--)
{
write_7seg(6,s[n-1]);
for(o=10;o>0;o--)
{
write_7seg(7,s[o-1]);
for(p=10;p>0;p--)
{
write_7seg(8,s[p-1]);
delay_ms(100);
}
}
}
}
}
}
}
}
}
}
//initialize 7 segment driver max7219
void init_7seg(void)
{
write_7seg(0x0b,0x07); //Scan limit
write_7seg(0x09,0x00); //Decode
write_7seg(0x0c,0x01); //Shutdown
write_7seg(0x0f,0x00); //Display Test
write_7seg(0x0a,0x0f); //Intensity
clear_7seg(); //clear 7segment display
}
}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}
Result:
Observe the display on 7-seg display units.
Exercise:
1. Write a C Program by interfacing 2 7-segment displays and display the count from 99
to 00. And it restarts the counting after reaches the final Count.
2. Write a C program by interfacing 8 7-segment displays and display the string
“CBIT-ECE”.
2 x 16
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
Command Encoding
Instruction RS RW D7 D6 D5 D4 D3 D2 D1 D0 Description
Clear Display 0 0 0 0 0 0 0 0 0 1 Clear all display and returns the cursor
DB Busy Bit
Activity RS RW DB7 DB5 DB4 DB3 DB2 DB1 DB0
6 readable?
Power On No
Wait more than 15ms
No
after Vcc raises to +4.5V
Send to LCD 0 0 0 0 1 1 * * * * No
Wait more than 4.1ms No
Send to LCD 0 0 0 0 1 1 * * * * No
Wait more than 100us No
Send to LCD 0 0 0 0 1 1 * * * * No
Send to LCD (function set) 0 0 0 0 1 1 N F * * Yes
Continuous with regular initialization sequence...
Flowchart :
START
DELAY 15MS
CALL
LCD INITIALIZATION
CALL DISPLAY
END
Program:
/*Program to interface lcd in 8 bit mode*/
#include<reg51.h> //include at89c51 microcontroller header file
sbit RS=P0^0; //connect p0.0 to rs pin of lcd
sbit EN=P0^1; //connect p0.1 to en pin of lcd
#define LCD P2 //connect p2 to 8 i/o pins of lcd
void init_lcd(void);
void cmd_lcd(unsigned char);
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 83
Exp 14: Interfacing LCD
void main(void)
{
init_lcd(); //initialize lcd
while(1) //infinite loop
{
cmd_lcd(0x01); //clear lcd
display_lcd("Good Morning");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Hello Everybody");
delay_ms(1000); //delay 1000 milliseconds
cmd_lcd(0x01); //clear lcd
display_lcd("Welcome to");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Spectrochem Ints");
delay_ms(1000); +
}
}
//initialize lcd
void init_lcd(void)
{
delay_ms(10); //delay 10 milliseconds
cmd_lcd(0x38); //8 bit initialize, 5x7 character font, 16x2 display
cmd_lcd(0x0e); //lcd on, cursor on
cmd_lcd(0x06); //right shift cursor automatically after each character is displayed
cmd_lcd(0x01); //clear lcd
}
Program:
/*Program to interface lcd in 4 bit mode*/
void init_lcd(void);
void main(void)
{
init_lcd(); //initialize lcd
while(1)
{
cmd_lcd(0x01); //clear lcd
display_lcd("Good Morning");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Hello Everybody");
delay_ms(1000); //delay 1000 milliseconds
cmd_lcd(0x01); //clear lcd
display_lcd("Welcome to");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Spectrochem Ints");
delay_ms(1000); //delay 1000 milliseconds
}
}
//initialize lcd
void init_lcd(void)
{
delay_ms(10); //delay 10 milliseconds
cmd_lcd(0x28); //4 bit initialize, 5x7 character font, 16x2 display
cmd_lcd(0x0e); //lcd on, cursor on
cmd_lcd(0x06); //right shift cursor automatically after each character is
displayed
cmd_lcd(0x01); //clear lcd
}
write_lcd(*s++);
}
Result:
Observed the display on LCD.
Exercise:
1. Program to interface a LCD, LED’s & Switches to create a user selectable menu and
perform the specified operation on given number.
1st Set of Display: WELCOME TO
SPECTROCHEM LTD
2nd Set of Display: 1 INC 2 DEC
3 SET 4 RESET
Logical operations
Mnemonic Description
AAA, AAS, AAM, ASCII adjust for addition, subtraction, multiplication and division
AAD (ASCII codes 30-39)
Transfer Operations
Mnemonic Description
Loop control
LOOP Loop unconditional, count in CX, short jump to target address
LOOPE (LOOPZ) Loop if equal (Zero), count in CX, short jump to target address
LOOPNE Loop if not equal (not zero), count in CX, short jump to target
(LOOPNZ) address
JCXZ Jump if CX equal zero (used to skip code in loop)
CALL, RET Call, return from procedure (inside or outside current segment)
INT, INTO Software interrupt, interrupt if overflow
IRET Return from interrupt
String Instructions
Mnemonic Description
Inactive states
NOP No operation
WAIT Wait for test pin activity
HALT Halt processor
J8
Relay’s,SSRC,Buzzer
1 2 3 4 5 6 7 8 9 10
J9 Expanding I/P
Controls
1 2 3 4 5 6 7 8 9 10
J11 ADC
Data
1 2 3 4 5 6 7 8 9 10
ADC0 ADC7 X X
J13 DAC
Data
1 2 3 4 5 6 7 8 9 10
DACD0 DCA7 X X
J14 Switches
1 2 3 4 5 6 7 8 9 10
SW1 SW2 SW3 SW4 SW5 SW6 SW7 X X X
J15 RC5
Remote
1 2 3 4 5 6 7 8 9 10
RC5 RXD RC5TX X X X X X X X X
D
J17
SPI
1 2 3 4 5 6 7 8 9 10
CS DIN CLK DOUT X X X X X X
J20 LCD 8-
Bit
1 2 3 4 5 6 7 8 9 10
DB0 DB7 X X
CBIT1(AUTONOMOUS)
2 – ECE – MICRCONTROLLER LAB MANUAL
Page 100
Appx. III. I/O Ports
GND RD- RD+ GND TD- TD+ GND LED9 LED1 LED LED1 3.3V
0 1 2
X1 X2 Y1 X3 X4 Y2 X5 X6 Y3
LM324 SPARE
1 2 3 4 5 6 7 8 9
X1 X2 Y1 X3 X4 Y2 X5 X6 Y3
1 2
MT2A MT2B
J3 PWM
CONTROLS
1 2 3 4 5 6 7 8 9 10
PWM1 PWM2 PWM3 PWM4 X X X X X X
J4
SERVOS
1 2 3 4 5 6 7 8 9 10
SERVO1 SERVO SERVO SERVO X X X X X X
2 3 4
J5 DC MOTORCONTROL
1 2 3 4 5 6 7 8 9 10
1A 2A 3A 4A 1,2 EN 3,4 EN X X X X