Embedded C Programs
Embedded C Programs
STEPPER MOTOR
* A stepper motor direction is controlled by shifting the
voltage across
* the coils. Port lines : P0.12 to P0.15
**********************************************************
#include <LPC21xx.H>
void clock_wise(void);
void anti_clock_wise(void);
int main(void)
{
PINSEL0 = 0x00FFFFFF; //P0.12 to P0.15 GPIo
IO0DIR |= 0x0000F000; //P0.12 to P0.15 output
while(1)
{
for(j=0;j<50;j++) // 20 times in Clock wise
Rotation
clock_wise();
} // End of while(1)
} // End of main
void clock_wise(void)
{
var1 = 0x00000800; //For Clockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1<<1; //For Clockwise
var2 = ~var1;
var2 = var2 & 0x0000F000;
IO0PIN = ~var2;
void anti_clock_wise(void)
{
var1 = 0x00010000; //For Anticlockwise
for(i=0;i<=3;i++) // for A B C D Stepping
{
var1 = var1>>1; //For Anticlockwise
var2 = ~var1;
var2 = var2 & 0x0000F000;
IO0PIN = ~var2;
for(k=0;k<3000;k++); //for step speed variation
}
}
7 SEGMENT DISPLAY
#include <LPC21XX.h>
// ****** changes made by JK 0n 090115
/*
while(1)
{
IO0SET |= ALLDISP; // select all
digits
IO0CLR = 0x00FF0000; // clear the data
lines to 7-segment displays
IO0SET = Disp[Switchcount]; // get the
7-segment display value from the array
}
}
}
}
}
DC MOTOR
#include<lpc214x.h>
void clock_wise(void);
void anti_clock_wise(void);
unsigned int j=0;
int main()
{
IO0DIR= 0X00000900;
IO0SET= 0X00000100; //P0.8 should
always high.
while(1)
{
clock_wise();
for(j=0;j<400000;j++); //delay
anti_clock_wise();
for(j=0;j<400000;j++); //delay
} //End of
while(1)
} //End of Main
void clock_wise(void)
{
IO0CLR = 0x00000900; //stop motor
and also turn off relay
for(j=0;j<10000;j++); //small delay to
allow motor to turn off
IO0SET = 0X00000900; //Selecting the
P0.11 line for clockwise and turn on motor
}
void anti_clock_wise(void)
{
IO0CLR = 0X00000900; //stop motor
and also turn off relay
for(j=0;j<10000;j++); //small delay to
allow motor to turn off
IO0SET = 0X00000100; //not selecting
the P0.11 line for Anti clockwise
}