Basic Logic does not change with change in micro controller, but this code is given to show how different programming another micro controller (in this case LPC2148) is. A 32-bit PINSEL register can control 16 pins with 2-bits to control each pin. Currently they are set to GPIO mode so all values are set to zero.
A 32-bit IODIR register is used to set direction of the pin - input/output. IOCLR clears the value of the pin when given 1, and IOSET sets the value of the pin when given 1. When zero is given, it does nothing.
IOPIN gives the status of the pins of the register. Value is read from this register.
1) keypad_lcd.c
#include<lpc214x.h>
#include"lcd.h"
int main(void)
{
PINSEL2=0X00000000;
IO1DIR|=0X000F0000;
lcd_init();
display("Hello world");
lcd_cmd(0x01);
while(1)
{
IO1CLR|=(1<<16);
IO1SET|=0X000E0000;
if(!(IO1PIN & 0X00100000))
{
lcd_data('1');
while((IO1PIN & 0X00100000) == 0);
}
if(!(IO1PIN & 0X00200000))
{
lcd_data('2');
while((IO1PIN & 0X00200000) == 0);
}
if(!(IO1PIN & 0X00400000))
{
lcd_data('3');
while((IO1PIN & 0X00400000) == 0);
}
IO1CLR|=(1<<17);
IO1SET|=0X000D0000;
if(!(IO1PIN & 0X00100000))
{
lcd_data('4');
while((IO1PIN & 0X00100000) == 0);
}
if(!(IO1PIN & 0X00200000))
{
lcd_data('5');
while((IO1PIN & 0X00200000) == 0);
}
if(!(IO1PIN & 0X00400000))
{
lcd_data('6');
while((IO1PIN & 0X00400000) == 0);
}
IO1CLR|=(1<<18);
IO1SET|=0X000B0000;
if(!(IO1PIN & 0X00100000))
{
lcd_data('7');
while((IO1PIN & 0X00100000) == 0);
}
if(!(IO1PIN & 0X00200000))
{
lcd_data('8');
while((IO1PIN & 0X00200000) == 0);
}
if(!(IO1PIN & 0X00400000))
{
lcd_data('9');
while((IO1PIN & 0X00400000) == 0);
}
IO1CLR|=(1<<19);
IO1SET|=0X00070000;
if(!(IO1PIN & 0X00100000))
{
lcd_data('*');
while((IO1PIN & 0X00100000) == 0);
}
if(!(IO1PIN & 0X00200000))
{
lcd_data('0');
while((IO1PIN & 0X00200000) == 0);
}
if(!(IO1PIN & 0X00400000))
{
lcd_data('#');
while((IO1PIN & 0X00400000) == 0);
}
}
}
2) lcd.h
void delay(unsigned int t)
{
unsigned int i;
for(i=0;i<=100000*t;i++)
{
}
}
void lcd_cmd(unsigned char c)
{
IOCLR0=0x0000FF00;
IOSET0 =(c<<8);
IOCLR0 |=(1<<16);
IOCLR0 |=(1<<17);
IOSET0 |=(1<<18);
delay(1);
IOCLR0 |=(1<<18);
delay(1);
}
void lcd_data(unsigned char d)
{
IOCLR0=0x0000FF00;
IOSET0 =(d<<8);
IOSET0 |=(1<<16);
IOCLR0 |=(1<<17);
IOSET0 |=(1<<18);
delay(1);
IOCLR0 |=(1<<18);
delay(1);
}
void lcd_init(void)
{
PINSEL0=0X00000000;
PINSEL1=0X00000000;
IODIR0=0X0007FF00;
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x0f);
lcd_cmd(0x06);
lcd_cmd(0x80);
}
void display(unsigned char *p)
{
while(*p)
{
lcd_data(*p++);
}
}
No comments:
Post a Comment