PROGRAM 1.a:
PROGRAM TO GENERATE SAW-TOOTH WAVE FORM
#include<lpc214x.h>
void main()
{
int i,x;
PINSEL1=0X00000000;
IODIR0=0X00FF0000;
while(1)
{
for(i=0; i<256; i++)
{
x=i<<16;
IOPIN0=x;
}
}
}
PROGRAM 1.b:
PROGRAM TO GENERATE SINE WAVE
#include<lpc21xx.h>
void delay(void);
int main()
{
unsigned int
sin[]={0X80,0X96,0XAB,0XC0,0XD2,0XE2,0XEE,0XF8,0XFE,
0X100,0XFE,0XF8,0XEE,0XE2,0XD2,0XC0,0XAB,0X96,
0X80,0X69,0X54,0X40,0X2D,0X1D,0X11,0X07,0X01,
0X00,0X01,0X07,0X11,0X1D,0X2D,0X40,0X54,0X69};
int x,i;
PINSEL0=0x00000000;
IODIR0=0x00ff0000;
while(1)
{
for(i=0;i<36;i++)
{
x=
sin[i]<<16;
IOPIN0=x;
}
}
void delay()
{
unsigned int i;
for(i=0;i<100000;i++);
}
PROGRAM 1.c:
PROGRAM TO GENERATE SQUARE WAVE FORM
#include<lpc214x.h>
void
delay(void);
void main()
PINSEL1=0X00000000;
IODIR0=0X00FF0000;
while(1)
{
IOPIN0=0X00FF0000;
delay();
IOPIN0=0X00000000;
delay();
}
}
void delay(void)
{
unsigned int i;
for(i=0;
i<10000; i++);
}
PROGRAM 1.d:
PROGRAM TO GENERATE TRIANGULAR WAVE FORM
#include<lpc214x.h>
void main()
{
int i,j,x;
PINSEL1=0X00000000;
IODIR0=0X00FF0000;
while(1)
{
for(i=0; i<256; i++)
{
x=i<<16;
IOPIN0=x;
}
for(j=256; j>0; j--)
{
x=j<<16;
IOPIN0=x;
}
}
}
PROGRAM 2:
PROGRAM TO INTERFACE UART WITH LPC2148 KIT
#include<lpc21xx.h>
void serial(void);
int main()
{
unsigned char msg[20]=("blueskytechi");
unsigned char i;
serial();
while(1)
{
for(i=0;i<12;i++)
{
while(!(U0LSR & 0x20));
U0THR=msg[i];
}
while(!(U0LSR &0X01));
U0THR=U0RBR;
}
}
void serial()
{
PINSEL0=0X00000005;
U0LCR=0X00000083;
U0DLL=0X61;
U0LCR=0X03;
U0IER=0X01;
}
PROGRAM 3:
PROGRAM TO INTERFACE UART WITH LCD
#include<LPC21xx.h>
void display(void );
void cmd(unsigned int);
void data(unsigned char);
void delay(void);
void serial(void);
void lcd_init();
unsigned char mg;
int main()
{
unsigned int
i;
unsigned
char msg[]={"blueskytechi"};
serial();
lcd_init();
while(1)
{
for(i=0;i<1;i++)
{
while(!(U0LSR
& 0x20));
U0THR
= msg[i];
}
while(!(U0LSR & 0x01));
mg=U0RBR;
data(mg);
//cmd(0x01) ;
delay();
}
}
void serial()
{
PINSEL0 =
0x00000005; //
set Txd and rxd
U0LCR =
0x83; //
Enable latch
U0DLL =
0x61; //
set baud rate
U0LCR =
0x03; //
disable latch
U0IER =
0x01; //
enable RBR interrupt
}
void lcd_init (unsigned char mg)
{
unsigned int
c[] = {0x30,0x20,0x28,0x01,0x06,0x0E,0x80};
unsigned int
i;
IODIR0 =
0x000000FC;
for(i=0;i<8;i++)
{
cmd(c[i]);
delay();
}
}
void cmd(unsigned int x)
{
unsigned int
value;
value = x;
value =
value & 0xF0;
IOCLR0 =
0xF0;
IOCLR0 =
0x04;
IOSET0 =
value;
IOSET0 =
0x08;
// delay();
IOCLR0 =
0x08;
value = x;
value =
value & 0x0F;
value =
value << 4;
IOCLR0 =
0xF0;
IOCLR0 =
0x04;
IOSET0 =
value;
IOSET0 =
0x08;
//SBIKJKJHJK
delay();
IOCLR0 =
0x08;
}
void data(unsigned char p)
{
unsigned int
value;
value = p;
value =
value & 0xF0;
IOCLR0 =
0xF0;
IOSET0 =
0x04;
IOSET0 =
value;
IOSET0 =
0x08;
//delay();
IOCLR0 =
0x08;
value = p;
value =
value & 0x0F;
value =
value << 4;
IOCLR0 =
0xF0;
IOSET0 =
0x04;
IOSET0 =
value;
IOSET0 =
0x08;
//delay();
IOCLR0 =
0x08;
}
void delay()
{
unsigned int
i;
for(i=0;i<65000;i++);
}
Very nice to learn ARM7 programs both assembly and C. thank you
ReplyDelete