智能车制作

标题: MC9S12DG128调试小程序,流水灯---旨在帮助新手入门,共同提高! [打印本页]

作者: wysh320    时间: 2009-3-7 13:56
标题: MC9S12DG128调试小程序,流水灯---旨在帮助新手入门,共同提高!

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

void Delay(unsigned int Time)
{
    unsigned char i;
    for(i=0; i<125; i++)
        for( ; Time>0; Time--);
}


void main(void)
{
unsigned char i,k;
DDRB=0XFF;

while(1)
{
    i=0xfe;
    for(k=0;k<8;k++)
    {
        PORTB=i;
        i<<=1;
        i+=0x01;
        Delay(50000);
        Delay(50000);

    }

  /* put your own code here */  
}
}

作者: wysh320    时间: 2009-3-7 14:00
/*同样的功能可以有不同的写法,借此比较一下*/

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"


unsigned char Data[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char Data1[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};


void Delay(unsigned int Time)
{
    unsigned char i;
    for(i=0; i<125; i++)
        for( ; Time>0; Time--);
}


void main(void)
{
  unsigned char i;
  DDRB=0xFF;

  while(1)
  {
    for(i=0;i<8;i++)
    {
      PORTB=Data1;
      Delay(50000);
      Delay(50000);

    }
  }
}
[img][/img]

作者: chenrunshe_007    时间: 2009-3-10 14:13
第二中方法都没有用到Data[8],设置它干嘛?
作者: chenrunshe_007    时间: 2009-3-12 09:26
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
这条语句是干嘛用的?
作者: chenrunshe_007    时间: 2009-3-22 18:43
请教如上
作者: yihai_11    时间: 2009-3-28 17:04
提示: 作者被禁止或删除 内容自动屏蔽
作者: chenrunshe_007    时间: 2009-3-29 14:26
无所谓大家共同学习我也是菜鸟一个 6# yihai_11
作者: xiaoxin77799    时间: 2009-4-2 09:52
敢问这程序是如何点亮小灯的,是单方向呢,还是从两侧一起呢?
作者: chengyongji    时间: 2009-4-5 14:11
可以不用延时程序来使他亮一段时间。
作者: chenrunshe_007    时间: 2009-4-16 18:43
貌似是单方向的 8# xiaoxin77799
作者: gallen    时间: 2009-6-23 15:49
可以用自带的计数器来延时用
作者: gladstone    时间: 2009-7-4 13:48
第二种main 中的 for循环里面 i 没起作用啊 !! 端口数据始终是第一个 没变啊  !!!不懂了

我是新手,来学习了
作者: 飞车达人    时间: 2009-7-7 16:54
请问 你的延时是多久,调试 的时候,在哪里可以看出来
作者: wysh320    时间: 2009-7-12 11:39
这是另一种亮灯的方式  恰好事data1的反模式~~~【抱歉  迟到的答复】 3# chenrunshe_007
作者: wysh320    时间: 2009-7-12 11:42
i 的作用就是循环调用data数组的数据 12# gladstone
作者: 封疆大吏    时间: 2009-12-30 16:08
有没有更简单的啊?
作者: CCGOGO    时间: 2011-2-22 10:24
新手一个  过来学习~  嘿嘿
作者: 隨風    时间: 2012-11-15 19:05
wysh320 发表于 2009-3-7 14:00
/*同样的功能可以有不同的写法,借此比较一下*/

#include       /* common defines and macros */

       PORTB=Data1;

少了个i 哦





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