欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: AVR_點亮LED程序 [打印本頁]

作者: liuqq    時間: 2015-5-22 01:11
標題: AVR_點亮LED程序
//++++++++++++++++++++++++++++++++++
很糾結的用ICC AVR寫了個程序。調試通過,木有仿真下載線。貌似挺貴,
窮人家的孩子買不起。鉆研下做個AVR ISP還是比較靠譜,加油!
+++++++++++++++++++++++++++++++++++//
#include <iom16v.h>
#include <macros.h>
#define  uchar unsigned char
#define  uint  unsigned int
void delay(uint ms)
{
    uint i,j;
for(i=0;i<ms;i++)
    {
    for(j=0;j<1141;j++);
       }
}
void main()
{
   uchar k;
   DDRA|=BIT(2);
   PORTA|=BIT(2);//我表示AVR的位操作比51單片機更加復雜,|運算是關鍵
   
   DDRB=0XFF;
   PORTB=0XFF;
   while(1)
   {
   for(k=0;k<8;k++) //for語句
   {
   PORTB&=~BIT(k);//取反操作
   delay(500);//延時500ms
   
   PORTB|=BIT(k);
   delay(500);
   }
   }
}//我靠!寫完了。滾床睡覺,很晚了, 明天是該死的體育考試,oh my god


作者: liuqq    時間: 2015-5-22 01:17
  1. #include <iom16.h>

  2. #include <macros.h>


  3. /* This seems to produce the right amount of delay for the LED to be

  4. * seen

  5. */

  6. void Delay()

  7. {

  8. unsigned char a, b;


  9. for (a = 1; a; a++)

  10. for (b = 1; b; b++)

  11. ;

  12. }


  13. void LED_On(int i)

  14. {

  15. PORTB = ~BIT(i);        /* low output to turn LED on */

  16. Delay();

  17. }


  18. void main()

  19. {

  20. int i;

  21. DDRB = 0xFF;        /* output */

  22. PORTB = 0xFF;        /* all off */


  23. while (1)

  24. {

  25. /* forward march */

  26. for (i = 0; i < 8; i++)

  27. LED_On(i);

  28. /* backward march */

  29. for (i = 8; i > 0; i--)

  30. LED_On(i);

  31. /* skip */

  32. for (i = 0; i < 8; i += 2)

  33. LED_On(i);

  34. for (i = 7; i > 0; i -= 2)

  35. LED_On(i);

  36. }

  37. }
復制代碼







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1