#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; // enable internal Pullup resistors on the GPIO pins GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PC15 - PC0 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0)|(GPIO_Pin_1); //in this example ALL the pins (PC15 - PC0) are outputs 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_DelayMillis1(3); GPIO_ResetBits(out_GPIO,(out1)); 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:sir kindly help me in mapping the many input and many output that is i want when i make high in0 my output should be high that is out0. when i give in1 then my out1 should be high all other pins should be low. kindly help me to configure.
sir i have given one condition in if condition such that i want many conditions so that when i give one input my relevant output should be high and all other pins should be low.
sir in the program i have to compare many pins in the 'if' condition by shifting(or) by using logic gates.i.e in the if condition i have given if(GPIO_ReadInputDataBit(GPIOA,(GPIO_Pin_0))==1) such that i have to compare 5 pins in this if condition is it possible and what is the logic???
Simple put all if-statements in an endless loop and omit all delays, so the loop was executed as fast as possible. If you need delays, then use a timer tick, which was handled in statemachines (swith/case).
thank you sir i got that point and now my task is to compare the pins with in the 'if' condition the same when we give 1st pin my 1st output should be high when i press my second button my second button only should be high not my first button. this all should happen in if condition that to in a single line kindly help me in this.
It's unable to see on your short words, what do you expect. So you should at first generate a flowchart, which tells exactly and completely, how all the inputs, outputs and actions you want to handle. https://en.wikipedia.org/wiki/Flowchart
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.