[Atmel] 用AtmelStudio6.2跑mega16例程(25)依次点亮LED

[复制链接]
950|0
 楼主| ddllxxrr 发表于 2014-10-3 19:56 | 显示全部楼层 |阅读模式
在GCC AVR里,#include <stdint.h>用来定义了数据类型。
如:

typedef signed char int8_t
typedef unsigned char uint8_t
typedef signed int int16_t
typedef unsigned uint16_t
typedef signed long int int32_t
typedef unsigned long int uint32_t

所以再用时就不用定义了,直接用就行:

程序就是使LED循环地点亮.

  1. /*
  2. * GccApplication9.c
  3. *
  4. * Created: 2014-10-3 19:31:56
  5. *  Author: Administrator
  6. */

  7. #define F_CPU 8000000UL
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. #include <stdint.h>
  11. int main(void)
  12. {
  13.    int8_t b=0,direction=0;
  14.    DDRA=0xFF;
  15.    while(1)
  16.    {
  17.          if(direction==0)
  18.          PORTA = 0x01<<b;
  19.          else
  20.          PORTA = 0x80 >>b;
  21.          if(++b==8)
  22.          {  
  23.            b=0;
  24.            direction = !direction;
  25.          }
  26.          _delay_ms(60);
  27. }
  28. }
以下是仿真结果:


以下是Studio中的编译截图:




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7002

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部