0% found this document useful (0 votes)
6 views5 pages

Lpc1768 Programs

The document contains multiple C programs for the LPC17xx microcontroller, demonstrating various functionalities such as generating square and triangle waves, controlling a stepper motor in both clockwise and anti-clockwise directions, displaying numbers on a 7-segment display, and operating a relay/buzzer/LED based on input. Each program includes necessary configurations for GPIO and loops to achieve the desired output. The implementations utilize basic delay functions and bit manipulation for controlling hardware components.

Uploaded by

ssrinivasubr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Lpc1768 Programs

The document contains multiple C programs for the LPC17xx microcontroller, demonstrating various functionalities such as generating square and triangle waves, controlling a stepper motor in both clockwise and anti-clockwise directions, displaying numbers on a 7-segment display, and operating a relay/buzzer/LED based on input. Each program includes necessary configurations for GPIO and loops to achieve the desired output. The implementations utilize basic delay functions and bit manipulation for controlling hardware components.

Uploaded by

ssrinivasubr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQUARE WAVE

#include <LPC17xx.H>
void delay(void);
int main ()
{
LPC_PINCON->PINSEL0 = 0x0 ;
LPC_GPIO0->FIODIR = 0x00000FF0 ;
while(1)
{
LPC_GPIO0->FIOPIN = 0x00000FF0 ;
delay();
LPC_GPIO0->FIOCLR = 0x00000FF0 ;
delay();
}
}
void delay(void)
{
unsigned int i=0;
for(i=0;i<=9500;i++);
}

TRIANGLE WAVE

#include <LPC17xx.H>
int main ()
{
unsigned long int temp=0;
unsigned int i=0;
LPC_PINCON->PINSEL0 = 0x0 ;
LPC_GPIO0->FIODIR = 0x00000FF0 ;
while(1)
{
for(i=0;i!=0xFF;i++)
{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}
for(i=0xFF; i!=0;i--)
{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}
}
}
STEPPER MOTOR(CLOCK WISE)
#include <LPC17xx.H>
void clock_wise(void);
unsigned long int var1;
unsigned int i=0,j=0,k=0;
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL4 = 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2->FIODIR = 0x0000000F; //P2.0 to P2.3 output
while(1)
{
for(j=0;j<50;j++) //50 times in Clock wise Rotation
clock_wise();
for(k=0;k<65000;k++); //Delay to show clock Rotation
} //End of while(1)
} //End of main
void clock_wise(void)
{
var1 = 0x00000008; //For Clockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1>>1; //For Clockwise
for(k=0;k<30000;k++); //for step speed variation
}
}
STEPPER MOTOR(ANTI CLOCK WISE)

#include <LPC17xx.H>
void anti_clock_wise(void);
unsigned long int var1;
unsigned int i=0,j=0,k=0;
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL4 = 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2->FIODIR = 0x0000000F; //P2.0 to P2.3 output
while(1)
{
for(k=0;k<65000;k++); //Delay to show anti_clock Rotation
for(j=0;j<50;j++) //50 times in Anti Clock wise Rotation
anti_clock_wise();
}
}
void anti_clock_wise(void)
{
var1 = 0x0000001; //For Anticlockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1<<1; //For Anticlockwise
for(k=0;k<30000;k++); //for step speed variation
}
}
7SEGMENT DISPLAY

#include <LPC17xx.h>
unsigned int delay, count=0, Switchcount=0,j;
unsigned int Disp[16]={0x000003f0, 0x00000060, 0x000005b0, 0x000004f0, 0x00000660,
0x000006d0, 0x000007d0, 0x00000070, 0x000007f0, 0x000006f0,
0x00000770,0x000007c0,0x00000390,
0x000005e0, 0x00000790, 0x00000710 };
#define ALLDISP 0x00180000
#define DATAPORT 0x00000ff0
int main (void)
{
LPC_PINCON->PINSEL0 = 0x00000000;
LPC_PINCON->PINSEL1 = 0x00000000;
LPC_GPIO0->FIODIR =0x00180ff0;
while(1)
{
LPC_GPIO0->FIOSET |= ALLDISP;
LPC_GPIO0->FIOCLR = 0x00000ff0;
LPC_GPIO0->FIOSET = Disp[Switchcount];
for(j=0;j<9;j++)
for(delay=0;delay<99000;delay++);
Switchcount++;
if(Switchcount == 0x10)
{
Switchcount = 0;
LPC_GPIO0->FIOCLR = 0x00180ff0;
}
}
}
RELAY/BUZZER/LED
#include <LPC17xx.H>
unsigned int count=0;
int main(void)
{
unsigned int i;
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL1 &= 0xFFF0FFFF; //P0.25 GPIO
LPC_GPIO0->FIODIR |= 0x03000000; //P0.25 output
while(1)
{
if(!(LPC_GPIO2->FIOPIN & 0x00000800))
{
for(i=0;i<10;i++)
{
LPC_GPIO0->FIOSET = 0x03000000; //relay on
for(i=0;i<10000;i++);
}
}
else
{
LPC_GPIO0->FIOCLR = 0x03000000; //relay off
for(i=0;i<100000;i++);
}
}
}

You might also like