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




Wednesday, August 31, 2022

7 segment display interface with LPC2148 : embedded C program with code


 








Circuit Diagram:



Source Code:

#include <LPC214x.H>                      

unsigned char dig[] = {0x88,0xeb,0x4c,0x49,0x2b,0x19,0x18,0xcb,0x8,0x9,0xa,0x38,0x9c,0x68,0x1c,0x1e};

void delay(unsigned int count)

{

  int j=0,i=0;

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

  {

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

  }

}

int main (void)

{

unsigned char count=0;

unsigned int i=0;

IO0DIR |= (1 << 11);        //Set Digit control lines as Outputs

IO0SET = (1 << 11);

IO0DIR |= 0x007F8000;

  while(1)

 {

                                count++;

                                if(count ==16) count = 0;

                                for (i=0; i < 100; i++)        //change to inc/dec speed of count

                                 {

                                  IO0CLR = 0x007F8000;

                                  IO0SET = (dig[count] << 15);

                                 delay(200);

                                }                             

  }

}

Tuesday, August 30, 2022

DAC interface with ARM7 LPC 2148 : Sine wave generation

 


PROGRAM LOGIC:

* Equation for generating sine wave is created.

* Program loop is created to send Sine wave value (0 to 360 radian ) to DAC

* DAC convert digital equivalent value of sine wave into analog signal

* CRO is connected in DAC output pin (P0.25) to display sine wave.



PROGRAM CODE

#include <lpc214x.h>

#include <stdio.h>

#include <math.h>

#define Rad 0.0174532925

int teta,DAC_In;

float sine_val;

int main()

{

PINSEL1 = 0X00080000;

while(1)

{

for(teta=0;teta<360;teta++)

{

sine_val = (1.65 * sin(teta*Rad));

DAC_In = ((sine_val * 1024 /3.3)+512);

DACR = (DAC_In<<6);

}

}

}


CIRCUIT DIAGRAM





Monday, August 29, 2022

ARM7 LPC 2148 Embedded C program to interface PC (UART)

 



Circuit Diagram




UART – Universal Asynchronous Receiver Transmitter (UART0 and UART1)

UART0 has lines TXD, RXD and Gnd lines for interfacing simple serial port.

UART1 has lines apart from the above, control lines for interfacing Modem also. Now, we are going to see only the registers available in UART0

UART0 is used to send the byte of data serially and receive the byte of the data serially.

At the time of receiving, it receives the bits seri ally and assembles as parallel 8 bit data and it places in the receiver buffer register U0RBR. It is the content of the top of the FIFO buffer registers. At the time of transmitting, the user is supposed to place the 8 bit data in Transmit Hold Register Namely U0THR.

In serial communication, the serial data is sent in the same rate at which the receiving system also receives. This is called baud rate (bits per second). For example, 9600 baud means 9600 bits per second. The internal clock is divided by 16 bit no. to arrive at the required baud rate.

The Most Significant 8 bits of the divider value are stored is called U0DLM. The Least Significant 8 bits of

the divider value are stored in the register called U0DLL. At the time of writing in these registers only, DLAB bit in the U0LCR register (Line Control Register) is to be made 1. Whenever, the U0THR register is empty, the next byte of data can be sent to send it out serially. Similarly, whenever, a byte of data is received, it is placed in U0RBR. As soon as it happen, interrupt may be raised to inform the user. But interrupts are to be enabled before the use. 

There is an interrupt enable register namely U0IER. By writing proper bits in the register, the above events will raise the interrupt. There is another register U0IIR, which is used to find what are all the interrupts pending. The register FIFO control register U0FCR is used to reset TX FIFO (Transmit First In First Out register set) and RX FIFO (Receive First In First Out) and to enable them.

The register U0LCR, line control register is used to write serial protocol parameters namely, the word length of the data, no. of stop bits, parity enable, parity select, Break control. The 7th bit in this register namely DLAB is used to enter the 16 bit divisor data. Line Status register U0LSR is the status register to know whether data has been received, data can be sent for transmission, to find out errors. There is another register U0TER which is used to enable the serial transmitter


PROGRAMLOGIC:

* Configure UART of ARM7 in 9600 baud rate.

* Program loop is created to send given string serially through transmitter pin of UART.

* Hyper terminal of PC is configured in 9600 baud rate in COM port 1

* Data transmitted through UART is received by receiver pin of COM port1 of PC.

* Received string is displayed in hyper terminal


PROGRAM CODE

