I’m using MIOS_AIN_Pin7bitGet() to get an unsigned 7 bit value (0-127) from my pots.
Some of the pots need to handle parameters as signed values -63 to +63 where center is 0.
I’m able to transmit the correct values over MIDI by:
parameter += 0x40;
parameter &= 0x7f;
However, I’m having trouble displaying the values correctly on the LCD.
Positive values are showing up fine, but as I turn into the negative range, the value is displayed as if it were unsigned (because ‘parameter’ is unsigned).
How can I display an unsigned char as a signed 7bit value?
Also, the MIOS_LCD_PrintBCD2 functions are not printing leading zeros eg " 6" instead of “06”.
Can anyone suggest a straight forward way of printing the zero?
; --------------------------------------------------------------------------
;; print dec value -64..63
CS_MENU_PRINT_PMDec7
movwf TMP1
movlw ' ' ; space or "-"?
btfss TMP1, 6; (if value <= 0x3f (6th bit cleared), print "-"
movlw '-'
call MIOS_LCD_PrintChar
CS_MENU_PRINT_PMDec7_WO_Sign
movf TMP1, W ; calc: 0x40-value
sublw 0x40
btfsc WREG, 7 ; negate value if negative to get absolute value
negf WREG, ACCESS
goto MIOS_LCD_PrintBCD2 ; and print it
[/code]
The same in C:
[code]
if( value \< 64 ) {
MIOS\_LCD\_PrintChar('-');
MIOS\_LCD\_PrintBCD2(64-value);
} else {
MIOS\_LCD\_PrintChar(' ');
MIOS\_LCD\_PrintBCD2(value-64);
}
The same for MIOS32:
MIOS32_LCD_PrintFormattedString("%3d", (int)value - 64);
[/code]
[code]
; --------------------------------------------------------------------------
;; print dec value patted with 0
CS\_MENU\_PRINT\_Dec000
clrf MIOS\_PARAMETER1
call MIOS\_HLP\_Dec2BCD
movf MIOS\_PARAMETER2, W
call MIOS\_LCD\_PrintHex1
movf MIOS\_PARAMETER1, W
goto MIOS\_LCD\_PrintHex2
The same in C:
MIOS_HLP_Dec2BCD(value);
MIOS_LCD_PrintHex1(MIOS_PARAMETER2);
MIOS_LCD_PrintHex2(MIOS_PARAMETER1);
[/code]
The same for MIOS32:
[code]
MIOS32\_LCD\_PrintFormattedString("%03d", value);
MIOS_LCD_BCD* uses MIOS_HLP_Dec2BCD internally, and removes the leading zeroes by spaces.
If you want to output leading zeroes, just print the original BCD code (binary coded digits, each digit is coded in 4 bits) with MIOS_LCD_PrintHex2 (to print the rightmost binary coded digits) resp. MIOS_LCD_PrintHex1 (to print a single (the leftmost) binary digit)
I changed the C example code (removed the bitshifting), so that it matches with the example given in the documentation.