void main(void)
{ int i,t,n;
unsigned char len = 0;
unsigned char str[10] = {' '};
unsigned char pulse[10]= {' '};
unsigned char s_H;
unsigned char s_L;
set_32MHZ();
uart_init(SYS_CLOCK_32MHZ , UART_BAUD_9600);
//uart_sendstring("hello world!
" , 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;
}
}
}
此帖出自
小平头技术问答
你现在整个处理流程都有问题,我提两点建议:
1. 把十六进制转十进制写成一个函数,函数接受两个字符的数组,返回一个整型。
2. 你串口接收凑够了两个字符之后,调用1的函数。
一周热门 更多>