cancel
Showing results for 
Search instead for 
Did you mean: 

test on the value of a vector

nad
Associate II
Posted on December 30, 2010 at 00:13

Hello, 

I want to write a program to make his test on the value of a vector. 

is that there is another simpler solution??

GPIO_DeInit(GPIOB);

GPIO_Init(GPIOB, GPIO_PIN_0, GPIO_MODE_IN_PU_NO_IT);

GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);

GPIO_Init(GPIOB, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT);

if (((GPIO_ReadInputData(GPIOB) & GPIO_PIN_0)== 0)) &(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0))&

(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_2)== 1))

{

  //do operation 1;

}

else 

if (((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0)) &(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0))&

(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_2)== 1))

{

// do operation 2;

}

........

........

........

........

else 

  operation n;

   

10 REPLIES 10
Andrew Neil
Chief II
Posted on January 01, 2011 at 04:02

That's the kind of thing - but don't you think that a switch statement might be more approrpriate...?

Andrew Neil
Chief II
Posted on December 30, 2010 at 02:06

You can read the entire port as an 8-bit value...

nad
Associate II
Posted on December 30, 2010 at 12:58

thank you for your answer.

did you mean:

if (((GPIO_ReadInputData(GPIOB) ==0x00 ))

{

    Operation 1 

}

else if (((GPIO_ReadInputData(GPIOB) ==0x01 ))

{

    Operation 2

}

else if (((GPIO_ReadInputData(GPIOB) ==0x10 ))

else 

{

     Operation n

 }

nad
Associate II
Posted on January 03, 2011 at 10:11

yes, it's just I have a few problems on the levels of reading data and syntax specific STM8S.

Thank you

Andrew Neil
Chief II
Posted on January 04, 2011 at 15:23

There is no syntax here specific to th STM8!

As far as syntax is concerned, you are just calling a function that returns an integral value!

nad
Associate II
Posted on January 05, 2011 at 00:40

yes you are right, it's a function call already defined. 

Another question I tried with the other method but it does not work. 

how to read the value of a port initialized as inpout. 

Thank you

Andrew Neil
Chief II
Posted on January 05, 2011 at 10:45

''I tried with the other method''

 

 

What other method?

''but it does not work''

 

Saying, ''it does not work'' is never useful.

You need to state precisely what you did, what you expected to happen, what actually happened, and what steps you have taken to explain the difference.

''how to read the value of a port''

 

Isn't that exactly what GPIO_ReadInputData does?!

nad
Associate II
Posted on January 05, 2011 at 13:52

I meant: I connected a sensor to port B which gives a value of 5 bit. with

 this value I will make the selection of outputs. 

for(;;)

{

switch(GPIO_ReadInputData(GPIOB) )

{

case 0: instruction 0; break;

case 1: instruction 1; break;

..

..

..

.. 

case 31:instruction n; break

default: instruction; brek

}

}

no problems with the compilation and debug. 

but every change of value of port B: I find no valid output

 
Andrew Neil
Chief II
Posted on January 08, 2011 at 18:11

''no problems with the compilation and debug''

 

What debugging have you actually done?

It would be a lot easier to debug if you read the value into an intermediate variable:

port_b_value = GPIO_ReadInputData(GPIOB);

switch( port_b_value ) ''but every change of value of port B: I find no valid output''

 

Pardon?

Note that you are constantly reading the value of port B, and running the switch() on it;

Wouldn't it be better to just run the switch() when the value has changed...?