Professional Documents
Culture Documents
MES LABORATORY Manual 2020
MES LABORATORY Manual 2020
MES LABORATORY Manual 2020
Introduction
LPC-P2148 Features
LPC-P2148is prototype board forLPC2148 ARM7TDMI-S microcontroller with USB 2.0 Full-speed device,
multiple UARTs, SPI, SSP to I2C-bus and on-chip SRAM up to 40 kB, produced by NXP Semiconductors.
With LPC-P2148 you can explore the features of LPC21XX family on budged, the board has everything
necessary to build simple applications: reset and oscillator circuits, JTAG port for programming and debugging,
USB, RS232, SD/MMC, Buzzer, three status LEDs, potentiometer and two user buttons. There are plenty of
GPIOs on extension headers and also a prototype area where you can connect your additional circuits.
Software Tool
Keil MDK-ARM™ is a complete software development toolkit for ARM processor-based microcontrollers. It is
the right choice for embedded applications based on the ARM Cortex™-M series, ARM7™, ARM9™, and
Cortex-R4 processors.
NOP
NOP
NOP
LOOP
ADD R1, R1, R0
SUBS R0, R0, #1
BNE LOOP
STOP B STOP
END
MOV R0, #7
MOV R1, #1
LOOP
MUL R2, R1, R0
MOV R1, R2
SUBS R0, R0, #1
BNE LOOP
STOP B STOP
END
4. Write a program to add an array of 16 bit numbers and store the 32 bit result in internal RAM
;/* PROGRAM TO ADD an array of 16BIT NUMBERS & STORE IN INTERNAL RAM*/
;/*ARRAY OF 6 NUMBERS0X1111,0X2222,0X3333,0XAAAA,0XBBBB,0XCCCC */
;/* THE SUM IS 29997H THE RESULT CAN BE VIEWED IN LOCATION 0X40000000 & ALSO IN R0*/
;/* SET A BREAKPOINT AT NOP INSTRUCTION,RUN THE PROGRAM & CHECK THE RESULT */
LOOP
LDR R2, [R1], #2 ; WORD ALIGN T0 ARRAY ELEMENT
ADD R0, R0, R2 ; ADD THE ELEMENTS
SUBS R5, R5,#1 ; DECREMENT COUNTER
CMP R5, #0
BNE LOOP ; LOOK BACK TILL ARRAY ENDS
NOP
NOP
NOP
VALUE1 DCW 0X1111, 0X2222, 0X3333, 0XAAAA, 0XBBBB, 0XCCCC ; Array oF 16 bit numbers(N=6)
5. Write a program to find the square of a number (1 to 10) using look-up table.
STOP B STOP ; Lookup table contains Squares of no’s from 0 to 10 (in hex)
END
;/* PROGRAM TO FIND LARGEST NUMBER IN AN ARRAY & STORE IN INTERNAL RAM*/
;/* ARRAY OF 7 NUMBERS 0X44444444 ,0X22222222,0X11111111,0X33333333,0XAAAAAAAA */
;/* 0X88888888 ,0X99999999 */
;/* RESULT CAN BE VIEWED IN LOCATION 0X40000000 & ALSO IN R2 */
;/* SET A BREAKPOINT AT NOP INSTRUCTION,RUN THE PROGRAM & CHECK THE RESULT */
STOP B STOP
END ; Mark end of file
START
LOOP0
LDR R1,[R2],#4 ; LOADING VALUES FROM CODE REGION
STR R1,[R3],#4 ; STORING VALUES TO DATA REGION
LOOP2
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
CMP R7,#0 ; COMPARING FLAG
BNE START1 ; IF FLAG IS NOT ZERO THEN GO TO START1
LOOP
NOP
NOP
NOP ; Array Of 32 Bit Numbers (N=4) In Code Region
CVALUE
DCD 0X44444444 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0X22222222 ;
AREA DATA1, DATA,READWRITE ;
DVALUE
STOP B STOP
END
PART B
Conduct the following experiments on an ARM7TDMI/LPC2148 evaluation board using Evaluation version
of Embedded 'C' & Kiel Uvision-4 tool/compiler.
void delay(void);
void LCD_init(void);
void LCD_cmd(char cmd);
void LCD_data(char data);
void LCD_string(char *ptr);
int main()
{
PINSEL2 = 0x00000000; //P1.16 to P1.31 configured as GPIO
IODIR1 = 0x03FF0000; //P1.16 to P1.25 configured as output port
LCD_init(); // Function call
while(1)
{
LCD_cmd(0x80); //LCD row 1st selection
LCD_string(" Welcome to ");//for multiple charactors(String) to be printed on the display
LCD_cmd(0xC0); //LCD 2nd row selection
LCD_string(" PESIT ");//for multiple charactors(string) to be printed on the display
}
}
void delay(void)
{
unsigned int i, j;
for(i = 0 ; i < 1000 ; i++)
for(j = 0 ; j < 500 ; j++);
}
void LCD_init()
{
LCD_cmd(0x38); //selection of the 8-data lines, 0x28 for 4-bit data
LCD_cmd(0x0C); //Display ON cursor OFF
LCD_cmd(0x06); //move the cursor right
LCD_cmd(0x01); //clear the LCD
// LCD_cmd(0x80); //firat line starting address
}
//******************************************************************************
// FileName : DC motor Programming using Port-1
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description :DC motor rotating clockwise and anticlockwise direction
// Pin Connection :P1.30 and P1.31 pins of Port-0 connected to L293D IC(DC motor driver)
//******************************************************************************
for(i=0;i<1000;i++)
for(j=0;j<2000;j++);
}
11. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
//******************************************************************************
// FileName : Stepper Motor Programming using Port-1
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description :Stepper Motor Roatating Clockwise direction after certain
delay roatating Anticlockwise direction
// Pin Connection :P1.28 to P1.31 connected to Stepper motor driver(ULN2003/2803)
//******************************************************************************
//*************** END of Stepper MOtor Clockwise and Anti clockwise Program **************//
//******************************************************************************
// FileName : ADC and LCD Programming
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description :Analog Signals Are Converted Into Digital Form And Result Printed In Lcd
// Pin Connection :LCD dataline (D0 to D7) connected to Port-1 pins of P1.16 to P1.23 respectively and
//Rs(Register Select) pin of LCD connected to P1. and
//En(Enable) pin of LCD connected to P1.25
//R/W pin of LCD always ground
//ADC channel Connected to Sensors or Resistor Pot. ADC cahnnels are - (P0.30, P0.29, P0,28, P0.25)
//******************************************************************************
#include<lpc214x.h>
#include<string.h>
void delay(void);
void LCD_init(void);
void LCD_cmd(char cmd);
void LCD_data(char data);
void LCD_string(char *ptr);
void adc_channel_select(unsigned int channel);
void adc(void);
void hex_dec(unsigned int lcd_data);
//********************* MAIN Program ******************//
int main()
{
PINSEL0 = 0x00000000; // P0.0 to P0.15 configured as GPIO
PINSEL1 = 0x01000000; // ADC cinfigure (P0.30, P0.29, P0,28, P0.25), remaining as GPIO
PINSEL2 = 0x00000000; // P1.0 to P1.31 configured as GPIO
IODIR1 = 0x03FF0000; // P1.16 to P1.25 configured as 0utput port
LCD_init(); // LCD-init function calling
LCD_cmd(0x01); // clear the display
LCD_cmd(0x80); // LCD row one selection
LCD_string("*** Welcome to ***"); // sting of data sent
LCD_cmd(0xC0); // LCD row second selection
LCD_string("*V V Tech*"); // sting of data sent
while(1)
{
adc(); // adc function calling
Dept. of Computer Science & Engineering , SJBIT Page 25
Microcontroller & Embedded Systems 18CSL48
}
}
// ******************** END of MAIN Program *********************//
// ******************** DELAY Program *********************//
void delay()
{
unsigned int i, j;
for(i = 0 ; i < 1000 ; i++)
for(j = 0 ; j < 1000 ; j++);
}
// ******************** END of DELAY Program *********************//
// ******************** LCD initilization Program *********************//
void LCD_init()
{
LCD_cmd(0x38); //selection of the 8-data lines, 0x28 for 4-bit data
LCD_cmd(0x0C); //Display ON cursor OFF
LCD_cmd(0x06); //move the cursor right
LCD_cmd(0x01); //clear the LCD
LCD_cmd(0x80); //firat line starting address
}
// ******************** END of LCD-init Program *********************//
// ******************** LCD CMD Program *********************//
LCD_cmd(0xC8);
voltage=temp*0.003;
LCD_cmd(0xC0); // LCD second row selection
LCD_string("Light:");
adc_channel_select(2); //selection of ADC channel 3
while(!(AD0GDR&0x80000000)); //checking for DONE bit high or not
ldr = (AD0GDR & 0x0000FFC0) >> 6; //take the result value from AD0GDR, Masking,
//Right shift 6 times and store it in variable
hex_dec(ldr); //Convert result value into ASCII/ decimal Value
delay();
// if(temp>45)
// {
// LCD_cmd(0xD4);
// LCD_string("Temperature is high ");
// }
// else
// {
// LCD_cmd(0xD4);
// LCD_string(" ");
// }
//
// if(ldr<250)
// {
// LCD_cmd(0xD4);
// LCD_string("Light Intensity Low ");
// }
// else
// {
// LCD_cmd(0xD4);
// LCD_string(" ");
// }
//
// if(gas>750)
// {
// LCD_cmd(0xD4);
// LCD_string(" Gas Detected ");
// }
// else
// {
// LCD_cmd(0xD4);
while(1)
{
value = 0;
DACR = ( (1<<16) | (value<<6) );
delay();
value = 1023;
DACR = ( (1<<16) | (value<<6) );
delay();
}
return 0;
}
void delay()
{ int i;
for (i=0; i<2000;i++)
{
;
}
}
14. Interface a 4x4 keyboard and display the key code on an LCD.
//******************************************************************************
// FileName : 8-bit LCD Programming using Port-1
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description :Printing some character in LCD using LPC2148 controller
// Pin Connection : LCD dataline (D0 to D7) connected to Port-0 pins
of P0.16 to P0.23 respectively and
// Rs(Register Select) pin of LCD connected to P0.6 and
// En(Enable) pin of LCD connected to P0.7
// R/W pin of LCD always ground
// : Keyapd Connected to Port-1
// : row(R1,R2,R3,R4) - (P1.22,P1.23,P1.24,P1.25)
// : col(C1,C2,C3,C4) - (P1.18,P1.19,P1.20,P1.21)
//******************************************************************************
#include"prototype.h"
int main()
{
PINSEL0 = 0x00050000;
PINSEL1 = 0x15000000;
PINSEL2 = 0x00000000;
IODIR0 = 0x00FFFCE0;
IODIR1 |= 0x0FC00000; //P1.25 to P1.22 as Output
IODIR1 &= ~(0x003C0000); //P1.18 to P1.21 as Input
IOCLR0 = 0x00FFF000;
LCD_init();
L1: LCD_cmd(0x01);
LCD_cmd(0x80);
LCD_string("Enter Key:");
for(i = 0 ; i < 16 ; i++)
{
key_value[i] = _getKey(); // c-4 to c-1 of kepad connected to P1.18 to P1.21 respectively and
R1 to R4 of keypad connected to P1.22 to P1.25 respectively
delay();delay();
LCD_cmd(0X8B);
LCD_data(key_value[i]);
delay_wait(50);
}
goto L1;
}
unsigned char _getKey(void)
{
while(1)
{
IOPIN1 &= ~0x03C00000;
IO1PIN |= (0x07<<22); //OP1 HIGH
if(((IOPIN1&0x003C0000)>>18) == 0x0E)
return(keys[3][0]);
else if(((IOPIN1&0x003C0000)>>18) == 0x0D)
return(keys[2][0]);
else if(((IOPIN1&0x003C0000)>>18) == 0x0B)
return(keys[1][0]);
else if(((IOPIN1&0x003C0000)>>18) == 0x07)
return(keys[0][0]);
IOPIN1 &= ~0x03C00000;
IO1PIN |= (0x0B<<22); //OP2 HIGH
if(((IOPIN1&0x003C0000)>>18) == 0x0E)
return(keys[3][1]);
else if(((IOPIN1&0x003C0000)>>18) == 0x0D)
return(keys[2][1]);
else if(((IOPIN1&0x003C0000)>>18) == 0x0B)
return(keys[1][1]);
else if(((IOPIN1&0x003C0000)>>18) == 0x07)
return(keys[0][1]);
//******************************************************************************
// FileName : LED Programming using Port-0
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description :Using PORT-0 all port pins of are making HIGH with certain delay and all port pin made LOW.
//******************************************************************************
//************* MAIN PROGRAM *****************************//
int main()
{
PINSEL0 = 0x00000000; // Using PINSEL0 making P0.0 to P0.15 as GPIO
PINSEL1 = 0x00000000; // Using PINSEL1 making P0.16 to P0.31 as GPIO
while(1)
{
for( j=0;j<=8;j++)
{
IOSET0 = a; // P0.0 to P0.31 as set to high
delay(); // Delay Function Cal
IOCLR0 = a; // P0.0 to P0.31 as set to low
a = (a >> 1);
}
a = 0x3;
for( j=0;j<=8;j++)
{
IOSET0 = a; // P0.0 to P0.31 as set to high
delay(); // Delay Function Cal
IOCLR0 = a; // P0.0 to P0.31 as set to low
a = (a << 1);
}
a = 0x000000C0;
}
for(i=0;i<1000;i++)
for(j=0;j<1000;j++);
}
//******************************************************************************
// FileName : Seven Segment Display Programming using Port-1
// Microcontroller : LPC2148
// Compiler : Keil v-4
// Target Hardware : ARM7 Development Board
// Description : Printing the numbers 0 to 9 in 7-segment Display using LPC2148 controller
// Pin Connection : P1.24 to P1.31 port pins are connected to Seven segment dispaly of ABCDEFGH
terminals respectively.
//******************************************************************************
IOSET1 = 0x3F << 18; // To display zero (0-display) (0x3F000000 - This value for common Anode)
delay();delay();delay();delay();
IOCLR1 = 0x3F << 18;;
delay();delay();delay();delay();
}
}
//*************** END of MAIN Program **************//