Ministère de l’Enseignement Supérieur, de la Recherche
Scientifique et des Technologies de l’Information et de la Architecture
Communication
Université de Carthage µC
Institut Supérieur des Technologies de l’Information et de la
Communication
Tp 1 :Configuration de gpio
#include<stm32f4_discovery.h>
void ledInit(void) //configuration pin5 et 6 port B « Sortie »
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB ,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB,&GPIO_InitStruct);
void CLAVIER(void) //configuration pin6 et 7 port C « Entrée »
{
GPIO_InitTypeDef GPIO_InitStruct1;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC ,ENABLE);
GPIO_InitStruct1.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct1.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct1.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct1.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct1.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC,&GPIO_InitStruct1);
void delay (uint32_t delay) //fonction 7adra
{
uint32_t i;
while(delay>0)
{
for(i=0;i<100000;i++);
delay--;
}
}
int main(void)
{ // ledInit();
CLAVIER();
int data;
while(1)
{
Bouchantouf SONIA Page 1
Ministère de l’Enseignement Supérieur, de la Recherche
Scientifique et des Technologies de l’Information et de la Architecture
Communication
Université de Carthage µC
Institut Supérieur des Technologies de l’Information et de la
Communication
data = GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_6);
{ if (data== 0)
{
GPIO_SetBits(GPIOB,GPIO_Pin_5);
delay(20);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
delay(20);
GPIO_ResetBits(GPIOB,GPIO_Pin_7);
}
else if (data== 1)
{//delay(20);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
GPIO_SetBits(GPIOB,GPIO_Pin_7);
delay(20);
GPIO_ResetBits(GPIOB,GPIO_Pin_7);
delay(20);
}}
}
}
Bouchantouf SONIA Page 2
Ministère de l’Enseignement Supérieur, de la Recherche
Scientifique et des Technologies de l’Information et de la Architecture
Communication
Université de Carthage µC
Institut Supérieur des Technologies de l’Information et de la
Communication
Tp 2 : AFFICHEUR LCD
Dans le main.c
#include <stm32f4_discovery.h>
#include "Board_Config/stm32f4_OpenShield.h"
#include "lcd/lcd.h"
//=========================================================================
=========
//function
//=========================================================================
=========
void delay (uint32_t delay)
{
uint32_t i;
while(delay>0)
{
for(i=0;i<100000;i++);
delay--;
}
}
//=========================================================================
=========
//main routine
//=========================================================================
=========
int main(void)
{
LCD_InitTypeDef LCD_InitStruct; //configuration LCD
// LCD Init
LCD_InitStruct.CharacterFont = LCD_CharacterFont_5x10Dots;
LCD_InitStruct.DataLength = LCD_DataLength_4Bit;
LCD_InitStruct.LineNumber = LCD_LineNumber_2Lines;
LCD_Init(&LCD_InitStruct);
//LCD_Puts("TEST");
//Appel aux fonction dans stm32F4_OpenShield.c
CTOpenShield_PB1Init();
CTOpenShield_PB2Init();
while(1)
{
if((CTOpenShield_PB1GetState())==0){/// logique inverse fel bouton !!
LCD_Clear();
LCD_Puts("pin 6");
delay(100);
LCD_Clear();}
Bouchantouf SONIA Page 3
Ministère de l’Enseignement Supérieur, de la Recherche
Scientifique et des Technologies de l’Information et de la Architecture
Communication
Université de Carthage µC
Institut Supérieur des Technologies de l’Information et de la
Communication
else if((CTOpenShield_PB2GetState())==0)
{
LCD_Clear();
LCD_Puts("pin 7");
delay(100);
LCD_Clear();
}
//delay(1);// delay a few time
}
}
Dans le stm32F4_OpenShield.c
void CTOpenShield_PB1Init() //configuration pin6 port C « Entrée »
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC ,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC,&GPIO_InitStruct);
void CTOpenShield_PB2Init() //configuration pin7 port C « Entrée »
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC ,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC,&GPIO_InitStruct);
}
int CTOpenShield_PB1GetState()
{ int data;
data = GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_6);
return(data);
}
int CTOpenShield_PB2GetState()
{
int data1;
data1 = GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7);
return(data1);
}
Bouchantouf SONIA Page 4