0% found this document useful (0 votes)
9 views43 pages

On & OFF CHIP Interfacing Codes

The document contains multiple ARM C code examples for controlling various hardware components such as buzzers, LCDs, stepper motors, and LEDs. It includes code for displaying messages on LCDs, controlling motors via UART, and implementing a 4x4 keypad for calculating LCM and GCD. Each code snippet is structured to perform specific tasks with appropriate delays and hardware configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views43 pages

On & OFF CHIP Interfacing Codes

The document contains multiple ARM C code examples for controlling various hardware components such as buzzers, LCDs, stepper motors, and LEDs. It includes code for displaying messages on LCDs, controlling motors via UART, and implementing a 4x4 keypad for calculating LCM and GCD. Each code snippet is structured to perform specific tasks with appropriate delays and hardware configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

ARM C code for buzzer

include<lpc21xx.h>
void delay(int);
int main()
{
​ IO0DIR=0x00000020;
​ while(1)
​ {
​ ​ IO0SET=0x00000020;
​ ​ delay(20000);
​ ​ IO0CLR=0x00000020;
​ ​ delay(20000);
​ }
}​
void delay(int x)
{
​ int i;
​ for(i=0;i<x;i++);
}

ARM C code for LCD

#include<lpc21xx.h>
void command(unsigned int);
void data(unsigned int);
void delay(unsigned int);
int main()
{
​ unsigned char message[]= {"hello"};
​ unsigned int c[]={0x30,0x30,0x20,0x20,0x28,0x01,0x06,0x0e,0x89};
​ unsigned int i,j;
​ IO0DIR=0x000000fc;
​ for(i=0;i<9;i++)
​ {
​ ​ command(c[i]);
​ ​ delay(2000);
​ }
​ while(1)
​ {
​ ​ command(0x89);
​ ​ delay(2000);
​ ​ for(j=0;j<5;j++)
​ ​ {
​ ​ ​ data(message[j]);
​ ​ ​ delay(2000);
​ ​ }
​ ​ delay(2000);
​ ​ command(0x10);
​ ​ delay(2000);
​ }
}
void command(unsigned int x)
{
​ unsigned int y;
​ y=x;
​ y=y & 0x0f;
​ IO0CLR=0x000000fc;
​ IO0CLR=0x00000004;
​ IO0SET=y;
​ IO0SET=0x00000008;
​ delay(2000);
​ IO0CLR=0x00000008;
​ y=x;
​ y=y & 0x0f;
​ y=y<<4;
​ IO0CLR=0x00000004;
​ IO0SET=y;
​ IO0SET=0x00000008;
​ delay(2000);
​ IO0CLR=0x00000008;
}
void data(unsigned int a)
{
​ unsigned int b;
​ b=a;
​ b=b & 0x0f;
​ IO0CLR=0x000000fc;
​ IO0SET=0x00000004;
​ IO0SET=b;
​ IO0SET=0x00000008;
​ delay(100);
​ b=a;
​ b=b& 0x0f;
​ b=b<<4;
​ IO0CLR=0x000000fc;
​ IO0SET=0x00000004;
​ IO0SET=b;
​ IO0SET=0x00000008;
​ delay(100);
​ IO0CLR=0x00000008;
}
void delay(unsigned int x)
{​
​ unsigned int i;
​ for(i=0;i<2000;i++);
}

​ ​

Stepper motor
#include<lpc21xx.h>
void delay(unsigned int);
int main()
{
​ unsigned int x;
​ PINSEL2=0x0010000;
​ IO0DIR=0xf0000000;
​ IO1DIR=0x00000000;
​ x=IOPIN1;
​ x=x & 0x00f00000;

​ while(1)
​ {​ if(x==0x00100000)
​ ​ {
​ ​ ​ IO0SET=0x10000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x10000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x20000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x20000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x40000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x40000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x80000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x80000000;
​ ​ ​ delay(20000);
​ ​ }
​ ​ else
​ ​ {
​ ​ ​ IO0SET=0x80000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x80000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x40000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x40000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x20000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x20000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0SET=0x10000000;
​ ​ ​ delay(20000);
​ ​ ​ IO0CLR=0x10000000;
​ ​ ​ delay(20000);
​ ​ }

​ }
}
void delay(unsigned int x)
{
​ unsigned int i;
​ for(i=0;i<x;i++);
}

Arm c code to have led walking display from left to right and right to left

Program:

#include<lpc21xx.h>

int main()

unsigned char I;

PINSEL1=0x00000000;

IODIR0=0x000f0000;

while(1)

IOCLR0=0x00010000;

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

IOSET0=0x00010000;

IOCLR0=0x00020000;

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

IOSET0=0x00020000;

IOCLR0=0x00040000;

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

IOSET0=0x00040000;

IOCLR0=0x00080000;

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

IOSET0=0x00080000;

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

IOSET0=0x00040000;

IOCLR0=0x00020000;

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

IOSET0=0x00020000;

IOCLR0=0x00010000;

//Arm C code to display Johnson counter using led’s

Program:

#include<lpc21xx.h>

int main()

unsigned char i;

PINSEL1=0x00000000;

IODIR0=0x000f0000;

while(1)

IOSET0=0x000f0000;

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

IOCLR0=0x00080000;

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

IOCLR0=0x00040000;

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

IOCLR0=0x00020000;

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

IOCLR0=0x000f0000;

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

IOSET0=0x00080000;

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

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

IOSET0=0x00020000;

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

//Program to control the stepper and dc motor using UART

If ‘s’-stepper motor

If ‘d’-DC motor

#include<LPC21xx.h>

void delay(void);

void serial(void);

unsigned char mg,g;

int main()

​ unsigned int k,y;

​ while(1)

serial();

​ while(!(U0LSR & 0X01));

​ mg=U0RBR;

​ U0THR=mg;

​ delay();

​ if(mg=='s')

