Hallo!
I wrote something like:
----------------------- VERSION that works ---------------------
void switchLEDs(unsigned char pattern, unsigned char and){
unsigned char i;
unsigned char pos;
for (i = 0; i < 8; i++){
MIOS_DOUT_PinSet1(32);
MIOS_DOUT_PinSet1(33);
MIOS_DOUT_PinSet1(34);
MIOS_DOUT_PinSet1(35);
MIOS_DOUT_PinSet1(36);
MIOS_DOUT_PinSet1(37);
}
}
This works.
BUT: all trials to make the pin setting dynamically depending on i failed!
----------------------- VERSION 1 that does not work ---------------------
void switchLEDs(unsigned char pattern, unsigned char and){
unsigned char i;
unsigned char pos;
for (i = 0; i < 8; i++){
MIOS_DOUT_PinSet1(32 + i);
}
}
This do not work, even if I use the temporär variable pos to store the result
of 32 + i. I thougth: ok, if it is a compiler bug and MIOS_DOUT_PinSet1 needs a contant parameter I reprogrammed it:
----------------------- VERSION 2 that does not work ---------------------
void switchLEDs(unsigned char pattern, unsigned char and){
unsigned char i;
unsigned char pos;
MIOS_DOUT_PinSet1(37); //see below!
for (i = 0; i < 8; i++){
switch(i){
case 0: MIOS_DOUT_PinSet1(32); break;
case 1: MIOS_DOUT_PinSet1(33); break;
case 2: MIOS_DOUT_PinSet1(34); break;
case 3: MIOS_DOUT_PinSet1(35); break;
case 4: MIOS_DOUT_PinSet1(36); break;
case 5: MIOS_DOUT_PinSet1(37); break;
}
}
}
This didn’t work, too. No pin is set, except pin 37. This was to indicate the function itselfs is called. I tried another version, with ifs:
----------------------- VERSION that works ---------------------
void switchLEDs(unsigned char pattern, unsigned char and){
unsigned char i;
unsigned char pos;
MIOS_DOUT_PinSet1(37);
for (i = 0; i < 8; i++){
if (i == 0) MIOS_DOUT_PinSet1(32);
else if (i == 1) MIOS_DOUT_PinSet1(33);
else if (i == 2) MIOS_DOUT_PinSet1(34);
else if (i == 3) MIOS_DOUT_PinSet1(35);
else if (i == 4) MIOS_DOUT_PinSet1(36);
else if (i == 5) MIOS_DOUT_PinSet1(37);
}
}
Even this did not work! Only LED 37 ligths.
If I look at the *.asm the call of MIOS_DOUT_PinSet1(constant) is always the same. Independently if there are switches or ifs around it. But only the “pure” constant method above works.
I have no ideas. The *.asm seem to be ok.
As you can guess, the parameter “pattern” is the bit-pattern which of the LEDs 32-37 shall lit. But this is future…even the primitive varants do not work.
I have no idea.