标题:
SCI 如何自动发送数据
[打印本页]
作者:
lingyun1
时间:
2011-8-24 09:39
标题:
SCI 如何自动发送数据
这是我的程序;但一直不能自动显示字符串:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
unsigned char uchar;
unsigned int uint;
void InitMCG (void)
{
MCGC2 = 0x00;
while(!MCGSC_LOCK);
MCGC2 = 0x36;
while (!MCGSC_OSCINIT);
MCGC1 = 0x38;
while (MCGSC_IREFST);
while(!MCGSC_LOCK);
while (MCGSC_CLKST != 0x00);
}
void SciBrInit(void)
{
SCI1BDH=0X00;
SCI1BDL= 8000000/16/9600; //设置波特率
SCI1C1&=0xec;
}
void SciEnable(void)
{
SCI1C2 = 0x2C; //允许发送,允许接受 ,允许接收中断
while(SCI1S1_TDRE==0); //发送一个空字节
SCI1D=0xFF;
}
void SciSendByte(uchar value)
{
while(SCI1S1_TDRE==0); //等待发送数据寄存器为空
SCI1D=value;
}
void SciSendString(uchar *pt) //*pt是字符串的指针
{
while(*pt)
{
SciSendByte(*pt++);
}
}
void main()
{
DisableInterrupts;
SOPT1_COPT=0; //禁止看门狗
SciEnable();
InitMCG();
SciBrInit () ;
SciSendString("xitong");
EnableInterrupts;
for(;;) //等待接收
{
;
}
}
interrupt 17 void SCIRecInt(void)
{
uchar receivedata;
while(SCI1S1_RDRF==0);
receivedata=SCI1D;
SciSendByte(receivedata);
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0