We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
#include "stm32f0xx.h" #include "stm32f0308_Discovery.h"
#define in0 GPIO_Pin_0 #define in1 GPIO_Pin_1 #define in2 GPIO_Pin_2 #define in3 GPIO_Pin_3 #define in4 GPIO_Pin_4 #define in5 GPIO_Pin_5 #define in_GPIO GPIOA
#define out0 GPIO_Pin_0 #define out1 GPIO_Pin_1 #define out2 GPIO_Pin_2 #define out3 GPIO_Pin_3 #define out4 GPIO_Pin_4 #define out5 GPIO_Pin_5 #define out_GPIO GPIOC
void TM_Delay_Init(void); void TM_DelayMillis(uint32_t millis); void TM_DelayMillis1(uint32_t millis); void TM_DelayMillis2(uint32_t millis);
GPIO_InitTypeDef GPIO_InitStructure ;
uint32_t multiplier;
int main(void) { SystemInit(); SystemCoreClockUpdate(); TM_Delay_Init(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure PA in input mode */ GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0)|(GPIO_Pin_1); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PC15 - PC0 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0)|(GPIO_Pin_1); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); while(1) { if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1) { GPIO_SetBits(out_GPIO,out0); TM_DelayMillis(7); GPIO_ResetBits(out_GPIO,out0); } while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1) { GPIO_SetBits(out_GPIO,out0); TM_DelayMillis(3); GPIO_ResetBits(out_GPIO,out0); TM_DelayMillis2(22); }}}
void TM_DelayMillis(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 100 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_DelayMillis1(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 1 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_DelayMillis2(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 1 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_Delay_Init(void) { RCC_ClocksTypeDef RCC_Clocks; /* Get system clocks */ RCC_GetClocksFreq(&RCC_Clocks); /* While loop takes 4 cycles */ /* For 1 us delay, we need to divide with 4M */ multiplier = RCC_Clocks.HCLK_Frequency / 4000000; }
Note:kindly make for many pins such that when i given in0 my out0 should be high all other pins low such that when i give my in1 my out1 should be high all other low. vice versa.
Your description infers some non-direct mapping, with priority, but whatever
// For the chronically clueless and lazy #include "stm32f0xx.h" #define in0 GPIO_Pin_0 #define in1 GPIO_Pin_1 #define in2 GPIO_Pin_2 #define in3 GPIO_Pin_3 #define in4 GPIO_Pin_4 #define in5 GPIO_Pin_5 #define in_GPIO GPIOA #define out0 GPIO_Pin_0 #define out1 GPIO_Pin_1 #define out2 GPIO_Pin_2 #define out3 GPIO_Pin_3 #define out4 GPIO_Pin_4 #define out5 GPIO_Pin_5 #define out_GPIO GPIOC int main(void) { GPIO_InitTypeDef GPIO_InitStructure; SystemInit(); // Doesn't Keil with CMSIS do this already? SystemCoreClockUpdate(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOC, ENABLE); /* Configure PA in input mode */ GPIO_InitStructure.GPIO_Pin = in0 | in1 | in2 | in3 | in4 | in5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(in_GPIO, &GPIO_InitStructure); /* Configure PC in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = out0 | out1 | out2 | out3 | out4 | out5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(out_GPIO, &GPIO_InitStructure); while(1) { uint16_t invec, outvec; invec = in_GPIO->IDR; outvec = 0; if (invec & in0) outvec = out0; else if (invec & in1) outvec = out1; else if (invec & in2) outvec = out2; else if (invec & in3) outvec = out3; else if (invec & in4) outvec = out4; else if (invec & in5) outvec = out5; out_GPIO->ODR = (out_GPIO->ODR & ~(out0 | out1 | out2 | out3 | out4 | out5)) | outvec; } }