​ {​

​ ​ PINSEL0=0x0000000;

​ ​ IODIR0=0xf0000000;

​ ​ IOCLR0=0Xf0000000;

​ ​ for(k=0;k<=25;k++)
​ ​ {​ ​ ​

​ ​ IOSET0=0x10000000;

delay();

delay();

​ ​ IOCLR0=0x10000000;

IOSET0=0x20000000;

​ ​ delay();

delay();

​ IOCLR0=0x20000000;

IOSET0=0x40000000;

​ ​ delay();

delay();

​ ​ IOCLR0=0x40000000;

IOSET0=0x80000000;

​ ​ delay();

delay();

IOCLR0=0x80000000;

​ ​

​ else if(mg=='d')

​ {​

​ PINSEL1=0x00000000;

IODIR0=0x00000C00;

IOCLR0=0x00000C00;

​ ​ for(y=0;y<=15;y++)

​ ​ {​ ​ ​

IOSET0=0x00000400;

​ ​ IOCLR0=0x00000800;

​ ​ delay();
IOSET0=0x00000800;

IOCLR0=0x00000400;

delay();

​ ​ }

​ }

}​

void serial()

PINSEL0=0X00000005;

U0LCR=0X83;

U0DLL=0X61;

U0LCR=0X03;

void delay()

unsigned int i;

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

//ARM C code to display a string of message both on UART AND LCD

PROGRAM:

#include<lpc21xx.h>
void delay(void);
void serial(void);
void cmd(unsigned int);
void data(unsigned int);

int main()
{ unsigned char mg;
​ unsigned int c[]={0x30,0x30,0x20,0x20,0x28,0x01,0x06,0x0e,0x89};
unsigned char i,j;
​ unsigned int k,m;
​ unsigned char msg[]={"BVB"};
​ PINSEL0=0x00000000;
IODIR0=0x000000fc;
IOCLR0=0x000000fc;
​ serial();
​ for(k=0;k<3;k++)
{
while(!(U0LSR&0x20));
U0THR=msg[k];
}​
​ while(!(U0LSR&0x01));
mg=U0RBR;
​ U0THR=mg;
delay();

for(i=0;i<9;i++)
{
cmd(c[i]);
delay();
}
​ while(1)
{
cmd(0xc0);
delay();
for(j=0;j<3;j++)
{
data(msg[j]);
for(m=0;m<500;m++);
}
for(m=0;m<65000;m++);
for(m=0;m<65000;m++);
for(m=0;m<65000;m++);
cmd(0x01);
for(m=0;m<65000;m++);
for(m=0;m<65000;m++);
for(m=0;m<65000;m++);
for(m=0;m<65000;m++);
}
}​

void serial()
{
PINSEL0=0x00000005;
U0LCR=0x83;
U0DLL=0x61;
U0LCR=0x03;
}
void cmd(unsigned int value)
{
unsigned int y,m;
y=value;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;

IOSET0=0x00000008;
for(m=0;m<10;m++);
IOCLR0=0x00000008;

y=value;
y=y&0x0f;
y=y<<4;
IOCLR0=0x000000fc;
IOCLR0=0X00000004;
IOSET0=y;

IOSET0=0x00000008;
for(m=0;m<10;m++);
IOCLR0=0x00000008;

}
void data(unsigned int data)
{
unsigned int y,m;
y=data;
y=y & 0xf0;
IOCLR0=0x000000fc;
IOSET0=0X00000004;
IOSET0=y;

IOSET0=0x00000008;
for(m=0;m<10;m++);
IOCLR0=0x00000008;

y=data;
y=y & 0x0f;
y=y<<4;
IOCLR0=0x000000fc;​ IOSET0=0X00000004;
IOSET0=y;

IOSET0=0x00000008;
for(m=0;m<10;m++);
IOCLR0=0x00000008;
}

void delay()
{
unsigned int l;
for(l=0;l<10000;l++);
}
ARM C program for displaying 0-99 on seven segment

#include<lpc21xx.h>
int delay1();
void delay()
{
​ int i;
​ for(i=0;i<2000000;i++);
}
main()
{
​ int j;
​ int
b[10]={0x003f0000,0x0006000,0x005b0000,0x004f0000,0x00660000,0x006d0000,0x007d0000,0x00
700000,0x007f0000,0x006f0000};
for(j=0;j<10;j++)
{
​ ​ ​ IO0DIR=0x10FF0000;
​ ​ ​ IO0SET=0x10000000;
​ ​ ​ IO0SET=b[j];
​ ​ ​ delay1();​ ​
​ }
}
int delay1()
{​ int i;
​ int
a[10]={0x003f0000,0x0006000,0x005b0000,0x004f0000,0x00660000,0x006d0000,0x007d0000,0x00
700000,0x007f0000,0x006f0000};
​ for(i=0;i<10;i++)
​ {
​ ​ IO0DIR=0x20FF0000;
​ ​ IO0SET=0x20000000;
​ ​ IO0SET=a[i];
​ ​ delay();
​ ​ IO0CLR=a[i];
​ ​ delay();
​ }
}

// ARM C code using 4x4 keypad to find LCM and GCD of a given two numbers based on choice of
following keys

Key10:LCM

Key15:GCD

Display the result on lcd.


Program:

#include<stdio.h>

#include<lpc214x.h>

void delay(unsigned int k);

void display(int i);

int lcm(int a,int b);

int gcd(int a,int b);

int main()

unsigned int value,i;

unsigned int row0[4]={0x00ee0000,0x00ed0000,0x00eb0000,0x00e70000};

unsigned int row1[4]={0x00de0000,0x00dd0000,0x00db0000,0x00d70000};

unsigned int row2[4]={0x00be0000,0x00bd0000,0x00bb0000,0x00b70000};

unsigned int row3[4]={0x007e0000,0x007d0000,0x007b0000,0x00770000};

PINSEL1=0x00000000;

IO1DIR=0xfff0ffff;

IODIR0=0X10FF0000;

IOSET0=0X10000000;

while(1)

IOPIN1=0x00ff0000;

IOCLR1=0x00100000;

value=IOPIN1;

delay(50000);

value=value&0x00ff0000;

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

if(value==row0[i])

display(i);

delay(65000);
delay(65000);

delay(65000);

delay(65000);

delay(65000);

IOPIN1=0x00ff0000;

IOCLR1=0x00200000;

value=IOPIN1;

delay(50000);

value=value&0x00ff0000;

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

if(value==row1[i])

display(i+4);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

IOPIN1=0x00ff0000;

IOCLR1=0x00400000;

value=IOPIN1;

delay(50000);

value=value&0x00ff0000;

if(value==row2[1])

i=lcm(1,4);
display(i);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

IOPIN1=0x00ff0000;

IOCLR1=0x00800000;

value=IOPIN1;

delay(50000);

value=value&0x00ff0000;

if(value==row3[3])

i=gcd(10,12);

display(i);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

delay(65000);

void delay(unsigned int k)

unsigned int i;

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

}
void display(int temp)

