17EC3652 Lab Manual
17EC3652 Lab Manual
Lab Manual
For
17EC3652
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
VELAGAPUDI RAMAKRISHNA
SIDDHARTHA ENGINEERING COLLEGE
(AUTONOMOUS)
(Sponsored by Siddhartha Academy of General & Technical Education)
VIJAYAWADA – 520 007
1
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Course Upon successful completion of the course, the student will be able to:
outcomes
CO1 Develop assembly language programs on 8051 and ARM.
CO2 Interface the peripherals to 8051 and ARM.
Contribution of PO PO PO PO PO PO PO PO PO PO PO PO PS PS
Course a b c d e f g h i j k l PO PO
1 2
Outcomes
towards
achievement of CO1 H H
Program
Outcomes
(L – Low, M -
Medium, H – CO2 H H
High)
Course Content List of lab Exercises:
Experiments Based on 8051:
1. Basic programs on Microcontrollers.
2. Programs on Serial Communication.
3. Programs on Interrupt Mechanism.
4. Programs on Timer/Counter concepts.
5. Programs on LCD Display interfacing.
6. Programs on Traffic Light Control.
Experiments Based on ARM:
1. Basic programs on ARM
2. Interfacing ADC and DAC.
3. Interfacing LED and PWM.
4. Interfacing real time clock and serial port.
5. Interfacing keyboard and LCD.
NB: A minimum of 10(Ten) experiments (5 from each section) have to be performed and
recorded by the candidate to attain eligibility for External Practical Examination
E-resources and 1. http://www.datasheetarchive.com/8051-datasheet.html - (8051
other digital datasheet).
material 2. www.engenuics.com – ARM Cortex-M3 Assembly language.
2
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
The port drivers and how they function both as ports and, for Ports 0 and 2, in bus
operations
The Timer/Counters
The serial Interface
The Interrupt System
Reset
The reduced Power Modes
A map of the on-chip memory area called SFR (Special Function Register) space is
shown in Figure. SFRs marked by parentheses are resident in the microcontrollers which
have the Timer2 feature. Note that not all of the addresses are occupied. Read accesses to
these addresses will in general return random data.
3
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
4
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Stack Pointer The Stack Pointer register is 8 bits wide. It is incremented before data is
stored during PUSH and CALL executions. While the stack may reside anywhere in on-
chip RAM, the Stack Pointer is initialized to 07H after a reset. This causes the stack to
begin at location 08H.
Data Pointer The Data Pointer (DPTR) consists of a high byte (DPH) and a low byte
(DPL). Its intended function is to hold a 16-bit address. It may be manipulated as a 16-bit
register or as two independent 8-bit registers.
Ports 0 to 3 P0, P1, P2 and P3 are the SFR latches of Ports 0, 1, 2 and 3, respectively.
Serial Data Buffer The Serial Data Buffer is actually two separate registers, a transmit
buffer and a receive buffer register. When data is moved to SBUF, it goes to the transmit
buffer where it is held for serial transmission. (Moving a byte to SBUF is what initiates
the transmission.) When data is moved from SBUF, it comes from the receive buffer.
Timer Registers Register pairs (TH0, TL0), (TH1, TL1), and (TH2, TL2) are the 16-bit
counting registers for Timer/Counters 0, 1, and 2, respectively.
Control Registers Special Function Registers IP, IE, TMOD, TCON, T2CON, SCON,
and PCON contain control and status bits for the interrupt system, the timer/counters, and
the serial port. They are described in later sections.
CPU Timing
X1 Mode (Standard Mode): A machine cycle consists of 6 states (12 oscillator periods).
Each state is divided into a Phase 1 half, during which the Phase 1 clock is active, and a
Phase 2 half, during which the Phase 2 clock is active. Thus, a machine cycle consists of
12 oscillator periods, numbered S1P1 (State 1, Phase 1), through S6P2 (State 6, Phase 2).
Each phase lasts for one oscillator period. Each state lasts for two oscillator periods.
Typically, arithmetic and logical operations take place during Phase 1 and internal
register-to-register transfers take place during Phase 2.
5
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Arithmetic Instructions
The menu of arithmetic instructions is listed in below Table. The table indicates the
addressing modes that can be used with each instruction to access the <byte> operand.
The execution times listed in the above Table assume a 12 MHz clock frequency and X1
mode. All of the arithmetic instructions execute in 1 μs except the INC DPTR instruction,
which takes 2 μs, and the Multiply and Divide instructions, which take 4 μs.
One of the INC instructions operates on the 16-bit Data Pointer. The Data Pointer is used
to generate 16-bit addresses for external memory, so being able to increment it in one 16-
bit operation is a useful feature.
The MUL AB instruction multiplies the Accumulator by the data in the B register and
puts the 16-bit product into the concatenated B and Accumulator registers.
The DIV AB instruction divides the Accumulator by the data in the B register and leaves
the 8-bit quotient in the Accumulator, and the 8-bit remainder in the B register.
Logical Instructions
Table shows the list of logical instructions. The instructions that perform Boolean
operations (AND, OR, Exclusive OR, NOT) on bytes perform the operation on a bit-by
bit basis. That is, if the Accumulator contains 00110101B and <byte> contains
01010011B, then ANL A,<byte> will leave the Accumulator holding 00010001B. The
addressing modes that can be used to access the <byte> operand are listed in Table.
Boolean operations can be performed on any byte in the internal Data Memory space
without going through the Accumulator. The XRL <byte>, # data instruction, for
example, offers a quick and easy way to invert port bits, as in
6
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Data Transfers
Internal RAM:
Table shows the menu of instructions that are available for moving data around
within the internal memory spaces, and the addressing modes that can be used with each
one. With a 12 MHz clock, all of these instructions execute in either 1 or 2 μs.
The MOV <dest>, <src> instruction allows data to be transferred between any two
internal RAM or SFR locations without going through the Accumulator. Remember the
Upper 28 bytes of data RAM can be accessed only by indirect, and SFR space only by
direct addressing.
In all 8051 devices, the stack resides in on-chip RAM, and grows upwards. The
PUSH instruction first increments the Stack Pointer (SP), then copies the byte into the
stack. PUSH and POP use only direct addressing to identify the byte being saved or
restored, but the stack itself is accessed by indirect addressing using the SP register.
7
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
The XCH A, <byte> instruction causes the Accumulator and addressed byte to exchange
data. The XCHD A, @ Ri instruction is similar, but only the low nibbles are involved in
the exchange.
Data Transfer Instructions that Access Internal Data Memory Space
External RAM
Table shows a list of the Data Transfer instructions that access external Data Memory.
Only indirect addressing can be used. The choice is whether to use a one-byte address,
@Ri, where Ri can be either R0 or R1 of the selected register bank, or a two byte address,
@DPTR.
Boolean Instructions:
8051 devices contain a complete Boolean (single-bit) processor. The internal RAM
contains 128 addressable bits, and the SFR space can support up to 128 other addressable
bits. All of the port lines are bit-addressable, and each one can be treated as a separate
single-bit port. The instructions that access these bits are not just conditional branches,
but a complete menu of move, set, clear, complement, OR and AND instructions. These
8
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
kinds of bit operations are not easily obtained in other architectures with any amount of
byte-oriented software. The instruction set for the Boolean processor is shown in Table
Jump Instructions :
The table lists a single “JMP addr” instruction, but in fact there are three -SJMP, LJMP,
AJMP -which differ in the format of the destination address. JMP is a generic mnemonic
which can be used if the programmer does not care how the jump is encoded. The SJMP
instruction encodes the destination address as relative offset, as described above. The
instruction is 2 bytes long, consisting of the opcode and the relative offset byte. The jump
distance is limited to range of -128 to + 127 bytes relative to the instruction following the
SJMP.
The LJMP instruction encodes the destination address as a 16-bit constant. The
instruction is 3 bytes long, consisting of the opcode and two address bytes. The
destination address can be anywhere in the 64K Program Memory space. The AJMP
instruction encodes the destination address as an 11-bit constant. The instruction is 2
bytes long, consisting of the opcode, which itself contains 3 of the 11 address bits,
followed by another byte containing the low 8 bits of the destination address. When the
instruction is executed, these 11 bits are simply substituted for the low 11 bits in the PC.
The high 5 bits stay the same. Hence the destination has to be within the same 2K block
as the instruction following the AJMP.
Above Table shows a single “CALL addr” instruction, but there are two of them –
CALL and ACALL -which differ in the format in which the subroutine address is given
to the CPU. CALL is a generic mnemonic which can be used if the programmer does not
care which way the address is encoded.
9
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
The LCALL instruction uses the 16-bit address format, and the subroutine can be
anywhere in the 64K Program Memory space. The ACALL instruction uses the 11-bit
format, and the subroutine must be in the same 2K block as the instruction following the
ACALL. In any case the programmer specifies the subroutine address to the assembler in
the same way: as a label or as a 16-bit constant. The assembler will put the address into
the correct format for the given instructions.
Subroutines should end a RET instruction, which returns execution following the
CALL. RETI is used to return from an interrupt service routine. The only difference
between RET and RETI is that RETI tells the interrupt control system that the interrupt in
progress is done. If there is no interrupt in progress at the time RETI is executed, then the
RETI is functionally identical to RET
Table shows the list of conditional jumps available to the Atmel 8051 user. All of
these jumps specify the destination address by the relative offset method, and so are
limited to a jump distance of -128 to + 127 bytes from the instruction following the
conditional jump instruction. Important to note, however, the user specifies to the
assembler the actual destination address the same way as the other jumps: as a label or a
16-bit constant.
There is no Zero bit in the PSW. The JZ and JNZ instructions test the Accumulator data
for that condition
10
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
11
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
12
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
13
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
14
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
I/O Configurations:
Below Figure shows a functional diagram of a typical bit latch and I/O buffer in each of
the four ports. The bit latch (one bit in the port’s SFR) is represented as a Type D flip-
flop, which will clock in a value from the internal bus in response to a “write to latch”
signal from the CPU. The Q output of the flip-flop is placed on the internal bus in
response to a “read latch” signal from the CPU. The level of the port pin itself is placed
on the internal bus in response to a “read pin” signal from the CPU. Some instructions
that read a port activate the “read latch” signal, and others activate the “read latch” signal,
and others activate the “read pin” signal.
15
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
16
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
TMOD. Modes 0, 1, and 2 are the same for both timer/counters. Mode 3 is different. The
four operating modes are described below.
Timer/Counter x (x = 0 or 1) in Mode 0
17
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Timer/Counter x (x = 0 or 1) in Mode 2
18
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
EXPERIMENT 1a:
Write a Program to find sum of the values and simulate on keil compliler. Assume that
RAM locations 40-44 have the values. At the end R6 should have the low byte and R7 the
high byte.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply
Program:
ORG 00H
MOV R0, #40H ;load pointer
MOV R2, #5 ;load counter
CLR A ;A=0
MOV R7, A ;clear R7
AGAIN: ADD A, @R0 ;add the byte pointer to by R0
JNC NEXT ;if CY=0 don't accumulate carry
INC R7 ;keep track of carries
NEXT: INC R0 ;increment pointer
DJNZ R2, AGAIN ;repeat until R2 is zero
MOV R6, A
END
EXPERIMENT 1B:
Write a Program to convert packed BCD to two ASCII numbers, place them in R2 and R6
and simulate on keil compliler.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply
Program:
ORG 00H
MOV A, #29H ;A=29H, packed BCD
MOV R2, A ;keep a copy of BCD data in R2
ANL A, #0FH ;mask the upper nibble(A=09)
ORL A, #30H ;make it an ASCII, A=39H (`9')
MOV R6, A ;save it (R6=39H ASCII char)
MOV A, R2 ;A=29H;get the original data
ANL A, #0F0H ;mask the lower nibble(A=20)
19
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
RR A ;rotate right
RR A ;rotate right
RR A ;rotate right
RR A ;rotate right,(A=02)
ORL A, #30H ;A=32H,ASCII char.'2'
MOV R2, A ;save ASCII char in R2
END
Viva Questions:
20
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Write a program for RS 232 serial transmission and simulate on keil compiler.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
5. In order to establish communication between PC and Microcontroller, Serial cable
RS232 and voltage converter MAX232 IC are used. This section is available on
the system board.
6. For serial communication, Port 3 (pins 10 and 11 of Microcontroller) are used as
reception and transmission pins respectively.
7. The pins 10 and 11 of Microcontroller are connected to the pins 12 and 11 of
MAX232 IC respectively.
8. Connect one end of the serial cable to the processor and the other end to the DB 9
pin provided on the system board.
9. Check the connections before switching on the mains.
10. An LED is provided in the power supply section of the trainer kit to indicate if the
board is powered or not.
11. After the board is powered up, the message written in the program will be
displayed in the PC in the Hyperterminal window.
12. According to the program written in the microcontroller, the message can be seen
in the Hyperterminal window in the PC.
Program:
ORG 00H
DPTR,#MSG
BACK: CLR A
MOVC A,@A+DPTR ;to load the message into accumulator
; character by character
JZ NEXT
ACALL TRANSMIT ;call subroutine for transmission
INC DPTR
SJMP BACK
21
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
MSG: DB "VRSEC",0
END
Write a program for RS 232 serial reception and simulate on keil compiler.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
5. In order to establish communication between PC and Microcontroller, Serial cable
RS232 and voltage converter MAX232 IC are used. This section is available on
the system board.
6. For serial communication, Port 3 (pins 10 and 11 of Microcontroller) are used as
reception and transmission pins respectively.
7. The pins 10 and 11 of Microcontroller are connected to the pins 12 and 11 of
MAX232 IC respectively.
8. Connect one end of the serial cable to the processor and the other end to the DB 9
pin provided on the system board.
9. Check the connections before switching on the mains.
10. An LED is provided in the power supply section of the trainer kit to indicate if the
board is powered or not.
11. After the board is powered up, open the Hyperterminal window in the PC.
12. According to the program written in the microcontroller, the characters entered in
the Hyperterminal window in the PC can be seen on the LCD display i.e., the
microcontroller receives the data from PC.
22
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Program:
ORG 00H
NEXT: MOV TMOD, #20H ;to select timer 1 in mode 2 (auto reload)
MOV SCON, #50H ; to select serial communication in mode 1
; and receiver enable
MOV TH1, #0FDH ; to set the baud rate to 9600
BACK: SETB TR1 ; to start the timer
JNB RI, $ ;wait for the character to be loaded into sbuf
CLR RI ; clear ri for the next reception
MOV A, SBUF ; To Move The Received Character Into A
ACALL DATA1 ; Call Subroutine For Display On The Lcd
JMP BACK
23
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Viva Questions:
24
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Write a program reads data from P1 and writes it to P2 continuously while giving a copy
of it to the serial COM port to be transferred serially and simulate on keil compiler.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
Program:
ORG 00H
LJMP MAIN
ORG 23H
LJMP SERIAL ;Jump to serial interrupt ISR
ORG 30H
ORG 100H
SERIAL: JB TI, TRANS ; Jump if TI is high
MOV A, SBUF ; Otherwise due to receive
CLR RI ; clear RI since CPU does not
RETI ; return from interrupt
END
Viva Questions:
Write a program to generate 5K Hz square wave on P1.5 (8051 board) and simulate on
keil compiler.
25
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
5. Now connect the Port pin P1.5 of Microcontroller) to the out put device (CRO)
6. Check the connections before switching on the mains.
7. After the board is powered up, the out put will be displayed on the CRO.
8. According to the program written in the microcontroller, the signal will be seen on
the CRO.
Program:
ORG 00H
MOV TMOD, #10H ;timer 1, mode 1(16-bit)
AGAIN: MOV TL1, #34H ;TL1=34H,low byte of timer
MOV TH1, #76H ;TH1=76H,Hi byte (7634H=Timer value)
SETB TR1 ;start the timer 1
BACK: JNB TF1, BACK ;stay till timer rolls over
CLR TR1 ;stop timer 1
CPL P1.5 ;comp. p1.5 to get hi, lo
CLR TF1 ;clear timer flag 1
AGAIN: SJMP AGAIN ;reload timer since mode 1
END
Viva Questions:
26
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
Program:
ORG 00H
END
Viva questions:
27
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
EXPERIMENT 5:
Develop necessary interfacing circuit to display the given data on LCD display and
program to display a message on the LCD and simulate on keil compiler.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. In order to display any message on the LCD, first the LCD should be initialized.
This is done by writing some commands in the programs. LCD contains both data
and commands.
3. 3 Pins for commands and 8 pins for data of LCD are connected to the
microcontroller port pins in the program.
4. Compile it and dump the hex file as per the procedure given above.
5. Place this microcontroller in the trainer kit and fix it properly.
6. Power up the trainer kit from the mains supply.
7. Now connect the Port 1(pins 1 to 8 of Microcontroller) to the data pins of LCD
provided on the system board using 8-pin connector.
8. Similarly connect the Port 2(pins 21, 22, 23 of microcontroller) to the command
pins of LCD provided on the system board using 3-pin connector.
9. Check the connections before switching on the mains.
10. An LED is provided in the power supply section of the trainer kit to indicate if the
board is powered or not.
11. After the board is powered up, the message will be displayed on the LCD.
12. According to the program written in the microcontroller, the message can be seen
on the LCD provided on the system board.
Program:
28
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
ACALL DATA1
MOV A,#'S' ;display letter S
ACALL DATA1
MOV A,#'E' ;display letter E
ACALL DATA1
MOV A,#'C' ;display letter C
ACALL DATA1
SJMP $ ;stay here
Viva Questions:
29
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
EXPERIMENT 6:
Write a program for Traffic Light Control and simulate on keil compiler
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
Program:
ORG 00H
30
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
END
Viva questions:
31
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Program:
i. #include<stdio.h>
ii. #include<stdio.h>
if (i > 10)
return;
printNumber(i);
}
void main() {
printNumber(1);
}
iii. #include<stdio.h>
32
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
int main() {
int a, b;
a = a + b;
b = a - b;
a = a - b;
return (0);
}
Output:
Enter value for num1 & num2: 10 20
iv. #include<stdio.h>
#include<stdlib.h>
int main(){
int a[10],n,i;
system ("cls");
printf("Enter the number to convert: ");
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nBinary of Given Number is=");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}
Output:
Enter the number to convert: 5
Binary of Given Number is=101
Viva Questions:
1. What is ARM?
33
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
34
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
35
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
while(1)
{
adc = ADC_GetAdcReading(); // Read AD0.7 reading
adc=(5*adc)/1023;// Convertion of ADC value in Volts
sprintf(adcreading,"\n ADC0 CH1= %.2f V",adc); // Convert result into ASCII to
display it on LCD
UART0Puts(adcreading) ; // Display result on UART
for(delay=0;delay<60000;delay++);
}
}
Peripheral Interface:
To give analog input from Potentiometer R15 present in Analog Input region on
ADTV1.1. Analog input range is from 0 to 1023.
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories-
>Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate:
19200,
Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)).
Click on OK. Go to Port -> Open. If required Reset the ADT board. Now vary the R15
POT and hence see the change in voltage on Hyper Terminal.
Result:
Thus interfacing of ADC with LPC1768 is executed and verified successfully.
36
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
{
for(AoutValue = 0 ; AoutValue < 1024 ; AoutValue ++) // For loop to count the 1024
times
{
for(delay=0;delay<1000;delay++);
LPC_DAC->DACR = AoutValue << 8 ; //AoutValue is shifted right by 6 bits
} //End of nested for loop
for(AoutValue = 1024 ; AoutValue > 0 ; AoutValue --) // For loop to count the 1024
times
{
for(delay=0;delay<1000;delay++);
LPC_DAC->DACR = AoutValue << 8 ; // AoutValue is shifted right by 6 bits
}
} // End of outer For loop
} // End of Main Function
Connect one pin of oscilloscope to TP2/DAC and another to GND.
Output:
You can see ramp wave on oscilloscope.
Note: Keep S11.2 switch in OFF position, after execution of program
Viva Questions:
1. What is ADC?
2. What is DAC?
3. Applications od ADC and DAC
4. What is successive approximation technique
37
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
38
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Peripheral Interface:
Keep S4.3 switch in ON position.
Output:
You can see RED,BLUE,GREEN color blinking on RGB Led.
Note: Keep S4.3 switch in OFF position, after execution of program
Result:
Thus interfacing of LEDS and PWM(RGB) with LPC1768 is executed and verified
successfully
Viva Questions:
1. Define PWM?
2. What is duty cycle?
3. Difference between timer and counter
4. What is PWMMR?
39
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Aim :
To interface Real Time Clock on Serial UART with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Enable Divisor latch access ,set 8 bit word length, stop bit no parity, disable break
transmission
Step 3: Set UPB bus clock divisor
Step 4: Set UART0 divisor latch(LSB)
Step 5: Set UART0 divisor latch(MSB)
Step 6: Clear TxFIFO and enable Rx and TxFIFOS
Step 7: Wait until Trasnsmit holding register is empty
Step 8: Store to transmit holding register.
Step 9: Wait until Trasnsmit holding register is empty
Step 10: Then Store to transmit holding register.
Step 11: Wait until there’s a character table read
Step 12: Then read from the receiver buffer register.
Program:
#include "LPC17xx.h"
#include "target.h"
#include "UART0.h"
#include <stdio.h>
#include <string.H>
#include "I2C_RTC.h"
#include "Timer.h"
char MAIN_u8buffer1[20];
char MAIN_u8buffer2[20];
#define PCF8523 1
#ifdef PCF8523
#define OFFSET 3
#endif
#ifdef DS1307
#define OFFSET 0
#endif
#define CONTROL_ADDR0 0
#define CONTROL_ADDR1 1
#define CONTROL_ADDR2 2
#define SECONDS_ADDR 3
#define MINUTES_ADDR 4
#define HOURS_ADDR 5
#define DATE_ADDR 6
#define DAY_ADDR 7
#define MONTH_ADDR 8
#define YEAR_ADDR 9
#define BYTE0 0x00
#define BYTE1 0x00
#define BYTE2 0x88
unsigned char MAIN_u8buffer[20] ;
volatile unsigned int delay,i;
40
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
41
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
printf("-%02x",MAIN_u8buffer[MONTH_ADDR-OFFSET]& 0x1F);
printf("-%02x",MAIN_u8buffer[YEAR_ADDR-OFFSET]);
printf(" Time : %02x",MAIN_u8buffer[HOURS_ADDR-OFFSET]& 0x1F);
printf(":%02x",MAIN_u8buffer[MINUTES_ADDR-OFFSET]& 0x7F);
printf(":%02x",MAIN_u8buffer[SECONDS_ADDR-OFFSET]& 0x7F);
while(1)
{
ss = MAIN_u8buffer[SECONDS_ADDR-OFFSET] & 0x7F;
if (!I2C_ReadFromRTC(OFFSET, MAIN_u8buffer, 7))
printf("\nMemory Read error..$");
if (ss != (MAIN_u8buffer[SECONDS_ADDR-OFFSET] & 0x7F))
break;
}
} }
Peripheral Interface:
No switches are there to turn ON/OFF I2C RTC
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories-
>Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate:
19200,
Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)).
Click on OK. Go to Port -> Open. If required Reset the ADT board.On terminal after
reset, press “Shift-S’ to set DD MM YY HH MM SS format and press enter. To save the
RTC press “Shift-Y”,now you can see the RTC getting updated.
Result:
Thus interfacing of real time clock on serial UART with LPC1768 is executed and
verified
successfully.
Viva questions:
1. What is UART?
2. Define baud rate
3. What does RTC do?
4. Application of RTC
42
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Aim: Write an assembly C program to interface LCD and keyboard with ARM
Proceedure:
1. Write the assembly C program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
Program:
#include <LPC17xx.H>
#include "interfaces.h"
if(key != 0)
{
delay(0xFF64);
do
{
key1 = (LPC_GPIO0->FIOPINH & 0x0780 )>> 7;
}while(key1 !=0);
delay(0xFF64);
delay(0xFF64);
delay(0xFF64);
delay(0xFF64);
delay(0xFF64);
for(j=1;j<=4;j++)
43
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
{
key >>= 1;
if(key == 0)
{
key = indx+j;
switch(key)
{
case 1: key = 0x0F;break;
case 2: key = 0x0B;break;
case 3: key = 0x07;break;
case 4: key = 0x03;break;
case 5: key = 0x0E;break;
case 6: key = 0x0A;break;
case 7: key = 0x06;break;
case 8: key = 0x02;break;
case 9: key = 0x0D;break;
case 10: key = 0x09;break;
case 11: key = 0x05;break;
case 12: key = 0x01;break;
case 13: key = 0x0C;break;
case 14: key = 0x08;break;
case 15: key = 0x04;break;
case 16: key = 0x00;break;
}
return key;
}
}
}
LPC_GPIO0->FIOCLR2 = i<<3;
indx += 4;
}
}
}
main()
{
unsigned char key;
Sys_Init();
LPC_PINCON ->PINMODE1 = 0x003FC000;
GLCD_DisplayString(4,0,__FI,"OnBoard KEYPAD Demo");
GLCD_DisplayString(5,0,__FI,"KeyPressed :");
while(1)
{
44
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
key = getKey();
GLCD_DisplayChar(5,12,__FI,key<=9?key+0x30:'A'+key-0x0A);
}
}
Viva questions:
1. LCD interfacing can be done in how many bit mode?
2. What are key matrices?
3. What does RS pin do in LCD board?
4. LCD device consists of how many pins and what are they?
45
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Write a program for I2C bus communication and simulate on keil compiler
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
Program:
ORG 00H
46
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
SETB 0x90.5
SJMP HERE2
CLR 90.5
SETB 0x90.4
RLC A
CLR 0x90.4
DJNZ R5, HERE1
SETB 0x90.5
SETB 0x90.4
HERE3: JNB 0x90.4, HERE3
CLR 0x90.4
RET
MOV R5, #0x08
MOV A, #0x00
CLR C
BACK1: SETB 0x90.4
SETB 0x90.5
RLC A
CLR 0x90.4
DJNZ R5, BACK1
MOV R0, A
CLR 0x90.5
SETB 0x90.4
NOP
CLR 0x90.4
RET
MOV B, A
ANL A, # 0x0F
CJNE A, #0x0A, N1
N1: JC N2
ADD A, #0x0A
N2: A, #0x2D
MOV R6, A
ANL A, #0x0F
CJNE A, #0x0A, N3
N3: JC N4
ADD A, #0x0A
ADD A, #0x2B
MOV R7, A
RET
JNB 0x98.1, SOUT
CLR TI
RET
END
Viva Questions:
47
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
Develop necessary interfacing circuit to read data from a sensor and process using the
8051 board. The data has to be displayed on a PC monitor.
Program to read the input from LM35 (Temperature sensor) and process using 8051
board and display on a PC monitor.
Procedure:
1. Write the assembly language program for this task in the keil compiler.
2. Compile it and dump the hex file as per the procedure given above.
3. Place this microcontroller in the trainer kit and fix it properly.
4. Power up the trainer kit from the mains supply.
5. LM35 is used as the temperature sensor to read the temperature value
continuously and convert it into electrical signals.
6. This LM35 is connected to ADC for the analog data conversion into digital
form.LM35 has three terminals. Two pins are given to the power supply and
ground connections. The analog temperature value is available at the second pin.
7. Now this LM35 output pin is connected to the Vin (pin 6 of ADC).
8. A 10K preset is used to adjust the reference voltage according to the input voltage
applied to ADC. The two terminals of preset are connected to the power supply
and ground. The third pin is connected to the Vref/2 (pin 9 of ADC).
9. The command pins (RD, WR and INTR) of ADC are connected to the Port 2 (pins
26, 27 and 28 of Microcontroller).
10. The data pins (D0-D7) of ADC are connected to the Port 1 (pins 1 to 7 of
Microcontroller).
11. In order to establish communication between PC and Microcontroller, Serial cable
RS232 and voltage converter MAX232 IC are used. This section is available on
the system board.
12. For serial communication, Port 3 (pins 10 and 11 of Microcontroller) are used as
reception and transmission pins respectively.
13. The pins 10 and 11 of Microcontroller are connected to the pins 12 and 11 of
MAX232 IC respectively.
14. Connect one end of the serial cable to the processor and the other end to the DB 9
pin provided on the system board.
15. Check the connections before switching on the mains.
16. An LED is provided in the power supply section of the trainer kit to indicate if the
board is powered or not.
17. After the board is powered up, the message and the room temperature will be
displayed continuously on the HyperTerminal window of the PC.
Program:
ORG 00H
MOV TMOD,# 20H ;to select timer 1 in mode 2 (auto reload)
MOV SCON,# 50h ; to select serial communication in mode 1
48
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
RET
49
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department
17EC3652 (VR17) Microcontrollers Lab
END
Viva Questions:
50
Velagapudi Ramakrishna Siddhartha Engineering College ECE Department