使用C将uint32_t十六进制值转换为ascii十进制LCD

时间:2015-02-08 04:40:30

标签: c microcontroller cortex-m3

我只是想知道是否有人对如何将uint32_t十六进制值转换为ascii十进制并将其显示到LCD有任何见解。算法会有所帮助,因此我可以使用C代码对其进行编程。我得到的十六进制值来自我采用的ADC并转换为LCD。 ADC数据给出16位值,lcd为16x2

void Hex2DecToLCD(){

算法在这里

}

此致

1 个答案:

答案 0 :(得分:0)

void Hex_To_BCD_To_LCD(uint32_t ADCData)

 {

   char BCD[5];

   uint32_t Dig_0, Dig_1, Dig_2, Dig_3, Dig_4;

   int i = 0;

   uint32_t temp = 0x0;

   uint32_t bin_inp = ADCData;

   bin_inp *= 0x8; // scale up the ADC value

   temp  = bin_inp;

   Dig_4 = temp/10000;

   BCD[4] = Dig_4 + 0x30;

   temp  = temp - (Dig_4 * 10000);
   Dig_3 = temp/1000;
   BCD[3] = Dig_3 + 0x30;
   temp  = temp - (Dig_3 * 1000);

   Dig_2 = temp/100;
   BCD[2] = Dig_2 + 0x30;
   temp  = temp - (Dig_2 * 100);

   Dig_1 = temp/10;
   BCD[1] = Dig_1 + 0x30;
   temp  = temp - (Dig_1 * 10);

   Dig_0 = temp;
   BCD[0] = Dig_0 + 0x30;

 //Data to LCD
for (i =0; i < 5; i++){

     Data_To_LCD(BCD[i++]);

   }
}