Professional Documents
Culture Documents
MCLab Manual Final
MCLab Manual Final
MCLab Manual Final
DEPARTMENT
OF
ELECTRONICS & COMMUNICATION ENGINEERING
B.E. (ECE)
AICTE Model Curriculum
(with effect from AY 2018-19)
MICROCONTROLLERS LAB
This lab is associated with the theory subject ‘Microcontrollers’. The objective of
the lab is to aid the student to understand the programming aspects of two different
microcontrollers INTEL 8051 and LPC2148and practically implement simple programs
and interfacing techniques.
The contents of the lab manual are presented in step by step format. Initially
programs are written using instructions of 8051 microcontroller that can perform simple
tasks like data transfer, manipulation of data, arithmetic operations, branching operations.
Experiments illustrating interfacing 8051 are also performed with different peripherals.
Typical peripheral devices like LED, Switch, Relay, Buzzer, Digital to Analog Converter,
Liquid crystal display and Stepper motor are included in the experiments.
In the second cycle small programs are written using instructions of ARM7 based
microcontroller. Experiments illustrating working of on-chip and off-chip peripherals of
LPC2148 are also performed. On-chip peripheral devices like Analog to Digital converter
and Digital to Analog Converter and off-chip peripherals like LED, Switch, Relay,
Buzzer and DC motor are included in the experiments.
18ECC24
MICROCONTROLLERS LAB
Instruction 2 P Hours per Week
Duration of SEE 2 Hours
SEE 35 Marks
CIE 15 Marks
Credits 1
Course Objectives:
This course aims to:
1. Develop and understand the 8051 and ARM7 C programming
2. Understand the usage of Integrated Development Environment (Keil)
3. Control the operation of various peripherals using 8051 and ARM7 microcontroller
Course Outcomes:
Upon completing this course, students will be able to:
1. Develop the programs of 8051 and ARM using their respective instruction set.
2. Understand the usage of various debugging tools available to program different microcontrollers
3. Build code for 8051 and ARM7 to interface various input/output modules
4. Analyze the hardware and software interaction and integration.
5. Design and develop the 8051 and ARM 7 based embedded systems for various applications
List of Experiments
I. 8051 Programming
1. Familiarity and use of 8051 microcontroller trainer kit, Keil IDE and simple programs under different
addressing modes.
2. Assembly programming using instruction set
3. Timer and counter operations and programming using 8051.
4. Interfacing applications using LED, switch, relay and buzzer.
5. Generation of waveforms using DAC by interfacing it with 8051.
6. Stepper motor interfacing.
7. LCD interfacing.
8. Development of Embedded 'C' Code based on the module specifications. (under Structured enquiry)
1. Study and use of LPC214x Microcontroller trainer kit and simple programs using its instruction set
2. Interfacing applications using LED, switch, relay and buzzer.
3. DC Motor interfacing.
4. Programming on-chip ADC.
5. Waveform generation using internal DAC.
6. Development of Embedded 'C' Code based on the module specifications. (under Structured enquiry)
III. Design an experiment related to the Embedded Application of your choice using 8051/ARM based
architectures. (under Open ended enquiry)
63
CBIT (A) AICTE Model Curriculum with effect from AY 2018-19
Suggested Reading:
1. Mazidi M.A, Mazidi JG &Rolin D. Mckinlay, “The 8051 Microcontroller & Embedded Systems using
Assembly and C”, 2/e, Pearson Education, 2007.
2. Philips semiconductors, “ARM 7 (LPC 214x) user manual”, 2005.
64
INDEX
1. Addressing modes 1
2. Bit Operations 5
7. LCD interfacing 24
3. DC Motor interfacing. 36
4. Programming on-chip ADC 38
5. Waveform generation using internal DAC 40
6. Development of Embedded 'C' Code based on the module
specifications. (under Structured enquiry) 42
1. ADDRESSING MODES
Aim: Program to copy the value 55H into RAM memory locations 30H to 35H using
a. Direct Addressing mode.
b. Register Indirect Addressing mode without a Loop.
c. Register Indirect Addressing mode with a Loop.
Hardware:
1. PC with
a. Keil Compiler
Program:
a.
ORG 0 ; Start at location 0
MOV A,#55H ; Load A with value 55H
Flowchart:
START
A 55H
[30H] A
[31H] A
[32H] A
[33H] A
[34H] A
1
STOP
Program:
b.
ORG 0 ; Start at location 0
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H
Flowchart:
START
A 55H
R0 30H
[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1
STOP
2
Program:
c.
ORG 0 ; Start at location 0
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H
MOV R2, #05 ; Load counter, R2 = 5
START
A 55H
R0 30H
R2 05
[R0] A
R0 R0+1
R2 R2-1
NO (R2=0)?
YES
STOP
Result:
3
Exercise:
1. Write a program to copy the value AAH into RAM memory locations 30H to 35H using
Stack operations.
2. Write a program to copy the complement of a block of 5 bytes of data from RAM
locations starting at 30H to RAM locations starting at 35H.
3. Write a program to copy the data after masking the upper nibble of a block of 5 bytes of
data from External RAM locations starting at 20F0H to RAM locations starting at 30H.
4. Write a program to convert BCD to 7-segment code.
5. Write a program to find the sum of five bytes from 30H to 34H. At the end of the
program, register A should contain the lower byte and register R7 the higher byte.
Assume that RAM locations 30H to 34H have the following values.
[30H] = 7D
[31H] = EB
[32H] = C5
[33H] = 5B
[34H] = 30
6. Write a program to add all digits of your mobile number and save the result in R2. The
result must be in BCD.
7. Write a program to subtract 197795 from 344548 and save the result in RAM memory
location starting at 30H.
8. Write a program that finds the number of zeros in an 8-bit data item.
9. Write a program that finds the position of the first HIGH in an 8-bit data item.
10. Write a program that sets the CY if the number in A is even else set CY = 0.
11. Write a program to convert packed BCD present in accumulator A, to two ASCII
numbers and places them in R2 and R6 registers.
4
2. BIT OPERATIONS
Aim: Program to generate a square wave of 50% duty cycle on bit 2 of port 1.
Hardware:
1. PC with
a. Keil Compiler
2. 8051 Microcontroller kit
3. Serial cable
4. Oscilloscope
Program:
ORG 0H ;Start at location 0
HERE: SETB P1.2 ;Set to high bit 2 of port 1
LCALL DELAY ;Call the delay sub routine
CLR P1.2 ;Clear bit 2 of port 1
LCALL DELAY ;Call the delay sub routine
SJMP HERE ;Jump unconditionally
;Dealy routine
DELAY: MOV R1, #0FFh
NEXT: DJNZ R1, NEXT
RET
Flowchart:
START
P1.2 0
CALL DELAY
P1.2 1
CALL DELAY
5
Result:
Connect P1.2 of 8051 pin to Oscilloscope and view square waveform.
Exercise:
1. Write a program to move bit 4 of RAM location 30H to bit 2 of A.
2. Write a program to see if the accumulator contains even number. If so divide it by 2 else
make it even and divide it by 2.
3. Write a program to save the status of bits P1.1 and P1.2 on RAM bit locations 8 and 9
respectively.
4. Write a program to see whether the accumulator is divisible by 8 or not.
6
3. TIMER AND COUNTER APPLICATIONS
Aim: Program to generate a square wave of 50Hz on P1.2 by using Timer 0 of 8051. Assume
that XTAL = 11.0592 MHz.
Hardware:
1. PC with
a. Keil Compiler
2. 8051 Microcontroller kit
3. Serial cable
4. Oscilloscope
Calculations:
7
Program:
; Polling method:
AGAIN: JNB TF0, AGAIN ; monitor flag 0, stay until timer rolls over
CPL P1.2 ; complement P2.3 to get hi, lo
CLR TR0 ; stop the timer 0
CLR TF0 ; clear timer 0 flag for next round
SJMP HERE
8
Flowchart:
START
NO
TF0 =1
YES
COMPLEMENT P2.3
P1.2 !P1.2
CLEAR TF0
TF 0
Result:
Connect P1.2 of 8051 pin to Oscilloscope and view square waveform.
Exercise:
1. Write a program to generate a rectangular wave of 1 kHz with 40% duty cycle on P1.6
pin using Timer 1 of 8051.
2. Write a program to generate a square wave of 100Hz on P1.6 pin using interrupt method.
9
4.a. INTERFACING AN LIGHT EMITTING DIODE (LED)
Flow Chart:
START
P1.0 = HIGH
TRANSISTOR ON
(LED ON)
DELAY = 1000 ms
P1.0 = LOW
TRANSISTOR OFF
(LED OFF)
DELAY = 1000 ms
STOP
10
Program:
/****Program to interface a LED with a 8051 micro controller***/
#include<reg51.h>
void delay_ms(unsigned int);
sbit LED = P1^0; /*equating P1^0 pin to a constant(LED)*/
void main(void)
{
P1= 0x00;
while(1)
{
LED = 1;
delay_ms(1000);
LED = 0;
delay_ms(1000);
}
}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}
Result:
Observe the LED’s status.
11
Exercise:
1. Write a C Program to generate the given pattern by interfacing 8 LEDs to 8051.
a. Blink all LEDs at a frequency of 1Hz.
b. Blink alternate LEDs at a frequency of 2Hz.
(Hint: use #define LED P1 to equate P1 port to a constant (LEDS)*/
12
4.b. INTERFACING A SWITCH AND AN LED
Circuit Diagram:
Program:
/*********Program to interface a led and a switch*********/
#include<reg51.h>
#include<delay.h>
void main(void)
{
LED = 0;
while (1) /*toggling a switch results in a led coming on and off*/
{
if ( SWITCH == 0)
{
13
LED = 1 – LED;
delay(200);
}
}
}
Result:
Observe the LED status when the switch toggles.
Exercise:
1. Write a C Program to Interface Switch and LED using an Interrupt.
2. Interface a LED in such a way that it should be ON only when the switch is closed. When
the switch is open LED should be OFF.
3. Interface a relay and a buzzer to 8051; and write a program to on the buzzer when the
relay is on.
14
5. INTERFACING DAC
Aim: Interfacing of 8 bit DAC
Hardware:
1. PC with
a. Keil Compiler
2. 8051 Microcontroller kit
3. Oscilloscope
Circuit diagram:
Program:
/*---------------------------------------------------------------------------------------------
Module Name : DAC
Detail : Interface dac to generate diffrent wave forms(sine,square,trangular,
ramp etc.) with variable frequuency and amplitude using variable pot.
Describition : This Module is used to select the wave form,default is sign wave
Procedure : To select the waveform first press the reset buteen (keep continuesly pressing
reset butten) after that press the key1 push butten switch and then relese the reset butten ,by
continuesly pressing key1 observe the wave form selection led on dac board select the wave
form an relese the key1.and then see the wave form on CRO.
---------------------------------------------------------------------------------------------*/
#include<reg51.h>
#define wave_sel P2
#define dac_databus P1
15
void main(void)
{
unsigned char temp=0;
unsigned char i,j;
unsigned char sample_point[]={0x80,0xc0,0xee,0xff,0xee,0xc0,0x80,0x40,0x11,
0x00,0x11,0x40,0x80} ;
P3=0;
while(1)
{
temp = wave_sel;
P3 = temp ;
P3 = temp ;
switch(temp)
{
case(0):
{
while(1)
{
for(i=0;i<=11;i++)
{
dac_databus = sample_point[i];
for(j=0;j<=50;j++);
}
}break;
}
case(1):
{
while(1)
{
for(dac_data=0;dac_data<255;dac_data++)
{
dac_databus=dac_data;
}
16
} break;
}
case(2):
{
while(1)
{
for(dac_data=0;dac_data<255;dac_data++)
{
dac_databus=dac_data;
}
for(dac_data=255;dac_data>0;dac_data--)
{
dac_databus=dac_data;
}
}
break;
}
case(4):
{
while(1)
{
dac_databus = 0x00;
delay_us(75);
dac_databus = 0xff;
delay_us(75);
}
break;
}
case(8):
{
while(1)
{
for(i=0;i<=11;i++)
{
dac_databus = sample_point[i];
for(j=0;j<=50;j++);
}
}break;
}
break;
}}}
17
}
Result:
Observe the waveform on Oscilloscope.
Exercise:
18
6. STEPPER MOTOR INTERFACING
Aim : Interfacing of Stepper motors to 8051.
Hardware :
1. PC with
a. Keil Compiler
2. 8051 Microcontroller kit
Circuit Diagram :
Program:
/*---------------------------------------------------------------------------------------------
Module Name : stepper motor speed and direction control
Describition : Interface stepper motor to control direction and speed by accepting key pressed.
19
3. Write the program and create hex file.Connect the serial cable to serial port.
Then apply poer supply to boards.Download the program trough flah magic.
4. Use the key1 and key2 on the SDM card to rotate the motor.If you press key1
to rotate the motor clockwise and if press key2 it rotate in anticlockwise. key3 & key4 ars used
for speed control.By pressing key3 speed goes on incremating and pressing key4 motor speed
decresing.
5. see it by practicaly.
---------------------------------------------------------------------------------------------*/
#include<reg51.h>
#define stm_databus P0
sbit REV = P0^4;
sbit FRW = P0^5;
sbit DCR = P0^6;
sbit INR = P0^7;
void main(void)
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
FRW = 0;
while(1)
{
if(FRW==0)
{
while(1)
{
stm_databus = 0x06;
delay_ms(count);
stm_databus = 0x0A;
delay_ms(count);
stm_databus = 0x09;
delay_ms(count);
stm_databus = 0x05;
delay_ms(count-5);
stm_databus =0XF5;
if(REV == 0)
{
stm_reverse(count);
}
if(DCR == 0)
{
20
count += 1;
if(count > 450)
{
count += 10;
}
if(count > 1000)
{
count += 100;
}
if(count > 5000)
{
count += 500;
}
}
if(INR==0)
{
count -= 1;
if(count > 450)
{
count -= 10;
}
if(count > 1000)
{
count -= 100;
}
if(count > 5000)
{
count -= 500;
}
if(count < 160)
{
count = 160;
}
if(REV==0)
{
while(1)
{
21
stm_databus= 0x05;
delay_ms(count);
stm_databus = 0x09;
delay_ms(count);
stm_databus = 0x0a;
delay_ms(count);
stm_databus = 0x06;
delay_ms(count-5);
stm_databus =0XF5;
if(FRW ==0)
{
stm_forward(count);
}
if(DCR ==0)
{
count += 1;
if(count>450)
{
count += 10;
}
if(count > 1000)
{
count += 100;
}
if(count > 5000)
{
count += 500;
}
}
if(INR ==0)
{
count -= 1;
if(count >450)
{
count -= 10;
}
if(count > 1000)
{
count -= 100;
}
if(count > 5000)
{
count -= 500;
22
}
if(count < 160)
{
count = 160;
}
}
}
}
}
}
Result:
Exercise:
2. Write a program to move the motor by an angle 180 degrees in anticlockwise direction by
applying
a. Full step sequence
b. Half step sequence
c. Wave drive sequence
3. Write a program to rotate the stepper motor by an angle 270 degrees in clockwise
direction by applying above different sequences.
23
7. INTERFACING LIQUID CRYSTAL DISPLAY (LCD) IN 8-BIT MODE
Circuit Diagram :
24
Command Encoding
Instruction RS RW D7 D6 D5 D4 D3 D2 D1 D0 Description
Clear all display and returns the cursor
Clear Display 0 0 0 0 0 0 0 0 0 1
to the home position, address 080h
Returns the cursor to the home position
(address 080h). Also returns the display
Return home 0 0 0 0 0 0 0 0 1 *
being shifted to the original position.DD
Ram contents remain unchanged.
Set the cursor move direction and
Entry Mode specifies or not the shift display. These
0 0 0 0 0 0 0 1 I/D S
Set operations are performed during data
write and read.
I/D=1 Increment(+1)
I/D=0 Decrement(-1)
S=1 Followsdisplayshift
Sets On/Off of all display (D), Cursor
Display On/
0 0 0 0 0 0 1 D C B On/Off (C), and blink of cursor position
Off Control
character (B)
Moves the Cursor and shifts the
Cursor and
0 0 0 0 0 1 SC RL * * display without changing DD Ram
Display Shift
contents
SC=1 DisplayShift
SC=0 Cursormove
RL=1 ShifttotheRight
RL=0 ShifttotheLeft
Sets Interface data length (DL), number
Function Set 0 0 0 0 1 DL N F * * of display lines (N) and
character font (F)
DL=1 bits:8
DL=0 bits:4
N=1 lines:2
25
N=0 lines:1
F=1 dots:5x10
F=0 dots:5x7
Write Data 1 0 Write Data Writes data into DD Ram
Read Data 1 1 Read Data Reads data from DD Ram
Set CG Ram Sets the CG Ram address. CG Ram
0 0 0 1 Address CG Ram
Address Data is sent and received after this.
Set DD Ram Sets the DD Ram address. DD Ram
0 0 1 Address DD Ram
Address Data is sent and received after this.
BF=1 ControllerBusy
BF=0 Contr.Available
DDRAM DisplayDataRam
CGRAM CharacterGeneratoruserRAM
Program:
26
back_lite =0;
for(c=0;c<5;c++)
{
lcdcmd(lcd_command[c]);
}
for(d=0;d<15;d++)
{
lcddata(lcd_message[d]);
MSDelay(30);
}
back_lite =1;
for(c=0;c<5;c++)
{
lcdcmd(lcd_command1[c]);
}
for(d=0;d<15;d++)
{
lcddata(lcd_message1[d]);
MSDelay(30);
}
while(1)
{
}
}
27
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
return;
}
Result:
Observed the display on LCD.
Exercise:
1. Program to interface a LCD, LED’s & Switches to create a user selectable menu and
perform the specified operation on given number.
1st Set of Display: WELCOME TO
MICROCONTROLLERS
nd
2 Set of Display: 1 INC 2 DEC
3 SET 4 RESET
28
8. PROGRAMS UNDER STRUCTURED ENQUIRY
1. Interface ADC0800 to 8051 and display the digital converted data in hex format after
applying analog input to it.
2. Write a C Program by interfacing two 7-segment displays and display the count from 99
to 00. And it restarts the counting after reaches the final Count.
3. Write a C program by interfacing four 7-segment displays and display the string
“CBIT”.
29
II. Programming with LPC 2148 Microcontroller
1. PROGRAMS USING ARM7 INSTRUCTION SET
Aim:
To find the maximum/ minimum from given set of numbers.
Hardware:
1. PC with
a. Keil Compiler
Program:
Result:
Exercise:
30
2. a. INTERFACING LED
Hardware:
1. PC with
a. Keil Compiler
2. LPC2148 kit
Theory:
Light Emitting Diodes (LED) is the most commonly used components, usually for displaying
pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of user
input such as a mouse click or keystroke.
Interfacing LED
Below figure shows how to interface the LED to microcontroller. As you can see the Anode is
connected through a resistor to GND & the Cathode is connected to the Microcontroller pin. So
when the Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned
ON.
31
Program:
#include <LPC21xx.h>
int main()
while(1)
Result:
Exercise:
32
2.b. INTERFACING SWITCH
Hardware:
1. PC with
a. Keil Compiler
2. LPC2148 kit
Theory:
A switch is an electrical component that can break an electrical circuit, interrupting the current or
diverting it from one conductor to another. A switch may be directly manipulated by a human as
a control signal to a system, or to control power flow in a circuit.
33
Program:
}
}
void Delay(int n)
{
int p,q;
for(p=0;p<n;p++)
{
for(q=0;q<0x9990;q++);
}
}
34
Result:
Exercise:
35
3. DC MOTOR INTERFACING
Hardware:
1. PC with
a. Keil Compiler
2. LPC2148 kit
3. DC Motor
Circuit Diagram:
The DC Motor can also be interfaced to the board by connecting it to the Reliamate RM4. The
direction of the rotation can be changed through software using Relay RLY1. Port lines used for
DC motor are P0.8 and P0.11. The BUZZER is connected through port line P0.9. The Relay
RLY2 is switched ON and OFF. The LED L12 will toggle while relay turns on and off. The NO
contacts of the relay can be checked at the MKDSN connector CN5 pins 1 & 2 using a DMM, a
click sound will be heard when the relay contact closes (check connectivity). The port line P0.10
is used for relay interface.
36
Program:
#include<lpc214x.h>
void clock_wise(void);
void anti_clock_wise(void);
unsigned int j=0;
int main()
{
IO0DIR= 0X00000900;
IO0SET= 0X00000100; //P0.8 should always high.
while(1)
{
clock_wise();
for(j=0;j<400000;j++); //delay
anti_clock_wise();
for(j=0;j<400000;j++); //delay
} //End of while(1)
} //End of Main
void clock_wise(void)
{
IO0CLR = 0x00000900; //stop motor and also turn off relay
for(j=0;j<10000;j++); //small delay to allow motor to turn off
IO0SET = 0X00000900; //Selecting the P0.11 line for clockwise and turn on motor
}
void anti_clock_wise(void)
{
IO0CLR = 0X00000900; //stop motor and also turn off relay
for(j=0;j<10000;j++); //small delay to allow motor to turn off
IO0SET = 0X00000100; //not selecting the P0.11 line for Anti clockwise
}
Result:
Exercise:
1. Write a program to generate a PWM output by using on-chip PWM of LPC 2148 and from
that drive the DC motor. (Motor Speed Control)
37
4. PROGRAMMING ON-CHIP ADC
Hardware:
1. PC with
a. Keil Compiler
2. LPC2148 kit
Circuit Diagram:
On board there is one interface for internal ADC. AD0.4 (pin P0.25) of controller is used to
convert the analog input voltage varied using POT1 to digital value. A 0.00 to 3.3V is the input
voltage range. 000 to 3FF is the converted digital voltage range here. Jumper JP9 (1, 2) has to be
shorted to use this interface.
Program:
//10-bit internal ADC
//AIN0 pin is selected. You can change the channel by changing PINSEL1 and ADCR value
#include<lpc214x.h>
void display(unsigned int);
void delay(unsigned int );
unsigned char Disp[16]={0x3F, 0x06, 0x5B, 0x4F, 0x66,0x6D,0x7D, 0x07, 0x7F,
0x6F,0x77,0x7c,0x39,0x5e,0x79,0x71};
int main()
{
unsigned int temp_adc,adc_value;
PINSEL1 = 0x00040000; ////AD0.4 pin is selected(P0.25)
IO0DIR = 0xE0FF0000;
while(1)
38
{
AD0CR = 0x01200010; //command register for ADC-AD0.4
while(!((temp_adc = AD0GDR) &0x80000000)); //to check the interrupt bit
adc_value = AD0GDR;
adc_value >>=6;
adc_value &= 0x000003ff;
display(adc_value);
}
}
void display(unsigned int val)
{
unsigned int temp, digit0, digit1,digit2, count;
temp = val;
digit0 = temp%16;
temp = temp/16;
digit1 = temp%16;
temp = temp/16;
digit2 = temp%16;
for(count=0;count<10000;count++)
{
IO0PIN = (Disp[digit0]<<16)|0x80000000; // get the 7-seg display value from the array
delay(10);
IO0PIN = (Disp[digit1]<<16)|0x40000000; // get the 7-seg display value from the array
delay(10);
IO0PIN = (Disp[digit2]<<16)|0x20000000; // get the 7-seg display value from the array
delay(10);
}
}
void delay(unsigned int i)
{
unsigned int j;
for (j=0;j<i;j++);
}
Result:
Observe the ADC output on 7-segment display unit.
39
5. WAVEFORM GENERATION USING INTERNAL DAC
Hardware:
1. PC with
a. Keil Compiler
2. LPC2148 kit
Circuit Diagram:
DAC0800 is used to convert the digital data into analog signals. Digital data from specified port
lines is given to DAC input. Amplitude of output waveform can be varied by varying POT3 (5K
Pot) that is by varying the reference voltage of DAC0800 when JP3 is closed. For Bipolar mode
open jumper JP11. To test DAC in Unipolar mode short jumper JP11. Port lines used for DAC
are P0.16, P0.23.
40
Program:
int main()
{
PINSEL1 = 0X00080000; //AOUT pin is selected(P0.25)
while(1)
{
DACR = 0x00000000;
for(count=0;count<1000;count++);
DACR = 0x0000ffc0;
for(count=0;count<1000;count++);
}
} //end of main()
Result:
Exercise:
41
6. PROGRAMS UNDER STRUCTURED ENQUIRY
1. Program the PLL of LPC2148 for CPU operating frequency of 60MHz and PCLK of 30
MHz.
2. Develop a Program to generate a single edge controlled PWM with 30% duty cycle on
PWM3 (P0.1).
3. Develop a Program to vary the intensity of the LED using PWM of LPC2148.
4. Write a program To find out frequency of the input signal using capture mode of
LPC2148
5. Write a program to generate a Square wave of 5Hz with 50% Duty cycle using timers of
LPC2148
42
III. Mini projects under Open ended enquiry
43
APPENDIX I
INTRODUCTION TO KEIL UVISION IDE AND FLASH MAGIC
44
a. Then go to option “Output”
6. Select “Create Hex file”.
a. Then go to option “Linker”
7. Select “Use Memory Layout for Target Dialog”.
ISP PROGRAMMING:
FLASH MAGIC software can be used to download the HEX files to the Flash memory of
controller. To download, Connect the serial cross cable from 9-pin DSUB Female connector
(DB2) to the PC COM port. Switch on both Switches of SW11. SW11(1-RTS), SW11(2-DTR).
Connect DC +5V Power, through the 9-pin DSUB FEMALE connector (DB1) applied from an
external source. Switch ON the power. Remove JP13 while downloading the software.
Step1. Communications:
Device : LPC2148
Com Port : COM1
Baud Rate : 9600
Interface : None(ISP)
Oscillator : 12MHz
Step2. ERASE:
45
Step3. Hex file:
Browse and select the Hex file which you want to Download.
Step4. Start:
After downloading the code the program starts executing in the hardware, then remove the ISP
jumper JP7.
46
APPENDIX II
Introduction to 8051 Development Board and Its Features
Introduction:-
Technical Specification:-
47
Features of P89V51rd2:-
48
APPENDIX III
. Introduction to LPC 2148 Development Board and Its Features
Introduction:-
The THUMB set’s 16-bit instruction length allows it to approach twice the density of standard
ARM code while retaining most of the Arm’s performance advantage over a traditional 16-bit
processor using 16-bit registers. This is possible because THUMB code operates on the same 32-
bit register set as ARM code. THUMB code is able to provide up to 65% of the code size of
ARM, and 160% of the performance of an equivalent ARM Processor connected to a 16-bit
memory system.
Features of LPC2148 :-
Following are the features of 16 bit /32 bit LPC2148 Arm Micro-controller:
PHILIPS LPC2148 is a 16-bit or 32-bit Micro-controller in a LQFP64-pin Package.
40 kB of on-chip static RAM and 512 kB of on-chip flash memory. 128-bit wide
interface/accelerator enables high-speed 60 MHz operation.
The LPC2148 provides 100000 erase/write cycles and 20 years of Data-retention.
49
In-System Programming/In-Application Programming (ISP/IAP) via on-chip boot loader
software. Single flash sector or full chip erase takes 400ms and Flash programming takes
1ms per 256-byte line.
USB 2.0 Full speed compliant device controller with 2 kB of endpoint RAM. In addition,
the LPC2148 provides 8 kB of on-chip RAM accessible to USB by DMA.
Embedded ICE-RT and Embedded Trace Macro cell (ETM) interfaces offer real time
debugging with on-chip Real Monitor software and high-speed real-time tracing of
instruction execution.
Two 10-bit ADCs provide a total of 14 analog inputs, with conversion times as low as
2.44μs per channel.
Single 10-bit DAC provides variable analog output.
Two 32-bit Timers/External event Counters (with four Capture and four Compare
channels each), PWM unit (six outputs) and watchdog.
Low power Real-Time Clock (RTC) with independent power and 32 kHz clock input.
Multiple serial interfaces including two UARTs (16C550 equivalent), two Fast I2C-bus
(400 kbit/s), SPI and SSP with buffering and variable data length capabilities.
Vectored interrupt controller (VIC) with configurable priorities and vector addresses.
Up to 45 numbers of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64
package.
Up to nine edge or level sensitive external interrupt pins available.
60 MHz maximum CPU clock available from programmable on-chip PLL with settling
time of 100 μs.
On-chip integrated oscillator operates with an external crystal in range from 1 MHz to 30
MHz and with an external oscillator up to 50 MHz.
Power saving modes include Idle and Power-down.
Individual power enable/disable of peripheral functions as well as peripheral clock
scaling for additional power optimization.
Processor wake-up from Power-down mode via external interrupt, USB, Brown-Out
Detect (BOD) or Real-Time Clock (RTC).
Single power supply chip with Power-On Reset (POR) and BOD circuits:CPU operating
voltage range of 3.0 V to 3.6 V (3.3 V ± 10 %) with 5 V tolerant I/O pads.
50