aw16和51串口通讯的问题,低波特率可以连上,高不行。谢谢
- UID
- 153375
- 性别
- 男
|
aw16和51串口通讯的问题,低波特率可以连上,高不行。谢谢
做SCI和51串口通讯的时候,波特率为1200的时候可以搞定,为62500的时候就完蛋了,(因51方面限制,波特率必须要62500)用中断方式接收,能接收到,但接收的数不对。这是怎么回事呢?
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "mainhead.h"
#define GREEN PTFD_PTFD4
#define RED PTAD_PTAD0
#define ON 1
#define OFF 0
#define YES 1
#define NO 0
byte FlashDelayCon;
byte COMM_BUF;
#define LedFlash FLAG_FLAG0
#define RD_FLAG FLAG_FLAG1
/*定时器1溢出中断服务程序*/
interrupt VectorNumber_Vtpm1ovf void isrTimer1(void) /*10ms溢出一次*/
{
TPM1SC &= 0x7F;
if (++FlashDelayCon > 15)
{
FlashDelayCon = 0;
LedFlash = ~LedFlash;
}
}
/*SCI1接收中断服务程序*/
interrupt VectorNumber_Vsci1rx void isrSCI1(void)
{
if (SCI1S1_RDRF)
{
COMM_BUF = SCI1D; //存缓冲区内容
GREEN = ON;
RED = OFF;
RD_FLAG = YES;
}
}
/*发送一个字节*/
void SCI_SEND_1(byte BUF)
{
while (!SCI1S1_TDRE);
SCI1D = BUF;
while (!SCI1S1_TC);
GREEN = OFF;
RED = ON;
}
/*LED闪烁功能程序*/
void LEDFlashFun(void)
{
if (LedFlash)
{
GREEN = ON;
RED = OFF;
}
else
{
GREEN = OFF;
RED = ON;
}
}
/*ICG初始化*/
void ICG_Init(void)
{
ICGC1 = 0b01111000;
ICGC2 = 0b00110000;
while(!ICGS1_LOCK);
SOPT=0x00; /* important step!*/
}
/*IO端口初始化*/
void IO_Init(void)
{
PTFDD_PTFDD4 = 1; //设定PTF4为输出端口
PTADD_PTADD0 = 1; //设定PTA0为输出端口
}
/*定时器1初始化,用作时间基准*/
void TPM1_Init(void)
{
TPM1SC = 0b01001110; //TPM源为BUSCLK,64分频,允许溢出中断,启动计数
TPM1CNTH = 0x00; //每3.2uS计数一次
TPM1CNTL = 0x00; //初值清零
//最大计数209MS.
TPM1MOD = 3125; //每隔10ms溢出一次
}
/*串口初始化*/
void SCI_Init(void)
{
SCI1BDH = 0x00;
SCI1BDL = 0x14; //设定baud为62500,BUSCLK = 20M
SCI1C1 = 0x00; //8bit
SCI1C2 = 0x2C; //允许接收中断,接收和发送允许
}
void main(void)
{
DisableInterrupts;
ICG_Init();
IO_Init();
TPM1_Init();
SCI_Init();
FlashDelayCon = 0;
EnableInterrupts; /* enable interrupts */
/* include your code here */
GREEN = OFF;
RED = OFF;
for(;;)
{
//LEDFlashFun();
if (RD_FLAG)
{
RD_FLAG = NO;
if (COMM_BUF == 0x01)
{
SCI_SEND_1(0x08);
}
else
{
GREEN = ON;
}
}
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
|
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
你用示波器看看通讯波形,看看波特率是否准确。另外AW16的时钟是否够精确? |
|
|
|
|
|
- UID
- 153375
- 性别
- 男
|
|
|
|
|
|
- UID
- 529491
- 性别
- 男
|
以下是引用strongchen在2007-9-7 9:51:00的发言: 你用示波器看看通讯波形,看看波特率是否准确。另外AW16的时钟是否够精确? 在发送数据的时候用示波器看? |
|
|
|
|
|