0% found this document useful (0 votes)
6 views3 pages

Ex 1

The document outlines a program to toggle an LED connected to a GPIO pin using an STM32 microcontroller. It includes an algorithm with steps to enable the GPIO clock, set the pin to output mode, and control the LED state. The program consists of a main function that calls the LED blinking function, which turns the LED on and off with a delay.

Uploaded by

201it022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Ex 1

The document outlines a program to toggle an LED connected to a GPIO pin using an STM32 microcontroller. It includes an algorithm with steps to enable the GPIO clock, set the pin to output mode, and control the LED state. The program consists of a main function that calls the LED blinking function, which turns the LED on and off with a delay.

Uploaded by

201it022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.

no: Program to toggle the state of an LED connected to a


GPIO pin
Date:

AIM:
To write a program to toggle the state of an LED connected to a GPIO pin.

ALGORITHM:
STEP 1: Start the program.
STEP 2: Enable the GPIOA clock.
STEP 3: Make the moder register as output mode.
STEP 4: Turn on the led of GPIO (PA5 pin) by using ODR register.
STEP 5: Turn off the led by using the ODR register.
STEP 6: Stop the program.

PROGRAM:

led_blink
#include "stm32f4xx.h"
void delayMs(int n);
void led_blink()
{
RCC->AHB1ENR |= 1; /* enable GPIOA clock */
GPIOA->MODER |= (0<<11);
GPIOA->MODER |= (1<<10); /* set pin to output mode */
while(1)
{
GPIOA->ODR |= 0x00000020; /* turn on LED */
delayMs(500);
GPIOA->ODR &= ~0x00000020; /* turn off LED */
delayMs(500);
}
}
void delayMs(int n)
{
int i;
for (; n > 0; n--)
for (i = 0; i < 3195; i++) ;
}

led_blink.h
void led_blink();

main.c
#include "led_blink.h"
void main()
{
led_blink();
}
OUTPUT:

RESULT:

You might also like