Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4xx_gpio.h"
- #define RCC_AHB1Periph_GPIOA ((uint32_t)0x00000001)
- #define RCC_AHB1Periph_GPIOB ((uint32_t)0x00000002)
- #define RCC_AHB1Periph_GPIOC ((uint32_t)0x00000004)
- void GPIO_Config(void){
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
- GPIO_InitTypeDef gpio;
- GPIO_StructInit(&gpio);
- gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3
- | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- gpio.GPIO_Mode = GPIO_Mode_OUT;
- gpio.GPIO_OType = GPIO_OType_PP;
- gpio.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOB, &gpio);
- GPIO_StructInit(&gpio);
- gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
- gpio.GPIO_Mode = GPIO_Mode_IN;
- gpio.GPIO_OType = GPIO_OType_PP;
- gpio.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOC, &gpio);
- }
- int main(void)
- {
- void sleep(int i){
- while(i) i--;
- }
- double x=0;
- GPIO_Config();
- while(1){
- GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 );
- if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0)==0){
- x=2^0;
- }
- else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1)==0){
- x=2^1;
- }
- else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2)==0){
- x=2^2;
- }
- else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_3)==0){
- x=2^3;
- }
- if (x<=4){
- GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5| GPIO_Pin_6 );
- }
- else
- {
- GPIO_ResetBits(GPIOB, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement