智能车制作
标题:
新人急求救!!!请大神看一下我这个实验程序(SCI收发)
[打印本页]
作者:
dessertfox
时间:
2013-1-24 17:07
标题:
新人急求救!!!请大神看一下我这个实验程序(SCI收发)
我的单片机是MC9S08JM60,有两个SCI(SCI1和SCI2),现在想SCI1接一个ASCII码字符串,SCI2发出去结果程序老不通,求大神门看一眼指导一下,小弟先行谢过!!!
字符串如:$GPGGA,123.436..........
程序如下:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
byte a;
byte i=0;
unsigned char Msg[];
void SendMsg(unsigned char msg[])
作者:
dessertfox
时间:
2013-1-24 17:16
程序没贴完:
从这里看:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
byte a;
byte i=0;
unsigned char Msg[];
void SendMsg(unsigned char msg[])
{
byte ix=0; // String pointer
byte dummy; // 读取SCI1S1
byte nxt_char;
SCI2C2_TE = 1; //允许发送器
dummy = SCI2S1; // 清除TDRE
nxt_char = msg[ix++]; //取出要发送的数据
while(nxt_char != 0x00) { //如果没有到字符串结尾
SCI2D = nxt_char; // 清除TDRE第二步
nxt_char = msg[ix++]; //数据送缓冲区后,取下一个
while(!SCI2S1_TDRE){ ;} //等待缓冲区空
}
while(!SCI2S1_TC){ ;} //等待最后一个字符发送完成
SCI2C2_TE = 0;
}
void main(void){
SCI1BD =9500000/16/9600; // 设置波特率
//
SCI2BD=9500000/16/9600;
SCI2C2=0X00;
SCI1C2=0X00;
for(;;){
SCI1C2_RE=1;
while(1)
{
while(SCI1S1_RDRF==0){};
a=SCI1D;
while(a!=0x24){};
Msg[i]=SCI1D; //接收数据寄存器满之后接收数据,并存到msg[]中
if((Msg[i-2]==0x26))
{i=0;SCI1C2_RE=0;break;}
i++;
}
SendMsg(Msg[i]);
}}
错误是“SendMsg(Msg[i])” type mismatch(expected“unsigned *char”given“unsigned char”)
作者:
wolflsh
时间:
2013-1-24 19:14
粗略看了下
第一、void SendMsg(unsigned char msg[]) 哪有这样定义指针的。 void SendMsg(unsigned char *msg)
第二、SendMsg(Msg[i]); 数组名实质是地址,但加了[i]表示变量,所以,要SendMsg(&Msg[i]);
其他的就不说了。
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2