micro controller assignment 3
TRANSCRIPT
-
8/6/2019 Micro Controller Assignment 3
1/9
5th sem ,ASSIGNMENT 3 ,HANJI VISHAL RAJENDRA,1MS07EC033
7.EXPLAIN THE REGISTERS AND PINS OF LCD PANEL AND WRITE AN 8051 ALP DISPLAY MESSAGE
MSRIT ON THE LCD PANEL.
ANS:
REGISTERS OF THE LCD PANEL:
a)command code register:It is used when command is sent to LCD panel
b)data register:It is used when data to be displayed is sent.
LCD command codes:
Code Command to LCD instruction register
1 Clear display screen
2 Return home4 Decrement cursor(shiftr cursor to left)
6 Increment cursor(shift cursor to right)
5 Shift display right
7 Shift display left
8 Display off,cursor off
A Display off ,cursor on
C Display on, cursor off
E Display on,cursor blinking
F Display on,cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift entire display to left
1c Shift entire display to right
80 Force cursor to beginning if 1st line
C0 Force cursor to beginning if 2nd line
38 2 lines and 5x7 matrix
Pin details:
i.RS,register select
If RS=0,the instruction command code register is selected,allowing user to send a command such as
clear display, cursorvat home etc.
If RS=1,data register is selected to send data data to be displayed on LCD.
ii.R/W,read /write
R/W input allows user to write information to LCD or read information from it,when R/W=1 when
reading,R/w=0 when writing.
iii.E,enable
-
8/6/2019 Micro Controller Assignment 3
2/9
Enable pin is used by LCD to latch information presented to it by data pins.When data is supplied to
data pins,a high to low pulse must be applied to this pin in ordr for the LCD to latch it.This pulse
must be a minimum of 450ns wide.
iv.D0-D7
The 8 bit data pins D0-D7 are used to send information to the LCD or read the contents of the LCDsinternal registers.To display letters and numbers ,we send ASCII values to these pins with RS=1.There
are also instruction command codes that can be sent to the display or force the cursor to home
position or blink the cursor.
With RS=0,busy flag is checked to see if LCD is ready to receive information.The busy flag is D7 and
can be read when R/W=1 and RS=0.When D7=1,LCD is is busy and will not accept any new
information.When RS=0,ready to receive to new information.Busy flag should be checked before
writing to the LCD.
Pin descriptions of LCD.
Pin Symbol I/O Description
1 Vss - GROUND
2 Vcc - +5V power supply
3 Vee - Power supply to control contrast
4 RS I RS=0 to select command register
RS=1 to select data register
5 R/W I R/W=1 for write,R/W=1 for read
6 E I/O Enable
7 DB0 I/O THE 8-bit data bus
8 DB1 I/O THE 8-bit data bus
9 DB2 I/O THE 8-bit data bus
10 DB3 I/O THE 8-bit data bus
11 DB4 I/O THE 8-bit data bus
12 DB5 I/O THE 8-bit data bus
13 DB6 I/O THE 8-bit data bus
14 DB7 I/O THE 8-bit data bus
-
8/6/2019 Micro Controller Assignment 3
3/9
ALP to display MSRIT:
ORG 0
MOV DPTR,#MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some delay
JZ SEND_DAT
INC DPTR
SJMP C1
SEND_ DAT:
MOV DPTR,#MYDATAD1: CLR A
MOVC A,@A+DPTR
RS
R/W
E
D0
D1
:
:
:
D7
P2.0
P2.1
P2.2
P1.0
P1.1
:
:
:
P1.7
LCD PANEL 8051 MICROCONTROLLER
-
8/6/2019 Micro Controller Assignment 3
4/9
ACALL DATAWRT ;call command subroutine
ACALL DELAY ;give LCD some elay
INC DPTR
JZ AGAIN
SJMP D1
AGAIN: SJMP AGAIN ;stay here
COMNWRT : ;send command LCD
MOV P1,A ;send command to P1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for command
SETB P2.2 ;E=1 for high pulse
SETB P2.2 ;give LCD some time
ACALL DELAY ;E=0 for H-t0-L
CLR P2.2
ACALL DELAY
CLR P2.2
RET
DATAWRT:
MOV P1,A ;send data to p1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-l pulse
RET
DELAY: MOV R3,#250 ;long delay for fast CPUs
HERE2: MOV R4,#255
-
8/6/2019 Micro Controller Assignment 3
5/9
HERE: DJNZ R4,#255
DJNZ R3,HERE2
RET
ORG 300H
MYCOM: DB 38H,0EH,01H,06H,80H,0 ;command and null
MYDATA: DB MSRIT,0 ;data nd null
END
8.DRAW 8051 CONNECTION T0 DAC0808 AT PORT P1 AND WRITE A C PROGRAM TO GENERATE
SINE WAVE.
ANS: +5V
8051 DAC0808 +5V
5K
Vout=0 to10V
.1uF
5K
.1uF
-12
In DAC 808 the digital unputs are converted to current (Iout) and by connecting a resistor to the Iout
pin we convert the result to voltage.Iout is a function of digital inputs and reference current as
below.
P1.0
P1.1
:
:
:
P1.7
RD VCC
WR Vref(+)
D0 OUT
D1
:
: Vref( -)
:
D7
VEE COMP GND
1K
-
8/6/2019 Micro Controller Assignment 3
6/9
Iout=Iref( )The Iref current is generally 2mA.The maximum output current,if all inputs to DAC are high is
1.99mA from figure above.
GENERATING SINE WAVE:
Full scale output of DAC is achieved when all data inputs of DAC are high.Therefore, to achieve
fullscale output we use the following equation.
Vout=5V+(5xsin@).
Vout for DAC for various angles is calculated as below at increment of 30 degrees.
Angle @
(degrees)
sin@ Vout(voltage mag)
5V+(5VXsin@)
Values sent to DAC(decimal)
(Voltage magX25.6)0 0 5 128
30 0.5 7.5 192
60 0.866 9.33 238
90 1.0 10 255
120 0.866 9.33 238
150 0.5 7.5 192
180 0 5 128
210 -0.5 2.5 64
240 -0.866 0.669 17
270 -1.0 0 0
300 -0.866 0.699 17
330 -0.5 2.5 64360 0 5 128
C program to generate sine wave:
#include
sfr DACDATA =P1;
void main()
{
Unsigned char wavevalue[12]={128,192,238,255,238,192,128,64,17,0,17,64};
Unsigned char x;
while(1)
{
-
8/6/2019 Micro Controller Assignment 3
7/9
for(x=0;x
-
8/6/2019 Micro Controller Assignment 3
8/9
0 1 DC motor moves moderately(50% duty cycle)
1 0 DC motor moves fast(75% duty cycle)
1 1 DC motor moves very fast(100% duty cycle)
#include
sbit mtr=P1^0;
void msdelay(unsigned int value);
void main()
{
Unsigned char x;
P2=0xFF;
z=P2;
z=z&0x03;
mtr =0;
while (1)
{
switch (z)
{
case(0):
{
mtr=1;
msdelay(25);
mtr=0;
msdelay(75);
break;
}
case(1):
{
mtr=1;
msdelay(50);
-
8/6/2019 Micro Controller Assignment 3
9/9
mtr=0;
msdelay(50);
break;
}
case(2):
{
mtr=1;
msdelay(75);
mtr=0;
msdelay(25);
break;
}
default:
mtr=1;
}
}