Colored Code Output
Colored Code Output
//////////////////////////////////////////////////////
// This program demonstrates a Master and slave
// communication using I2C interface of LPC2148
// In this example Master is LPC2148 device
// and slave is a I2CtoLCD converter PCF8574
// Author: www.tmisystems.in
//////////////////////////////////////////////////////
#include
#include
////////////////////////
#define SLAVE_ADDR 78
#define MAX 12
#define AA 2
#define SI 3
#define STO 4
#define STA 5
#define I2EN 6
////////////////////////////
// Delay Function
//
wait(int count)
{
while(count-- );
}
//////////////////////////
// Initialize I2c
//
//
//
void I2C_Init (void)
{
VPBDIV = 0x02; // sets FOSC = 60MHHZ
PINSEL0 = 0x00000050; // set po.2,p0.3 to sda scl
I2C0SCLH = 150; //50%duty,I2CFreq->100KHz,PCLK=30MHz
I2C0SCLL = 150;
I2C0CONSET = (1<
//PINSEL1 = 0x00000000 ; // Configure P0.16 to P0.31 as GPIO
// IO0DIR = 0x000F0000 ;
// IO0CLR = 0x000F0000;
}
//////////////////////////
// Enter Master
// transmitter Mode
//
int I2C_Start ()
{
I2C0CONCLR = 1 << STO;
I2C0CONCLR = 1 << SI;
I2C0CONSET = 1 << STA;
return 0;
}
//////////////////////////////////////
// Delay function
//
//
void delay_ms(int count)
{
int j=0,i=0;
for(j=0;j
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
///////////////////////////////////////////////////////
// Function to send data from Master to slave I2C
// device
//
////rs=1; rw =0 ; en=1;
data = (char_data << 4)|0x08|0x05;/* Send lower nibble */
senddata(data);
delay_ms(1);
////rs=1; rw =0 ; en=0;
data = (char_data << 4)|0x08|0x01;
senddata(data);
delay_ms(5);
senddata(0x08);
}
void LCD_String (char *str) /* Send string to LCD function */
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}
//void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD
function */
//{
//if (row == 0)
//LCD_Command((pos & 0x0F)|0x80);
//else if (row == 1)
//LCD_Command((pos & 0x0F)|0xC0);
// LCD_String(str); /* Call LCD string function */
//}
int main(){
LCD_Command(0x02);
LCD_Command (0x28); /* Initialization of
16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF
*/
LCD_Command (0x06); /* Auto Increment cursor
*/
LCD_Command (0x01); /* Clear display */
LCD_Command (0x80); /* Cursor at home
position */
LCD_String(str);
//LCD_String_xy(1,0,"HELLO WORLD");
// while(1){
// IO0CLR = 0x000F0000;
// for(i=0; i < 2000;i++)wait(800);
// IO0SET = 0x000F0000;
// for(i=0; i < 2000;i++)wait(800);
// } ;
}
}
}//END OF MAIN
====== LCD I2C Interface with LPC2148 ======
(File: lcd_i2c_final.c)
//////////////////////////////////////////////////////
// This program demonstrates a Master and slave
// communication using I2C interface of LPC2148
// In this example Master is LPC2148 device
// and slave is a I2CtoLCD converter PCF8574
// Author: www.tmisystems.in
//////////////////////////////////////////////////////
#include
#include
////////////////////////
#define SLAVE_ADDR 78
#define MAX 12
#define AA 2
#define SI 3
#define STO 4
#define STA 5
#define I2EN 6
////////////////////////////
// Delay Function
//
wait(int count)
{
while(count-- );
}
//////////////////////////
// Initialize I2c
//
//
//
void I2C_Init (void)
{
VPBDIV = 0x02; // sets FOSC = 60MHHZ
PINSEL0 = 0x00000050; // set po.2,p0.3 to sda scl
I2C0SCLH = 150; //50%duty,I2CFreq->100KHz,PCLK=30MHz
I2C0SCLL = 150;
I2C0CONSET = (1<
//PINSEL1 = 0x00000000 ; // Configure P0.16 to P0.31 as GPIO
// IO0DIR = 0x000F0000 ;
// IO0CLR = 0x000F0000;
}
//////////////////////////
// Enter Master
// transmitter Mode
//
int I2C_Start ()
{
I2C0CONCLR = 1 << STO;
I2C0CONCLR = 1 << SI;
I2C0CONSET = 1 << STA;
return 0;
}
//////////////////////////////////////
// Delay function
//
//
void delay_ms(int count)
{
int j=0,i=0;
for(j=0;j
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
///////////////////////////////////////////////////////
// Function to send data from Master to slave I2C
// device
//
////rs=1; rw =0 ; en=1;
data = (char_data << 4)|0x08|0x05;/* Send lower nibble */
senddata(data);
delay_ms(1);
////rs=1; rw =0 ; en=0;
data = (char_data << 4)|0x08|0x01;
senddata(data);
delay_ms(5);
senddata(0x08);
}
void LCD_String (char *str) /* Send string to LCD function */
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}
//void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD
function */
//{
//if (row == 0)
//LCD_Command((pos & 0x0F)|0x80);
//else if (row == 1)
//LCD_Command((pos & 0x0F)|0xC0);
// LCD_String(str); /* Call LCD string function */
//}
int main(){
LCD_Command(0x02);
LCD_Command (0x28); /* Initialization of
16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF
*/
LCD_Command (0x06); /* Auto Increment cursor
*/
LCD_Command (0x01); /* Clear display */
LCD_Command (0x80); /* Cursor at home
position */
LCD_String(str);
//LCD_String_xy(1,0,"HELLO WORLD");
// while(1){
// IO0CLR = 0x000F0000;
// for(i=0; i < 2000;i++)wait(800);
// IO0SET = 0x000F0000;
// for(i=0; i < 2000;i++)wait(800);
// } ;
}
}
}//END OF MAIN
#include
void delay(unsigned int);
void disp(unsigned int);
//Main function
int main()
{
unsigned long int value,i;
unsigned int row0[4]={ 0x00ee0000,0x00ed0000,0x00eb0000,0x00e70000};
unsigned int row1[4]={ 0x00de0000,0x00dd0000,0x00db0000,0x00d70000};
unsigned int row2[4]={ 0x00be000,0x00bd0000,0x00bb0000,0x00b70000};
unsigned int row3[4]={ 0x007e0000,0x007d0000,0x007b0000,0x00770000};
IO1DIR = 0XFFF0FFFF; //set rows as output and colomn as input
PINSEL1=0x00000000;
IODIR0=0xf0ff0000; // making po.16 to p0.23 and p0.28 to p0.31 output lines for
disp
IOSET0=0XF0000000;
while(1)
{
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00100000; //enable row0
value=IOPIN1;
delay(50000);
value=value & 0x00ff0000;
for(i=0; i<4;i++)
{
if(value==row0[i])
{
disp(i);
delay(65000);
delay(65000);
//delay(65000);delay(65000);delay(65000);
}
}
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00200000; //enable row1
value=IOPIN1;
delay(50000);delay(50000);
value=value & 0x00ff0000;
for(i=0; i<4;i++)
{
if(value==row1[i])
{
disp(i+4);
delay(65000);delay(65000);//delay(65000);
//delay(65000);delay(65000);
}
}
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00400000; //enable row2
value=IOPIN1;
delay(65000);delay(65000);delay(65000);
delay(65000);delay(65000);
value=value & 0x00ff0000;
for(i=0; i<4;i++)
{
if(value==row2[i])
{
disp(i+8);
delay(50000);
}
}
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00800000; //enable row3
value=IOPIN1;
delay(65000); delay(65000);//delay(65000);delay(65000);delay(65000);
value=value & 0x00ff0000;
for(i=0;i<4;i++)
{
if(value==row3[i])
{
disp(i+12);
delay(65000);delay(65000);//delay(65000);
//delay(65000);delay(65000);
}
}
}
}
//Display function
void disp(unsigned int temp)
{
unsigned int i;
unsigned int da[16]={0xf03F0000, 0xf0060000, 0x305B0000, 0x304F0000,
0x00660000,0x006D0000,
0x007D0000, 0x00070000, 0x007F0000, 0x006F0000,
0x00770000,0x007C0000,
0x00390000, 0x005E0000, 0x00790000, 0x00710000 };
// Delay function
void delay(unsigned int del)
{ unsigned int k;
for(k=0;k
}
#include
#include
unsigned int i;
void lcd_init(void);
void delay(unsigned long int);
void cmd(unsigned int );
void hascii(int *);
unsigned int adc_value=0,temp_adc=0;
void data(unsigned int );
int temp;
int var[10];
char val[10];
int main()
{ PINSEL1 = 0X00040000; //AD0.4 pin is selected(P0.18)
IO0DIR = 0x000000FC; //configure o/p lines for lcd
lcd_init();
while(1)
{
//CONTROL register for ADC
AD0CR = 0x09200010; //command register
for ADC-AD0.4
delay(100);
while((temp_adc = AD0GDR) == 0x80000000); //to check the interrupt bit
adc_value = AD0GDR; //reading the ADC value
adc_value >>=6;
adc_value &= 0x000003ff;
temp=adc_value & 0x00000f00;
var[0]= temp>>8 ;
temp=adc_value & 0x000000f0;
var[1]= temp>>4;
temp=adc_value & 0x0000000f;
var[2]=temp;
hascii(var);
for(i=0;i<3;i++)
{
delay(32000);
data(val[i]);
delay(32000); delay(32000); delay(32000);
}
cmd(0x01); delay(120000); delay(120000);
}
}
void lcd_init(void)
{
unsigned int i;
unsigned int c[]={0x30,0x20,0x28,0x01,0x06,0x0E,0x80};
IODIR0=0x000000fc;
IOCLR0=0x000000fc;
for(i=0;i<7;i++)
{
cmd(c[i]);
delay(10000);
}
}
void cmd(unsigned int value)
{
unsigned int y;
y=value;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
y=value;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
}
void data(unsigned int dat)
{
unsigned int y;
y=dat;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOSET0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
y=dat;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOSET0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
}
for (i=0;i<3;i++)
val[i]=asc[var[i]];
}
#include
void delay(unsigned int);
void disp(unsigned int);
int main()
{
PINSEL1=0x00000000;
IODIR0=0xf0ff0000; // making po.16 to p0.23 and p0.28 to p0.31 output lines for
disp
IOSET0=0XF0000000;
while(1)
{
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00100000; //enable row0
value=IOPIN1;
delay(50000);
}
}
IO1PIN=0x00ff0000; //initialize rows and colomns with one
IOCLR1=0x00200000; //enable row0
value=IOPIN1;
delay(50000); delay(50000);
}
}
}
void disp(unsigned int temp)
{
unsigned int i;
unsigned int da[16]={0x003F0000, 0x00060000, 0x005B0000, 0x004F0000,
0x00660000,0x006D0000,
0x007D0000, 0x00070000, 0x007F0000, 0x006F0000,
0x00770000,0x007C0000,
0x00390000, 0x005E0000, 0x00790000, 0x00710000 };
IOSET0=da[i];
delay(65000); delay(65000);delay(65000);delay(65000);delay(65000);
IOCLR0=0X00FF0000;
}
#include
#include
unsigned int i;
void lcd_init(void);
void delay(unsigned long int);
void cmd(unsigned int );
//void hascii(int *);
unsigned int adc_value=0,temp_adc=0;
void data(unsigned int );
int temp;
//int var[10];
char arr[20];
int main()
{ PINSEL1 = 0X00040000; //AD0.4 pin is selected(P0.25)
IO0DIR = 0x000000FC; //configure o/p lines for lcd
lcd_init();
while(1)
{
//CONTROL register for ADC
AD0CR = 0x09200010; //command register
for ADC-AD0.4
delay(100);
while((temp_adc = AD0GDR) == 0x80000000); //to check the interrupt bit
adc_value = AD0GDR; //reading the ADC value
adc_value >>=6;
adc_value &= 0x000003ff;
sprintf(arr,"adc value=%x",adc_value);
for(i=0;i<13;i++)
//while(arr[i]!=)
{
delay(32000);
data(arr[i]);
delay(65000); delay(65000); delay(65000);
// i++;
}
{
unsigned int i;
unsigned int c[]={0x30,0x20,0x28,0x01,0x06,0x0E,0x80};
IODIR0=0x000000fc;
IOCLR0=0x000000fc;
for(i=0;i<7;i++)
{
cmd(c[i]);
delay(10000);
}
}
void cmd(unsigned int value)
{
unsigned int y;
y=value;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
y=value;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
}
void data(unsigned int dat)
{
unsigned int y;
y=dat;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOSET0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
y=dat;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOSET0=0X00000004;
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
}
#include
void clock_wise(void) ;
void anti_clock_wise(void) ;
int main(void)
{
PINSEL1 = 0x00FFFFFF ; //P0.28 to P0.31 GPIO
IO0DIR |= 0xF0000000 ; //P0.28 to P0.31 made as output
while(1)
{
for( j = 0 ; j < 50 ; j++ ) // 20 times in Clock wise Rotation
clock_wise() ;
void clock_wise(void)
{
var1 = 0x08000000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ; //For Clockwise
void anti_clock_wise(void)
{
var1 = 0x80000000 ; //For Anticlockwise
IO0CLR =0xF0000000 ; //clearing all 4 bits
IO0CLR =0xF0000000 ;
IO0SET = var1 ;
#include
void cmd(unsigned int);
void data(unsigned int);
void delay(unsigned int);
int main()
{
unsigned char msg[]={"welcome KLETECH"};
unsigned int c[]={0x30,0x30,0x20,0x20,0x28,0x01,0x06,0x0e,0x80};
unsigned char i,j;
PINSEL0=0x00000000;
IODIR0=0x000000fc;
IOCLR0=0x000000fc;
for(i=0;i<9;i++)
{
cmd(c[i]);
delay(10000);
}
while(1)
{
cmd(0x80);
delay(10000);
for(j=0;j<15;j++)
{
data(msg[j]);
delay(500);
}
delay(65000);
delay(65000);
delay(65000);
cmd(0x01);
delay(65000);
delay(65000);
delay(65000);
delay(65000);
}
}
void cmd(unsigned int value)
{
unsigned int y;
y=value;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOCLR0=0X00000004; //rs=0
IOSET0=y;
IOSET0=0x00000008; //en=1
delay(10);
IOCLR0=0x00000008; //en=0
y=value;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOCLR0=0X00000004; //rs=0
IOSET0=y;
IOSET0=0x00000008;
delay(10);
IOCLR0=0x00000008;
}
#include
#include
void delay(unsigned int);
void extint0_ISR(void)__irq;
void delay(unsigned int );
int main(void)
{
PINSEL1=0x00000001;
EXTMODE=0x00000001;
VICVectAddr0=(unsigned long)extint0_ISR;
VICVectCntl0=0x20|14;
VICIntEnable|=0x00004000;
while(1);
}
void extint0_ISR(void)__irq
{
PINSEL0=0x00000000;
IODIR0=0x000f0000;
IOCLR0=0X00040000; // ON LEDS
delay(100000);
IOSET0=0X00040000; // OFF LEDS
delay(100000);
EXTINT|=0X00000001; //Clear interrupt flag
VICVectAddr=0; // End of interrupt execution
}
void delay(unsigned int x)
{
unsigned int i;
for(i=0;i
}