Professional Documents
Culture Documents
}
Find 2’s compliment of a number. (1-Bytes user defined array)
Code:
#include<lpc214x.h>
int main(void)
{
unsigned int b,c,i,a[]={0x14,0x3E,0xDF,0xAB,0x77,0x56,0x28,0xE5,0x8C,0x99};
// Defining array containing numbers whose 2's compliment is to be found out.
for(i=0;i<10;i++)
{
b=a[i]; // Take the number indexed to by the loop and
store it into b.
c=~b; // Take compliment of the number (1's
compliment).
c=c+0x01; // Add 1 to it to find the 2's compliment.
IO0PIN=c; // Display the 2's compliment value at Port0.
}
}
Q.2
To understand looping constraints in C.
Arrange 20 bytes of data in descending order. (Assume
user defined array)
Code:
#include<lpc214x.h>
int main(void)
unsigned int
b,c,i,j,a[]={0x55,0x78,0x34,0x12,0x67,0x23,0x44,0x89,0x90,0x09,0x70,0x55,0x39,0x11,0x15,0x21,0x22,0x9
9,0x33,0xAA};
b=a[i];
d[i]=b;
for(i=0;i<20;i++)
if(d[i]<d[j])
c=d[i];
d[i]=d[j];
d[j]=c;
b=d[i];
a[i]=b;
}
}
Generate a square wave on P1.16 pin of 50-50 duty cycle of
20KHz. Explain the delay calculation in detail. (Assume crystal
of 30MHz is connected to ARM7).
Code:
#include<lpc214x.h>
main(void)
{
IO1DIR=0x00010000;
while(1)
delay();
delay();
void delay(void)
}
Delay calculations:
Since it is given that we have to consider 50% duty cycle for the wave.
i.e. Ton = 25 usec = 0.025 msec and Toff = 25usec = 0.05 msec.
= 375
-3:
Aim: - To develop algorithms pertaining to Simple GPIO interfacing.
#include<lpc214x.h>
}
Connect two switches on P0.0 and P0.1 and a single seven
segment display in Common anode across P0.16 to P0.23 pins.
Demonstrate a Hex up and down counter where when P0.0 is
pressed count to be displayed on seven segment increases
and when P0.1 is pressed the count to be displayed decreases.
Minimum count in Hex code is 0 and maximum count in Hex
code is F.
Code:
#include<lpc214x.h>
#define switch_1
(IO0PIN&(1<<0)) #define
switch_2 (IO0PIN&(1<<1)) void
delay(int j);
int main(void)
{
unsigned int
i,a[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98,0x88,0x80,0xC6,0x
C0,0x86,0x8E};
PINSEL0=0x0007F000;
IO0DIR=0xFFF7FFFD;
while(1)
{
if(switch_1==1)
{
for(i=0;i<16;++i)
{
IO0SET=(a[i]<<16);
delay(3000);
IO0CLR=(a[i]<<16);
delay(3000);
}
}
else if(switch_2==0)
{
for(i=16;i>0;--i)
{
IO0SET=(a[i]<<16);
delay(3000);
IO0CLR=(a[i]<<16);
delay(3000);
}
}
else
{
for(i=16;i>0;++i)
{
IO0SET=(a[i]<<16);
delay(3000);
IO0CLR=(a[i]<<16);
delay(3000);
}
}
}
}
void delay(int j)
{
int b,c;
for(b=0;b<j;b++)
{
for(c=0;c<1000;c++);
}
}