From 4fd7019fd33b74db470676a34ea15c9472794c9b Mon Sep 17 00:00:00 2001 From: Uttam Ambappa Bhavimani Date: Fri, 20 Sep 2024 20:21:11 +0530 Subject: [PATCH] Add Delay Function --- main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.c b/main.c index 02ec3b3..9ec13b9 100644 --- a/main.c +++ b/main.c @@ -29,3 +29,12 @@ void systick_setting(void) // SYSTICK SETUP FUNCTION STCTRL |= (1 << 0) | (1 << 2); // Enable SysTick with system clock STCURRENT = 0; // Clear current 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 +}