wsgypb 发表于 2010-12-5 20:04

那位大虾帮忙看一下!

那位大虾帮忙看一下这个mc9s12xs128的串口程序那里错了!该怎么写!唉!小弟是刚学单片机不久的!!特向各位请教了!在这先感谢了!!!


#include <hidef.h>      /* common defines and macros */
#include <MC9S12XS128.h>   /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define ReSendStatusR SCI0SR1
#define ReTestBit 5
#define SendTestBit 7
#define ReSendDataR SCI0DLR
unsigned char INT8U;
void SCIInit(void);
//void SCISend1(INT8U o)
//void SCIRel(INT8U *p)
#ifndef ISR_H
#define ISR_H
#define ENABLE_INTERRUPTS _asm_("cli")
#define DISABLE_INTERRUPTS _asm_("sei")
#define EnableSCIReInt SCI0CR2 |=0x20
#define DisableSCIReInt SCI0CR2 &=0xdf
#endif
void SCIInit(void)
{
INT8U t;
SCI0BDL=0x80;
SCI0BDH=0x00;
t=SCI0DRL;
t=SCI0SR1;
SCI0CR2=0x2c;
}
void _attribute_((interrupt)) ISR_Receive(void)
{
INT8U i;
INT8U SerialBuff;
DISABLE_INTERRUPTS;
i=SCIReN(1,SerialBuff);
if (i==0) SCISendN(1,SerialBuff);
ENABLE_INTERRUPTS;
}
void _attribute_((interrupt)) ISR_Empty(void)
{
}
void main(void)
{
DISABLE_INTERRUPTS;
SCIInt();
EnableSCIReInt;
ENABLE_INTERRUPTS;
void ISR_Receive(void);
void _attribute_((interrupt)) ISR_Receive(void);
void _start(void);

/* put your own code here */
//EnableInterrupts;
for(;;) {




         } /* wait forever */
             /* please make sure that you never leave this function */
}

必有我师 发表于 2010-12-6 14:38

什么单片机啊?

wsgypb 发表于 2010-12-6 15:17

不好意思!刚接触单片机没两个月!!不知道你问的是不是这个:FreescaleMC9S12XS128
终于有人回复了!!你是第一个!谢谢你了!

wsgypb 发表于 2010-12-7 21:02

额!一个串口初始化!用查询或者中断模式接收发送!!

void SCI_Init(void)
{
    SCI0CR1 =0x00;
    SCI0CR2 =0x2c; //enable Receive Full Interrupt,RX enable,Tx enable      
    SCI0BD=0x106; //SCI0BDL=busclk/(16*SCI0BDL)
                  //busclk8MHz, 9600bps,SCI0BD=0x34
                  //busclk 16MHz, 9600bps,SCI0BD=0x68
                  //busclk 24MHz, 9600bps,SCI0BD=0x9C
}               //busclk 32MHz, 9600bps,SCI0BD=0xD0
                  //busclk 40MHz, 9600bps,SCI0BD=0x106
中断模式
#pragma CODE_SEG __NEAR_SEG NON_BANKED

void interrupt 20SCI0_ISR(void)
{   
unsinged char i;                                 //此处为串口中断需要处理的事情
i=SCI0DRL ;
SCI0SR1_RDRF = 0;   
}
页: [1]
查看完整版本: 那位大虾帮忙看一下!