From 3304d132238d873190f57391bdda0142e4a4a327 Mon Sep 17 00:00:00 2001 From: Uttam Bhavimani Bhavimani Date: Sun, 22 Sep 2024 19:41:56 +0530 Subject: [PATCH] Update Group21_Lab06_Task1/main.c Add Delay Function --- Group21_Lab06_Task1/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Group21_Lab06_Task1/main.c b/Group21_Lab06_Task1/main.c index e4adfd9..42c2771 100644 --- a/Group21_Lab06_Task1/main.c +++ b/Group21_Lab06_Task1/main.c @@ -39,3 +39,12 @@ void systick_setting(void) STCTRL |= (CLKINT | ENABLE | INTEN); // Set internal clock, enable the timer STCURRENT = 0; // Clear STCURRENT value } + +void delay(int us) // DEFINING DELAY FUNCTION +{ + STRELOAD = SYSTICK_RELOAD_VALUE(us); // RELOAD VALUE FOR REQUIRED DELAY + STCURRENT = 0; // Clear STCURRENT + STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick + while ((STCTRL & (1 << 16)) == 0); // Wait until flag is set + STCTRL &= 0x0; // Stop the timer +}