MC Lab Manual
MC Lab Manual
VISION
To be the centre of excellence in teaching
and learning to produce the competent &
socially responsible professionals in the
domain of Electrical & Electronics
Engineering.
MISSION
To educate students with core knowledge of
Electrical & Electronics Engineering by
developing problem solving skills,
professional skills and social awareness to
excel in their career.
Microcontroller Laboratory 18EEL57
Microcontroller Laboratory
SEMESTER –V
Course objectives:
1. To explain writing assembly language programs for data transfer, arithmetic, Boolean and
Logical instructions.
2. To explain writing assembly language programs for code conversions.
3. To explain writing assembly language programs using subroutines for generation of delays,
Counters, configuration of SFRs for serial communication and timers.
4. To perform interfacing of stepper motor and dc motor for controlling the speed.
5. To explain generation of different waveforms using DAC interface.
Experiments
Note: For the experiments 1 to 6, 8051 assembly programming is to be used.
1. Data transfer – Program for block data movement, sorting, exchanging, finding largest
element in an array.
2 Arithmetic instructions: Addition, subtraction, multiplication and division. Square and
cube operations for 16 bit numbers.
3 Counters
4 Boolean and logical instructions (bit manipulation).
5 Conditional call and return instructions.
6 Code conversion programs – BCD to ASCII, ASCII to BCD, ASCII to decimal, Decimal
to ASCII, Hexa decimal to and Decimal to Hexa.
7 Programs to generate delay, Programs using serial port and on-chip timer/counters.
Note: Single chip solution for interfacing 8051 is to be with C Programs for the
following experiments.
8 Stepper motor interface.
9 DC motor interface for direction and speed control using PWM.
10 Alphanumerical LCD panel interface.
11 Generate different waveforms: Sine, Square, Triangular, Ramp using DAC interface.
12 External ADC and Temperature control interface.
13 Elevator interface.
Course outcomes:
At the end of the course the student will be able to:
1. Write assembly language programs for data transfer, arithmetic, Boolean and logical
instructions.
2. Write ALP for code conversions.
3. Write ALP using subroutines for generation of delays, counters, configuration of SFRs for
serial communication and timers.
4. Perform interfacing of stepper motor and dc motor for controlling the speed.
5. Generate different waveforms using DAC interface.
6. Work with a small team to carryout experiments using microcontroller concepts and
prepare reports that present lab work.
The most universally employed set of microcontrollers come from the 8051 family. 8051
Microcontrollers persist to be an ideal choice for a huge group of hobbyists and experts. The
original 8051 microcontroller was initially invented by Intel. The two other members of this
8051 family are-
8052-This microcontroller has 3 timers & 256 bytes of RAM. Additionally it has all the
features of the traditional 8051 microcontroller. 8051 microcontroller is a subset of 8052
microcontroller.
8031 - This microcontroller is ROM less, other than that it has all the features of a
traditional 8051 microcontroller. For execution an external ROM of size 64K bytes can
be added to its chip.
8051 microcontroller brings into 2 different sorts of memory such as - NV- RAM,
UV - EPROM and Flash.
FEATURES OF 8051
The programming mode of this micro-controller includes GPRs (general purpose registers),
SFRs (special function registers) and SPRs (special purpose registers).
1. ALU
All arithmetic and logical functions are carried out by the ALU.
Addition, subtraction with carry, and multiplication come under arithmetic operations.
Logical AND, OR and exclusive OR (XOR) come under logical operations.
3. Registers
Registers are usually known as data storage devices. 8051 microcontroller has 2 registers,
namely Register A and Register B. Register A serves as an accumulator while Register B
functions as a general purpose register. These registers are used to store the output of
mathematical and logical instructions. The operations of addition, subtraction, multiplication
and division are carried out by Register A. Register B is usually unused and comes into
picture only when multiplication and division functions are carried out by Register A.
Register A also involved in data transfers between the microcontroller and external memory.
PINOUT DESCRIPTION
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By
applying logic zero to this pin, the program starts execution from the beginning.
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.
Pin 18, 19: XTAL2, XTAL1 are internal oscillator input and output pins. A quartz crystal which
specifies operating frequency is usually connected to these pins. Instead of it, miniature
ceramics resonators can also be used for frequency stability. Later versions of
microcontrollers operate at a frequency of 0 Hz up to over 50 Hz.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher address
byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of
64Kb is not used, which means that not all eight port bits are used for its addressing, the rest
of them are not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower
address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the
ALE pin, the external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the
state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is
returned its previous logic state and P0 is now used as a Data Bus. As seen, port data
multiplexing is performed by means of only one additional (and cheap) integrated circuit. In
other words, this port is used for both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even
there is a program written to the microcontroller, it will not be executed. Instead, the program
written to external ROM will be executed. By applying logic one to the EA pin, the
microcontroller will use both memories, first internal then external (if exists).
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE
pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
1. Keil uVision 3
2. Flash Magic
Double Click on ATMEL from the wizard then select AT89c51 and Press OK
Micro vision 3 will load 8051 Microcontroller Projects file and Display as :
Type the program in the work space window. Now save the file and right click source group
1
Select Add files to group source group Let the files be in ASM. Select the corresponding file
from the list and click OK.
To assemble select build target, if no error(s) are found the output window will display.
If error(s) are found then select Rebuild Target and then the Programmer will find it
easy to correct the error(s).
d) Debugging
To debug Click on debug button.
For memory display, select Memory window icon under View option. Enter the bytes(s) at
memory window (address). Now Click on Run button to run the program continuously. After
debugging ends the value will be stored in registers memory and will also be displayed in
memory window.
2. Flash Magic
Generally we use ISP (In System Programming) when it comes to micro controllers with
flash memory. One of the basic software for such purpose is FLASH MAGIC .
Steps:
1. Click on the icon “flash magic”.
4. Click on “browse” and select the .hex file to be loaded on the chip.
5. Click on “start” and following window will appear and it will ask “reset
8. After completion of loading .hex file into chip, it will show as “finished”.
9. Now press “reset” switch from flash board and the device starts executing the program loaded
in it.
Sl.
List of Experiments
No.
1 Data transfer – Program for block data movement, sorting, exchanging, finding
largest element in an array
1a) Write an ALP to move a block of data from one internal memory location to other.
1b) Write an ALP to move a block of data from one external memory location to other
1c) Write an ALP to exchange a block of data from one internal memory location to other.
1d) Write an ALP to exchange a block of data from one external memory location to other
1e) Write an ALP to find smallest number in the array.
1f) Write an ALP to find largest number in an array.
1g) Write an ALP to arrange numbers in ascending order.
1h) Write an ALP to arrange numbers in descending order.
2 Arithmetic instructions: Addition, subtraction, multiplication and division.
Square and cube operations for 16 bit numbers.
2a) Write an ALP to find addition of two 8 bit numbers.
2b) Write an ALP to find subtraction of two 8 bit numbers.
2c) Write an ALP to find multiplication of two 8 bit numbers.
2d) Write an ALP to find division of two 8 bit numbers.
2e) Write an ALP to square of a 8 bit numbers.
2f) Write an ALP to cube of a 8 bit numbers.
2g) Write an ALP to find addition of two 16 bit numbers.
2h) Write an ALP to find subtraction of two 16 bit numbers.
2i) Write an ALP to square of a 16 bit numbers.
3 Counter
3a) Write an ALP to generate Hex up counter.
3b) Write an ALP to generate Hex down counter.
3c) Write an ALP to generate BCD up counter
3d) Write an ALP to generate BCD down counter.
4 Boolean and logical instructions (bit manipulation).
4a) Write an ALP to compute the following.
IF X=0; THEN NUM1 (AND) NUM2, IF X=1; THEN NUM1 (OR) NUM2,
IF X=2; THEN NUM1 (XOR) NUM2, ELSE RES =00, RES IS 23H LOCATION
Using logical instructions in byte level.
5 Conditional call and return instructions.
5a) Write a program to toggle all the bits of port 1 continuously by sending the values 55H
and AAH using call and return instructions.
5b) Write an ALP to find factorial of a number using call and return instructions.
Sl.
List of Experiments
No.
Code conversion programs – BCD to ASCII, ASCII to BCD, ASCII to decimal,
6
Decimal to ASCII, Hexa decimal to and Decimal to hexa.
6a) Write an ALP to convert hexadecimal number to decimal number.
6b) Write an ALP to convert decimal number to hexadecimal number.
6c) Write an ALP to convert packed BCD number to ASCII number.
6d) Write an ALP to convert ASCII number to BCD number
Programs to generate delay, Programs using serial port and on-chip
7
timer/counters.
Write an ALP to toggle the content of port 0 continuously using timer delay in
7a)
between.
Write an ALP to transmit characters to a PC HyperTerminal using the serial port and
7b)
display on the serial window.
Interfacing
8 Stepper motor interface.
8a) Write a C program to rotate stepper motor in clockwise/anticlockwise direction.
9 DC motor interface for direction and speed control using PWM.
9a) Write a C program to show the on off control of DC motor.
10 Alphanumerical LCD panel interface.
10a) Write a C program to send letters to LCD using delays.
Generate different waveforms: Sine, Square, Triangular, Ramp using DAC
11
interface.
11a) Write a C program to generate Square wave using DAC interface to 8051.
11b) Write a C program to generate Ramp wave using DAC interface to 8051.
11c) Write a C program to generate triangular wave using DAC interface to 8051.
11d) Write a C program to generate Sine wave using DAC interface to 8051.
12 ADC Interface
12a) Write a C program to interface ADC to measure temperature.
13 Elevator interface.
13a) Write a C program to show control and operation of elevator using 8051.
1a) Write an ALP to move a block of data from one internal memory location to other.
Before Execution
After Execution
1b) Write an ALP to move a block of data from one external memory location to other
LJMP 8000H
ORG 8000H
MOV R0,#04H ;load the counter as 04h (n) in register r0
MOV R1,#81H ;higher byte of initial block=81h in register r1
MOV R2,#85H ;higher byte of memory location where data has to
transfer=85h in reg r2
MOV R3,#00H ;lower byte of both initial and final block=00h in register
r3
UP: MOV DPH,R1 ;DPH=contents of register r1
MOV DPL,R3 ;DPL=contents of register r3
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTR
into reg A
MOV DPH,R2 ;dph=contents of register r2
MOVX @DPTR,A ;copy the contents of reg A into memory location pointed
by reg dptr
INC R3 ;increment register r3
DJNZ R0,UP ;decrement register r0 if not equal to zero jump to up
LCALL 0003H ;end of asm file
Before Execution
After Execution
1c) Write an ALP to exchange a block of data from one internal memory location to
other.
LJMP 8000H
ORG 8000H
MOV R0,#30H ;r0=30h i.e. initial block memory location
MOV R1,#40H ;r1=40h i.e. block memory location where data has to
transfer
MOV R4,#04H ; load counter as 04h (n) in register r4
UP: MOV A,@R0 ;copy the contents of memory location pointed by
register r0 into A
MOV R6,A ;copy the contents of register A into memory location
pointed by reg r6
MOV A,@R1 ;copy the contents of memory location pointed by
register r1 into reg A
MOV @R0,A ;copy the contents of register A into memory location
pointed by reg r0
MOV A,R6 ;copy the contents of r6 in register A
MOV @R1,A ;copy the contents of register A into memory location
pointed by reg r1
INC R0 ;increment register r0
INC R1 ;increment register r1
DJNZ R4,UP ;decrement register r4 if not equal to zero jump to up
LCALL 0003H ;end of asm file
Before Execution
After Execution
1d) Write an ALP to exchange a block of data from one external memory location to
other
Before Execution
After Execution
SKIP: DJNZ R0,AGAIN ;decrement register r0 if not equal to zero jump to again
Before Execution
After Execution
Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV ;dptr=8500h
DPTR,#8500H
MOV R0,#04H ;load counter as 04h (n-1) in register r0
MOVX A,@DPTR ;contents of memory location pointed by DPTR are copied
in reg A
MOV B,A ; move the content of A into B register
AGAIN: INC DPTR ; increment DPTR
MOVX A,@DPTR contents of memory location pointed by DPTR are copied
in reg A
CJNE A,B,NEXT ;compare a and b if not equal jump to next
AJMP SKIP ;absolute jump to skip
SKIP: DJNZ R0,AGAIN ;decrement register r0 if not equal to zero jump to again
MOV ;dptr=9000h
DPTR,#9000H
MOVX @DPTR,A ;store the largest number in 9000h
LCALL 0003H ;end of asm file
Before Execution
After Execution
Before Execution
After Execution
Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV R0,#04H ;load the outer counter as 04h (n-1) in register r0
AGAIN: MOV DPTR,#8500H ;dptr=8500h
MOV R1,#04H ;load the inner counter as 04h (n-1) in register r1
BACK: MOV R2,DPL ;dptr=contents of r2
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTR
into reg A
MOV B,A ;copy the contents of register A in register B
INC DPTR ;increment the dptr
MOVX A,@DPTR ;copy the contents of memory location pointed by reg
DPTR into reg A
CJNE A,B,NEXT ;compare a and b if equal jump to next
AJMP SKIP ;absolute jump to skip
NEXT: JC SKIP ;jump if carry to skip
MOV DPL,R2 ;DPL=contents of register r2
MOVX @DPTR,A ;copy the contents of reg A into memory location pointed
by reg DPTR
INC DPTR ;increment DPTR
MOV A,B ;copy the contents of register B in register A
MOVX @DPTR,A ;copy the contents of register a into memory location
pointed by DPTR
SKIP: DJNZ R1, BACK ;decrement register r1 if not equal to zero jump to Back
DJNZ R0,AGAIN ;decrement register r0 if not equal to zero jump to again
LCALL 0003H ;end of asm file
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;store the number in register a from memory location
8500h
MOV B,A ;copy the number in register B
INC DPTR ;dptr=8501h
MOVX A,@DPTR ; store the number in register a from memory location
8501h
MUL AB ;multiply A and B
INC DPTR ;increment DPTR
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the higher byte in memory location in 8501h
MOV A,B ;copy the contents of register b in register a
DEC DPL ;decrement DPL
MOVX @DPTR,A ;store the lower byte in memory location 8502h
LCALL 0003H ;end of asm file
Before Execution
After Execution
LJMP 8000H
ORG 8000H
MOV DPTR,#8501H ;dptr=8501h
MOVX A,@DPTR ;store the number in register a from memory location
8500h
MOV B,A ;copy the number in register B
DEC DPL ; dptr=8500h
MOVX A, @DPTR store the number in register a from memory location
8501h
DIV AB ;divide A by B
MOV DPTR, #9500H ;increment DPTR
MOVX @DPTR,A ;store the quotient in memory location in 9500h
MOV A,B ;store the reminder in register b
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the reminder in memory location 9501h
LCALL 0003H ;end of asm file
Before Execution
After Execution
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;store the number in register a from memory location
8500h
MOV B,A ;copy the number in register B
MUL AB ;multiply A and B
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the higher byte in memory location in 8501h
MOV A,B ;copy the contents of register b in register a
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the lower byte in memory location 8502h
LCALL 0003H ;end of asm file
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
3 Counter
3a) Write an ALP to generate Hex up counter.
3b) Write an ALP to generate Hex down counter.
3c) Write an ALP to generate BCD up counter
3d) Write an ALP to generate BCD down counter.
5a) Write a program to toggle all the bits of port 1 continuously by sending the values
55H and AAH using call and return instructions.
Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV R5, #05H ; r5=05h
GO: MOV A, #55H ;a=55h
MOV P1, A ; ;store the number in from memory location
LCALL 300H ; Long call to 300h i.e delay program
MOV A, #0AAH ; move the content aaH to A
MOV P1, A ; move the content of A in P1
LCALL 300H ; Long call to 300h i.e delay program
DJNZ R5, GO ; R5=R5-1, if R5 is not equal to zero then jump to go
LCALL 0003H ; Long call to 300h i.e delay program
ORG 300H ; Start delay program
HERE: MOV R0, #0FFH ; R0=FFH
BACK1: MOV R1, #0FFH ; R1=FFH
BACK: DJNZ R2, BACK ; R2=R2-1, if R2 is not equal to zero then jump to back
DJNZ R1, BACK1 ; R1=R1-1, if R1 is not equal to zero then jump to back1
DJNZ R0, HERE ; R0=R0-1, if R2 is not equal to zero then jump to here
RET ; Return to main program
5b) Write an ALP to find factorial of a number using call and return instructions.
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
Before Execution
After Execution
7a) Write an ALP to toggle the content of port 0 continuously using timer delay in
between.
Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV R0, #0AH ; R0=0AH
GO: MOV A, #55H ; A=55H
MOV P0, A ; Move the content of A in P0
ACALL DELAY ; Call delay program
MOV A, #0AAH ; A=AAh
MOV P0, A ; Move the content of A in P0
ACALL DELAY ; Call delay program
DJNZ R0, GO ; R0=R0-1, if R0 is not equal to zero then jump to go
LCALL 0003H ; End of main program
DELAY: MOV TMOD, #01H ; Load TMOD
START: MOV TL0, #00H ; Load TL0
MOV TH0, #00H ;Load TH0
SETB TR0 ; TR0=1;
HERE: JNB TF0, HERE ;if TF0 is not equal 1 then jump to here
CLR TR0 ; TR0=0
CLR TF0 ;TF0=0
RET ;Return to main program
7b) Write an ALP to transmit characters to a PC HyperTerminal using the serial port and
display on the serial window.
LJMP 8000H
ORG 8000H
MOV TMOD, #20H ; TMOD= 20H
MOV TH1, #-3 ;TH1=-3H
MOV SCON, #50H ;SCON= 50H
SETB TR1 ;TR1=1;
MOV A, #‟H‟ ;Load letter „H‟ in A
ACALL TRANS ;Call transmit program
MOV A, #‟I‟ ;Load letter „I‟ in A
ACALL TRANS ;Call transmit program
MOV A, #‟T‟ ;Load letter „T‟ in A
ACALL TRANS ;Call transmit program
LCALL 0003H ;Stop the program
TRANS: MOV SBUF, A ; Load SBUF with letter stored in A
HERE: JNB TI, HERE ; if TI is not equal 1 jump to here
CLR TI ; Clear TI
RET ; Return
END ; End
After Execution
#include<reg51.h> else
{
sbit sw=P1^6; P2=0xcc;
delay(22000);
void delay(unsigned int ); P2=0x99;
delay(22000);
void main() P2=0x33;
{ delay(22000);
sw=1; P2=0x66;
while(1) delay(22000);
{ }
if(sw==0) }
{ }
P2=0x66;
delay(22000); void delay(unsigned int itime)
P2=0x33; {
delay(22000); unsigned int I, j;
P2=0x99; for(i=0;i<=itime;i++);
delay(22000); for(j=0;j<=6000;j++);
P2=0xcc; }
delay(22000);
}
#include<reg51.h>
sbit ok=P2^4;
void main(void)
{
TCON=0;
TMOD=0x20;
while(1)
{
ok=0;
turn_onoff(50000);
ok=1;
turn_onoff(50000);
}
}
11a) Write a C program to generate Square wave using DAC interface to 8051.
11b) Write a C program to generate Ramp wave using DAC interface to 8051.
11c) Write a C program to generate triangular wave using DAC interface to 8051.
11d) Write a C program to generate Sine wave using DAC interface to 8051.
11a) Write a C program to generate Square wave using DAC interface to 8051.
#include<reg51.h>
void delay(unsigned int );
void main(void)
{
while(1)
{
P1=0x00;
delay(250);
P1=0xff;
delay(250);
}
}
11b) Write a C program to generate Ramp wave using DAC interface to 8051.
#include<reg51.h>
void delay(unsigned int );
void main(void)
{
unsigned int i;
while(1)
{
for(i=0;i<255;i++)
{
P1=i;
delay(2);
}
}
}
11c) Write a C program to generate triangular wave using DAC interface to 8051.
#include<reg51.h>
void delay(unsigned int );
void main(void)
{
unsigned int i,j;
while(1)
{
for(i=0;i<255;i++)
{
P1=i;
delay(2);
}
for(j=255;j>0;j--)
{
P1=j;
delay(2);
}
}
}
11d) Write a C program to generate Sine wave using DAC interface to 8051.
#include<reg51.h>
sfr dacdata=0x90;
void main(void)
{
unsigned char sine_value[12]={128, 192,238,255,238,192,128,64,17,0,17,64};
unsigned int x;
while(1)
{
for(x=0;x<12;x++)
dacdata=sine_value[x];
}
}
12 Elevator interface.
12a) Write a C program to show control and operation of elevator using 8051.
12a) Write a C program to show control and operation of elevator using 8051.
#include<reg51.h>
void delay (unsigned int);
main()
{
unsigned char Flr[9]={0xff,0x00,0x03,0xff,0x06,0xff,0xff,0xff,0x09};
unsigned char Fclr[9]={0xff,0x0e0,0x0d3,0xff,0x0b6,0xff,0xff,0xff,0x79};
unsigned char ReqFlr, CurFlr=0x01, i,j;
P0=0x00;
P0=0x0f0;
while(1)
{
P1=0x0f;
ReqFlr=P1|0x0f0;
while(ReqFlr==0x0ff)
ReqFlr=P1|0x0f0;
ReqFlr=~ReqFlr;
if(CurFlr==ReqFlr)
{
P0=FClr[CurFlr];
continue;
}
else if (CurFlr>ReqFlr)
{
i=Flr[CurFlr]-Flr[ReqFlr];
j=Flr[CurFlr];
for(;i>0;i--)
{
P0=0x0f0|j;
j--;
delay(50000);
}
}
else
{
i=Flr[ReqFlr]-Flr[CurFlr];
j=Flr[CurFlr];
for(;i>0;i--)
{
P0=0x0f0|j;
j++;
delay(50000);
}
}
CurFlr=ReqFlr;
P0=FClr[CurFlr];
}
}
void delay(unsigned int x)
{
for(;x>0;x--);
}
13 ADC Interface
13a) Write a C program to interface ADC to measure temperature.
#include<reg51.h>
sbit cs=P2^0;
sbit rd=P2^1;
sbit wr=P2^2;
sbit intr=P2^3;
main()
{
int result;
P1=255;
P2=0;
P0=0;
while(1)
{
cs=0;
wr=0;
delay(50);
wr=1;
while(intr!=0);
cs=0;
rd=1;
delay(50);
rd=0;
result=P1;
P0=(((result/10)*16)+(result%10));
}
}
Circuit Diagram
As per the datasheet LM35 gives output of 10mV per degree centigrade of temperature.
Example:
Room Temperature in Degrees 28 Decimal 1C Hex
LM 35 Output (DC) 280mV=0.28V
1C Hex
ADC 0804 Output
0 0 0 1 1 1 0 0
(28/10 X 16) + (28%20) (1C%0A) X 10) + (1C%0A)
Conversion Formula
Decimal Hex
Conversion Formula Result 32+8= 40 Decimal 20+8= 28 Hex
Output of Port P0 is given to 2 (MSB) 8 (LSB)
7447 display driver to display it
0 0 1 0 1 0 0 0
on 7 segment display
7-segment display