谁有飞思卡尔单片机串口模块收发数据的程序,发个详细的帮我理解,谢谢!

2024-12-18 23:41:01
推荐回答(2个)
回答1:

#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "MC9S08AW32.h"
/*************************************************************************/
/**************************define function********************************/
void InitICG();
void InitSCI0();
void InitGPIO();
void interrupt 17 Vsci0rx_isr(void);
void SCIProcess();
void TransSCI(byte ReceivedByte);
/*************************************************************************/
/**************************define parameter********************************/
byte ReceivedByte;
int IsSCI;
void InitSCI0()
{
SCI1C1=0x00;
SCI1C2=0x2C;
SCI1C3=0x00;
SCI1BDH=0x00;
SCI1BDL=0x1a; //baud=9600;
}
__interrupt void Vsci0rx_isr(void)
{
IsSCI=1;
if(SCI1S1_RDRF)
ReceivedByte=SCI1D;//存缓冲区内容
ReceivedByte+=1;
}
void TransSCI(byte TransByte) //发送一个字节
{
while(SCI1S1_TDRE==0);
SCI1D=TransByte;
}
/*********************main()*****************************************/
void main(void)
{
IsSCI = 0;
InitSCI0();
EnableInterrupts;
for(;;)
{
__RESET_WATCHDOG();

if(IsSCI==1)
{
TransSCI(ReceivedByte);
IsSCI=0;
}
}
}

回答2:

还不错