Tuesday, September 27, 2022

Keypad Interface with ARM LPC2148





Source Code:

#include<lpc214x.h>

void delay(unsigned int);

unsigned int seg[]={0x00000006,0x0000005B,0x0000004F,0x00000066,0x0000006D,0x0000007D,0x00000007,0x0000007F,0x0000006F,0x0000003F};

#define c0 0x00010000

#define c1 0x00020000

#define c2 0x00040000

#define r0 0x00080000

#define r1 0x00100000

#define r2 0x00200000

#define r3 0x00400000

int main(void)

{

IO0DIR=0x000000FF;

IO1DIR=0x00780000;

while(1)

IO1CLR|=r0;

IO1SET|=(r1|r2|r3);

if(!(IO1PIN& c0))

{

while(!(IO1PIN&c0));


IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[5]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[0];

}

if(!(IO1PIN&c1))

{

while(!(IO1PIN&c1));


IO0CLR=(seg[0]|seg[2]|seg[3]|seg[4]|seg[5]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[1];

}

if(!(IO1PIN&c2))

{

while(!(IO1PIN&c2));

IO0CLR=(seg[0]|seg[1]|seg[3]|seg[4]|seg[5]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[2];


}

IO1CLR|=r1;

IO1SET|=(r0|r2|r3);

if(!(IO1PIN & c0))

{

while(!(IO1PIN& c0));

IO0CLR=(seg[1]|seg[2]|seg[0]|seg[4]|seg[5]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[3];


}

if(!(IO1PIN& c1))

{

while(!(IO1PIN& c1));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[0]|seg[5]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[4];


}

if(!(IO1PIN& c2))

{

while(!(IOPIN1& c2));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[0]|seg[6]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[5];


}

IO1CLR|=r2;

IO1SET|=(r1|r0|r3);

if(!(IO1PIN& c0))

{

while(!(IO1PIN& c0));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[5]|seg[0]|seg[7]|seg[8]|seg[9]);

IO0SET=seg[6];


}

if(!(IO1PIN& c1))

{

while(!(IO1PIN& c1));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[5]|seg[6]|seg[0]|seg[8]|seg[9]);

IO0SET=seg[7];


}

if(!(IO1PIN& c2))

{

while(!(IO1PIN& c2));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[5]|seg[6]|seg[7]|seg[0]|seg[9]);

IO0SET=seg[8];


}

IO1CLR|=r3;

IO1SET|=(r1|r2|r0);

if(!(IO1PIN& c1))

{

while(!(IO1PIN& c1));

IO0CLR=(seg[1]|seg[2]|seg[3]|seg[4]|seg[5]|seg[6]|seg[7]|seg[8]|seg[0]);

IO0SET=seg[9];


}


}

}

void delay(unsigned int count)

 { int i,j;

  

for(i=count;i>0;i++)

{

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

}

}


Circuit Diagram:



Saturday, September 24, 2022

Interfacing of LEDs with PIC microcontroller

Algorithm 

Step1: LEDs are connected in Port A of PIC microcontroller

Step2: Make Port A as output port

Step3: Making all LEDs glow by sending value “0F” at port A

Step4: After time delay of 500ms, turned off all LEDs by sending value of “00” at port A

Step5: After another 500ms delay, repeat steps 3



Circuit Diagram





Program code

 #include <pic.h> //Define PIC Registers

__CONFIG(0x3f72); //Select HS oscillator, Enable (PWRTE,BOREN), Turn OFF 

(CPD,CP,WDTEN,In-circuit Debugger).

void DelayMs(unsigned int);

void main()

{

ADCON1 = 7; //Select all the PORTA & PORTE as Digital I/O pins

TRISA = 0x00; //PORTA Configured as O/P

while(1)

{

PORTA = 0x0f; //Enable all the LED's connected to PORTA

DelayMs(500); //Half second Delay

PORTA = 0; //Turn OFF all the LED's connected to PORTA

DelayMs(500); //Half second Delay

}

}

void DelayMs(unsigned int Ms)

{

int delay_cnst;

while(Ms>0)

{

Ms--;

for(delay_cnst = 0;delay_cnst <220;delay_cnst++);

}

}

Tuesday, September 20, 2022

Graphical LCD interface with LPC2148


 



The graphical LCD used in this experiment is Winstar’s WDG0151 -TMI module, which is a 128×64 pixel monochromatic display. It uses two Neotic display controller chips: NT7108C and NT7107C, which are compatible with Samsung KS0108B and KS0107B controllers . The KS0108B (or NT7108C) is a dot matrix LCD segment driver with 64 channel output, and therefore, the WDG0151 module contains two sets of it to drive 128 segments. On the other hand, the KS0107B (or NT7107C) is a 64 -channel common driver which generates the timing signal to control the two KS0108B segment drivers. The KS0108B and KS0107B are very popular controllers and have made their way into many graphical LCDs. The internal block diagram of the

WDG0151 GLCD module is shown below.

The NT1707C drives the 64 display lines, COM1 – COM64. The first NT7108C drives the left half segments (SEG1 to SEG64) and the second one drives the right half segments (SEG65 to SEG128) of the display. The two halves of the display can be individually accessed through th e chip select pins (CS1 and CS2) of the two NT7108C drivers. Each half consists of 8 horizontal pages (0 -7) which are 8 bits (1 byte) high. This is illustrated in the drawing below.

Starting from page 0 on the left half (/CS1 = 0) if you transmit one data byte, it will appear on the first column of page 0. If you repeat this 64 times, then switch to the second half, and repeat until 128th position is reached, the first 8 display lines will be plotted. The next 8 lines can be plotted similarly by switching to page address 1.The total amount of bytes needed for a complete display frame (128×64 pixels) is, therefore, 2 * 64 pixels * 8 bits = 1024 bytes.




Source Code:

#include <LPC214X.H>

#define CS2 0

#define CS1 1

#define RS 4

#define RW 5

#define EN 6

#define RST 7

extern const char MY_LOGO[];

unsigned char D0;

unsigned char CMD[] = {0x3e,0xc0,0xb8,0x40,0x3f};

unsigned char i;

void GLCD_Init(unsigned long *, unsigned char);

void GLCD_Page(unsigned char);

void GLCD_Cmd (unsigned long *, unsigned char, unsigned char);

void GLCD_Data (unsigned long *, unsigned char, unsigned char);

void GLCD_Draw (unsigned long *GLCDPort, unsigned char Datt, const char *Base);

void Delay();


const char MY_LOGO[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,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  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,128,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,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  3,  3,  3,  3,255, 

 255,255,255,255,  3,  3,  3,  3,  3,  1,  0,  0,252,252,252,248, 

  24, 28, 12, 12, 12,  0,  0,224,240,248,248,124,108,108,108,108, 

 108,124,120,120,112,  0,  0,  0,248,252,252,252,248, 24, 12, 12, 

  12, 12,252,252,248,248,  0,  0,  0,  0,240,248,248,252, 28, 12, 

  12, 12,  8, 24,255,255,255,255,  0,  0,  0, 12, 28,124,252,240, 

 224,192,128,192,240,248,124, 60, 28,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  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, 

   3,  3,  3,  1,  0,  0,  0,  0,  0,  0,  0,  0,  3,  3,  3,  3, 

   0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  3,  3,  3,  3,  3,  3, 

   3,  3,  3,  3,  0,  0,  0,  0,  1,  3,  3,  3,  1,  0,  0,  0, 

   0,  0,  3,  3,  3,  3,  0,  0,  0,  0,  1,  1,  3,  3,  3,  3, 

   3,  3,  3,  1,  1,  3,  3,  3,  0,  0,  0,  0,  0,  0,  0, 25, 

  31, 31, 15, 15,  3,  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,192,224,240,240,112, 

  56, 24, 24, 24, 24, 24, 24, 24, 48, 16,  0,  0,  0,128,128,192, 

 192,192,192,192,192,192,192,192,192,128,128,  0,  0,  0,  0,128, 

 128,192,192,192,192,192,192,192,128,248,248,248,248,  0,  0,  0, 

   0,216,216,216,216,  0,  0,  0,  0,192,192,192,192,128,192,192, 

 192,192,192,192,192,192,128,  0,  0,  0,  0,128,192,192,192, 64, 

  64, 64,192,192,192,192,192,192,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  7, 15, 31, 31, 28, 

  56, 56, 48, 48, 48, 48, 48, 48, 24, 24,  0,  0,  6, 15, 31, 31, 

  57, 48, 48, 48, 48, 48, 48, 61, 31, 31, 15,  7,  0,  0,  6, 31, 

  31, 63, 57, 48, 48, 48, 48, 24, 24, 31, 63, 63, 63,  0,  0,  0, 

   0, 63, 63, 63, 63,  0,  0,  0,  0, 31, 63, 63, 63,  1,  0,  0, 

   0,  0,  0, 31, 63, 63, 63,  0,  0,  0,232,255,255,255,190,188, 

 188,188,190,183,247,243,241, 96,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 

   0,  0,  0,  0,  0,  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,  1,  1, 

   1,  1,  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 

 };

int main()

{

PINSEL0 = 0;

PINSEL1 = 0;

IODIR0 = 0x0000FFFF;

GLCD_Init (&IO0PIN, 8);

while(1)

{

Delay(10);Delay(10);Delay(10);Delay(10);

GLCD_Draw(&IO0PIN, 8,MY_LOGO);

}

}

void GLCD_Init(unsigned long *GLCDPort, unsigned char Datt)

{

D0 = Datt;

IOPIN0 = 0;

IOSET0 = 1 << RST;

Delay();

IOCLR0 = 1 << RST;

Delay();

IOSET0 = 1 << RST;

GLCD_Page(1);

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

{

GLCD_Cmd(GLCDPort, D0, CMD[i]);

}

GLCD_Page(0);

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

{

GLCD_Cmd(GLCDPort, D0, CMD[i]);

}

}

void GLCD_Page(unsigned char PagE)

{

if (PagE)

{

IOCLR0 = 1 << CS1;

IOSET0 = 1 << CS2;

}

else


{

IOCLR0 = 1 << CS2;

IOSET0 = 1 << CS1;

}

}

void GLCD_Cmd (unsigned long *GLCDPort, unsigned char Datt, unsigned char c)

{

D0 = Datt;

if(c & 0x80) IOSET0 = 1 << (D0+7); else IOCLR0 = 1 << (D0+7);

if(c & 0x40) IOSET0 = 1 << (D0+6); else IOCLR0 = 1 << (D0+6);

if(c & 0x20) IOSET0 = 1 << (D0+5); else IOCLR0 = 1 << (D0+5);

if(c & 0x10) IOSET0 = 1 << (D0+4); else IOCLR0 = 1 << (D0+4);

if(c & 0x08) IOSET0 = 1 << (D0+3); else IOCLR0 = 1 << (D0+3);

if(c & 0x04) IOSET0 = 1 << (D0+2); else IOCLR0 = 1 << (D0+2);

if(c & 0x02) IOSET0 = 1 << (D0+1); else IOCLR0 = 1 << (D0+1);

if(c & 0x01) IOSET0 = 1 << (D0); else IOCLR0 = 1 << (D0);

IOCLR0 = 1 << RS;

IOCLR0 = 1 << RW;

IOSET0 = 1 << EN;

Delay();

IOCLR0 = 1 << EN;

}

void GLCD_Data (unsigned long *GLCDPort, unsigned char Datt, unsigned char c)

{

D0 = Datt;

if(c & 0x80) IOSET0 = 1 << (D0+7); else IOCLR0 = 1 << (D0+7);

if(c & 0x40) IOSET0 = 1 << (D0+6); else IOCLR0 = 1 << (D0+6);

if(c & 0x20) IOSET0 = 1 << (D0+5); else IOCLR0 = 1 << (D0+5);

if(c & 0x10) IOSET0 = 1 << (D0+4); else IOCLR0 = 1 << (D0+4);

if(c & 0x08) IOSET0 = 1 << (D0+3); else IOCLR0 = 1 << (D0+3);

if(c & 0x04) IOSET0 = 1 << (D0+2); else IOCLR0 = 1 << (D0+2);

if(c & 0x02) IOSET0 = 1 << (D0+1); else IOCLR0 = 1 << (D0+1);

if(c & 0x01) IOSET0 = 1 << (D0); else IOCLR0 = 1 << (D0);

IOSET0 = 1 << RS;

IOCLR0 = 1 << RW;

IOSET0 = 1 << EN;

Delay();

IOCLR0 = 1 << EN;

}

void GLCD_Draw (unsigned long *GLCDPort, unsigned char Datt, const char *Base)

{

int Page, Column;

D0 = Datt;

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

{

GLCD_Page(1);

GLCD_Cmd (GLCDPort, D0, (0xB8 | Page));

GLCD_Cmd (GLCDPort, D0, 0x40);

for (Column = 0; Column < 128; Column++)

{

if (Column == 64)

{

GLCD_Page (0);

GLCD_Cmd (GLCDPort, D0, (0xB8 | Page));

GLCD_Cmd (GLCDPort, D0, 0x40);

}

GLCD_Data (GLCDPort, D0, *Base++);

Delay();

}

}

}

void Delay()

{

unsigned int i,j;

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

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

}


Circuit Diagram



Friday, September 16, 2022

How to interface Buzzer with LPC2148

 



Program code

#include <LPC214x.h>

#include <stdio.h>


#define BUZZ 7


void Delay(void);

void Wait(void);




void Delay()

{

unsigned int i,j;

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

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

}



void main()

{

PINSEL0 = 0x00; //Configure Port0.7 as GPIO

IODIR0 = 3 << BUZZ; //Configure Port0.7 as OutPut pin

while(1)

{

IOSET0 = 1 << BUZZ;

Delay();

IOCLR0 = 1 << BUZZ;

Delay();

}

}


Circuit Diagram



Thursday, September 15, 2022

Real time clock implementation using LPC2148/38

 



Program code


RTC.C


#include <LPC213X.H>

#include "LCD.h"

#include "Delays.h"


/**********Function Prototype***********/

void RTC_Init(void);


__irq void RTC_ISR(void); //RTC Interrupt Function Prototype

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


unsigned char flag = 1;


int main()

{

unsigned char msg[] = "Trendy Coding";

unsigned char rtc_example[] = "RTC with ARM";

unsigned char TIME[] = " TIME:";

unsigned char DATE[] = "DATE:";

RTC_Init();

VICVectAddr13 = (unsigned)RTC_ISR; //Vector Address of RTC Interrupt

VICVectCntl13 = 0x20 | 0x0D; //Enable the Vector IRQ Slot for RTC Interrupt

VICIntEnable = (1UL<<13); //Enable the RTC Interrupt

Lcd_Init();

Delay_ms(10);

Lcd_Write_Text(msg);

Lcd_Cmd(SECOND_ROW);

Lcd_Write_Text(rtc_example);

Delay_ms(500);

Lcd_Cmd(LCD_CLEAR);

Lcd_Write_Text(TIME);

Lcd_Cmd(SECOND_ROW);

Lcd_Write_Text(DATE);

while(1)

{

if(flag)

{

Lcd_Cmd(FIRST_ROW+8);

Lcd_Write(HOUR/10 + 0x30);

Lcd_Write(HOUR%10 + 0x30);

Lcd_Write(':');

Lcd_Write(MIN/10 + 0x30);

Lcd_Write(MIN%10 + 0x30);

Lcd_Write(':');

Lcd_Write(SEC/10 + 0x30);

Lcd_Write(SEC%10 + 0x30);

Lcd_Cmd(SECOND_ROW+6);

Lcd_Write(DOY/10 + 0x30);

Lcd_Write(DOY%10 + 0x30);

Lcd_Write('/');

Lcd_Write(MONTH/10 + 0x30);

Lcd_Write(MONTH%10 + 0x30);

Lcd_Write('/');

Lcd_Write(YEAR/1000 + 0x30);

Lcd_Write((YEAR/100)%10 + 0x30);

Lcd_Write((YEAR/10)%10 + 0x30);

Lcd_Write(YEAR%10 + 0x30);

flag = 0;

}

}

}


