Well, I want to change the time of a RTC IC by input a command line from terminal.
Example:
settime,10,20,30,40,50,60,70
There's an array to store the time information. Example:
Code:
unsigned char time[7] = {0x00,0x30,0x09,0x01,0x03,0x00,0x11};
I use a for loop and the strtok to separate the string into
10
20
30
40
50
60
70
Code:
unsigned char time[7] = {0x00,0x30,0x09,0x01,0x03,0x00,0x11}; // original data
unsigned char newtime[7];
unsigned char * tmp;
int x;
if (strncmp(uart_tmp, "settime", 7) == 0)
{ tmp = strtok(uart_tmp, ",");
for (x=7; x>0; x--)
{ tmp = strtok(NULL,",");
newtime[x-1] = tmp;
printf ("tmp: %s, newtime[%d] %d\n", tmp, (x-1), newtime[x-1]);
}
When I type in "settime,10,20,30,40,50,60,70":, the output shows:
tmp: 10, newtime[6] 20
tmp: 20, newtime[5] 23
tmp: 30, newtime[4] 26
tmp: 40, newtime[3] 29
tmp: 50, newtime[2] 32
tmp: 60, newtime[1] 35
tmp: 70, newtime[0] 38
Then, how can I repalce the array content with these seven data?
Thanks.