LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it...

29
LCD 4-Bit Mode The LPC2148 Development board has a 16x2 LCD Connected to it and the speci Connected here in 4-Bit mode, that is despite of using 8 Data pins for sen 4-pins, thereby reducing the number of pins by 4. The Connection Diagram for Interfacing LCD with LPC2148 is as follow:-

Transcript of LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it...

Page 1: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

LCD 4-Bit ModeThe LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using 8 Data pins for sending data, this board uses only 4-pins, thereby reducing the number of pins by 4.

The Connection Diagram for Interfacing LCD with LPC2148 is as follow:-

Page 3: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

/**********LCD Pin Configuration**********/#define EN 19#define RS 17#define RW 18//These all are connected on Port-1 of Controller, so make sure before using IOSET and IOCLR Functions/*****************************************/

/***********FUNCTION PROTOTYPE***********/void Delay(unsigned long value);void Write_Cmd(unsigned int value);void Write_Data(unsigned int value);void Lcd_Init(void);                        //Initialize Lcd Modulevoid Lcd_Data(unsigned int value);void Lcd_Cmd(unsigned int value);void Lcd_String(unsigned char*);/****************************************/

int main(){    Lcd_Init();    Delay(10000);    Lcd_String(" EMBEDDED LAB..");    Delay(100000);    Delay(100000);    Lcd_Cmd(0xC0);    Lcd_String(" LPC2148 DEVBRD");    while(1);}

/***********FUNCTION DEFINITION************/

void Delay(unsigned long value){     while(value>0)    {        value--;    }}void Lcd_Init(void){        IO1DIR |= 0x00FE0000;    //Pins P1.17 to P.23 as Output Pin    Delay(200000);    Write_Cmd(0x30<<16);    Delay(100000);    Write_Cmd(0x30<<16);    Delay(100000);    Write_Cmd(0x30<<16);    Delay(100000);    Write_Cmd(0x20<<16);    //These are the Commands for LCD Initialization in 4-Bit Mode    Lcd_Cmd(0x01);    Lcd_Cmd(0x06);    Lcd_Cmd(0x0C);    Lcd_Cmd(0x80);}

void Write_Cmd(unsigned int value){    //First of all Clear the LCD Data Pins    IO1CLR |= 0x00F00000;

Page 4: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    //To Write RW = 0    IO1CLR |= (1<<RW);    //Write to Command Register RS = 0    IO1CLR |= (1<<RS);    //Write to Pins    IO1SET |= 0x00F00000 & value;    IO1SET |= (1<<EN);    Delay(30000);    IO1CLR |= (1<<EN);}

void Write_Data(unsigned int value){       //First of all Clear the LCD Data Pins    IO1CLR |= 0x00F00000;    //To Write RW = 0    IO1CLR |= (1<<RW);    //Write to Data Register RS = 1    IO1SET |= (1<<RS);    //Write to Pins    IO1SET |= 0x00F00000 & value;    IO1SET |= (1<<EN);    Delay(30000);    IO1CLR |= (1<<EN);}void Lcd_Cmd(unsigned int value){    Write_Cmd(value<<16);    Write_Cmd(value<<20);}void Lcd_Data(unsigned int value){    Write_Data(value<<16);    Write_Data(value<<20);}void Lcd_String(unsigned char *data){    while(*data != '\0')    {        Lcd_Data(*data);        data++;        Delay(10000);    }}/*******************************************/

Page 6: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

2LED

In this basic tutorial to blink the led's connected at the port of LPC2138 is shown, the led's are connected to Pin-16 to Pin 23 of PORT1 of the micro-controller.The code is written in Keil uVision 4 IDE with the help if GCC Compiler.

The schematic diagram is as follow:-

Page 7: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

Here is the code.LED Dance//Simple Led Dance Program

#include <LPC213X.H>void wait (void){                                            long  d;      for (d = 0; d < 10000; d++)                {          for (d = 0; d < 100000; d++);    }}

int main (void){

Page 8: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    unsigned int i;                            IODIR1 = 0x00FF0000;    //PORT1 pin number 16 to 24 are Output Pin                      while (1)                 //Infinite Loop      {                                             for (i = 1<<16; i < 1<<24; i <<= 1)        {              IOSET1 = i;              wait ();       //Wait for Some Time              IOCLR1 = i;        }        for (i = 1<<24; i > 1<<16; i >>=1 )        {                            IOSET1 = i;              wait ();    //Wait for Some Time              IOCLR1 = i;        }    }}

This video will show the output, illustrating how this code worksLed Dance

For more information contact us at [email protected]

The above program is for LPC2138 and the following program is for LPC2148, which is based on the Development Board we are having with us.The Interfacing of LED's with micro-controller is done with the help of a buffer, as micro-controller can't provide enough current to drive Led's, but by using buffer we can do so.

Page 9: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The program written is in Keil uVision IDE and it uses the Compiler provided by Keil not the gcc as we have used it above.

The following program is for LED Blinking:-LED Blinking

/*****Led Blinking Program on LPC2148 ARM Board*****/

#include<lpc21xx.h>

/***********FUNCTION PROTOTYPE***********/void Delay(unsigned long value);

/****************************************/

int main(){

Page 10: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    IO1DIR = 0x00FF0000;              /* Port1 16-23 as output*/    while(1)                        /* Infinite loop    */    {        IO1SET = 0x00FF0000;        /* Port1 16-23 High    */        Delay(1000000);        Delay(1000000);        IO1CLR = 0x00FF0000;        /* Port1 16-23 low    */        Delay(1000000);        Delay(1000000);    }}

/***********FUNCTION DEFINITION************/

void Delay(unsigned long value){     while(value>0)    {        value--;    }}

/*******************************************/

Have a look at this video:-LED Blink

And the Following program is for LED Dance in forward and backward direction:-LED Dance

/**********LED Dance Program*********/

#include <LPC214X.H>/***********FUNCTION PROTOTYPE***********/void Delay(unsigned long value);

/****************************************/

int main(){    unsigned int i;

    IODIR1 = 0x00FF0000;    //LED Port as Output Port

    while(1)    {        for(i = 1<<16; i < 1<<23; i <<= 1)         {            IOSET1 = i;              Delay(1000000);            IOCLR1 = i;        }        for (i = 1<<23; i > 1<<16; i >>=1 )        {            IOSET1 = i;            Delay(1000000);

Page 11: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

            IOCLR1 = i;        }    }}

/***********FUNCTION DEFINITION************/

void Delay(unsigned long value){     while(value>0)    {        value--;    }}

/*******************************************/

Have a look at this video also:-LED Dance

31LCD Interfacing

LCD means liquid Crystal Display, to have a more insight on LCD's have a look at this link of our site LCD Interfacing with PIC18F4550.The circuit Diagram for LPC2138 and LCD interfacing is as follow:-

Page 12: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The code for this is as follow :- LCD Interfacing//Arm Simple Code

#ifndef _STRING_H    #define _STRING_H    #include <string.h>#endif

#ifndef _LPC2138_H    #define _LPC2138

Page 13: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    #include <LPC213X.H>    #endif

#include "lcd.h"

//Function Prototypevoid custom_delay(unsigned int itime);

//Message to Print on LCDconst unsigned char heart[] = {0,0,10,31,31,14,4,0};const unsigned char msg1[] = " EMBEDDED LAB!!";const unsigned char msg2[] = " ARM LPC2138!";const unsigned char msg3[] = " TUTORIAL-->LCD";const unsigned char msg4[] = "CUSTOM CHARACTER"; /***************************************************/

/******************MAIN PROGRAM*********************/int main(void){    IODIR0 = 0xFFFFFFFF;    //Make all Pins of Port-0 as Output Pin        LCD_Init();    LCD_Str((unsigned char*)msg1);    custom_delay(10);    custom_delay(10);    custom_delay(10);    custom_delay(10);    LCD_Clear();    custom_delay(10);    LCD_GOTOXY(1,2);    LCD_Str((unsigned char*)msg2);    LCD_Second_Line();    custom_delay(10);    LCD_Str((unsigned char*)msg3);    custom_delay(10);    custom_delay(10);    custom_delay(10);    custom_delay(10);    LCD_Clear();    LCD_Str((unsigned char*)msg4);    LCD_Second_Line();    LCD_Special_Char(64,0xC0,(unsigned char*)heart);    while(1);    //Stop Here    return 0;}

//Function Definiton

void custom_delay(unsigned int itime){    #ifndef _COUNTER        #define _COUNTER        unsigned int i;    #endif    for(i=0;i<itime;i++)    {            delay();    //delay function present in LCD Library    }}

Page 14: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The following video shows how this code works in the LPC2138.LCD Intefacing with LPC2138

4Graphical LCD

A very good tutorial on Graphical LCD is available on our site if you haven't read that then have a look at it by The Circuit Diagram for this is as follow:-

Page 15: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The code is as follow:-Graphical LCD Code//Graphical LCD Interfacing with LP2138 (ARM-7 Core) Mirco-controller

//Header File Inclusion#ifndef _MY_GRAPHICAL_LCD_H    #define    _MY_GRAPHICAL_LCD_H    #include "my_graphical_lcd.h"#endif

Page 16: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

#ifndef _LPC2138_H    #define _LPC2138_H    #include <LPC213X.H>    #endif

//Image Code for Showing Graphical LCD on the Screenconst char img1[1024] = {  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 128,  64,  64,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32, 32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  64,  64, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 248,   6,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   6, 248,   0,   0,   0,   0,   0,   0,   0, 255,   0,   0,   0, 224, 248,  24,  12,  12,  12,  12,  28,  56,  16,   0,   0, 224, 224, 192,  96,  96,   0, 192, 224,  96,  96,  96, 224, 192,   0,   0, 224, 224, 192,96,  96, 224, 192,   0,   0, 236, 236,   0,   0, 128, 192, 224,  96,  96, 224, 192,   0,   0, 192, 224,  96,  96,  96, 224, 192,   0,   0, 252, 252,   0,   0,   0,   0,0, 224, 248,  24,  12,  12,  12,  12,  28,  56,  16,   0,   0, 252, 252,  12,  12,  12,  12,  12,  24, 248, 224,   0,   0,   0, 255,   0,   0,   0,   0,   0,   0,   0, 255,   0,   0,   0,   7,  31,  24,  48,  48,  51,  51,  59,  31,  15,   0,   0,  63,  63,   0,   0,   0,   0,  28,  62,  54,  51,  51,  31,  63,  32,   0, 255, 255,  24,63,   0,   0,  63,  63,   0,   0,  15,  31,  56,  48,  48,  56,  24,   0,   0,  28,  62,  54,  51,  51,  31,  63,  32,   0,  63,  63,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,48,  48,  48,  56,  28,   8,   0,   0,  63,  63,  48,  48,  48,  48,  48,  24,  31,   7,   0,   0,   0, 255,   0,   0,   0,   0,   0,   0,   0,   1,   6,   8,  16,  32,  32,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  65,  65,64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64, 64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  32,  32,  16,   8,   6,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0};

const char img2[1024] = {  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  16,  16, 240, 240,  16,  16,  16, 144,  16, 112,   0,  16,  16, 240, 112, 224, 128,   0,   0,   0,   0, 128,240, 224,   0,   0,  16,  16, 240, 240,  16,  16,  16, 144,  16, 112,   0,  16,  16, 240, 240,  16,  16,  16,  16,  48,  96, 192, 128,   0,  16,  16, 240, 240,  16,16,  16, 144,  16, 112,   0,  16,  16, 240, 240,  16,  16,  16,  16,  48,  96, 192, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 128, 128, 255, 255, 130, 130, 130, 143, 128, 192,  32, 128, 128, 255, 128, 129,  15,  60, 240,  48,130, 130, 130, 199, 125,  56,   0, 128, 128, 255, 255, 130, 130, 130, 143, 128, 192,  32, 128, 128, 255, 255, 128, 128, 128, 128,  64,  96,  63,  31,   0, 128, 128, 255, 255, 128, 128, 128, 128,128, 128, 255, 255, 130, 130, 130, 143, 128, 192,  32, 128, 128, 255, 255, 128, 128, 128, 128,  64,  96,  63,  31,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  32,  32, 224,  32,  32,   0,   0,   0,   0,   0,   0,   0,   0, 128,  96, 128,   0,   0,   0,   0,  32,  32, 224,  32,  32,  32,128,   0,   0,  32,  32, 224,  32,  32,  32,  64, 128,   0,   0,   0,   0,   0,   0, 128,  96, 128,   0,   0,   0,   0, 224,  32,  32,  32, 224,  32,  32,  32, 224,   0,   0, 128,32,  32,  32,  64, 128,   0,   0,   0,  32,  32, 224,  32,   0,   0, 160,  96,  32,  32,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 128, 128, 255, 128, 128, 128, 128, 192,  32, 128, 128, 224, 156,  19,  16,  19, 156, 224, 128, 128, 128, 128, 255, 132, 132, 132, 134,128, 128, 128,  64,  32,  31,   0, 128, 128, 255, 132, 132,  12,  50,  65, 128, 128, 128, 128, 224, 156,  19,  16,  19, 156, 224, 128, 128,   0,   0, 128, 128, 255, 128, 128,64,  32,  31,   0, 128, 128, 255, 132, 132,  12,  50,  65, 128, 128,   0,   0,   0, 128, 131, 252, 130, 129,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 192, 248, 252, 254, 254, 252, 248, 224,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,240, 240, 248, 252, 252, 254, 254, 254, 252, 248, 248, 240, 224, 224, 192, 128, 128,   0,   0,   0,   0,  14,  31,  31,  63, 127, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 127,  63,  31,  31,  14,   0,   0,   0,0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254,  28,   0,   0,   0,   0,   0,   0, 252, 255, 255, 127, 127,  63,  63,  31,  31,  31,  31,  63,  63, 127, 127, 255, 255, 252,  32,   1,  15, 113, 128,  97,  25,   7, 121, 128,240,   8,   8, 152,   0,   0, 240,   8,   8,   8, 240,   0,  16, 248,  16,   8, 248,  16,   8, 240,   0,   0, 240,  40,  40, 176,   0,   0, 176,  40,  72, 216,   0,   0,   0,127,   0,   0,   0,   7,  31, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,  63,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,   0,   0,   0,   0,   1,   0,   0,   0,   0,   0,   0,1,   1,   0,   0,   1,   1,   1,   0,   1,   1,   0,   1,   1,   0,   0,   1,   1,   0,   0,   0,   1,   1,   1,   0,   0,   0,   0,   0,   0,   0,   1,   1,   1,   1,   0,   0,   0,   0,   1,   0,3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,   0,   0,   0,   0,   0};

Page 17: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

//Function Prototyprvoid custom_delay(unsigned long itime);

int main(void){    IODIR0|=0xFFFFFFFF;    glcd0108_init();    //Initialize the Graphical LCD    delay_small();    delay_small();    while(1)    {        glcd0108_image(img1);    //Display the Image        custom_delay(100000);        glcd0108_clear();        delay_small();        custom_delay(100000);        glcd0108_image(img2);    //Display the Image        custom_delay(100000);            }}

//Function Definition Starts from Herevoid custom_delay(unsigned long itime){    #ifndef _CUSTOM_DELAY_VARIABLE        #define _CUSTOM_DELAY_VARIABLE        unsigned long i;    #endif    for(i=0;i<itime;i++)    {                         delay_small();            }}    

The video showing how this code works is as follow:-Graphical LCD

5Serial Communication

LPC2148 ARM-7 Core is having two UART in it, UART0 and UART1. We will provide tutorial for both these one after another.

Built in Features of UART0 in LPC2148:-

• 16 byte Receive and Transmit FIFOs• Register locations conform to ‘550 industry standard.• Receiver FIFO trigger points at 1, 4, 8, and 14 bytes.

Page 18: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

• Built-in fractional baud rate generator with autobauding capabilities.• Mechanism that enables software and hardware flow control implementation.

The Circuit Diagram for Interfacing COM Port with LPC2148 is as follow:-

The UART0 is operating at a Baud Rate of 9600bps, the Baud Rate is determined by the Crystal Frequency, U0DLM, U0DLL, DivAddVal, MulVal Values.The Formula for Calculation is as follow:-

Page 19: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The Configuration bits are arranged in order to produce the 30MHz Instruction Cycle.

The Program for this is as follow:-UART0 Test Code//Serial Port Test on UART0

#include <LPC214X.H>#include <string.H>

void UART0_Init(void);void UART0_Write(unsigned char value);void UART0_Write_String(unsigned char msg[]);unsigned char UART0_ReadByte(void);

int main(){    UART0_Init();        UART0_Write_String("Embedded laboratory..\r\n");    UART0_Write_String("UART0 Example...\r\n");

Page 20: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    UART0_Write_String("ECHO TEST BEGINS..\r\n");    while(1)    {        UART0_Write(UART0_ReadByte());    }}

void UART0_Init(){    //Assign P0.0 as TXD and P0.1 as RXD    PINSEL0 |= ((1<<0) | (1<<2));    //UART0 Line Control Register, used to configure Serial Port Parameters    U0LCR = 0x83;    //8-bit Data, No Parity and 1-Stop Bit

    //U0DLL and U0DLM Values to be loaded, to get Baud Rate of 9600bps    U0DLL = 0XC3;    U0DLM = 0X00;

      U0LCR = 0X03;    }

void UART0_Write(unsigned char value){    /*TEMT (Transmitter Empty)    TEMT = 0 --> U0THR and U0TSR Contains Some Valid Data    TEMT = 1 --> U0THR and U0TSR are Empty    */    while((U0LSR&0x20) == 0);    //While U0THR Contains Some Valid Data Stay Here    U0THR = value;}unsigned char UART0_ReadByte(){    /*U0LSR0 is Set When U0RBR Contains Some Valid Data    otherwise U0LSR0 is Clear*/    while((U0LSR&0x01) == 0);    //Stay Here until U0LSR0 set to 1    return U0RBR;}void UART0_Write_String(unsigned char msg[]){    #ifndef LENGTH_UART        #define LENGTH_UART        unsigned char len_uart;        unsigned char i_uart;    #endif    len_uart = strlen(msg);    for(i_uart=0;i_uart<len_uart;i_uart++)    {        UART0_Write(msg[i_uart]);    }}

The following video shows how this works in Keil uVision IDE:-UART0 Serial Code

Page 21: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The following figure shows the testing of the hardware with PC (Real Hardware Test)..

Have a look at this video also:-

6Timer Example

Page 22: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

The following table shows the important registers associated with Timer/Counter of LPC2148, have a look at it :-

The Interrupt Register IR (T0IR/T1IR) consists of four bits for the match interrupts and four bits for the capture interrupts. If an interrupt is generated then the corresponding bit in the IR will be high. Otherwise, the bit will be low. Writing a logic one to the corresponding IR bit will reset the interrupt. Writing a zero has no effect.

The Code for this tutorial is as follow,Timer LED Test Code

#include<lpc21xx.h>  int main() {      IO1DIR = 0x00FF0000;              /* Port1 16-23 as output*/     while(1)                   {         IO1SET = 0x00FF0000;        T0MCR = 0X0003;        T0PR  = 0X00;        T0MR0 = 0x00FFFFFF;         T0TCR = 0x01;         while((T0IR & 0x01) == 0);         T0IR = 1;    //Clear Flags.         IO1CLR = 0x00FF0000;        /* Port1 16-23 low    */         T0MCR = 0X0003;              T0PR  = 0X00;        T0MR0 = 0x00FFFFFF;          T0TCR = 0x01;         while((T0IR & 0x01) == 0);         T0IR = 1;    //Clear Flags.     } } 

Page 23: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

7Internal ADC

The Analog-To-Digital Converter on some LPC2000 variant is 10-bit successive approximation converter, with a conversion time of 2.44usec or just say 410 KSps. The A/D converter has either 4 or 8 multiplexed input depending on the variant.The Programming interface is shown below:-

The A/D Control Register establishes the configuration of the converter and controls the start of conversion. The first step in configuring the converter is to set up the peripheral clock. As with all other peripherals, the A/D clock is derived from the PCLK. This PCLK must be divided down to equal 4.5 MHz. This is a maximum value and if PCLK cannot be divided down to equal 4.5 MHz. This is maximum value and if PCLK cannot be divided down to equal 4.5MHz then the nearest value below 4.5MHz which can be achieved should be selected.

PCLK is divided by the value stored in the CLKDIV field plus one. Hence the equation for the A/D clock is as follows:-

CLKDIV = (PCLK/Adclk) - 1

Page 24: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

Prior to conversion the resolution of the result may be defined by programming the CLKS field. The A/D has a maximum resolution of 10-bit but can be programmed to give any resolution down to 3 bits. The conversion resolution is equal to the number of clock cycles per conversion time minus one.

Hence for a 10-bit result the A/D requires 11 ADCLK cycles and four for a 3-bit result. The result is stored in ADDR Register, the format of ADDR is register is shown below:

Now come to the Hardware we are having, 

When the POT is rotated the result is displayed on LCD, for LCD tutorial click here.The Code is given below:-ADC Tutorial

#include <LPC214X.H>

/**********LCD Pin Configuration**********/#define EN 19#define RS 17#define RW 18//These all are connected on Port-1 of Controller, so make sure before using IOSET and IOCLR Functions/*****************************************/

/***********FUNCTION PROTOTYPE***********/void ADC_Init(void);unsigned int Read_ADC(void);void Delay(unsigned long value);void Write_Cmd(unsigned int value);void Write_Data(unsigned int value);void Lcd_Init(void);                        //Initialize Lcd Modulevoid Lcd_Write(unsigned int value);void Lcd_Cmd(unsigned int value);void Lcd_Write_Text(unsigned char*);/****************************************/

int main(){    unsigned int adc_data;    unsigned char ones,tens,hundreds,thousands;    Lcd_Init();    Delay(10000);    Lcd_Write_Text("   WELCOME...");    Delay(100000);    Delay(100000);    Lcd_Cmd(0xC0);    Lcd_Write_Text(" LPC2148 DEVBRD");    Delay(100000);    Delay(100000);

Page 25: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Delay(100000);    Lcd_Cmd(0x01);    Lcd_Write_Text("ADC EXAMPLE");    ADC_Init();    Delay(100000);    while(1)    {        adc_data = Read_ADC();

        ones = adc_data % 10;        adc_data = adc_data / 10;        tens = adc_data % 10;        adc_data = adc_data / 10;        hundreds = adc_data % 10;        adc_data = adc_data / 10;        thousands = adc_data % 10;

        Lcd_Cmd(0xC0);        //Second Row        Lcd_Write(thousands | 0x30);        Lcd_Write(hundreds | 0x30);        Lcd_Write(tens | 0x30);        Lcd_Write(ones | 0x30);        Delay(100000);        Delay(100000);        Delay(100000);        Delay(100000);    }}

/***********FUNCTION DEFINITION************/

void Delay(unsigned long value){     while(value>0)    {        value--;    }}void Lcd_Init(void){        IO1DIR |= 0x00FE0000;    //Pins P1.17 to P.23 as Output Pin    Delay(200000);    Write_Cmd(0x30<<16);    Delay(100000);    Write_Cmd(0x30<<16);    Delay(100000);    Write_Cmd(0x30<<16);

Page 26: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    Delay(100000);    Write_Cmd(0x20<<16);    //These are the Commands for LCD Initialization in 4-Bit Mode    Lcd_Cmd(0x01);    Lcd_Cmd(0x06);    Lcd_Cmd(0x0C);    Lcd_Cmd(0x80);}

void Write_Cmd(unsigned int value){    //First of all Clear the LCD Data Pins    IO1CLR |= 0x00F00000;    //To Write RW = 0    IO1CLR |= (1<<RW);    //Write to Command Register RS = 0    IO1CLR |= (1<<RS);    //Write to Pins    IO1SET |= 0x00F00000 & value;    IO1SET |= (1<<EN);    Delay(30000);    IO1CLR |= (1<<EN);}

void Write_Data(unsigned int value){       //First of all Clear the LCD Data Pins    IO1CLR |= 0x00F00000;    //To Write RW = 0    IO1CLR |= (1<<RW);    //Write to Data Register RS = 1    IO1SET |= (1<<RS);    //Write to Pins    IO1SET |= 0x00F00000 & value;    IO1SET |= (1<<EN);    Delay(30000);    IO1CLR |= (1<<EN);}void Lcd_Cmd(unsigned int value){    Write_Cmd(value<<16);    Write_Cmd(value<<20);}void Lcd_Write(unsigned int value){    Write_Data(value<<16);    Write_Data(value<<20);}void Lcd_Write_Text(unsigned char *data){    while(*data != '\0')    {        Lcd_Write(*data);        data++;        Delay(10000);    }}void ADC_Init(){    PINSEL1 |= 0x01000000;        //Configure P0.28 as AD0.2    AD0CR = 0x00200F02;

Page 27: LED - Web view20.12.2014 · The LPC2148 Development board has a 16x2 LCD Connected to it and the special thing is that the LCD Connected here in 4-Bit mode, that is despite of using

    /*    SEL = 0x02 as AD0.1 is Choosen    CLKDIV = 0x0F    CLKS and BURST = 0x0 means that 11 Intruction Cycles used,resulting in 10-Bit Data    And Don't Start the Conversion Now    */}unsigned int Read_ADC(){    unsigned int adc_data;    AD0CR |= 0x01000000;        //Start the ADC Conversion    //Delay(100000);    do    {        adc_data = AD0DR1;    }while(!(adc_data & 0x80000000));    //Wait untill the DONE bits Sets    AD0CR &= ~0x01000000;                 /* Stop A/D Conversion            */    //AD0CR &= 0xFE000000;        //Stop the ADC Conversion        adc_data = adc_data>>6;    adc_data = adc_data & 0x3FF;    //Clearing all other Bits    return (adc_data);}/*******************************************/