0% found this document useful (0 votes)
20 views

AMC Practical 1-8

The documents describe experiments with interfacing LEDs, LCD displays, and other peripherals to an LPC2148 microcontroller. The experiments utilize functions for initializing and controlling the peripherals, generating delays, and transmitting data via UART. Example code is provided to demonstrate configuring the pins and timers for blinking LEDs, initializing and updating an LCD display, and transmitting/receiving data through the UART interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

AMC Practical 1-8

The documents describe experiments with interfacing LEDs, LCD displays, and other peripherals to an LPC2148 microcontroller. The experiments utilize functions for initializing and controlling the peripherals, generating delays, and transmitting data via UART. Example code is provided to demonstrate configuring the pins and timers for blinking LEDs, initializing and updating an LCD display, and transmitting/receiving data through the UART interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Exp 1:-

#include<lpc21xx.h>

void delay();

int main()

PINSEL2=0x00000000; // All pins are GPIO

IODIR1=0xFFFFFFFF; ;//Configuring GPIO pin as output pin

while(1)

IOSET1=0XFFFFFFFF; // to turn on the LEDS

delay(); //LEDs will remain ON

IOCLR1=0xFFFFFFFF; // to turn off the LEDS

delay(); //LEDs will remain OFF

void delay() //to produce delay

int i,j;

for(i=0;i<1275;i++)

for(j=0;j<1275;j++);

Exp 2:-

#include<lpc214x.h>

void delay(unsigned int msec);

void PLL_Init(void);

void main()

PINSEL2=0x00000000;//All pins are GPIO

IO1DIR=0Xffffffff;//Configuring GPIO pin as output pin

PLL_Init();

while(1)

IO1SET=0Xffffffff;//to turn on the LEDS

delay(1000);

IO1CLR=0Xffffffff;//to turn off the LEDS


delay(1000);

void PLL_Init(void)

PLL0CON=0x01; //enable PLL0

PLL0CFG=0x24; //M=5, P=2

PLL0FEED=0Xaa; //feed sequence

PLL0FEED=0x55; //feed sequence

while(!(PLL0STAT&0x0400)); //wait until PLOCK=1

PLL0CON=0x03; //connect and enable PLL0

PLL0FEED=0Xaa; //feed sequence

PLL0FEED=0x55; //feed sequence

VPBDIV=0x01; //PCLK same as CCLK

void delay(unsigned int msec)

T0CTCR=0x0; //select timer mode

T0TCR=0x00; //timer off

T0PR=59999; //prescaler value for 1ms

T0TCR=0x02; //timer reset

T0TCR=0x01; //timer On

while(T0TC<msec); //1sec delay

T0TCR=0x00; //timer Off

T0TC=0; //Clear the TC value.This is optional

#include<lpc214x.h>

void delay(unsigned int msec);

void PLL_Init(void);

void main()

PINSEL2=0x00000000;// All pins are GPIO

IO1DIR=0Xffffffff;// Configuring GPIO pin as output pin

PLL_Init();

while(1)
{

IO1SET=0Xffffffff;// to turn on the LEDS

delay(1000);

IO1CLR=0Xffffffff;// to turn off the LEDS

delay(1000);

void PLL_Init(void)

PLL0CON=0x01; //enable PLL0

PLL0CFG=0x24; //M=5, P=2

PLL0FEED=0Xaa; //feed sequence

PLL0FEED=0x55; //feed sequence

while(!(PLL0STAT&0x0400)); //wait until PLOCK=1

PLL0CON=0x03; //connect and enable PLL0

PLL0FEED=0Xaa; //feed sequence

PLL0FEED=0x55; //feed sequence

VPBDIV=0x01; //PCLK same as CCLK

void delay(unsigned int msec)

T0CTCR=0x00; //select timer mode

T0TCR=0x00; //timer off

T0PR=59999; //prescaler value for 1ms

T0MR0=1000; //to generate the delay of 1sec

T0MCR=0x0002; //reset TC when TC=MR0

T0TCR=0x02; //timer reset

T0TCR=0x01; //timer On

while(T0TC!=T0MR0); //wait until TC matches MR0

T0TCR=0x00; //timer O

Exp 3:-

#include<lpc214x.h>

#define LCD_PORT 0x00FFO000

#define EN 1<<10 //define RS pin |


#idefine RS 1<<11 //define EN pin

#define RW 1<<20 //define RW pin P|

#define LCD_SHIFT 16 //shift data by LCD_SHIFT bits

Void LCD_init(void);

Void LCD_data(unsigned char);

Void LCD_cmd(unsigned char);

Void LCD_display(int, int, char);

Void lcd_delay(unsigned int time)

Inti,j;

For(i=0;i<time;i++)

For(j=0;j<200;j++);

Void LCD_data(unsigned char ch)//function to send data

IOCLR1=LCD_PORT;

IOSET1 = ch<<LCD_SHIFT; //shift data and set only the data bits

IOSET0= RS; //RS =1

IOCLRO = RW; //[RW =0

IOSETO = EN;

Lcd_delay(100);

IOCLRO = EN;//EN pulse

Void LCD_cmd(unsigned char ch) //function to send command

IOCLR1 = LCD_PORT;

IOSET1 = ch<<LCD_SHIFT;

IOCLRO = RS; //RS=0

IOCLRO = RW;//RW=0

IOSETO=EN;

Lcd_delay(100);

IOCLRO = EN;//EN pulse

Void LCD_init(void)

{
PINSELO &= 0xFF0FFFFF;//Pins P0.10 and P0.11 as GPIO

PINSEL1 &= 0xFFFFFCFF; //Pin P0.20 as GPIO

PINSEL2&= 0xFFFFFFF3;//PORT1 as GPIO

IODIRO=RS | EN | RW;

IODIR1 = LCD_PORT;

LCD_cmd(0x38); //set the pins as output

LCD cmd(0x06);

LCD_cmd(0x0C);

LCD_cmd(0x01);

LCD_cmd(0x80);

Void LCD_display(int row, intpos, char *ch)

Unsigned char temp;

If(row==1)

Temp=0x80 | (pos-1); //set cursor at 1st line posposition

Else

Temp = 0xc0 | (pos-1); //set cursor at 2nd line posposition

LCD_cmd(temp);

While(*ch)

LCD_data(*ch++);//while data is valid, display the string

Void delay(unsigned int time)

Unsigned inti,j;

For(i=0;i<time;i++)

For(j=0;j<5000;j++);

Int main()

Unsigned int temp;

LCD_init();
While(1)

LCD display(1,4,”SANIKA”);

LCD display(2,4,”TYETC225”);//display buffer

Delay(20);

Exp 4:-

/* Interfacing:

**

** D0- D7 -> P1.16 - P1.23

** RW -> P0.11

** EN -> P0.10

** D/I -> P1.25

** CS1 -> P1.26

** CS2 -> P1.27

** GRESET -> P1.24

*/

#include"lpc214x.h"

#define LCD_PORT 0x00FF0000

#define EN 1<<10

#define RS 1<<25

#define CS1 1<<26

#define CS2 1<<27

#define GRST 1<<24

#define RW 1<<11

#define LCD_SHIFT 16

const unsigned char temp[1024] = {

};

const unsigned char LED_OFF[1024] = {

};

const unsigned char LED_ON[1024] = {

};

void delay(unsigned int time) //small delay

int i,j;
for(i=0;i<time;i++)

for(j=0;j<50;j++);

void ldelay(unsigned int time) //long delay

int i,j;

for(i=0;i<time;i++)

for(j=0;j<5000;j++);

void LCD_strobe(void) //generate ENABLE pulse

IO0SET = EN;

delay(5);

IO0CLR = EN;

delay(5);

void GLCD_data(unsigned char ch)

IO1CLR = LCD_PORT;

IO1SET = ch<<LCD_SHIFT;

IO1SET = RS;

LCD_strobe();

void GLCD_cmd(unsigned char ch)

IO1CLR = LCD_PORT;

IO1SET = ch<<LCD_SHIFT;

IO1CLR = RS;

LCD_strobe();

void GLCD_init()

int i;

PINSEL0 = 0; //set pins as GPIO

PINSEL1 = 0;

PINSEL2 = 0;

IODIR0 = EN | RW; //set pins as output

IODIR1 = LCD_PORT | RS | CS1 | CS2 | GRST;

IOCLR1 = LCD_PORT;
IOSET1 = GRST | CS1 | CS2;

IOCLR0 = RW | EN;

IOCLR1 = RS;

for(i=0;i<10;i++)

GLCD_cmd(0x3F); //Display ON

GLCD_cmd(0x40); //Set Y address as 0 (range 0-63)

GLCD_cmd(0xB8); //Set X address as 0 (page address) (range 0-7)

void GLCD_disp(const unsigned char *temp1) //display routine

int i,j;

for(i=0;i<8;i++)

IO1SET = CS1; //select controller 1

IO1CLR = CS2;

GLCD_cmd(0xB8 | i);

GLCD_cmd(0x40);

for(j=0;j<64;j++) //display controller 1 data

GLCD_data(temp1[(i*128)+j]);

IO1CLR = CS1; //select controller 2

IO1SET = CS2;

GLCD_cmd(0xB8 | i);

GLCD_cmd(0x40);

for(j=64;j<128;j++) //display controller 2 data

GLCD_data(temp1[(i*128)+j]);

int main()

GLCD_init();

GLCD_disp(temp);

ldelay(4000);

while(1)

GLCD_disp(LED_OFF);

ldelay(2000);

GLCD_disp(LED_ON);

ldelay(2000);

}
}

Exp 5:-

#include “lpc214x.h”

#include <stdio.h>

Void UartInit(unsigned int );

Unsigned char UART_GetChar(void);

Int UART_PutChar(unsigned char);

Int main(void)

UartInit(9600);

Printf(“\r\nThis is a Demonstration for \r\nUART peripheral for LPC2148\r\nDone on SBC_ARM7 Board \r\n”);

Printf(“\r\nHit any Key on your PC Keyboard to see result\r\n”);

While(1)

UART_PutChar(UART_GetChar());

Void UartInit(unsigned int baudrate)

Unsigned int FDiv;

PINSEL0 = PINSEL0 & 0xFFFFFFF0;

PINSEL0 = PINSEL0 | 0x00000005;

U0LCR = 0x83;

FDiv = (15000000 / 16 ) / baudrate ;

U0DLM = FDiv /256;

U0DLL = FDiv %256;

U0LCR = 0x03;

U0TER = 0x80;

Unsigned char UART_GetChar(void)

While(!(U0LSR & 0x1));

Return(U0RBR);

}
Int UART_PutChar(unsigned char Ch)

While(!(U0LSR & 0x20));

Return( U0THR = Ch);

Int fputc(int ch, FILE *f)

Return (UART_PutChar(ch));

Struct __FILE

{ int handle;

};

FILE __stdout;

Exp 6:-

#include “lpc214x.h”

#include “UART.h”

#include “stdio.h”

#include “string.h”

Void delay(unsigned int time)

Unsigned int I,j;

For(i=0;i<time;i++)

For(j=0;j<5000;j++);

Void GSM_cmd(unsigned char *cmd)

Printf(“\r\ncommand: %s”,cmd);

Printf(“response: “);

UART1_PutS(cmd);

Delay(100);

Int main()

Unsigned char *msg = “MicroEmbedded Technologies\r”;

Uart0Init(9600);
Uart1Init(9600);

Printf(“GSM program\r\n”);

GSM_cmd(“ATE0\r\n”); //Turn OFF echo

Delay(3000);

GSM_cmd(“ATD9673693053;\r\n”); //Call (CHANGE THIS NUMBER)

Delay(20000);

GSM_cmd(“ATH0\r”);

//disconnect call

Delay(3000);

GSM_cmd(“AT+CMGF=1\r\n”); //Send SMS: Select Text mode

Delay(1000);

GSM_cmd(“AT+CSCS=\”GSM\”\r\n”); //GSM Character Set

Delay(1000);

GSM_cmd(“AT+CMGS=\”9673693053\”\r\n”); //Number (CHANGE THIS

NUMBER)

Delay(1000);

UART1_PutS(msg); //Send string

Delay(1000);

UART1_PutChar(0x1A);

//SUBSTITUTE character <CTRL+Z>

While(1);

Return 0;

Exp 7:-

Name : LCD.c

Interface :

D0 – P1.16

D1 – P1.17

D2 – P1.18

D3 – P1.19

D4 – P1.20

D5 – P1.21

D6 – P1.22
D7 – P1.23

EN – P0.10

RS – P0.11

RW – P0.20

#include<lpc214x.h>

#include <stdio.h>

#define LCD_PORT 0x00FF0000

#define EN 1<<10 //define RS pin

#define RS 1<<11 //define EN pin

#define RW 1<<20 //define RW pin

#define LCD_SHIFT 16 //shift data by LCD_SHIFT bits

Void lcd_delay(unsigned int time)

Int I,j;

For(i=0;i<time;i++)

For(j=0;j<200;j++);

Void LCD_data(unsigned char ch) //function to send data

IOCLR1 = LCD_PORT; //clear LCD pins

IOSET0 = RS; //RS =1

IOCLR0 = RW; //RW = 0

IOSET0 = EN;

lcd_delay(100);

IOCLR0 = EN;

lcd_delay(100); //EN pulse

void LCD_cmd(unsigned char ch) //function to send command

IOCLR1 = LCD_PORT;

IOSET1 = ch<<LCD_SHIFT;

IOCLR0 = RS; //RS = 0

IOCLR0 = RW; //RW = 0


IOSET0 = EN;

lcd_delay(100);

IOCLR0 = EN;

lcd_delay(100); //EN pulse

void LCD_init(void)

PINSEL0 &= 0xFF0FFFFF;//Pins P0.10 and P0.11 as GPIO

PINSEL1 &= 0xFFFFFCFF;//Pin P0.20 as GPIO

PINSEL2 &= 0xFFFFFFF3;//PORT1 as GPIO

IODIR0 = RS | EN | RW;//set the pins as output

IODIR1 = LCD_PORT;

LCD_cmd(0x38); //8bit use both lines

LCD_cmd(0x06); //Entry mode

LCD_cmd(0x0C); //display ON cursor OFF

LCD_cmd(0x01); //Clear display

LCD_cmd(0x80);//cursor at 1st line 1st position

void LCD_display(int row, int pos, char *ch)

unsigned char temp;

if(row==1)

temp = 0x80 | (pos-1);//set cursor at 1st line pos position

else

temp = 0xC0 | (pos-1);//set cursor at 2nd line pos position

LCD_cmd(temp);

while(*ch) //while data is valid, display the string

LCD_data(*ch++);

} void ADCInit(void)

PINSEL1 |= 0x05000000; //Configure pins P0.28 and P0.29 as ADC pins


}

unsigned int ADC_Read(unsigned char channel)

static unsigned int ad1_data;

AD0CR = 0x00200300 | (1<<channel); //Set Burst mode to 0, CLK_DIV, Channels,

10bit ADC/11 cycles

AD0CR |= 1<<24; //Start ADC

while(!(AD0GDR & 0x80000000)); //Check DONE bit

ad1_data = (AD0GDR & 0x0000FFC0)>>6; //Assign ADC result to

ad1_data n display in mV

return ad1_data;

void delay(unsigned int time)

unsigned int i,j;

for(i=0;i<time;i++)

for(j=0;j<5000;j++);

int main()

unsigned int temp;

char buf[16];

LCD_init();

ADCInit();

while(1)

temp = ADC_Read(1); //read AN0.1

sprintf(buf," ADC result:0x%03X",temp); //convert to string and store

in a buffer

LCD_display(1,1,buf); //display buffer

delay(20);

Exp 8:-

Program for generating a square wave.


#include <lpc214x.h> //Program for generating a square wave

Void delay()

Int I;

For(i=0;i<600000;i++);

Int main(void)

{ unsigned int value;

PINSEL1 = 0x00080000; //Select AOUT function for P0.25. bits[19:18]=[10]

Value=0;

While(1)

Value=1023;

DACR = (1<<16)|(value<<6);

Delay();

Value=0;

DACR = (1<<16)|(value<<6);

Delay();

Program for generating a traiangular wave.

#include <lpc214x.h> //Program for generating a triangular wave

void delay()

int i;

for(i=0;i<60000000;i++);

int main(void)

{ unsigned int value;

PINSEL1 = 0x00080000; //Select AOUT function for P0.25. bits[19:18]=[10]

value=0;

while(1)

while(value!=1023)
{

DACR = (1<<16)|(value<<6);

value++;

while(value!=0)

DACR = (1<<16)|(value<<6);

value--;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy