#include /* common defines and macros */ #include /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12xdp512" #define LEDdate PORTB //为LED数据线接口 #define LEDdate_D DDRB //为LED的数据方向寄存器 #define LEDcs PORTK //LED位选接口 #define LEDcs_D DDRK void LedDelay(int n); //声明延时函数 //位选初始化,最高位为小数点显示位,0为显示 ,1为不显示 const unsigned char PK[]={0x7E,0x7D,0x7B,0x77,0x6F,0x5F}; //数据初始化,显示数据为0~9 const unsigned char Table[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; void MCU_CLK_Init(void){ SYNR = 0x02; //时钟合成寄存器 REFDV = 0x01; //时钟分频寄存器 //锁相环产生的时钟频率f=2*foscclk*(SYNR+1)/(REFDV+1) //对于S12dg128 16MHz外部晶体振荡器,总线时钟为24MHz //片内系统时钟为48MHz /*等待锁相环频率锁定*/ while((CRGFLG & 0x08) !=0x08); CLKSEL |= 0x80; //时钟选择寄存器 } //主函数 void main(void) { int i,j; EnableInterrupts;//允许中断 //初始化端口B和端口K的方向寄存器 MCU_CLK_Init(); LEDdate_D=0xFF; LEDcs_D=0xFF; //主循环 for(;;){ //外循环 for(i=0;i<6;i++){ LEDcs=PK[i]; //内循环 for(j=0;j<10;j++) { LEDdate=Table[j]; LedDelay(1000); } LedDelay(500); } } } //定义延时函数 void LedDelay(int n){ unsigned int i; unsigned int j; for(i=1;i0;j--); } }