#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.
You have a truly trivial task. And you still want someone else to supply the answer.
Have you not checked how to read an input? Have you not checked how to write to an output? Have you not checked how perform "if" conditions in C?
Exactly how is it possible that you can be stuck, unless you spent exactly all your time on Facebook, playing Tetris, taking selfies or whatever during the time when the other students listened to the teacher's presentations or spent a bit of time reading the recommended literature?
The problem complexity here isn't that far higher than how to press the button on a ballpoint pen... You can do it the traditional way with your thumb, or be creative and bounce a tennis ball on the button and get the same outcome. For the above problem you can select a large number of different ways to write the code to control the outputs based on the inputs. And the majority of them are absolutely trivial. You can use explicit if statements. You can implement a state machine. You can make each output a function of the set of input states. You can convert the individual input bits into a binary number and make a lookup to get an output number where each bit represents an output pin. You can play with abstract algebra and use rings and fields. You can implement truth tables. You can draw a logic circuit with and/or/not gates and then implement as code.
If you can copy/paste the code in your initial post, then you must also be able to locate and copy/paste code that looks at pin states, sets pin states and performs different actions based on a pin state.
Why do you even need all the delay code, when your requirement specification doesn't involve any delays?
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; } }