I am trying to implement a program with the following functionality.
An SPI-Master sends 3 bytes of data to an SPI-Slave. For certain value of these data bytes, certain functions are to be called. For example
FF FF FF
calls the functionA
,FF FF FE
calls the functionB
, and so on.
One possible solution might be using switch case statement, however switching each possible case would be too long. Is there any other way to do this?
For example the last data byte has to set the PWM Dutycycle.
10 = 0000 1010
20 = 0001 0100
30 = 0001 1110
40 = 0010 1000
50 = 0011 0010
60 = 0011 1100
70 = 0100 0110
80 = 0101 0000
90 = 0101 1010
The Slave receives the last Byte and for each of these cases it has to set the duty cycle. The Second Byte determines prescaler. For example:
0000 00001 0000 1010
sets the prescaler to1
and duty cycle to10
0000 00010 0000 1010
would set prescaler to8
and duty cycle to10
and so on.
So there are like many different combinations possible, what is the best way to handle all the possible cases?