高级会员
- 积分
- 594
- 威望
- 390
- 贡献
- 88
- 兑换币
- 37
- 注册时间
- 2012-7-28
- 在线时间
- 58 小时
|
程序如下,请懂的人不吝赐教一下,多谢啦!!!
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include<mc9s12g128.h>
//#include"PLL.h"
unsigned char b[]="ranbeabcdefg";
unsigned char a[]={'h','e','l','l','o',' ','w','o','r','l','d','!','!','!',' '};
int i;
void delayms(int z){
int x, y;
for(x=z;x>0;x--)
for(y=8010;y>0;y--);
}
/*********************************
****************PLL***************
**********************************/
void SetBusCLK_nM(byte nM)
{
MMCCTL1=0X00;
PKGCR =0X06;
DIRECT =0x00;
IVBR =0xFF;
ECLKCTL=0xC0;
CPMUPROT =0x26; //停止保护时钟配置寄存器
CPMUCLKS_PSTP=0; //
CPMUCLKS_PLLSEL=1; //应用PLL
//CPMUSYNR =nM-1; //设置分频因子
CPMUSYNR =0xc0|(nM-1); //设置分频因子
CPMUREFDIV =0x80|0x00; //pllclock=2*(1+SYNR)= MHz;
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPLL =0x10; // Set the PLL frequency modulation
while(CPMUFLG_LOCK == 0); /* Wait until the PLL is within the desired tolerance of the target frequency */
CPMUPROT=0x00; /* Enable protection of clock configuration registers */
}
//初始化
//-----------------------------------------------------
static void SCI_Init(void)
{
SCI0CR1 =0x00; ///注意这里的SCI0CR2yekeyi改为0x0c,因为这里没有中断
SCI0CR2 =0x2c; //0x2c,enable Receive Full Interrupt,RX enable,Tx enable
SCI0BD =312; //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 SCI_Tx(unsigned char shuju) {
unsigned char temp;
/*clear flag* 状态寄存器 */
while(!(SCI0SR1&0x80));
// while((SCI0SR1_TC&0x80));
temp=SCI0SR1;
SCI0DRH = 0;
SCI0DRL = shuju;
}
unsigned char SCI_Rev(unsigned char shuju)
{
unsigned char temp;
temp=SCI0SR1; /*clear flag* 状态寄存器 */
while(!(SCI0SR1&0x20));
shuju = SCI0DRL;
temp=SCI0SR1;
return(shuju);
}
void main(void) {
DDRD = 0xff;
PORTD = 0x00;
SetBusCLK_nM(48);
SCI_Init();
for(;;){
// for(i=0;i<15;i++)
// {
// SCI_Rev(a[i]); ?????????为什么串口助手非的改成十六进制显示才可以呢
// SCI_Tx('e');
// SCI_Rx(a[i]); //向串口发送
// delayms(10);
// }
SCI_Tx('0');
delayms(500);
}
}
|
|