常驻嘉宾
- 积分
- 5654
- 威望
- 2351
- 贡献
- 1473
- 兑换币
- 1454
- 注册时间
- 2012-9-15
- 在线时间
- 915 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
//#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
unsigned char Data1[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
void SetBusCLK_64M(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x07;
REFDV=0x80 | 0x01;
POSTDIV=0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=128MHz;
_asm(nop); //BUS CLOCK=64M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void PIT_init(void)//定时中断初始化函数 5MS定时中断设置
{
PITCFLMT_PITE=0; //定时中断通道0关
PITCE_PCE0=1;//定时器通道0使能
PITMTLD0=64-1;//8位定时器初值设定,64分频,在64MHzBusClock下,为1MHz。即1us
PITLD0=1000-1;//16位定时器初值设定。PITTIME*0.125uS 即1ms中断一次
PITINTE_PINTE0=1;//定时器中断通道0中断使能
PITCFLMT_PITE=1;//定时器通道0使能
}
//void delay(int);
void main(void) {
unsigned char i;
i=0;
SetBusCLK_64M();
PIT_init();
while(1) {
DDRB=0xff;
PORTB=Data1[i];
}
}
void interrupt 66 PIT0(void){
int num,num2;
num++;
if(num>1999){
num=0;
num2++;
i++;
if(num2>7){
num2=0;
PORTB=0xff;
i=0;
}
}
}
|
|