Microcontroller Embedded C Programming C Lecture 109| Procedure to turn ON the LED

  • Post author:
  • Post category:Blog

 

Procedure to turn ON the LED

 

 

In this article onwards let’s understand the procedure to turn on the LED.

To write a code to turn on the LED is not that easy. That’s what makes the embedded system programming so unique that you must know memory map, peripheral registers, peripheral register addresses, hardware connections, etc. 

 

Procedure to turn ON the LED

1. Identify the GPIO port(a peripheral)used to connect the LED. 

We have identified that. That is GPIOD.

2. Identify the GPIO  pin where the LED is connected.

 We also identified pin number 12 of Port D.

3. Activate the GPIOD peripheral: By default in the microcontroller most of the peripherals are dead, you have to activate them. So, activating a peripheral is nothing but enabling the clock for them.

    • Until you enable the clock for a peripheral, the peripheral is dead and it neither functions nor it takes any configuration values set by you. 

You cannot configure the peripheral until you activate the clock.

    • Once you activate the clock for a peripheral, the peripheral is ready to take your configuration and control-related commands or arguments(configuration values). 
    • Note: For some microcontrollers, the peripheral may be ON by default, and you need not to do any activation. (You should explore by the device datasheet for reference manual

4. Configure the GPIO pin mode as output: 

Since you are driving an LED (to ON or OFF), the operation mode of the GPIO pin has to be configured as OUTPUT. 

5. Write to the GPIO pin:

1(HIGH)to make the GPIO pin state HIGH(3.3V)

0(LOW) to make the GPIO pin state LOW(0V)

 

Procedure to turn on the LED: Summary

  1. Identify the GPIO port(a peripheral) used to connect LED
  2. Identify the GPIO pin number where the LED is connected
  3. Activate the GPIOD peripheral(Enable the clock)
  4. Configure the GPIO pin mode as output 
  5. Write to the GPIO pin

 

The next question is how to enable the peripheral clock. We will understand this in the following post.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply