You are on page 1of 3

Correction TP1

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

GPIO_InitTypeDef GPIO_InitStructure;
int i;
void main(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;


GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
while (1)
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,SET) ;
for(i=0;i<0x100000;i++);
GPIO_WriteBit(GPIOD,GPIO_Pin_13,SET) ;
for(i=0;i<0x100000;i++);
GPIO_WriteBit(GPIOD,GPIO_Pin_14,SET) ;
for(i=0;i<0x100000;i++);
GPIO_WriteBit(GPIOD,GPIO_Pin_15,SET) ;
}
}

Partie2 LED AVEC BOUTTON POUSSOIR  :


#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

GPIO_InitTypeDef GPIO_InitStructure ;

void main(void)
{
while (1)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);

if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0))
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,SET) ;
}
else
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,RESET) ;
}
}
}

Methode 2 :
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

GPIO_InitTypeDef GPIO_InitStructure ;

int etat;

void main(void)
{
while (1)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);

etat= GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0);
if (etat)
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,SET) ;
}
else
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,RESET) ;
}
}
}
LES 4 LED AVEC BOUTON POUSSOIR
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

GPIO_InitTypeDef GPIO_InitStructure ;

int etat;

void main(void)
{
while (1)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14|
GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);

etat= GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0);
if (etat)
{
GPIO_WriteBit(GPIOD,GPIO_Pin_12,SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_13,SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_14,SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_15,SET);
}
else
{

GPIO_WriteBit(GPIOD,GPIO_Pin_12,RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_13,RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_14,RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_15,RESET);
}
}
}

You might also like