Es II Lab Manual
-
Upload
jadinaresh -
Category
Documents
-
view
220 -
download
3
description
Transcript of Es II Lab Manual
![Page 1: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/1.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
EMBEDDED SYSTEMS LAB MANUAL
M.TECH 1ST YEAR –IIND SEM
PRAGNA BHARATH INSTITUTE OF TECHNOLOGY
MUDMYAL , CHEVELLA
![Page 2: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/2.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
LIST OF EXPERIMENTS: PART-A
1. Assembly programs for addition, subtraction, multiplication
2. Configuring the Port bits
3. Configuring the port bit by setting and clearing
4. Write a program to Configure P0.13 and P0.19 as Output and Setting them High
5. Write a program to Configure 1st 16 Pins of Port 0 (P0.0 to P0.15) as Output and Setting them High:
6. Write a program for toggling the port
7. Write a program for toggling the port with some delay
8. Write a program for toggling the port with delay using timer0.
9. Write a program for generation of interrupt using timers
10.Write a program for generation of PWM signal.
11.Write a program to implement buzzer interface
12.Demonstration of serial communication using RS-232
13.Write a program for interfacing LCD display unit
14.Write a program to interface keypad
![Page 3: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/3.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
1. Write an assembly program for addition, subtraction, multiplication.
ADDITION:
AREA ADD, CODE, READONLY
ENTRY
START
MOV R1,#23
MOV R2,#23
ADD R3,R2,R1
END
SUBTRACTION:
AREA ADD, CODE, READONLY
ENTRY
START
MOV R1,#23
MOV R2,#23
SUB R3,R2,R1
END
MULTIPLICATION:
AREA ADD, CODE, READONLY
ENTRY
START
MOV R1,#23
MOV R2,#23
![Page 4: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/4.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
MUL R3,R2,R1
END
2. Write a program to configure Pin 19 of Port 0 as Output and want to drive it High(Logic1)
#include <lpc214x.h>int main(void){IO0DIR |= (1<<19); // Config P0.19 as Ouput
While (1)
{
IO0SET |= (1<<19); // Make ouput High for P0.19
}
3. Write a program to configure Pin 15 High of Port-0 as output i.e P0.15 and then Low
#include <lpc214x.h>int main(void){IO0DIR |= (1<<15); // P0.15 is Output pin
While (1)
{
IO0SET |= (1<<15); // Output for P0.15 becomes High
IO0CLR |= (1<<15); // Output for P0.15 becomes Low
}
}
![Page 5: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/5.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
4. Write a program to Configure P0.13 and P0.19 as Ouput and Setting them High:
#include <lpc214x.h>int main(void){
IO0DIR |= (1<<13) | (1<<19); // Config P0.13 and P0.19 as Ouput
While (1)
{
IO0SET |= (1<<13) | (1<<19); // Make ouput High for P0.13 and P0.19
}
}
5. Write a program to Configure 1st 16 Pins of Port 0 (P0.0 to P0.15) as Ouput and Setting them High:
#include <lpc214x.h>int main(void){
IO0DIR |= 0x0000FFFF; // Config P0.0 to P0.15 as Ouput
While (1)
{IO0SET |= 0x0000FFFF; // Make ouput High for P0.0 to P0.15
}
}
![Page 6: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/6.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
6. Write a program for toggling the port
#include <lpc214x.h>int main (void){ IO0DIR = 0xFFFFFFFF; // Configure all pins on Port 0 as Output while(1) { IO0SET = 0xFFFFFFFF; // Turn on LEDs
IO0CLR = 0xFFFFFFFF; // Turn them off } }
![Page 7: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/7.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
7. Write a program for toggling the port with some delay
include <lpc214x.h>
void delay(void);
int main(void){ IO0DIR = 0xFFFFFFFF; // Configure all pins on Port 0 as Output while(1) { IO0SET = 0xFFFFFFFF; // Turn on LEDs delay(); IO0CLR = 0xFFFFFFFF; // Turn them off delay(); } return 0; // normally this wont execute}
void delay(void){ int i,j; for(i=0; i<4000000; i++) // { for(j=0;j<10000;j++); }}
![Page 8: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/8.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
8. Write a program for toggling the port with delay using timer0.
Include <lpc214x.h>void delay(void);int main(void){ IO0DIR = 0xFFFFFFFF; // Configure all pins on Port 0 as Output while(1) { IO0SET = 0xFFFFFFFF; // Turn on LEDs delay(); IO0CLR = 0xFFFFFFFF; // Turn them off delay(); } return 0; // normally this wont execute}
void delayMS(unsigned int milliseconds) //Using Timer0
{
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
while(T0TC < milliseconds); //wait until timer counter reaches the desired delay
T0TCR = 0x00; //Disable timer
}
![Page 9: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/9.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
9. Write a program for generation of interrupt using timers
#include <lpc214x.h>#define MR0I (1<<0) //Interrupt When TC matches MR0#define MR0R (1<<1) //Reset TC when TC matches MR0
#define DELAY_MS 500 //0.5 Second(s) Delay#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1
void initClocks(void);void initTimer0(void);__irq void T0ISR(void);void initClocks(void);
int main(void){ initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz initTimer0(); //Initialize Timer0 IO0DIR = 0xFFFFFFFF; //Configure all pins on Port 0 as Output IO0PIN = 0x0; T0TCR = 0x01; //Enable timer
while(1); //Infinite Idle Loop
}
void initTimer0(void){ /*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/ //----------Configure Timer0-------------
T0CTCR = 0x0; T0PR = PRESCALE-1; //(Value in Decimal!) - Increment T0TC at every 60000 clock cycles //Count begins from zero hence subtracting 1 //60000 clock cycles @60Mhz = 1 mS
T0MR0 = DELAY_MS-1; //(Value in Decimal!) Zero Indexed Count - hence subtracting 1 T0MCR = MR0I | MR0R; //Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0
![Page 10: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/10.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
//----------Setup Timer0 Interrupt-------------
VICVectAddr4 = (unsigned )T0ISR; //Pointer Interrupt Function (ISR)
VICVectCntl4 = 0x20 | 4; //0x20 (i.e bit5 = 1) -> to enable Vectored IRQ slot //0x4 (bit[4:0]) -> this the source number - here its timer0 which has VIC channel mask # as 4 //You can get the VIC Channel number from Lpc214x manual R2 - pg 58 / sec 5.5 VICIntEnable = 0x10; //Enable timer0 int T0TCR = 0x02; //Reset Timer}
__irq void T0ISR(void){ long int regVal; regVal = T0IR; //Read current IR value IO0PIN = ~IO0PIN; //Toggle all pins in Port 0 T0IR = regVal; //Write back to IR to clear Interrupt Flag
VICVectAddr = 0x0; //This is to signal end of interrupt execution
}
void initClocks(void)
{
// This function is used to config PPL0 and setup both
// CPU and Peripheral clock @ 60Mhz
// You can find its definition in the attached files or case #2 source
}
![Page 11: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/11.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
10.Write a program for generation of PWM signal.
#include <lpc214x.h>
#define PLOCK 0x00000400#define PWMPRESCALE 60 //60 PCLK cycles to increment TC by 1 i.e 1 Micro-second
void init_PWM(void);void init_Clocks(void);
int main(void){ init_Clocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz init_PWM(); //Initialize PWM
//IO0DIR = 0x1; This is not needed! //Also by default all pins are configured as Inputs after MCU Reset. while(1) { if( !((IO0PIN) & (1<<1)) ) // Check P0.1 { PWMMR1 = 1000; PWMLER = (1<<1); //Update Latch Enable bit for PWMMR1 } else if( !((IO0PIN) & (1<<2)) ) // Check P0.2 { PWMMR1 = 1250; PWMLER = (1<<1); } else if( !((IO0PIN) & (1<<3)) ) // Check P0.3 { PWMMR1 = 1500; PWMLER = (1<<1); } else if( !((IO0PIN) & (1<<4)) ) // Check P0.4 { PWMMR1 = 1750; PWMLER = (1<<1); } } //return 0; //normally this wont execute ever}
![Page 12: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/12.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
void init_PWM(void){ /*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/ /*This is a per the Setup & Init Sequence given in the tutorial*/
PINSEL0 = (1<<1); // Select PWM1 output for Pin0.0 PWMPCR = 0x0; //Select Single Edge PWM - by default its single Edged so this line can be removed PWMPR = PWMPRESCALE-1; // 1 micro-second resolution PWMMR0 = 20000; // 20ms = 20k us - period duration PWMMR1 = 1000; // 1ms - pulse duration i.e width PWMMCR = (1<<1); // Reset PWMTC on PWMMR0 match PWMLER = (1<<1) | (1<<0); // update MR0 and MR1 PWMPCR = (1<<9); // enable PWM output PWMTCR = (1<<1) ; //Reset PWM TC & PR PWMTCR = (1<<0) | (1<<3); // enable counters and PWM Mode
//PWM Generation goes active now!! //Now you can get the PWM output at Pin P0.0!
}
![Page 13: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/13.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
11.Write a program to implement buzzer interface
#include<lpc21xx.h>
int main(void)
{
unsigned int i;
IO0DIR = 0Xffffffff;
IO1DIR=0Xffffffff;
while(1)
{
for (i=0;i<10000;i=i+100)
{
IO0SET = 0X00000080;
IO1SET = 0X00ff0000;
delay(i*10);
IO0CLR = 0X00000080;
IO1CLR = 0X00ff0000;
delay(i*10);
}
for (i=10000;i>0;i=i-100)
{
IO0SET = 0X00000080;
IO1SET = 0X00ff0000;
delay(i*10);
IO0CLR = 0X00000080;
IO1CLR = 0X00ff0000;
![Page 14: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/14.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
delay(i*10);
}
}
}
void delay(unsigned long cnt)
{
unsigned long temp,val;
for(temp=0;temp<cnt;temp++)
for (val=0;val<10;val++);
}
NOTE:
1. Make P0.7 to operate as GPIO pin using PINSEL.
2. Configure PO.7 as output pin using IO0DIR.
3. Provide signals on P0.7 to control buzzing sound from buzzer.
![Page 15: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/15.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
12.Demonstration of serial communication using RS-232
#include <LPC21xx.H> /* LPC21xx definitions*/
//#include "serial.h"
int main(void)
{
int j=0;
init_serial (); // initialise serial port with 9600bps
SendChar ('A'); // transmit char A
SendChar ('\n'); // transmit new line character
SendString("Ellenki"); // transmit string Ellenki
SendChar ('\n'); // transmit new line character
SendDigit(236); // transmit digit 236
}
void init_serial (void)
{ /*Initialize Serial Interface */
PINSEL0 = PINSEL0 | 0X00000005; /* Enable RxD0 and TxD0 */
U0LCR = 0X83; /*8 bits, no Parity, 1 Stop bit */
U0DLL = 0XC3;
U0DLM = 0X00; /* 9600bps baud rate */
U0LCR = 0X03; /* DLAB = 0 */
}
int GetChar (void)
{ /* Read character from Serial Port */
while (!(U0LSR & 0x01));
return (U0RBR);
}
![Page 16: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/16.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
char SendChar (char SDat)
{ /* Write character to Serial Port */
while (!(U0LSR & 0x20));
return (U0THR = SDat);
}
void SendString(char *lcd_string)
{
while (*lcd_string)
{
SendChar(*lcd_string++);
}
}
void SendDigit(unsigned int dat)
{
unsigned int temp,i=0, buf[10];
while(dat>=10)
{
buf[i]=dat%10;
dat=dat/10;
i++;
}
buf[i]=dat;
for(temp=0;temp<=i;temp++)
{
SendChar(buf[i-temp]+'0');
}
}
![Page 17: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/17.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
13.Write a program for interfacing LCD display unit
#include <LPC21xx.h>
#include "lcd4bit.h"
int main(void) {
init_lcd();
while(1)
{
lcd_command(0x01);
lcd_command(0x80);
printlcd("Welcome To");
lcd_command(0xC0);
printlcd("ELLENKI");
Delay(50000000);
lcd_command(0x01);
lcd_command(0x80);
printlcd("LCD Interface ");
lcd_command(0xC0);
printlcd("with LPC 2148");
Delay(50000000);
lcd_command(0x01);
lcd_command(0x80);
printlcd("Developed By:");
lcd_command(0xC0);
printlcd("ELLENKI STUDENTS");
Delay(50000000);
}
![Page 18: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/18.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
}
void init_lcd(void)
{
IO1DIR |= 0x00FE0000;
Delay(200000) ;
Delay(100000);
write_command(0x30 << 16);
Delay(100000);
write_command(0x20 << 16);
lcd_command(0x01); /* clear display */
lcd_command(0x06); /* auto address inc */
lcd_command(0x0c); /* cursor off */
lcd_command(0x80); /* first location */
}
void Delay(unsigned long b)
{
while (--b!=0);
}
void write_command(int cmd)
{
IO1CLR |= 0x00f00000; // Clear Data pins
IO1CLR |= 0x00040000; // RW = 0
IO1CLR |= 0X00020000; // RS= 0,
IO1SET |= 0x00f00000 & cmd; //Set Data pins
IO1SET |= 0X00080000; // Enable = 1
Delay(30000); // Provide Delay
IO1CLR |= 0x00080000; // Set Enable=0
![Page 19: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/19.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
}void write_data(int dat){IO1CLR |= 0x00f00000; // Clear Data pins4-D7IO1CLR |= 0x00040000; // RW= 0IO1SET |= 0X00020000; //RS= 1IO1SET |= 0x00f00000 & dat; // Set Data pinsIO1SET |= 0X00080000; // Enable = 1
Delay(30000); //Provide Delay
IO1CLR |= 0x00080000; //Set Enable=0
}
void lcd_data(char dat)
{
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd)
{
write_command(cmd << 16);
write_command(cmd << 20);
}
void printlcd(char *CPtr)
{
while(*CPtr != '\0')
{
lcd_data(*CPtr);
CPtr++;
Delay(20000); } }
![Page 20: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/20.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
14.Write a program to interface keypad and lcd
#include<lpc21xx.h>
#include "lcd4bit.h"
#define CLR 0x0003C000
Unsigned char check (int);
void delay(int);
int main(void)
{
init_lcd();
lcd_command(0x01);
lcd_command(0x80);
printlcd("4x4 KEYPAD");
lcd_command(0xC0);
printlcd("with LPC 2148");
delay(2000);
lcd_command(0x01);
lcd_command(0x80);
printlcd("Developed By:");
lcd_command(0xC0);
printlcd("Shekar ");
delay(2000);
lcd_command(0x01);
lcd_command(0x80);
printlcd("Enter Value");
lcd_command(0xC0);
IO0DIR = 0X0003C000;
while(1)
![Page 21: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/21.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
{
IO0CLR = CLR;
IO0SET = O1;
delay(10);
if(check(I1))
{
lcd_data('0');
}
if(check(I2))
{
lcd_data('1');
}
if(check(I3))
{
lcd_data('2');
}
if(check(I4))
{
lcd_data('3');
}
IO0CLR = CLR;
IO0SET = O2;
if(check(I1))
{
lcd_data('4');
}
if(check(I2))
![Page 22: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/22.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
{
lcd_data('5');
}
if(check(I3))
{
lcd_data('6');
}
if(check(I4))
{
lcd_data('7');
}
IO0CLR = CLR;
IO0SET = O3;
if(check(I1))
{
lcd_data('8');
}
if(check(I2))
{
lcd_data('9');
}
if(check(I3))
{
lcd_data('A');
}
if(check(I4))
![Page 23: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/23.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
{
lcd_data('B');
}
IO0CLR = CLR;
IO0SET = O4;
if(check(I1))
{
lcd_data('C');
}
if(check(I2))
{
lcd_data('D');
}
if(check(I3))
{
lcd_data('E');
}
if(check(I4))
{
lcd_data('F');
}
}
}
char check(int val) /* scanning a a key */
{
while((IO0PIN & 0X00003C00)==val)
{
![Page 24: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/24.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
delay(50);
if((IO0PIN & 0X00003C00)== 0X00003C00)return(1);
}
return(0) ;
}
void delay(int n) /* generates one milisecond delay */
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=40000; j++);
}
void write_command(int cmd)
{
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1CLR |= 0X00020000; /* Register Select = 0,Command */
IO1SET |= 0x00f00000 & cmd; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
Delay(30000);
IO1CLR |= 0x00080000; /* set E to low */
}
void write_data(int dat)
{
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1SET |= 0X00020000; /* Register Select = 1,Data */
![Page 25: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/25.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
IO1SET |= 0x00f00000 & dat; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
Delay(30000); //delay ~2ms
IO1CLR |= 0x00080000; /* Set E to low */
}
void lcd_data(char dat)
{
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd)
{
write_command(cmd << 16);
write_command(cmd << 20);
}
void printlcd(char *CPtr)
{
while(*CPtr != '\0')
{
lcd_data(*CPtr);
CPtr++;
Delay(20000);
}
}
void init_lcd(void)
{
IO1DIR |= 0x00FE0000;
![Page 26: Es II Lab Manual](https://reader035.fdocuments.us/reader035/viewer/2022062520/5695d4c31a28ab9b02a2ac12/html5/thumbnails/26.jpg)
EMBEDDED SYSTEMS LAB DEPT.OF ECE
Delay(200000) ;
write_command(0x28 << 16);
Delay(100000);
lcd_command(0x01); /* clear display */
lcd_command(0x06); /* auto address inc */
lcd_command(0x0c); /* cursor off */
lcd_command(0x80); /* first location */
}