0% found this document useful (0 votes)
12 views19 pages

Embedded EXP 2

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)
12 views19 pages

Embedded EXP 2

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/ 19

23MPE0005

SCHOOL OF ELECTRICAL ENGINEERING

MPED610P - Embedded System Design for Power Electronic Applications Lab

LABORATORY RECORD

Name of the Student SRIYA MAHESWARI

Reg. Number 23MPE0005

Course / Semester. M-Tech / Second Semester

Branch Electrical and Electronic Engineering

Subject Power Electronics and Drives

1
23MPE0005

EXPERIMENT NO : 2

LED INTERFACING

AIM:

Write an embedded C program to interface LED/LEDs and push button with ARM cortex controller using

 Nucleo Board

 Discovery Board

a) Blinking all leds

b) Individual leds on and off

c) Each leds going on in first cycle and the each LEDs going off

And verify the same in hardware.

APPARATUS:

Device used: STM32476RGT6 (Nucleo), STM32F407VGT6 (Discovery) , STM32 Cube IDE.


Programme: Embedded C language.

2
23MPE0005

PROGRAM:

(i) LED INTERFACING USING NUCLEO BOARD WITH PUSH BUTTON

#include "stm32l4xx.h"
void configureLEDSWITCH(void);
volatile unsigned int LED_state;
volatile unsigned int PB_state;
void msDelay(volatile int msTime);
int a=600;
int main(void)
{
//configure LED
configureLEDSWITCH();
//Define Delay Function
msDelay(1000);
//GPIOD->ODR = (0x5UL<<12);
while(1)
{
if((GPIOC->IDR & 0x00002000)==0x00000000)
a=a-25;
PB_state = GPIOC->IDR; //to check the
status of push button
GPIOA->ODR^=(0x1UL<<5);
LED_state = GPIOA->ODR; //to check the
status of led

3
23MPE0005

msDelay(a);
}
}
void configureLEDSWITCH(void)
{
RCC->AHB2ENR |=(1UL<<0);
RCC->AHB2ENR |=(1UL<<2);
GPIOA->MODER &=~(0xFFUL<<5*2);
GPIOC->MODER &=~(0xFFUL<<26);
GPIOA->MODER |=(0x01UL<<5*2);
}
void msDelay(int msTime)
{
//Assume for loop take 12 clock cycles
and system 16MHz
int Time=msTime*1333;
for(int i=0;i<Time;i++);
}

4
23MPE0005

OUTPUT

5
23MPE0005

(ii) LED INTERFACING USING DISCOVERY BOARD WITH PUSH BUTTON

a) Blinking all leds

#include "stm32f4xx.h"

void configureLED(void);
volatile unsigned int LED_state;
void msDelay(volatile int msTime);
int main(void)
{
//configure LED using discovery board
configureLED();
//define delay function
msDelay(1000);
6
23MPE0005

//gpiod->odr = (0x5UL<<12);
while(1)
{
GPIOD->ODR ^= (0xFUL<<12);
LED_state = GPIOD->ODR;
msDelay(250);
}
}
void configureLED(void)
{
RCC->AHB1ENR |=(1UL<<3);
GPIOD->MODER &= ~(0xFFUL<<12*2);
GPIOD->MODER |= (0x55UL<<12*2);
}
void msDelay(int msTime)
{
//Assume for loop take 12 clock cycles and system clock is 16MHz
int Time=msTime*1333;
for(int i=0;i<Time;i++);
}

OUTPUT

7
23MPE0005

8
23MPE0005

9
23MPE0005

b) Individual leds on and off

#include "stm32f4xx.h"

void configureLED(void);

volatile unsigned int LED_state;

void msDelay(volatile int msTime);

int main(void)

//configure LED

configureLED();

msDelay(1000);

while(1)

GPIOD->ODR ^=(0X1UL<<12);

msDelay(250);

GPIOD->ODR &=~(0X1UL<<12);

GPIOD->ODR ^=(0X2UL<<12);

msDelay(250);

GPIOD->ODR &=~(0X2UL<<12);

GPIOD->ODR ^=(0x4UL<<12);

msDelay(250);

GPIOD->ODR &=~(0X4UL<<12);

GPIOD->ODR ^=(0X8UL<<12);
10
23MPE0005

msDelay(250);

GPIOD->ODR &=~(0X8UL<<12);

void configureLED(void)

RCC->AHB1ENR |=(1ul<<3);

GPIOD->MODER &= ~(0xFFUL<<12*2);

GPIOD->MODER |= (0x55UL<<12*2);

void msDelay(int msTime)

int Time=msTime*1333;

for(int i=0;i<Time;i++);

OUTPUT

11
23MPE0005

12
23MPE0005

13
23MPE0005

c) Each leds going on in first cycle and the each LEDs going off

#include "stm32f4xx.h"

void configureLED(void);

volatile unsigned int LED_state;

void msDelay(volatile int msTime);

int main(void)

//configure LED individual

configureLED();

//define delay function

msDelay(1000);

//gpiod->odr = (0x5UL<<12);

while(1)

GPIOD->ODR ^= (0x1UL<<12);

LED_state = GPIOD->ODR;

msDelay(250);

GPIOD->ODR ^= (0x2UL<<12);

msDelay(500);

GPIOD->ODR ^= (0x4UL<<12);

msDelay(750);
14
23MPE0005

GPIOD->ODR ^= (0x8UL<<12);

msDelay(900);

void configureLED(void)

RCC->AHB1ENR |=(1UL<<3);

GPIOD->MODER &= ~(0xFFUL<<12*2);

GPIOD->MODER |= (0x55UL<<12*2);

void msDelay(int msTime)

//Assume for loop take 12 clock cycles and system clock is 16MHz

int Time=msTime*1333;

for(int i=0;i<Time;i++);

15
23MPE0005

OUTPUT

16
23MPE0005

17
23MPE0005

18
23MPE0005

RESULT
Embedded C program to interface LED/LEDs and push button with ARM cortex controller
using Nucleo Board and Discovery Board was done and verified the same in hardware.

19

You might also like