Embedded EXP 2
Embedded EXP 2
LABORATORY RECORD
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
c) Each leds going on in first cycle and the each LEDs going off
APPARATUS:
2
23MPE0005
PROGRAM:
#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
#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
#include "stm32f4xx.h"
void configureLED(void);
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 |= (0x55UL<<12*2);
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);
int main(void)
configureLED();
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 |= (0x55UL<<12*2);
//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