[求助]菜鸟求助,AW16的ICG怎么配置使用外置晶振呢?谢谢
- UID
- 153375
- 性别
- 男
|
[求助]菜鸟求助,AW16的ICG怎么配置使用外置晶振呢?谢谢
外部用16M晶振,怎么配置BUSCLK合适呢?现在在调试串口,被搞的一塌糊涂,怀疑是BUSCLK有问题,我配置了半天,BDM仿真,COMMAND串口总是显示MCU频率为4M,这个频率是什么频率呢? |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
你要确认外部晶振确实起振而且稳定了。然后配置寄存器再选择外部时钟即可。 |
|
|
|
|
|
- UID
- 343883
- 性别
- 男
|
不会吧,data里有例程,要按照例程写就行了,另外总线好像被4分频了,
串口的分频也要对 |
|
|
|
|
|
- UID
- 153375
- 性别
- 男
|
谢谢大家,我好像折腾明白了
void ICG_Init(void)
{
ICGC1 = 0b01111000;
ICGC2 = 0b00110000;
while(!ICGS1_LOCK);
SOPT=0x00;
}
外面改用4M晶振,这样搞了一下后BUSCLK为20M了:)
不过我还有个问题,做SCI和51串口通讯的时候,波特率为1200的时候可以搞定,为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)
{
SCI1BD = 1042;
//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 */
}
|
|
|
|
|
|