小弟编写S12单片机的SCI程序时总出问题,望指教!!
小弟是让单片机和PC能够进行简单的通信:PC发任意一个字符给单片机,单片机接受到后,给PC
发一定变量的值。程序如下:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
unsigned char a[4];
void SCI0_init(void) {
SCI0BDH=0x00;
SCI0BDL=0x9c;
SCI0CR1=0x00;
SCI0CR2=0x6c;
}
interrupt void SCI0_int(void){
//接受中断
if(SCI0SR1_RDRF==1){
while(!SCI0SR1_RDRF);
while (!SCI0SR1_TDRE); //确保发送缓存为空
SCI0DRL=a[1];
while (!SCI0SR1_TC); //确保发送完成
}
//发送中断
if(SCI0SR1_TC==1){
while (!SCI0SR1_TDRE); //确保发送缓存为空
SCI0DRL = a[2];
while (!SCI0SR1_TC); //确保发送完成
}
}
void main(void)
{
DisableInterrupts;
SCI0_init();
EnableInterrupts;
a[0]='a';
a[1]='b';
a[2]='c';
a[3]='d';
for (;;)
{
}
}
VECTOR ADDRESS 0xffd6 SCI0_int
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |