Re: ADC problems Kategorie: Programmierung C (von Tobias - 30.07.2016 23:13) | |
Als Antwort auf Re: ADC problems von Bram Vooys - 30.07.2016 19:35
| |
> Hello there, > > I only get characters return and not (hex) decimal characters ? > > Help? > > > void main(void) > { > int ADC_Value; > > Serial_Init(0,SR_8BIT|SR_1STOP|SR_NO_PAR,SR_BD9600); > > while (true) > { > ADC_Set(0x40,0); > ADC_Value = (ADC_Read()); > Serial_WriteText(0,"AD0 = "); > Serial_Write(0,ADC_Value); > Serial_WriteText(0,":"); > Serial_Write(0,CR); > AbsDelay(100); > } > } > > Bram Dear Bram, the function "Serial_Write" send the value as a decimal value over the serial interface. The representation are ASCII-values. That's the reason why you see characters. As an example: If the AD-value is 65 digit you receive an "A". Please check for a better understanding the ASCII-table: ASCII-table For your task you must use another function: #define CR 0x0D void main(void) { int ADC_Value; char adc_string[10]; Serial_Init(0,SR_8BIT|SR_1STOP|SR_NO_PAR,SR_BD9600); while (true) { ADC_Set(0x40,0); ADC_Value = (ADC_Read()); Str_WriteInt(ADC_Value,adc_string,0); //Convert value to string Serial_WriteText(0,"AD0 = "); Serial_WriteText(0,adc_string); //Send value as string Serial_WriteText(0,":"); Serial_Write(0,CR); AbsDelay(100); } } Note: I have not tested the code, because I havn't an µC at present. It could be that you must adjust it a little bit. But you can see the way of programming. Best regards, Tobias | |
Antwort schreiben Antworten: |
Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum