智能车制作

标题: 求mc9s12xs128流水灯程序 [打印本页]

作者: yuweiyang    时间: 2010-11-15 16:29
标题: 求mc9s12xs128流水灯程序
求mc9s12xs128流水灯程序
作者: sunhao11    时间: 2010-11-18 16:22
#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */

       char a=0;
   void PLL_int(void);

void main(void)
{   //int a;
   DDRA=0xFF;
                        // PORTA=0XFE;                  /* put your own code here */
   PLL_int();
   CRGINT_RTIE=1;
  
    RTICTL=0xF9;
           EnableInterrupts;
  for(;;)
   {
    _FEED_COP();              /* feeds the dog */
   }                        /* loop forever */
                           /* please make sure that you never leave main */
}
       void PLL_int() {
      
       CLKSEL_PLLSEL=0;
      POSTDIV=0;
      SYNR=0x44;
      REFDV=0x81;   
      while(!CRGFLG_LOCK);
       CLKSEL_PLLSEL=1;
       }
       #pragma CODE_SEG NON_BANKED
      void interrupt RTI_ISR()
      
       {               
         CRGFLG_RTIF=1;
          a=a<<1;
         if( a==0  )
         a=1; PORTA=a;
       }
作者: 隨風    时间: 2012-11-15 19:21
#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
unsigned char Data1[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
void Delay(unsigned int Time)
{
    unsigned char i;
    for(i=0; i<200; i++)
        for( Time=200; Time>0; Time--);
}
void main(void)
{
  unsigned char i;
  DDRB=0xFF;

  while(1)
  {
    for(i=0;i<8;i++)
    {
      PORTB=Data1[i];
      Delay(50000);
      Delay(50000);
     }
     if(i==8)
      {
      for(i=7;i>0;i--)
      {
      PORTB=Data1[i];
      Delay(50000);
      Delay(50000);
      }
    }
  }
}

新手··初学、共同进步~~
作者: 昌林旺旺    时间: 2012-11-17 23:15

#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#define uint unsigned int
#define uchar unsigned char

//同51和AVR的延时函数完全保持一致
void delay_ms(uint del) {

  uint i,j;
  for(i=0;i<del;i++)
  for(j=0;j<1827;j++);
}
//各种端口初始化
void port_init() {

   DDRB=0XFF;
   PORTB=0XFF;
}

//例程中所给的流水灯程序
/*void main() {
  uchar temp;
  DDRB=0XFF;
  temp=0;
  while(1) {
  
    switch(temp) {
   
      case 0: PORTB=0XFE;break;
      case 1: PORTB=0XFd;break;
      case 2: PORTB=0XFb;break;
      case 3: PORTB=0XF7;break;
      case 4: PORTB=0XEF;break;
      case 5: PORTB=0XDF;break;
      case 6: PORTB=0XBF;break;
      case 7: PORTB=0X7F;break;
    }
    temp++;
    if(temp==8) {
   
        temp=0;
    }
    delay_ms(500);
  }

} */


//完全从51单片机程序中移植过来的流水灯程序
void main() {

    uchar temp;
    uchar i;
    port_init();
   // DDRB=0XFF;
    while(1) {
   
        temp=0xfe;
        for(i=0;i<8;i++){
        
            PORTB=temp;
            delay_ms(50);
            temp=temp<<1; /*** 注意此处的变量temp变量是如何进行运算的
            开始时为1111 1110经过左移一位之后变为1111 1100左边的数字溢出,右边的数字
            补0,如果想要实现移位则需要将1111 1100与0000 00001进行或运算,以此来实现
            移位的运算****/
            temp =temp|0x01;
        }
    }
}

/***通过此程序可以看出MC9S12XS的程序和AVR单片机完全可以移植过来,只不过是在寄存器
的配置上会有所不同罢了 ***/
作者: 赵宇    时间: 2012-12-21 17:54
很好啊啊呵呵




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2