標(biāo)題: AVR_點(diǎn)亮LED程序 [打印本頁(yè)]

作者: liuqq    時(shí)間: 2015-5-22 01:11
標(biāo)題: AVR_點(diǎn)亮LED程序
//++++++++++++++++++++++++++++++++++
很糾結(jié)的用ICC AVR寫了個(gè)程序。調(diào)試通過(guò),木有仿真下載線。貌似挺貴,
窮人家的孩子買不起。鉆研下做個(gè)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單片機(jī)更加復(fù)雜,|運(yùn)算是關(guān)鍵
   
   DDRB=0XFF;
   PORTB=0XFF;
   while(1)
   {
   for(k=0;k<8;k++) //for語(yǔ)句
   {
   PORTB&=~BIT(k);//取反操作
   delay(500);//延時(shí)500ms
   
   PORTB|=BIT(k);
   delay(500);
   }
   }
}//我靠!寫完了。滾床睡覺(jué),很晚了, 明天是該死的體育考試,oh my god


作者: liuqq    時(shí)間: 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. }
復(fù)制代碼







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