/**********Function Definition**********/

void RTC_Init(void)

{

DOY = 15; //Enter Date

MONTH = 10; //MONTH

YEAR = 2022; //Year

HOUR = 03; //Hour

MIN = 05; //Min

SEC = 0; //Sec

PREINT = 0x392; //To Generate clock of 32.768KHz for RTC Module

PREFRAC = 0x4380; //when PCLK = 30MHz

/*

Formula For Calculation is as follow:-

PREINT  = (int)(PCLK/32768)-1

PREFRAC = PCLK - ((PREINT+1)*32768

Example:-

if PCLK = 30MHz

PREINT = 914 = 0x392

PREFRAC = 17280 = 0x4380

*/

CIIR = 0x01; //Enables Second Counter Interrupt

CCR = 0x01; //Start RTC

}


__irq void RTC_ISR(void)

{

flag = 1;

ILR = 0x01; //Clear the RTC Interrupt Flag

VICVectAddr = 0x00;

}


LCD.C

#include <LPC213X.H>

#include "LCD.h"

#include "Delays.h"


/*****************LCD Functions***************/

void Lcd_Init(void)

{

PINSEL0 = 0x00;

IODIR0 |= (1<<RS); //RS Pin as Output Pin

IODIR0 |= (1<<RW); //RW Pin as Output Pin

IODIR0 |= (1<<EN); //EN Pin as Output Pin

IODIR0 |= 0x0000FF00; //P0.8 to P0.15 as Data Line of LCD

Lcd_Cmd(0x38); //Send 8-bit initialization command to lcd

Delay_ms(10);

Lcd_Cmd(CURSOR_OFF); //Cursor OFF

Delay_ms(10);

Lcd_Cmd(LCD_CLEAR);

Delay_ms(1);

Lcd_Cmd(FIRST_ROW);

}


void Lcd_Data_Shift(unsigned char value)

{

/*

This Function will shift the eight bit data stored in variable value,

to the Port Pin P0.8 to P0.15 Successfully.

*/

unsigned char i;

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

{

if(value & 0x01)

{

IOSET0 |= (1<<(i+8));

}

else

{

IOCLR0 |= (1<<(i+8));

}

value = value >> 1;

}

}


void Lcd_Cmd(unsigned char value)

{

/*Configure LCD for receiving Command Data*/

IOCLR0 |= (1<<RS);

IOCLR0 |= (1<<RW);

IOSET0 |= (1<<EN);

Lcd_Data_Shift(value);

Enable_Pulse();

}


void Lcd_Write(unsigned char value)

{

/*Configure LCD for receiving Display Data*/

IOSET0 |= (1<<RS);

IOCLR0 |= (1<<RW);

IOSET0 |= (1<<EN);

Lcd_Data_Shift(value);

Enable_Pulse();

}


void Lcd_Write_Text(unsigned char msg[])

{

while(*msg)

{

Lcd_Write(*msg);

msg++;

}

}


Delays.C

#include "Delays.h"

void Delay_ms(unsigned long times)

{

unsigned long i,j;

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

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

}


LCD.H

#define LCD_CLEAR 0x01

#define CURSOR_OFF 0x0C

#define FIRST_ROW 0x80

#define SECOND_ROW 0xC0

#define Enable_Pulse() IOSET0|=1<<EN;Delay_ms(1);IOCLR0=1<<EN;Delay_ms(1);

/*Pin Configuration for LCD*/

#define RS 2

#define RW 3

