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

Q1. Draw the pin diagram of 8051 microcontroller and explain the role of each pin in brief.

8051 microcontroller is a 40 pin Dual Inline Package (DIP). These 40 pins serve different
functions like read, write, I/O operations, interrupts etc. 8051 has four I/O ports wherein each
port has 8 pins which can be configured as input or output depending upon the logic state of
the pins. Therefore, 32 out of these 40 pins are dedicated to I/O ports. The rest of the pins are
dedicated to VCC, GND, XTAL1, XTAL2, RST, ALE, EA’ and PSEN’.

Description of the Pins :

Pin 1 to Pin 8 (Port 1) –

Pin 1 to Pin 8 are assigned to Port 1 for simple I/O operations. They can be configured as
input or output pins depending on the logic control i.e. if logic zero (0) is applied to the I/O
port it will act as an output pin and if logic one (1) is applied the pin will act as an input pin.
These pins are also referred to as P1.0 to P1.7 (where P1 indicates that it is a pin in port 1 and
the number after ‘.’ tells the pin number i.e. 0 indicates first pin of the port. So, P1.0 means
first pin of port 1, P1.1 means second pin of the port 1 and so on). These pins are
bidirectional pins.

Pin 9 (RST) –

Reset pin. It is an active-high, input pin. Therefore if the RST pin is high for a minimum of 2
machine cycles, the microcontroller will reset i.e. it will close and terminate all activities. It is
often referred as “power-on-reset” pin because it is used to reset the microcontroller to it’s
initial values when power is on (high).

Pin 10 to Pin 17 (Port 3) –

Pin 10 to pin 17 are port 3 pins which are also referred to as P3.0 to P3.7. These pins are
similar to port 1 and can be used as universal input or output pins. These pins are
bidirectional pins.

These pins also have some additional functions which are as follows:

P3.0 (RXD) :

10th pin is RXD (serial data receive pin) which is for serial input. Through this input signal
microcontroller receives data for serial communication.

P3.1 (TXD) :

11th pin is TXD (serial data transmit pin) which is serial output pin. Through this output
signal microcontroller transmits data for serial communication.

P3.2 and P3.3 (INT0′, INT1′ ) :

12th and 13th pins are for External Hardware Interrupt 0 and Interrupt 1 respectively. When
this interrupt is activated(i.e. when it is low), 8051 gets interrupted in whatever it is doing and
jumps to the vector value of the interrupt (0003H for INT0 and 0013H for INT1) and starts
performing Interrupt Service Routine (ISR) from that vector location.

P3.4 and P3.5 (T0 and T1) :

14th and 15th pin are for Timer 0 and Timer 1 external input. They can be connected with 16
bit timer/counter.

P3.6 (WR’) :

16th pin is for external memory write i.e. writing data to the external memory.

P3.7 (RD’) :

17th pin is for external memory read i.e. reading data from external memory.
Pin 18 and Pin 19 (XTAL2 And XTAL1) –

These pins are connected to an external oscillator which is generally a quartz crystal
oscillator. They are used to provide an external clock frequency of 4MHz to 30MHz. Pin 20
(GND) –

This pin is connected to the ground. It has to be provided with 0V power supply. Hence it is
connected to the negative terminal of the power supply.

Pin 21 to Pin 28 (Port 2) –

Pin 21 to pin 28 are port 2 pins also referred to as P2.0 to P2.7. When additional external
memory is interfaced with the 8051 microcontroller, pins of port 2 act as higher-order address
bytes. These pins are bidirectional.

Pin 29 (PSEN) –

PSEN stands for Program Store Enable. It is output, active-low pin. This is used to read
external memory. In 8031 based system where external ROM holds the program code, this
pin is connected to the OE pin of the ROM.

Pin 30 (ALE/ PROG) –

ALE stands for Address Latch Enable. It is input, active-high pin. This pin is used to
distinguish between memory chips when multiple memory chips are used. It is also used to
de-multiplex the multiplexed address and data signals available at port 0.

During flash programming i.e. Programming of EPROM, this pin acts as program pulse input
(PROG).

Pin 31 (EA/ VPP) –


EA stands for External Access input. It is used to enable/disable external memory interfacing.
In 8051, EA is connected to Vcc as it comes with on-chip ROM to store programs. For other
family members such as 8031 and 8032 in which there is no on-chip ROM, the EA pin is
connected to the GND.

Pin 32 to Pin 39 (Port 0) –

Pin 32 to pin 39 are port 0 pins also referred to as P0.0 to P0.7. They are bidirectional
input/output pins. They don’t have any internal pull-ups. Hence, 10 K? pull-up registers are
used as external pull-ups. Port 0 is also designated as AD0-AD7 because 8051 multiplexes
address and data through port 0 to save pins.

Pin 40 (VCC) –

This pin provides power supply voltage i.e. +5 Volts to the circuit.

Q2. Describe the architecture of 8051 microcontroller with the help of neat diagram.

The 8051 Microcontroller is one of the basic type of microcontroller, designed by Intel in
1980’s. This microcontroller was based on Harvard Architecture and developed primarily for
use in embedded systems technology. Normally, this microcontroller was developed using
NMOS technology, which requires more power to operate. Therefore, Intel redesigned
Microcontroller 8051 using CMOS technology and their updated versions came with a letter
C in their name, for instance an 80C51 it is an 8 bit microcontroller. These latest
Microcontrollers requires less power to operate as compared to their previous versions. The
8051 Microcontroller has two buses and two memory spaces of 64K X 8 size for program
and data units. It has an 8 bit processing unit and 8 bit accumulator units.
Central Processor Unit (CPU)

the CPU is the brain of any processing device of the microcontroller. It monitors and controls
all operations that are performed on the Microcontroller units. The User has no control over
the work of the CPU directly . It reads program written in ROM memory and executes them
and do the expected task of that application.

Interrupts

As its name suggests, Interrupt is a subroutine call that interrupts of the microcontrollers
main operations or work and causes it to execute any other program, which is more
important at the time of operation. The feature of Interrupt is very useful as it helps in case of
emergency operations. An Interrupts gives us a mechanism to put on hold the ongoing
operations, execute a subroutine and then again resumes to another type of operations.

The Microcontroller 8051 can be configured in such a way that it temporarily terminates or
pause the main program at the occurrence of interrupts. When a subroutine is completed,
Then the execution of main program starts. Generally five interrupt sources are there in 8051
Microcontroller. There are 5 vectored interrupts are shown in below INTO

 TFO
 INT1
 TF1
 R1/T1
Out of these, (INT0) ̅ and (INT1) ̅ are external interrupts that could be negative edge
triggered or low level triggered. When All these interrupts are activated, set the
corresponding flogs except for serial interrupt,.The interrupt flags are cleared when the
processor branches to the interrupt service routine (ISR). The external interrupt flags are
cleared when the processor branches to the interrupt service routine, provides the interrupt is
a negative edge triggered whereas the timers and serial port interrupts two of them are
external interrupts, two of them are timer interrupts and one serial port interrupt terminal in
general.

Memory

Microcontroller requires a program which is a collection of instructions. This program tells


microcontroller to do specific tasks. These programs require a memory on which these can be
saved and read by Microcontroller to perform specific operations of a particular task. The
memory which is used to store the program of the microcontroller is known as code memory
or Program memory of applications. It is known as ROM memory of microcontroller also
requires a memory to store data or operands temporarily of the micro controller. The data
memory of the 8051 is used to store data temporarily for operation is known RAM memory.
8051 microcontroller has 4K of code memory or program memory,that has 4KB ROM and
also 128 bytes of data memory of RAM.

BUS

Basically Bus is a collection of wires which work as a communication channel or medium for
transfer of Data. These buses consists of 8, 16 or more wires of the microcontroller. Thus,
these can carry 8 bits,16 bits simultaneously. Hire two types of buses that are shown in below

Address Bus

Data Bus

Address Bus: Microcontroller 8051 has a 16 bit address bus for transferring the data. It is
used to address memory locations and to transfer the address from CPU to Memory of the
microcontroller. It has four addressing modes that are

Immediate addressing modes.


Bank address (or) Register addressing mode.

Direct Addressing mode.

Register indirect addressing mode.

Data Bus: Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of
particular applications.

Oscillator

Generally, we know that the microcontroller is a device, therefore it requires clock pulses for
its operation of microcontroller applications. For this purpose, microcontroller 8051 has an
on-chip oscillator which works as a clock source for Central Processing Unit of the
microcontroller. The output pulses of oscillator are stable. Therefore, it enables synchronized
work of all parts of the 8051 Microcontroller.

Input/Output Port

Normally microcontroller is used in embedded systems to control the operation of machines


in the microcontroller. Therefore, to connect  it to other machines, devices or peripherals we
require I/O interfacing ports in  the microcontroller interface. For this purpose
microcontroller 8051 has 4 input, output ports to connect it to the other peripherals

Timers/Counters

8051 microcontroller has two 16 bit timers and counters. These counters are again divided
into a 8 bit register. The timers are used for measurement of intervals to determine the pulse
width of pulses.

Q3. Define and explain the addressing modes of 8051 microcontroller.

What is an Addressing Mode?

An Addressing Mode is a way to locate a target Data, which is also called as Operand. The
8051 Family of Microcontrollers allows five types of Addressing Modes for addressing the
Operands. They are:

 Immediate Addressing
 Register Addressing
 Direct Addressing
 Register – Indirect Addressing
 Indexed Addressing

Immediate Addressing

In Immediate Addressing mode, the operand, which follows the Opcode, is a constant data of
either 8 or 16 bits. The name Immediate Addressing came from the fact that the constant data
to be stored in the memory immediately follows the Opcode.

The constant value to be stored is specified in the instruction itself rather than taking from a
register. The destination register to which the constant data must be copied should be the
same size as the operand mentioned in the instruction.

Example:  MOV A, #030H 

Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand indicates that it
is a data and not the address of a Register.

Immediate Addressing is very fast as the data to be loaded is given in the instruction itself.

Register Addressing

In the 8051 Microcontroller Memory Organization Tutorial, we have seen the organization of
RAM and four banks of Working Registers with eight Registers in each bank.

In Register Addressing mode, one of the eight registers (R0 – R7) is specified as Operand in
the Instruction.

It is important to select the appropriate Bank with the help of PSW Register. Let us see a
example of Register Addressing assuming that Bank0 is selected.

Example:  MOV A, R5 

Here, the 8-bit content of the Register R5 of Bank0 is moved to the Accumulator.

Direct Addressing
In Direct Addressing Mode, the address of the data is specified as the Operand in the
instruction. Using Direct Addressing Mode, we can access any register or on-chip variable.
This includes general purpose RAM, SFRs, I/O Ports, Control registers.

Example:  MOV A, 47H 

Here, the data in the RAM location 47H is moved to the Accumulator.

Register Indirect Addressing

In the Indirect Addressing Mode or Register Indirect Addressing Mode, the address of the
Operand is specified as the content of a Register. This will be clearer with an example.

Example:  MOV A, @R1 

The @ symbol indicates that the addressing mode is indirect. If the contents of R1 is 56H, for
example, then the operand is in the internal RAM location 56H. If the contents of the RAM
location 56H is 24H, then 24H is moved into accumulator.

Only R0 and R1 are allowed in Indirect Addressing Mode. These register in the indirect
addressing mode are called as Pointer registers.

Indexed Addressing Mode

With Indexed Addressing Mode, the effective address of the Operand is the sum of a base
register and an offset register. The Base Register can be either Data Pointer (DPTR) or
Program Counter (PC) while the Offset register is the Accumulator (A).

In Indexed Addressing Mode, only MOVC and JMP instructions can be used. Indexed
Addressing Mode is useful when retrieving data from look-up tables.

Example:  MOVC A, @A+DPTR 

Here, the address for the operand is the sum of contents of DPTR and Accumulator.

Q4. Explain the following instructions giving proper format and example of each

i) DAA
ii) SWAP
iii) CALL & RET
iv) PUSH & POP

Q5. Explain Timer/Counter of 8051 microcontroller in detail.

There are two 16-bit timers and counters in 8051 microcontroller: timer 0 and timer 1. Both
timers consist of 16-bit register in which the lower byte is stored in TL and the higher byte is
stored in TH. Timer can be used as a counter as well as for timing operation that depends on
the source of clock pulses to counters.

Timers and counters


Counters and Timers in 8051 microcontroller contain two special function registers: TMOD
(Timer Mode Register) and TCON (Timer Control Register), which are used for activating
and configuring timers and counters.
Timer Mode Control (TMOD): TMOD is an 8-bit register used for selecting timer or
counter and mode of timers. Lower 4-bits are used for control operation of timer 0 or
counter0, and remaining 4-bits are used for control operation of timer1 or counter1.This
register is present in SFR register, the address for SFR register is 89th.

Timer Mode Control (TMOD)


Gate: If the gate bit is set to ‘0’, then we can start and stop the “software” timer in the same
way. If the gate is set to ‘1’, then we can perform hardware timer.
C/T: If the C/T bit is ‘1’, then it is acting as a counter mode, and similarly when set C+
=/T bit is ‘0’; it is acting as a timer mode.
Mode select bits: The M1 and M0 are mode select bits, which are used to select the timer
operations. There are four modes to operate the timers.
Mode 0: This is a 13-bit mode that means the timer operation completes with “8192” pulses.
Mode 1: This is a16-bit mode, which means the timer operation completes with maximum
clock pulses that “65535”.
Mode 2: This mode is an 8-bit auto reload mode, which means the timer operation completes
with only “256” clock pulses.
Mode 3: This mode is a split-timer mode, which means the loading values in T0 and
automatically starts the T1.
Mode Selection Bits

Mode selection Values of timers and counter in 8051

Mode selection values of timers and counters

Timer Control Register (TCON): TCON is another register used to control operations of
counter and timers in microcontrollers. It is an 8-bit register wherein four upper bits are
responsible for timers and counters and lower bits are responsible for interrupts.

Timer Control Register (TCON)

TF1: The TF1 stands for ‘timer1’ flag bit. Whenever calculating the time-delay in timer1, the
TH1 and TL1 reaches to the maximum value that is “FFFF” automatically.
EX: while (TF1==1)

Whenever the TF1=1, then clear the flag bit and stop the timer.

TR1: The TR1 stands for timer1 start or stop bit. This timer starting can be through software
instruction or through hardware method.
EX: gate=0 (start timer 1 through software instruction)
TR1=1; (Start timer)

TF0: The TF0 stands for ‘timer0’ flag-bit. Whenever calculating the time delay in timer1, the
TH0 and TL0 reaches to a maximum value that is ‘FFFF’, automatically.
EX: while (TF0==1)
Whenever the TF0=1, then clear the flag bit and stop the timer.
TR0: The TR0 stands for ‘timer0’ start or stop bit; this timer starting can be through software
instruction or through hardware method.
EX: gate=0 (start timer 1 through software instruction)
TR0=1; (Start timer)

Time Delay Calculations for 8051 Microcontroller

The 8051 microcontroller works with 11.0592 MHz frequency.

Frequency 11.0592MHz=12 pules

1 clock pulse =11.0592MHz/12

F =0.921 MHz

Time delay=1/F

T=1/0.92MHz

T=1.080506 us (for ‘1’ cycle)

1000us=1MS

1000ms=1sec

Procedure to Calculate the Delay Program

1. First we have to load the TMOD register value for ‘Timer0’ and ‘Timer1’in different
modes. For example, if we want to operate timer1 in mode1 it must be configured as
“TMOD=0x10”.

2. Whenever we operate the timer in mode 1, timer takes the maximum pulses of 65535.
Then the calculated time-delay pulses must be subtracted from the maximum pulses, and
afterwards converted to hexadecimal value. This value has to be loaded in timer1 higher bit
and lower bits. This timer operation is programmed using embedded C in a microcontroller.
Example: 500us time delay

500us/1.080806us

461pulses

P=65535-461

P=65074
65074 conveted by hexa decimal =FE32

TH1=0xFE;

TL1=0x32;

3. Start the timer1 “TR1=1;”

4. Monitor the flag bit “while(TF1==1)”

5. Clear the flag bit “TF1=0”

6. Cleat the timer “TR1=0”

Q6. Write an assembly language program of 8051 microcontroller to count the number of
zeros in byte.

Algorithm:

1) Initializing R0 to the numbers to be checked and R1 to the number of bits to be checked.

2) Left or Right rotating the number with carry.

3) Checking whether the carry has zero or one.

4) If the carry is one then incrementing the counter for one and if the carry is zero then
incrementing       the counter for one.

5) Checking the number of bits and repeating the above steps till the goal is reached.

This program finds the number of zeros and ones in binary equivalent number.

 Code

ORG 0000h

LJMP MAIN

ORG 40h

MAIN: MOV R0,#12 ; number to be checked whether zero or one

MOV R1,#08 ; number of bits to be checked

MOV A,R0
LOOP: RLC A ; left rotating it to check each bit of number

JC LABEL1 ; if the bit is one jumping to one's counter

INC R2 ; incrementing the counter for zero bit

SJMP LABEL2

LABEL1:INC R3 ;incrementing the counter for zero bit

LABEL2:DJNZ R1,LOOP ; checking the counter of bits

END

Q7. Write an assembly language program of 8051 microcontroller to find the sum of 10
numbers stored in an array. Draw the flow chart to specify the steps of the design flow.

Algorithm:

1. Start
2. Store the value(N) up to which sum has to be found in a register(Ra)
3. Initialize a register(Rb) to 1
4. Enter the loop
 Add Rb and Accumulator register(A) and store the value in A
 Increment Rb
 Decrement and check whether Ra is zero
o If Ra is zero exit the loop and move value stored in A to destination register(Rd)
o Else, jump back and repeat the steps in loop
5. Stop

here is an example code to find the sum of first 10 natural numbers.


Code:
ORG OOOOh

LJMP main

ORG 0x40h

main:
MOV R0,#0Ah ; N=10 value

MOV R1,#01h #initialise counter to 1

loop:

ADD A,R1 #add counter to sum

INC R1

DJNZ R0, loop

MOV R4,A ; Final result is stored in register R4

end

Q8. In a semester, a student has to take six courses. The marks of the student (out of 25) are
stored in RAM location 47H onward. Find the average marks and output it on port 1.

MOV R1, #04 ; R1 NUMBER OF COURSES FOR COUNTING


MOV B, #O4 ; B AGAIN NUMBER OF COURSES FOR DIVISION
MOV R0, #30H ; RAM STARTING ADDRESS
MOV A, #0 ;
LOOP: ADD A, @R0 ; WHERE @R0 REFERS TO DATA AT LOCATION 30H
INC R0 ;
DJNZ R1, LOOP ; REPEAT ADDITION UNTIL R1 = 0
DIV AB ; CAUSE ONLY DIVISION OPERATION AVAILABLE
MOV P1, A ; IGNORE REMAINDER AND OUTPUT PORT 1 THE AVERAGE

END ; END OF PROGRAM

Q9. WAP to generate a pulse of 2 kHz on port P1.1 (Assume that XTAL = 11.0592 MHz).

(a) T = 1 / f = 1 / 2 kHz = 500 us the period of square wave.

(b) 1 / 2 of it for the high and low portion of the pulse is 250 us.

(c) 250 us / 1.085 us = 230 and 65536 – 230 = 65306 which in hex is FF1AH.

(d) TL = 1A and TH = FF, all in hex. The program is as follow.

MOV TMOD,#01 ;Timer 0, 16-bitmode

AGAIN: MOV TL1,#1AH ;TL1=1A, low byte of timer


MOV TH1,#0FFH ;TH1=FF, the high byte

SETB TR1 ;Start timer 1

BACK: JNB TF1,BACK ;until timer rolls over

CLR TR1 ;Stop the timer 1

CLR P1.5 ;Clear timer flag 1

CLR TF1 ;Clear timer 1 flag

SJMP AGAIN ;Reload timer

Q10. Write an 8051 assembly language program that creates a square wave of 10 kHz on
P1.0 using Timer0. (Assume crystal oscillator frequency = 12 MHz)

Same as previous find values for 10KHz

Q11. What value do we need to load the timer’s register if we want to have a time delay of 5
milliseconds? Show the program for timer 0 to create pulse width of 5 milliseconds on P2.3.
(Assume that XTAL = 11.0592 MHz)

MOV TMOD,#01 ;Timer 0, mode 1(16-bit mode)

HERE: MOV TL0,#0FFH ;TL0=F2H, the low byte

MOV TH0,#DBH ;TH0=FFH, the high byte

SETB TR0 ;start the timer 0

AGAIN: JNB TF0,AGAIN ;monitor timer flag 0 until it rolls over

CLR TR0 ;stop timer 0

CLR TF0 ;clear timer 0 flag

RET

Q12. Write an assembly language program for the 8051 to transfer “MANAV” serially at
9600 baud, 8-bit data, 1 stop bit, do this continuously.

ORG 0

MOV P2, #0FFH ; make P2 an input port

MOV TMOD,#20H ;timer 1, mode 2

MOV TH1, #0FAH ;4800 baud rate

MOV SCON, #50H ; 8-bit, 1 stop, REN enabled

SETB TR1 ; start timer 1


MOV DPTR, #MYDATA ; load pointer for message

H_1: CLR A

MOV A,@A+DPTR ;get the character

JZ B_1 ;if last character get out

ACALL SEND ;otherwise call transfer

INC DPTR ;next one

SJMP H_1 ;stay in loop

B_1: MOV a,P2 ;read data on P2

ACALL SEND ;transfer it serially

ACALL RECV ;get the serial data

MOV P1,A ;display it on LEDs

SJMP B_1 ;stay in loop indefinitely

; ---------serial data transfer. ACC has the data-------------

SEND: MOV SBUF,A ;load the data

H_2: JNB TI,H_2 ;stay here until last bit gone

CLR TI ; get ready for next char

RET ;return to caller

--Receive data serially in ACC----------------

RECV: JNB RI, RECV ; wait here for char

MOV A, SBUF ; save it in ACC

CLR RI ; get ready for next char

RET ; return to caller

; ------------The message---------------

MYDATA: DB “MANAV”, 0

END
Q13. Write an assembly language program for the 8051 to receive bytes of data serially, and
put them in P1, set the baud rate at 4800, 8-bit data and 1 stop bit.

MOV TMOD, #20H ; timer 1,mode 2(auto reload)

MOV TH1, #-3 ; 9600 baud rate

MOV SCON, #50H ; 8-bit, 1 stop, REN enabled

SETB TR1 ; start timer 1

HERE: JNB RI, HERE ; wait for char to come in

MOV A, SBUF ; saving incoming byte in A

MOV P2, A ; send to port 1

CLR RI ; get ready to receive next byte

SJMP HERE ; keep getting data

Q14. Interface 16*2 LCD with 8051 microcontroller and write the assembly language
program to display “12” on it.

What Is  16*2 LCD ?

The LCD ( liquid crystal display) is device to good communicate between user and machine.
It display the Software status, Errors, Indicators, Data as per user program by which a good
Control method and a good communication occurs between user and electronics system and
make a more user Friendly and attractive.

16*2 LCD Display


Features:
Lcd displays are widely used because of its low current consumption as compared to seven
segment displays. And another, it is more attractive to the seven segment display (SSD).

16*2 LCD is mostly used to interfacing of 8051 Microcontroller. LCD Initialization........

Give the Supply and Wait for a Second to Stabilize the Display.

Give the Instruction 38h for Initialize 2 Line display of 5*7 Matrix LCD.

Wait for a few millisecond (approx 5ms) to Complete Operation and LCD take Action as per
given Command.

Give 0fh Command to Display ON & Cursor ON and Blinking.

Wait for some time (approx 5 ms).

Give command 01h to clear the Display of LCD.

Wait for some time (approx 5ms).

Give command 06h for making Increment Cursor mode of LCD. By this, cursor should
increase after every Character is Written to display automatically.

Wait for some time (approx 5 ms).

Give the command 80h for Cursor take position at 1st Line 1st Character.

This above 10 step is Require and Basic Common Instruction for 16*2 LCD Initialization.
Thus it write to start up of every Program Related to the LCD Projects. Then the User can
Program to display the Data or Information on LCD as per requirement of User. This is
Explain with a Short Program example of to Display the "Welcome to Here" on the LCD
Display.

Circuit Diagram:

Circuit diagram of LCD interfacing with 8051 Microcontroller

Circuit diagram of LCD interfacing with 8051 Microcontroller

Assembly Language Program to Display "Welcome to Here" in 16*2 LCD Display:

org 0000h

port_ini:
mov p1,#00h

setb p3.4

setb p3.5

setb p3.6

acall delay_1s

Lcd_ini:

mov a,#38h

acall command

mov a,#06h

acall command

mov a,#0ch

acall command

mov a,#01h

acall command

mov a,#80h

acall command

acall delay_1s

Display:

mov a,#'W'

acall write

mov a,#'e'

acall write

mov a,#'l'

acall write

mov a,#'c'

acall write
mov a,#'o'

acall write

mov a,#'m'

acall write

mov a,#'e'

acall write

mov a,#14h

acall command

mov a,#'t'

acall write

mov a,#'o'

acall write

mov a,#14h

acall command

mov a,#'H'

acall write

mov a,#'e'

acall write

mov a,#'r'

acall write

mov a,#'e'

acall write
here:

sjmp here

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

command:

mov p1,a

clr p3.4

clr p3.5

setb p3.6

acall delay

clr p3.6

acall delay

acall delay

ret

write:

lcall ready

mov p1,a

setb p3.4

clr p3.5

setb p3.6

acall delay

clr p3.6

acall delay

acall delay

ret
ready:

setb p1.7

clr p3.4

setb p3.5

wait:

clr p3.6

acall delay

setb p3.6

jb p1.7,wait

ret

delay:

mov r0,#1ch

rep:

djnz r0,rep

ret

delay_1s:

mov r3,#08h

df1s:

mov r2,#0ffh

d1s:

mov r1,#0ffh

de1s:

djnz r1,de1s

djnz r2,d1s

djnz r3,df1s
ret

end

 How 16*2 LCD Interface With 8051 Microcontroller ?


Command to Operate 16*2 LCD Display Module:

Hex Code Work Function

38h - Initialize 2 line display of 5*7 Matrix.

01h - Clear Display

02h - Cursor Return to Home

04h - Decrement Cursor ( in Left Side )

05h - Shift Display Right

06h - Increment Cursor ( in Right Side )

07h - Shift Display Left Side

08h - Display Off & Cursor Off

0ah - Display Off & Cursor On

0ch - Display On & Cursor Off

0eh - Display On & Cursor On

0fh - Display On & Cursor On and Blinking

10h - Move Cursor One Position Left Side

14h - Move to Cursor One Position Right Side

18h - Shift Entire Display Left Side

1ch - Shift Entire Display Right Side

80h - Move Cursor to Beginning of 1st Line

c0h Move Cursor to Beginning of 2nd Line


Q15. Draw and explain the interfacing of ADC 0804 to 8051 microcontroller. Also write the
assembly language code.

ADC (Analog to digital converter) forms a very essential part in many embedded projects and
this article is about interfacing an ADC to 8051 embedded controller. ADC 0804 is the ADC
used here and before going through the interfacing procedure, we must neatly understand
how the ADC 0804 works. ADC 0804.

ADC0804 is an 8 bit successive approximation analogue to digital converter from National


semiconductors. The features of ADC0804 are differential analogue voltage inputs, 0-5V
input voltage range, no zero adjustment, built in clock generator, reference voltage can be
externally adjusted to convert smaller analogue voltage span to 8 bit resolution etc. The pin
out diagram of ADC0804 is shown in the figure below.

PROGRAM

ORG 00H

MOV P1,#11111111B // initiates P1 as the input port

MAIN: CLR P3.7 // makes CS=0

SETB P3.6 // makes RD high

CLR P3.5 // makes WR low

SETB P3.5 // low to high pulse to WR for starting conversion

WAIT: JB P3.4,WAIT // polls until INTR=0

CLR P3.7 // ensures CS=0

CLR P3.6 // high to low pulse to RD for reading the data from ADC
MOV A,P1 // moves the digital data to accumulator

CPL A // complements the digital data (*see the notes)

MOV P0,A // outputs the data to P0 for the LEDs

SJMP MAIN // jumps back to the MAIN program

END

You might also like