EmbDev.net

Forum: ARM programming with GCC/GNU tools mapping the exact input to the output


Author: aadhii88 (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
#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.

Author: Question Mark (Guest)
Posted on:

Rate this post
0 useful
not useful
WHAT?

Author: aadhii88 (Guest)
Posted on:

Rate this post
0 useful
not useful
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.

Author: io/out (Guest)
Posted on:

Rate this post
0 useful
not useful
out0 = in0 ?

Author: aadhii88 (Guest)
Posted on:

Rate this post
0 useful
not useful
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???

Author: peda (Guest)
Posted on:

Rate this post
0 useful
not useful
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).

Author: aadhii88 (Guest)
Posted on:

Rate this post
0 useful
not useful
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.

Author: peda (Guest)
Posted on:

Rate this post
0 useful
not useful
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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.