unsigned int i,j,k;

int a[10]={0x003f0000,0x00060000,0x005b0000,0x004f0000,0x00660000,

0x006d0000,0x007d0000,0x00070000,0x007f0000,0x006f0000};

j=temp%10;

i=temp/10;

IOCLR0=0x00ff0000;

for(k=0;k<30000;k++)

IOSET0=a[j]|0x20000000;

delay(150);

IOCLR0=a[j]|0x20000000;

delay(150);

IOSET0=a[i]|0x10000000;

delay(150);

IOCLR0=a[i]|0x10000000;

delay(150);

int gcd(int a,int b)

if(a==0||b==0)

return 0;

if(a==b)

return a;

if(a>b)
return(gcd(a-b,b));

return (gcd(a,b-a));

int lcm(int a,int b)

return((a*b)/gcd(a,b));

UART controlled sorting of array of user defined elements (upto 10)

If ' a ' is pressed - sort given array in half ascending and half descending format.

If ' b ' is pressed - sort given array in half descending and half ascending format.

CODE:

#include<lpc21xx.h>

void delay(void);

void serial(void);

unsigned int i,j,a;

unsigned char k;

unsigned char msg1[]={"Enter the length of array: \n"};

unsigned char msg2[]={"a for ascending b for descending \n"};

unsigned int mg;

int main()

unsigned int i;

unsigned int number[20];

serial();

for(i=0;i<29;i++)
{

while(!(U0LSR & 0x20));

U0THR = msg1[i];

while(!(U0LSR & 0x01));

mg = U0RBR;

while(!(U0LSR & 0x20));

U0THR = mg;

mg = mg - 48;

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

while(!(U0LSR & 0x01));

number[i] = U0RBR;

while(!(U0LSR & 0x20));

U0THR = number[i];

delay();

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

while(!(U0LSR & 0x20));

U0THR = msg2[i];

while(!(U0LSR & 0x01));

k = U0RBR;

if(k == 'a')
{

for (i = 0; i < mg/2; ++i)

for (j = i + 1; j < mg/2; ++j)

if (number[i] > number[j])

a = number[i];

number[i] = number[j];

number[j] = a;

​ ​ for (i = mg-1; i >= mg/2; --i)

for (j = i - 1; j >= mg/2; --j)

if (number[i] > number[j])

a = number[i];

number[i] = number[j];

number[j] = a;

​ if(k == 'b')

for (i = 0; i < mg/2; ++i)

{
for (j = i + 1; j < mg/2; ++j)

if (number[i] < number[j])

a = number[i];

number[i] = number[j];

number[j] = a;

​ ​ for (i = mg-1; i >= mg/2; --i)

for (j = i - 1; j >= mg/2; --j)

if (number[i] < number[j])

a = number[i];

number[i] = number[j];

number[j] = a;

​ for(i=0;i<mg;i++)

​ {

​ while(!(U0LSR & 0x20));

​ U0THR = number[i];

​ delay();

​ }

void serial(void)
{

PINSEL0 = 0x00000005;

U0LCR = 0x83;

U0DLL = 0x61;

U0LCR = 0x03;

void delay(void)

unsigned int i;

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

Control the message display on lcd using 4x4 keypad as follows.

Key1:right to left display of message

Key2: scrolling display of message using both first and second line(circular fashion).

PROGRAM:
#include<lpc21xx.h>

void cmd(unsigned int);

void delay(unsigned int);

void d1(unsigned int);

void d2(unsigned int);

void data(unsigned int);

int main(){

unsigned long int val, i;

unsigned int row0[4] = {0x00ee0000, 0x00ed0000, 0x00eb0000, 0x00e70000};

IODIR1 = 0xFFF0FFFF;

PINSEL1 = 0x00000000;

IODIR0 = 0xF0FF0000;

IOSET0 = 0xE0000000;
while(1){

IOPIN1 = 0x00ff0000;

IOCLR1 = 0x00100000;

val = IOPIN1;

delay(50000);

val = val & 0x00ff0000;

for(i=0; i<4; i++){

if(val==row0[i])

​ ​ ​ {

​ ​ ​ if(i==1)

d1(i);

​ ​ ​ else if(i==0)

​ ​ ​ d2(i);

​ ​ ​

delay(65000); delay(65000); delay(65000); delay(65000);

void delay(unsigned int x){

unsigned int i;

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

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;

void d1(unsigned int x)

unsigned char msg[] = {"hello"};

unsigned int c[] = { 0x20, 0x20, 0x28,0x28, 0x01, 0x06, 0x0e, 0xcf};

unsigned char i,j;

PINSEL0 = 0x00000000;

IODIR0 = 0x000000fc;

IOCLR0 = 0x000000fc;

for(i=0; i<9;i++){

cmd(c[i]);

delay(10000);

}
​ while(1){

​ cmd(0xcf);

​ ​ delay(1000000);

​ ​

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

​ ​ {

data(msg[j]);

​ ​ ​ cmd(0x10);

delay(1000000);

​ ​ ​ cmd(0x18);

​ ​ ​ delay(650000);

delay(650000);

delay(650000);

​ ​

delay(650000);

delay(650000);

​ ​ ​ ​

​ ​ ​

void d2(unsigned int x)

unsigned char msg[] = {"hi"};

unsigned int c[] = { 0x20, 0x20, 0x28,0x28, 0x01, 0x06, 0x0e, 0x8f};

unsigned char i,j;

PINSEL0 = 0x00000000;
IODIR0 = 0x000000fc;

IOCLR0 = 0x000000fc;

for(i=0; i<9;i++){

cmd(c[i]);

delay(10000);

​ while(1){

​ cmd(0x8f);

​ ​ delay(1000000);

​ ​

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

​ ​ {

data(msg[j]);

​ ​ ​ cmd(0x10);

delay(1000000);

​ ​ ​ cmd(0x18);

​ ​ ​ delay(650000);

delay(650000);

delay(650000);

delay(650000);

​ ​ delay(650000);

​ ​ break;

delay(650000);

delay(650000);

delay(650000);
delay(650000);

​ ​

Use 4x4 keypad to demonstrate the function of mobile keypad

Program:

#include<lpc21xx.h>

void delay(unsigned int);

void disp(unsigned int);

void cmd(unsigned int);

void data(unsigned int);

int z=0,g=0,h=0;

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]={ 0x00be0000,0x00bd0000,0x00bb0000,0x00b70000};

unsigned int row3[4]={ 0x007e0000,0x007d0000,0x007b0000,0x00770000};

IODIR1 = 0X00F00000;​

PINSEL0=0x00000000;

IODIR0=0x000000FC;

IOCLR0=0x000000FC;

while(1)

{
IOPIN1=0x00ff0000;

IOCLR1=0x00100000;

​ value=IOPIN1;

​ delay(50000);

value=value & 0x00ff0000;

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

if(value==row0[0])

​ //temp1=row0[i];

​ //while(value==temp1)

​ disp(49);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ }​ }

if(value==row0[2])

if(z==3)

​ {

​ disp(51);

​ ​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);
​ delay(1275000);

​ z=0;

​ }​ //temp1=row0[i];

​ else

​ {//while(value==temp1)

​ disp(z+68);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);​

z++;}

​ }

if(value==row0[1])

if(g==3)

​ {

​ disp(50);

​ ​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ g=0;

​ }

​ //temp1=row0[i];

​ //while(value==temp1)

​ else

​ {
​ disp(g+65);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ g++;

​ }

​ }​

IO1PIN=0x00ff0000;

IOCLR1=0x00200000;

value=IOPIN1;

delay(50000);​

delay(50000);

value=value & 0x00ff0000;

if(value==row1[0])

if(h==3)

​ {

​ disp(52);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ h=0;

​ }

​ //temp1=row0[i];
​ //while(value==temp1)

​ else

​ {

​ disp(h+71);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ h++;

​ }​ }

if(value==row1[1])

if(z==3)

​ {

​ disp(53);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ z=0;

​ }​ //temp1=row0[i];

​ else

​ {//while(value==temp1)

​ disp(z+74);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);
​ delay(1275000);

​ delay(1275000);​

z++;}

​ }

if(value==row1[2])

if(g==3)

​ {

​ disp(54);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ g=0;

​ }

​ //temp1=row0[i];

​ //while(value==temp1)

​ else

​ {

​ disp(g+77);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ g++;

​ }
​ }​ }

if(value==row2[0])

if(h==3)

​ {

​ disp(52);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ h=0;

​ }

​ //temp1=row0[i];

​ //while(value==temp1)

​ else

​ {

​ disp(h+71);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ h++;

​ }​ }

if(value==row2[1])

if(z==3)
​ {

​ disp(53);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ z=0;

​ }​ //temp1=row0[i];

​ else

​ {//while(value==temp1)

​ disp(z+74);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);​

z++;}

​ }

if(value==row2[2])

if(g==3)

​ {

​ disp(54);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);
​ delay(1275000);

​ g=0;

​ }

​ //temp1=row0[i];

​ //while(value==temp1)

​ else

​ {

​ disp(g+77);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ delay(1275000);

​ g++;

​ }

​ }​ }

void disp(unsigned int temp)

unsigned char msg=temp;

unsigned int c[]={0x30,0x30,0x20,0x20,0x28,0x01,0x06,0x0e,0x89};

unsigned char i;

PINSEL0=0x00000000;

IODIR0=0x000000FC;

IOCLR0=0x000000FC;

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

cmd(c[i]);

delay(10000);

delay(65000);
​ cmd(0x01);

delay(65000);

​ cmd(0x80);

delay(100000);

data(msg);

delay(50000);

​ //delay(50000);

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;

​ 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 data)

​ {​

​ unsigned int y;

​ y=data;

​ y=y & 0xf0;

​ IOCLR0=0x000000fc;

​ IOSET0=0x00000004;

​ IOSET0=y;

​ IOSET0=0x00000008;

​ delay(10);
​ IOCLR0=0x00000008;

​ y=data;

​ y=y & 0x0f;

​ y=y<<4;

​ IOCLR0=0x000000fc;

​ IOSET0=0x00000004;

​ IOSET0=y;

​ IOSET0=0x00000008;

​ delay(10);

​ IOCLR0=0x00000008;

void delay(unsigned int del)

​ unsigned int k;

​ for(k=0;k<del;k++);

4x4 keypad controlled stepper motor and display the number of rotationgs on seven segment

Program:

#include<lpc21xx.h>

void delay(unsigned int);

void disp(unsigned int);

int main()

unsigned long int value,i,j;

Unsigned int b=1;

unsigned int row0=0x00ee0000;

IO1DIR =0XFFF0FFFF;

PINSEL1=0x00000000;

IODIR0=0xf0ff0000;
IOSET0=0X20000000;

while(1)

IO1PIN=0x00ff0000;

IOCLR1=0x00100000;

value=IOPIN1;

delay(50000);

value=value & 0x00ff0000;

if(value==row0)

PINSEL0=0x00000000;

IODIR0=0xf0000000;

IOCLR0=0Xf0000000;

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

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

​ ​ {​ ​ ​

​ ​ IOSET0=0x80000000;

delay(30000);

// delay(1000000);

​ ​ IOCLR0=0xF0000000;

IOSET0=0x40000000;

​ ​ delay(30000);

//delay(1000000);

​ IOCLR0=0xF0000000;

IOSET0=0x20000000;

​ ​ delay(30000);

// delay(1000000);

​ ​ IOCLR0=0xF0000000;

IOSET0=0x10000000;

​ ​ delay(30000);
//delay(1000000);

IOCLR0=0x10000000;

​ ​

​​ disp(b);

b++;

void disp(unsigned int temp)

unsigned int da[16]={0x003F0000,0x00060000,0x005B0000,0x004F0000,0x00660000,0x006D0000,

0x007D0000,0x00070000,0x007F0000,0x006F0000,

0x00770000,0x007F0000,

0x00390000,0x003F0000,0x00790000,0x00710000};

unsigned int i;

i=temp;

PINSEL1=0X00000000;

IODIR0=0X30FF0000;

IOSET0=0X20000000;

IOSET0=da[i];

delay(65000);

delay(65000);

delay(65000);

delay(65000);

delay(65000);
IOCLR0=0X00FF0000;

void delay(unsigned int del)

{unsigned int k;

for(k=0;k<del;k++);

ARM C program tp demonstrate the working of calculator using UART

PROGRAM:

#include<lpc21xx.h>

#include<stdio.h>

int main()

unsigned char x;

unsigned char a[100];

unsigned int p,b,c,i=0;

PINSEL0=0X00000005;

U0LCR=0X83;

U0DLM=0X00;

U0DLL=0X61;

U0LCR=0X03;

while(1)

while(!(U0LSR & 0X01));

p=U0RBR;

while(!(U0LSR & 0X20));

U0THR=p;

p=p-48;

while(!(U0LSR & 0X01));

x=U0RBR;

while(!(U0LSR & 0X20));


U0THR=x;

if(x=='+')

while(!(U0LSR & 0X01));

b=U0RBR;

while(!(U0LSR & 0X20));

U0THR=b;

b=b-48;

c=p+b;

sprintf(a,"=%d \n",c);

while(a[i]!='\0')

while(!(U0LSR & 0x20));

U0THR=a[i];

i++;

else if(x=='-')

while(!(U0LSR & 0X01));

b=U0RBR;

while(!(U0LSR & 0X20));

U0THR=b;

b=b-48;

c=p-b;

sprintf(a,"=%d \n",c);

while(a[i]!='\0')

{
while(!(U0LSR & 0x20));

U0THR=a[i];

i++;

else ​ if(x=='*')

while(!(U0LSR & 0X01));

b=U0RBR;

while(!(U0LSR & 0X20));

U0THR=b;

b=b-48;

c=p*b;

sprintf(a,"=%d \n",c);

while(a[i]!='\0')

while(!(U0LSR & 0x20));

U0THR=a[i];

i++;

else

while(!(U0LSR & 0X01));

b=U0RBR;

while(!(U0LSR & 0X20));

U0THR=b;

b=b-48;

c=p/b;
sprintf(a,"=%d \n",c);

while(a[i]!='\0')

while(!(U0LSR & 0x20));

U0THR=a[i];

i++;

You might also like