Is it comment or a part of instruction -- not clear?
Inconsistent -- data is in decimal base and RAM address is in hex base? Shouln't both be of the same base?
The ; symbol:
Everything that comes after the ; character is a comment.
The machine ignores it.
Only the instruction before the ; is the real code.
You cannot load data directly into I/O registers like 0xC4 or 0xC5.
You must first load the value into a working register (like r16 or r17) using ldi, and then move it to the final address using sts.
So, in the line:sts 0xC5, r17 Copy number 0 from drawer r17 into speed box 0xC5
sts 0xC5, r17 is the real instruction that the processor executes.
Copy number 0... is just the comment explaining what happens.
From your answer, it appears that either you are a bot or you have used a bot to know the answer as this not the answer to my question.
yes , The compiler handles all the conversions automatically. It translates decimals, hexadecimals (0x), and binary numbers (0b) into the exact same raw binary code (ones and zeros) that the processor understands.
For the hardware, it makes no difference. Using decimal for data and hex for memory addresses is just a common habit for human programmers because:
- Addresses (
0xC4) are easier to find in datasheet memory maps when written in hex. - Values (
103) are often easier to think about in decimal.
This is exactly why spending even just a few minutes playing with Assembly (ASM) is so useful, even for simple projects. It helps you really understand core concepts like int, char, or signed numbers. Learning these things from theory books can be very boring, but seeing how they work directly in registers and memory makes everything click!
it's pretty common syntax that hex #s are prefixed with 0x, sometimes octal just with a leading 0, otherwise the value is decimal if not suffixed with a 'd'. In some cases binary values are suffixed with a 'b'.
this is one reason why symbols, as well as keywords cannot start with a digit. for example "r16" is a keyword in this assembler.
this is lexical analysis. parsing then processes tokens which are keywords and operators (e.g. +, ==, ...), symbols and numeric values (hex, decimal, octal). don't forget about parenthesis and braces
another approach, avoiding the float processing limitation when formating the string is to multiply the float by 100 and transmitt them as integers. this way sprintf() and sscanf() can just format and decoder the string as "%s,%d,%d,%d"
This works on a Mega2560
double a = 12.34;
double b = 34.56;
char a_str[8] = "";
char b_str[8] = "";
char out_str[16] = "";
char* in_double = "";
double a_double = 0.0;
double b_double = 0.0;
int loopcount = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
// convert doubles to char arrays to send
dtostrf(a,6,2,a_str);
Serial.println(a_str);
dtostrf(b,6,2,b_str);
Serial.println(b_str);
sprintf(out_str,"%s,%s",a_str,b_str);
Serial.println(out_str);
delay(1000);
// parse char array and convert to double
in_double = strtok(out_str,",");
a_double = atof(in_double);
while(in_double != NULL){
if(loopcount == 0) {
Serial.println(in_double);
in_double = strtok(NULL,",");
b_double = atof(in_double);
}
loopcount++;
}
loopcount = 0;
Serial.println();
// read new values test
a = a + 1.1;
b = b + 2.2;
delay(1000);
}
not quite. looks like sscanf() has a hard time extracting the string up to the comma. So put it last
output. rec shows what it received
rec: 97,123,987,5:30
97
1.23
9.87
5:30
send: 97,123,987,5:30
struct {
char time [10];
float temp;
float volt;
int id;
} data;
const float K = 100.0;
const char *Fmt = "%d,%d,%d,%s";
char s [90];
// -----------------------------------------------------------------------------
void
rec (
char *s )
{
Serial.print ("rec: ");
Serial.println (s);
int temp;
int volt;
sscanf (s, Fmt, &data.id, &temp, &volt, data.time);
data.temp = temp /K;
data.volt = volt /K;
// dump values
Serial.print (" "); Serial.println (data.id);
Serial.print (" "); Serial.println (data.temp);
Serial.print (" "); Serial.println (data.volt);
Serial.print (" "); Serial.println (data.time);
}
// -----------------------------------------------------------------------------
void
send ()
{
char s [90];
Serial.print ("send: ");
int temp = K*data.temp;
int volt = K*data.volt;
sprintf (s, Fmt, data.id, temp, volt, data.time);
Serial.println (s);
}
// -----------------------------------------------------------------------------
void loop ()
{
if (Serial.available ()) {
char buf [90];
int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
buf [n] = '\0';
rec (buf);
send ();
}
}
// -----------------------------------------------------------------------------
void setup ()
{
Serial.begin (9600);
Serial.println (" serial tx/rx");
}
I am not sure what is going on but the "Solution" button is not greyed out for me
I think it could be interpreted as being "grayed out" because (at least with the light forum theme), the control is gray in color:

However, this coloration does not indicate that the control is disabled. If you click on that, you will find that it does cause the post to be marked as a solution:
![]()
@bill_lancaster please give it a try. If it doesn't work, just let us know and we'll investigate further.
The solution button is now functioning, it still looks greyed-out but it works
But now the button does not respond and I need to unset the 'Solution' status
What happens when you click on the green, ticked box alongside the green "Solution" text ?
It briefly show a 'forbidden' symbol then its greyd-out