From 55d79fbe6abd1bd069e931273b6ee07766b589fc Mon Sep 17 00:00:00 2001 From: aadit Date: Thu, 4 Sep 2025 13:11:04 +0530 Subject: [PATCH] Add ES/Lab/Lab7/SwitchUPDOWN.c --- ES/Lab/Lab7/SwitchUPDOWN.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ES/Lab/Lab7/SwitchUPDOWN.c diff --git a/ES/Lab/Lab7/SwitchUPDOWN.c b/ES/Lab/Lab7/SwitchUPDOWN.c new file mode 100644 index 0000000..60053f9 --- /dev/null +++ b/ES/Lab/Lab7/SwitchUPDOWN.c @@ -0,0 +1,24 @@ +// 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. Alternatively, when it is not pressed, it should be a down counter. +#include + +int main(){ + unsigned long x; + unsigned char 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); // Counter + LPC_GPIO0 -> FIOPIN = count << 4; // Modifying FIOPIN value to match count + } else { + count = (count - 1); // Counter + LPC_GPIO0 -> FIOPIN = count << 4; // Modifying FIOPIN value to match count + } + } +}