#define EN 4

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


/**************Function Prototypes************/

extern void Lcd_Init(void);

extern void Lcd_Cmd(unsigned char value);

extern void Lcd_Write(unsigned char value);

extern void Lcd_Write_Text(unsigned char msg[]);

extern void Lcd_Data_Shift(unsigned char value);


delays.h

/***********Function Prototype***********/

extern void Delay_ms(unsigned long times);

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



Circuit diagram




Tuesday, September 13, 2022

LCD interface with ARM LPC2148

 


THEORY:

Liquid crystal display (LCD):

A display that consists of two polarizing transparent panels and a liquid crystal surface

sandwiched in between. An electric current passed through the liquid causes the crystal to align so that

light cannot pass through them. The LCD has ability to display numbers, characters and graphics. A

sample photo of the LCD module is shown in Figure.


LCD Pin Description:
The LCD we used in the module has 16 pins. The functions of each pin is
RS (Register select):
There are two very important registers inside the LCD
1. Command code register

2. Data register

 The RS pin is used for selection of this registers. If RS = 0, Instruction command code register is selected, allowing the user to send a command. If RS= 1 the data register is

selected, allowing the user to send data to be displayed on the LCD.

R/W (Read/ Write):

R/W input allows the user to write information to the LCD or write information from it.

R/W = 1 ; When reading

R/W = 0 ; When Writing

E (Enable):

The enable pin is used by the LCD to latch information presented to its data pins.When data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide.

D0 – D7 (Data pins):

The 8 bit data pins, D0 – D7, are used to send information to the LCD or read the contents of the

LCD‟s internal registers.


Program code

#include <lpc214x.h> 

void  delay_ms(unsigned char time)    

{  

 unsigned int  i, j;

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

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

}


void LCD_command(unsigned char command)

{

IOCLR0 = 0xFF<<16; // Clear LCD Data lines

IOCLR1=1<<16; // RS=0 for command

IOCLR1=1<<17; // RW=0 for write

IOSET0=command<<16; // put command on data line

IOSET1=(1<<18); // en=1 

delay_ms(10) ; // delay

IOCLR1=(1<<18); // en=0

}


LCD_data(unsigned char data)

{

IOCLR0 = 0xFF<<16; // Clear LCD Data lines

IOSET1=1<<16; // RS=1 for data

IOCLR1=1<<17; // RW=0 for write

IOSET0= data<<16; // put command on data line

IOSET1=(1<<18); //en=1 

delay_ms(10) ;   //delay

IOCLR1=(1<<18); //en=0

 }


LCD_init()

{

LCD_command(0x38); //8bit mode and 5x8 dotes (function set)

delay_ms(10) ; // delay

LCD_command(0x0c); //display on, cursor off, cursor char blinking off(display on/off)

delay_ms(10) ; // delay

LCD_command(0x06);  //cursor increament and display shift(entry mode set)

delay_ms(10) ; // delay

LCD_command(0x01); //clear lcd(clear command)

delay_ms(10) ; // delay

LCD_command(0x80); //set cursor to 0th location 1st lne

}

 

LCD_write_string(unsigned char *string)

{

  while(*string) //Check for End of String

  LCD_data(*string++); //sending data on LCD byte by byte

}


int main(void)

{

PINSEL1 = 0x00; //Configure PORT0 as GPIO

PINSEL2 = 0X00; //Configure PORT1 as GPIO

IODIR1= 0x07<<16; //Configure P1.18, P1.17, P1.16 as output

IODIR0= 0xFF<<16; //Configure P0.23 - P0.16 as output

LCD_init(); //Initialize LCD 16x2


LCD_write_string("Trendy Coding");

LCD_command(0xc0);//second line

LCD_write_string("Subscribe it");

while (1);

}


Circuit diagram




GPS sensor interface with ESP8266 using Blynk IoT cloud

   Circuit diagram: Source Code: #include <TinyGPS++.h> #include <SoftwareSerial.h> #define BLYNK_PRINT Serial #include <ESP8...