Hi Folks,
I have interfaced a DC motor and a keyboard with LPC2138, so that I can use the switches to control the direction of DC Motor. Here is the code which I used to perform the desired operation, but somehow this code is not responding. Can anyone please help me on this.
Here's the code :
#include<lpc21XX.h>
/*void Delay (int a) { int i; for (i=0;i<a*100;i++); }*/ int MotorDirection() {
int w; IO0SET = 0X000E0000; IO0CLR = 0X00010000; // Row 1 used w = IO1PIN & 0X00F00000; // Read the columns switch(w) {
case 0X00E00000 : IO1SET = 0X00050000; // Clk rotation of Motor return IO1SET;
case 0X00D00000 : IO1SET = 0X00060000; // AntiClk rotation of Motor return IO1SET;
case 0X00B00000 : IO1SET = 0X00050000; // Clkwise return IO1SET;
case 0X00700000 : IO1SET = 0X00060000; // AntiClkwise return IO1SET; } }
int main() {
IO1DIR = 0X00070000; // IN1=1.16,IN2=1.17,EN=1.18 - Output to L293D IO0DIR = 0X000F00000; // 0.16,0.17,0.18,0.19 as Rows & 0.20 - 0.23 as Columns
while(1)
{
MotorDirection();
}
Perhaps you could simplify the code so it is very understandable at first use writes to registers followed by long delays say 1 second delays.
I was going to write that there was no delay in your code. But then I remembered you said it was a keyboard input. Still you can have mistakes and then the case statement will not change the data at all.
I changed the code and was able to achieve what was expected. Thanks :D !!