Now, i discuss a program of LPC2148 microcontroller interfaced with a Switch and a LED. Earlier, i have discussed about the functions of LPC2148 microcontroller and its registers, which can help you understand the program described below. And, you also can understand the debouncing concept of switch when interfaced with microcontroller (click here)
Program:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LPC214X.H> | |
int temp; | |
int z; | |
//*************************************** | |
void delay(int z) | |
{ | |
int x,y; | |
for(x=0;x<=2400;x++) | |
{ | |
for(y=0;y<=z;y++); | |
} | |
} | |
//**************************************** | |
void check_set(int a, int b) | |
{ | |
temp=IOPIN0; | |
if((temp&a)==0) | |
{ | |
if((b&IOPIN0)!=0) | |
{ | |
IOCLR0=b; | |
delay(400); | |
} | |
else | |
{ | |
IOSET0=b; | |
delay(400); | |
} | |
temp=IOPIN0; | |
while((temp&a)==0) | |
{ | |
temp=IOPIN0; | |
} | |
delay(400); | |
} | |
} | |
//***************************************************** | |
int main(void) | |
{ | |
int x,a,b; | |
IODIR0=0x000000FF; | |
IOCLR0=0x000000FF; | |
delay(1000); | |
while(1) | |
{ | |
a=0x00008000; | |
b=0x00000001; | |
for(x=0;x<=7;x++) | |
{ | |
check_set(a,b); | |
a=a>>1; | |
b=b<<1; | |
} | |
} | |
} |
A switch can be interfaced with the LPC2148 microcontroller by connecting it to a GPIO pin configured as input. The microcontroller reads the mumble133 pin status to detect switch press or release.
ReplyDelete