#include <LPC214x.H>
#define PCLK 30000000 // PCLK for configuration baudrate
void UART0_Init(unsigned int baudrate);
void UART0_PutC(char c);
void UART0_PutS(char *p);
unsigned int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
UART0_Init(9600);
while(1)
{
UART0_PutS("\f*** TRENDY CODING ***\n\n\r");
}
}
unsigned int getchar (void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void UART0_Init(unsigned int baudrate)
{
unsigned short BAUD_REG;
BAUD_REG = PCLK/(16*baudrate); // Calculate for U0DL value
PINSEL0|= 0x00000005; // Enable rx,tx
U0LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U0DLL = BAUD_REG & 0xFF; // U0DL for low by te
U0DLM = (BAUD_REG>>8); // U0DL for high byte
U0LCR = 0x00000003; // DLAB =0
}
void UART0_PutC(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
void UART0_PutS(char *p)
{
while(*p) // Point to character
{
UART0_PutC(*p++); // Send character then point to next character
}
}

Saturday, August 27, 2022

ARM LPC2148 embedded C programming : Timer implementation

ARM LPC2148 Timer programming



TIMERS (Timer0 and Timer1) & SFR Registers:

There are 2 nos. of 32 bit timers in this Microcontroller. Timer is basically a counter. For timer, internal clock is given as input. Internally, PCLK, Peripheral clock is given as the input pulses.

Timer0 registers

TC0 – Timer Counter Register (32 bit register). For every clock pulse, this register is incremented. Before the clock pulse is given to TCO, the clock pulses are given to the Prescale Counter namely

PC0 – 32 bit register. Along with PC0, there is another register namely Prescale Register PR0 – 32 bit register.

The PC0 gives one output pulse for each prescale register value. For example, if the PR0 has the value of decimal 10, then the PC0 gives one output pulse fo r every 10 input clock pulses. The Prescale  Counter output is given as the clock pulse to Timer Counter register TC0. In this way, 32 bit Prescale divider is included in the timer operation.

TCR0 – Timer Control Register. This register is used to reset the counter and disable/enable the Timer

Counter Register TC0.

T0MR0 – Match0 Register. It is a 32 bit register. The 32 bit content entered is compared with the content of  Timer/Counter Register TC0 continuously. When the match occurs, the following functions can be actuated.

1. If the interrupt enable bit is made 1, interrupt flag bit for MR0 is made 1 in T0IR register.

2. The Timer/Counter register can be made to reset.

3. The Timer/Counter register can be disabled.

4. In the corresponding pin MAT0.0 for MR0 , output can be generated.

The first 3 functions can be actuated by writing control bits in MCR register – Match Control Register.

Similar to T0MR0, there are T0MR1, T0MR2, T0MR3 match registers. They can be also used for comparing with the contents of Timer/Counter (TC) register. On match, the above functions for the corresponding match register can be actuated.

T0IR – It is an 8 bit interrupt register. For every match, corresponding bit in this interrupt register is set. On writing again the same bit in t he Interrupt Service Routine, the corresponding bit will be cleared. Similar to match registers, there are 4 capture registers namely T0CR0, T0CR1, T0CR2 and

T0CR3. The content of Timer/Counter (TC) register value is loaded into T0CR0, when an event on physical pin CAP0.0, one particular physical input.

T0CCR is a 32 bit register which controls which edges of the capture inputs are used to load the Capture registers and whether or not an interrupt is generated when a capture takes place. In order to use the timer as counter, T0CTCR register is used. It is used to change to counter mode and to determine in which pin, physical count input pulses is given.


PROGRAMLOGIC:

* Configure 8 pins of port1 from P1.16 to P1.23as output pins by writing value ‘1’ to these pins

* Connect 8 LEDS in output pins.

*Timer 0 of ARM7 is configure to produce delay of 0.5 Second

* Program loop is created to toggle LEDs connected in PORT1 for every 0.5 sec.


Program code

#include <LPC214x.h>

#define DELAY_MS 1000 //0.5 Second(s) Delay

#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1

void Timer0_Init(void);

void Timer0_Run(void);

int main(void)

{

VPBDIV = 0x01; //PCLK=60Mhz

IO1DIR = 0x00FF0000; //P1.16 to P1.23 are output

Timer0_Init(); //Initialize Timer0

while(1)

{

Timer0_Run();

}

}

void Timer0_Init(void)

{

/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/

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 = 3; //Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0

T0TCR = 0x02; //Reset Timer

T0TCR = 0x01; //Enable timer

}

void Timer0_Run(void)

{

unsigned char regVal;

if(T0IR) //Polling the Interrupt Flag

{

regVal = T0IR;  //R ead current IR value

IO1PIN ^= 0x00FF0000; // Toggle LED pins in Port 1

T0IR = regVal; // Write back to IR to clear Interrupt Flag

}

}




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...