中级会员
- 积分
- 208
- 威望
- 178
- 贡献
- 22
- 兑换币
- 0
- 注册时间
- 2009-11-2
- 在线时间
- 4 小时
|
1贡献
我的 程序是网上下的,然后如果不用PLL的 话是可以用的,我照着思路改波特率,然后用上PLL,用调试工具始终接受不到。。。郁闷哪。。。弄了好些天了 。。各位大哥大姐给看看吧?如果程序没问题的话还可能是?
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#include <ctype.h>
#include <string.h>
#include <stdarg.h>
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#pragma CODE_SEG DEFAULT
unsigned char uart_getkey(void)
{
while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
return SCI0DRL;
}
void uart_putchar(unsigned char ch)
{
while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
SCI0DRL=ch;
}
void putstr(char ch[])
{
unsigned char ptr=0;
while(ch[ptr]){
uart_putchar((unsigned char)ch[ptr++]);
}
}
void pll_Init(void)
{
CLKSEL = 0x00; //disengage PLL to system
PLLCTL_PLLON = 1; //turn on PLL
SYNR = 4;
REFDV = 1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=80MHz;
_asm(nop); //BUS CLOCK=40MHz
_asm(nop);
while(!(CRGFLG_LOCK == 1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL = 1; //engage PLL to system;
}
//-----------------------------------------------------
static void SCI_Init(void)
{
SCI0CR1 =0x00;
SCI0CR2 =0x2c; //enable Receive Full Interrupt,RX enable,Tx enable
SCI0BD =0x106; //SCI0BDL=busclk/(16*SCI0BDL)
//busclk 8MHz, 9600bps,SCI0BD=0x34
//busclk 16MHz, 9600bps,SCI0BD=0x68
//busclk 24MHz, 9600bps,SCI0BD=0x9C
} //busclk 32MHz, 9600bps,SCI0BD=0xD0
//busclk 40MHz, 9600bps,SCI0BD=0x106
void main(void){
pll_Init();
SCI_Init();
DDRA=0xFF;
uart_putchar(0x11) ;
EnableInterrupts;
for(;;)
{
}
} |
最佳答案
查看完整内容
回复 5# simpleliu
我忘了,倍频寄存器不一样。你把你邮箱给我,我发个程序你。
|