首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

SCI串口调试助手~~~

SCI串口调试助手~~~

我用串口调试助手想调试S12DG128模块的SCI部分,一直接收不到数据,忘版主帮忙看看程序~~~~~~~
#include /* common defines and macros */
#include /* derivative information */
#define U_char unsigned char
#define uint unsigned int
unsigned char count3=0,ch;
#define INBUF_LEN 4
unsigned char flag=0 ;
unsigned char inbuf1[INBUF_LEN];


#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

void SCI0Init(void) {

SCI0BDL = 52;

SCI0CR2 = 0x2C;

}
void send_string_com(U_char *address,U_char n)
{
U_char i;
SCI0CR2_RE=0; //接收禁止
SCI0CR2_TE=1; //发送允许
for(i=0;i=8;i++) {
while(!SCI0SR1_TC);
while(!SCI0SR1_TDRE);
SCI0DRL=*address;
// delay(1);
}
SCI0CR2_TE=0; //发送禁止
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED

interrupt 20 void SCI0_interrupt(void)
{
while(SCI0SR1_RDRF)
{
inbuf1[count3]=ch;
count3++;
if( (count3==(INBUF_LEN-1)))
{
flag=1;
}
}

}
#pragma CODE_SEG DEFAULT

void main(void)
{

SCI0Init();
// init_io();
EnableInterrupts;
for(;;)
{
if(flag) //如果取数标志位已置位,就将读到的数从串口发出
{
flag=0; //取数标志位清零
send_string_com(inbuf1,INBUF_LEN);
}
} /* wait forever */
}


我已经把工程传上去了,帮忙看一下,谢谢~~~
程序经过修改已经能收到数据了,但是用十六进制发送时收到乱码,不知道为什么~~~~~
#include /* common defines and macros */
#include /* derivative information */
#define U_char unsigned char
#define uint unsigned int
//#define INBUF_LEN 1 //Êý¾Ý³¤¶È
unsigned char flag=0 ;
unsigned char inbuf1;


#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

void SCI0Init(void) {

SCI0BDL = 52;

SCI0CR2 = 0x2c;

}
void send_string_com(U_char address)
{

while(!SCI0SR1_TDRE);

SCI0DRL=address;

}

#pragma CODE_SEG __NEAR_SEG NON_BANKED

interrupt 20 void SCI0_interrupt(void)
{
while(SCI0SR1_RDRF)

{
inbuf1=SCI0DRL;

flag=1;

}
}

#pragma CODE_SEG DEFAULT

void main(void)
{

SCI0Init();

EnableInterrupts;

for(;;)

{
if(flag!=0) //如果取数标志位已置位,就将读到的数从串口发出

{

flag=0; //取数标志位清零

send_string_com(inbuf1);//,INBUF_LEN);

}

} /* wait forever */

}


返回列表