Add ES/Lab/Lab7/SwitchCounter.c
This commit is contained in:
parent
e606c2cfb3
commit
279b278d8f
1 changed files with 21 additions and 0 deletions
21
ES/Lab/Lab7/SwitchCounter.c
Normal file
21
ES/Lab/Lab7/SwitchCounter.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// Question - Connect a key on P1.23 and LEDs on P0.4-0.11. WAP in EC to display the number of times the PUSH to OFF switch is pressed on LEDs.
|
||||||
|
#include <LPC17xx.h>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
unsigned long x, count = 0;
|
||||||
|
|
||||||
|
LPC_PINCON -> PINSEL0 = 0x0000<<8 ; // LED
|
||||||
|
LPC_PINCON -> PINSEL3 = 0; // SWITCH
|
||||||
|
|
||||||
|
LPC_GPIO0 -> FIODIR = 0xFF<<4; // LED
|
||||||
|
LPC_GPIO1 -> FIODIR = 0 << 23; // SWITCH
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
x = LPC_GPIO1 -> FIOPIN & 1 << 23; // Initial value to refer to
|
||||||
|
if(!x){
|
||||||
|
count = (count + 1)%255; // Counter
|
||||||
|
LPC_GPIO0 -> FIOPIN = count << 4; // Modifying FIOPIN value to match count
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue