Lab 8
Lab 8
Lab 8
Reg No FA18-BEE-121-E
LAB #8
This Lab has been designed to familiarize with STM Led and Push
button operations
Objectives
To explain the working of switch and led interfacing with the STM32F407 using trainer board and modify
the program and display its output on STM32F407 trainer board using C programming.
Methodology
This Lab consisted of a different aspect of STM operation and programming. The basic objective
was to manipulate LEDs. Light Emitting Diodes are the mostly commonly used components in
many applications. They are made of semiconducting material. A light-emitting diode is a two-
lead semiconductor light source. It is a pn-junction diode, which emits light when activated. When
a suitable voltage is applied to the leads, electrons can recombine with electron holes within the
device, releasing energy in the form of photons. This effect is called electroluminescence. The Led
is can be interfaced in either source or sink configurations. The push-button, switch is assumed to
be bounce free, implying that when it is pressed and then released, a single pulse is produced. Push
Button can interface in two types of configurations i.e. Pull up and Pull Down. The STM32F4
training board has an LED driven by I/O pin PB11. In order to configure this pin, clocks must first
be enabled for General Purpose Input Output (GPIO) port. This Lab had two pre lab tasks and four
lab tasks that were to be implemented and the results were to be observed. The Lab consisted of
three pre lab tasks and two in lab tasks. The tasks were to be completed and the results were to be
verified.
Conclusion
The lab helped understand the use of STM Trainer Board. The Lab also helped in the understanding
of different configurations of the LEDs and push buttons. The lab also helped in interfacing and
understanding of the microcontroller. The results after changing the codes were observed. All the
Lab Tasks were completed. Observations were made and the results were verified.
Lab task
Task 1
#include <stdio.h>
#include <stm32f4xx.h>
SystemCoreClockUpdate();
RCC->AHB1ENR |= (1 << 1) ;
GPIOB->MODER = 0x55444444;
GPIOB->OTYPER = 0x00000000;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
while(1) {
}}
Task 3
#include <stdio.h>
#include <stm32f4xx.h>
volatile uint32_t msTicks; /* counts 1ms timeTicks */
volatile uint32_t bt=0;
void SysTick_Handler(void)
{
msTicks++;
}
void Delay (uint32_t dlyTicks)
{
uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++)
{
for(loope=0;loope<29000;loope++)
{
__nop();
}
}}
if(i>8)
{ i=1;}
}}
}
Task 5
#include <stdio.h>
#include <stm32f4xx.h>
volatile uint32_t msTicks;
volatile uint32_t bt=0;
volatile uint32_t bt1=0;
void SysTick_Handler(void)
{
msTicks++;
}
void Delay (uint32_t dlyTicks)
{
uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++)
{
for(loope=0;loope<29000;loope++)
{
__nop();
}
}}
}}
Task 6
#include <stdio.h>
#include <stm32f4xx.h>
volatile uint32_t msTicks;
volatile uint32_t bt=0;
volatile uint32_t bt1=0;
void SysTick_Handler(void)
{
msTicks++;
}
void Delay (uint32_t dlyTicks)
{
uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++)
{
for(loope=0;loope<29000;loope++)
{
__nop();
}
}}
int main (void)
{
SystemCoreClockUpdate();
RCC->AHB1ENR |= (1 << 1) ;
RCC->AHB1ENR |= (1 << 2) ;
GPIOB->MODER = 0x55444444;
GPIOB->OTYPER = 0x00000000;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
GPIOC->MODER = 0x00000000;
GPIOC->OTYPER = 0x00000000;
GPIOC->OSPEEDR = 0xAAAAAAAA;
GPIOC->PUPDR = 0x00000000;
while(1) { // Infinite Loop
bt=(GPIOC->IDR&(1<<6));
bt1=(GPIOC->IDR&(1<<7));
GPIOB->BSRRH = ((1 << 11) );
GPIOB->BSRRH = ((1 << 12) );
if( bt!=(1 << 6))
{
GPIOB->BSRRL = ((1 << 11) );
}
if( bt1!=(1 << 7))
{
GPIOB->BSRRL = ((1 << 11) );
}
if( bt1!=(1 << 7)&bt!=(1 << 6))
{
GPIOB->BSRRL = ((1 << 12) );
}
}}