你好,这是我用的一个最简单的sci发送接收的程序,是用串口调试助手发送一个数据,收到后再发送回去用调试工具显示接收的结果,你试试能不能用.我这里可以 #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" int i,j,k,m=0;char t[]={0xaa,0xff,0xa5,0x55}; void main() {DisableInterrupts; /*禁止中断*/ //初始化SCI SCI0BDL=0x34; /*波特率常数为52,设置波特率为9600*/ SCI0BDH=0x00;
SCI0CR1=0x00; //SCI0CR1_LOOPS=0; /*正常工作模式*/ //SCI0CR1_SCISWAI=0; /*等待模式下继续工作*/ //SCI0CR1_RSRC=0; /*LOOPS为零此位无效*/ //SCI0CR1_M=0; /*传输数据位为8位*/ //SCI0CR1_WAKE=0; /*介质唤醒方式*/ //SCI0CR1_ILT=0; /*保守检测*/ //SCI0CR1_PE=0; /*不进行奇偶校验*/ //SCI0CR1_PT=0; /*SCI0CR1_PE=0;此位无效*/ SCI0CR2=0x0c; //SCI0CR2_SCTIE=0; /*禁止发送器中断*/ //SCI0CR2_TCIE=0; /*禁止发送结束中断*/ //SCI0CR2_RIE=0; /*禁止接受中断*/ //SCI0CR2_ILIE=0; /*禁止空闲中断*/ //SCI0CR2_TE=1; /*发送允许*/ //SCI0CR2_RE=1; /*允许接受*/ //SCI0CR2_RWU=0; /*接收器正常唤醒*/ //SCI0CR2_SBK=0; /*中止符发送器关闭*/ i=SCI0SR1; i=SCI0DRL;
DDRB=0xff;
while(1) {
if(SCI0SR1_RDRF!=0){ PORTB=SCI0DRL; k=SCI0DRL;
if(SCI0SR1_TDRE==1){ SCI0DRL=k; /*发送字符串*/ SCI0DRH=0; m++; }
}
}
}
[此贴子已经被作者于2009-3-9 0:24:43编辑过] |