高级会员
- 积分
- 772
- 威望
- 297
- 贡献
- 293
- 兑换币
- 0
- 注册时间
- 2010-1-16
- 在线时间
- 91 小时
|
3#
楼主 |
发表于 2010-3-13 12:03:18
|
只看该作者
- #include <hidef.h> /* common defines and macros */
- #include <MC9S12XS128.h> /* derivative information */
- #pragma LINK_INFO DERIVATIVE "mc9s12xs128"
- //unsigned char g,s,b,q;
- unsigned char table[]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90,0xff };
- void delay(unsigned int t)
- { unsigned int i,j;
- for(i=0;i<t;i++)
- for(j=0;j<110;j++);
- }
- void disp(unsigned char g,unsigned char s,unsigned char b,unsigned char q)
- { DDRM=0xff;
- DDRH=0xff;
- PTM=0b00000001;
- PTH=table[g];
- delay(20);
- PTM=PTM<<1;
- PTH=table[s];
- delay(20);
- PTM=PTM<<1;
- PTH=table[b];
- delay(20);
- PTM=PTM<<1;
- PTH=table[q];
- delay(20);
- }
- void PLL_Init(void) //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)
- { //锁相环时钟=2*16*(2+1)/(1+1)=48MHz
- REFDV=1; //总线时钟=48/2=24MHz
- SYNR=2;
- while(!(CRGFLG&0x08));
- CLKSEL=0x80;
- }
- void pwminitial0()
- {
- PWMPOL=0X81; //通道0、7输出波形开始极性为高 output waveform which high first then low when the duty counter is reached
- PWMCAE=0x80; //0左对齐输出模式、7居中对齐 output left align waveform
- PWMCLK=0X81; //PWM时钟源为0 SA,7-SB SAClock SA is the clock source for PWM channel 0
- PWMPRCLK=0X23; //时钟A8分频 Clock A is 24MHz/8=3MHz
- PWMSCLA=0X96; //时钟SA为3MHz/300=10khz
- PWMSCLB=0X96;
- PWMPER0=100; //设定输出周期=通道时钟周期*20 f=100hz
- PWMPER7=100;
- PWMDTY0=50; //占空比初始为0 Duty is 50%,and PWM waveform's frequent is 16
- PWMDTY7=50;
- PWME=0X81; //通道0使能 enable pwm channel 0
- }
- /*void pwminitial1()
- {
- PWMPOL=0X02; //通道1输出波形开始极性为1 output waveform which high first then low when the duty counter is reached
- PWMCAE=0x02; //居中对齐输出模式 output left align waveform
- PWMCLK=0X03; //PWM时钟源为 SAClock SA is the clock source for PWM channel 1
- PWMPRCLK=0X06; //时钟A8分频 Clock A is 8MHz/8=1MHz
- PWMSCLA=0Xff; //时钟SA为1MHz/128/2 Clock SA is 1MHz/128/2=4KHz
- PWMPER1=122; //设定输出周期=通道时钟周期*256
- PWMDTY1=61; //占空比初始为0.5 Duty is 50%,and PWM waveform's frequent is 16
- PWME=0X02; //通道1使能 enable pwm channel 0
- }*/
- void main()
- {
- pwminitial0();
- DDRA=0xff;
- // pwminitial1();
- for(;;) {
- PORTA_PA1=PTP_PTP7;
- PORTA_PA3=PTP_PTP0;
- PORTA_PA4=0;
- PORTA_PA5=0;
- PORTA_PA6=0;
- PORTA_PA7=0;
- PORTA_PA0=1;
- // PORTA=PTP;
- if(PORTA_PA3==0&&PORTA_PA1==1)
- disp(1,10,10,10) ;
- else if(PORTA_PA3==0&&PORTA_PA1==0)
- disp(10,2,10,10) ;
- else if(PORTA_PA3==1&&PORTA_PA1==0)
- disp(10,10,3,10) ;
- else//(PTP_PTP0==1&&PTP_PTP1==1)
- disp(10,10,10,4) ;
- }
- /* please make sure that you never leave this function */
- }
复制代码 |
|