|
大神们,在IAR里面十六进制转成十进制为什么不成功,读取数值范围是0x0f-0x3f
[复制链接]
void main(void)
{ int i,t,n;
unsigned char len = 0;
unsigned char str[10] = {'\0'};
unsigned char pulse[10]= {'\0'};
unsigned char s_H;
unsigned char s_L;
set_32MHZ();
uart_init(SYS_CLOCK_32MHZ , UART_BAUD_9600);
//uart_sendstring("hello world!\r\n" , 14);
while(1)
{ unsigned char p;
int sum=0;
str[i] = uart_readstring(str , 10);
s_H=(str[i]&0xf0)>>4;
s_L=str[i]&0x0f;
if(len == 0)
{
for(i=0;str[i];i++)
{
if( s_H <='9')
t=s_H-'0';
else t=s_H-'A'+10;
if (s_L <='9')
n=s_L-'0';
else n=s_L-'A'+10;
sum=t*16+n;
}
p=3000/sum;
pulse[i]=p;
U0DBUF = *pulse;
uart_sendstring(pulse, len);
// len = 0;
}
}
}
|
|