Lab 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Name Ubaid Ur Rehman

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>

volatile uint32_t msTicks;


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) ;

GPIOB->MODER = 0x55444444;
GPIOB->OTYPER = 0x00000000;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;

while(1) {

GPIOB->BSRRL = ((1 << 11) );


Delay(1000);
GPIOB->BSRRH = ((1 << 11) );
Delay(1000);
}
}
Task 2
#include <stdio.h>
#include <stm32f4xx.h>
volatile uint32_t msTicks;
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();
}
}}

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) {
bt=(GPIOC->IDR&(1<<6));
if( bt!=(1 << 6))
{
GPIOB->BSRRL = ((1 << 11) );
}
else
{
GPIOB->BSRRH = ((1 << 11) );
}

}}
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();
}
}}

int main (void)


{
SystemCoreClockUpdate(); // Get Core Clock Frequency
RCC->AHB1ENR |= (1 << 1) ; // Enable GPIOB clock
GPIOB->MODER = 0x55444444; // Setting Direction of Port B
GPIOB->OTYPER = 0x00000000; // To configure the output type of Port B
GPIOB->OSPEEDR = 0xAAAAAAAA; // To configure the speed of Port B
GPIOB->PUPDR = 0x00000000; // To configure the Port B Pull-up or Pull-down
while (1) { // Infinite Loop
int i;
for (i=1;i<=5;i++)
{
GPIOB->BSRRL = ((1 << (i+10)) );
Delay(1000);
if(i>8)
{
i=1;
}
}}
}
Task 4
#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();
}
}}
int main (void)
{
SystemCoreClockUpdate();
RCC->AHB1ENR |= (1 << 1) ;
GPIOB->MODER = 0x55444444;
GPIOB->OTYPER = 0x00000000;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
while (1) {
int i;
for (i=1;i<=5;i++)
{
GPIOB->BSRRL = ((1 << (i+10)) );
Delay(1000);
GPIOB->BSRRH = ((1 << (i+10)) );

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();
}
}}

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) {
bt=(GPIOC->IDR&(1<<6));
bt1=(GPIOC->IDR&(1<<7));
if( bt!=(1 << 6))
{
GPIOB->BSRRL = ((1 << 11) );
}
else {
GPIOB->BSRRH = ((1 << 11) );
}
if( bt1!=(1 << 7))
{
GPIOB->BSRRL = ((1 << 12) );
}
else
{
GPIOB->BSRRH = ((1 << 12) );
}

}}
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) );
}
}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy