Hello everyone…
I’m trying to convert 12bit decimal numbers to single ascii chars and stumbled over this quite helpful mios function MIOS_HLP_Dec2BCD(unsigned int value)…
However, the numbers generated from MIOS seem to be others than I would expect following the descriptions. My AC-Sim debugger produces the right numbers (I implemented a function that does exactly what I would MIOS expect to do: 12345 => 0x1, 0x23, 0x45 in MIOS_PARAMETER3, -2 and -1):
// from the debug_mios.c file that simulates MIOS
extern void MIOS_HLP_Dec2BCD(unsigned int value) {
// decimals to hex (eg 123456 to 0x12, 0x34, 0x56)
unsigned char a;
unsigned char b;
// get 100.000
a = (unsigned char)(value / 100000);
b = (unsigned char)((value / 10000) - (a * 10));
MIOS_PARAMETER3 = (a << 4) + b;
// get 1.000
value = value - (a * 100000 + b * 10000);
a = (unsigned char)(value / 1000);
b = (unsigned char)((value / 100) - (a * 10));
MIOS_PARAMETER2 = (a << 4) + b;
// get 10
value = value - (a * 1000 + b * 100);
a = (unsigned char)(value / 10);
b = (unsigned char)(value - (a * 10));
MIOS_PARAMETER1 = (a << 4) + b;
}
I tried to debug this with MIOSStudio, but I don’t know where to find MIOS_PARAMETER1 to -3 (tried to read RAM from 0x0 to 0x0f, but couldn’t get anything back :-[ ) before I have to rewrite an asm-optimized custum function (huh, I’m an ASM-Idiot), I try the forum, maybe anyone knows a hint for me? google has way too much unrelated search resuls and I can’t believe it would take so much complicated code to do a dec2BCD-conversion ??? This is the relevant code so far: (input 0..127 => 0..4064 (12bit) => ‘0’..‘4’,‘0’,‘6’,‘4’) …just produces unordered garbage numbers in the range from 0 to 8149
#define NUM2ASCII(num) (num + 0x30)
unsigned char IIC_SPEAKJET_Transmit12bit(unsigned short value) __wparam {
unsigned char c;
unsigned char result = 0;
MIOS_HLP_Dec2BCD(value);
/* // skipping param3: hundret-thousands
c = MIOS_PARAMETER3 >> 4;
if(c > 0) { result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); }
// param3: ten-thousands
c = MIOS_PARAMETER3 & 0x0F;
if((c > 0) || result) { result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); }
*/
// param2: thousands
c = MIOS_PARAMETER2 >> 4;
if(c > 0) { result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); }
// param2: hundrets
c = MIOS_PARAMETER2 & 0x0F;
if((c > 0) || result) { result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); }
// param1: tens
c = MIOS_PARAMETER1 >> 4;
if((c > 0) || result) { result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); }
// param2: ones
c = MIOS_PARAMETER1 & 0x0F;
result = IIC_SPEAKJET_TransmitByte( NUM2ASCII(c) ); // also transmit '0'
return result;
}
void IIC_SPEAKJET_OSCFreq(unsigned char osc, unsigned short value, unsigned char valueIs14bit) __wparam {
// osc = 1..5, value = 0..16383 or 0..127
unsigned short value12bit;
if(valueIs14bit) {
value12bit = value;
} else {
// value is 0..127, SCP_FREQ_MAX is 3999
value12bit = value << 5; // 0..4064 (12 bit)
}
IIC_SPEAKJET_TransmitStart(0);
// write frequency to register
IIC_SPEAKJET_Transmit12bit(value12bit);
IIC_SPEAKJET_TransmitByte(SCP_MEMWRT);
IIC_SPEAKJET_TransmitStop();
}
thanksalot,
Michael ![]()