用AtmelStudio6.2跑mega16例程(32)拨码盘控制LED

[复制链接]
 楼主| ddllxxrr 发表于 2014-10-10 22:35 | 显示全部楼层 |阅读模式
根据拨码盘的状态来显示数字。因为拨码盘是7位最多255外数字。所以再主程序转换成要显的字模后显示。
原理图如下:




程序:
  1. /*
  2. * GccApplication15.c
  3. *
  4. * Created: 2014-10-10 21:55:49
  5. *  Author: Administrator
  6. */

  7. #define F_CPU 8000000UL
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. #include <stdint.h>
  11. const int8_t SEG_CODE[] = {0x3F,0x06,0x58,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  12. int8_t DSY_Buffer[3] = {0,0,0};       
  13. int main(void)
  14. {
  15.     while(1)
  16.     {
  17.        uint8_t i,Num;
  18.            DDRC = 0xFF;PORTC = 0xFF;
  19.            DDRB = 0xFF;PORTB = 0xFF;
  20.            DDRD = 0x00;PORTD = 0xFF;
  21.            while(1)
  22.            {
  23.                 Num = PINB;
  24.                         DSY_Buffer[0] = Num / 100;
  25.                         DSY_Buffer[1] = Num /10 % 10;
  26.                         DSY_Buffer[2] = Num % 10;
  27.                         for(i=0;i<3;i++)
  28.                         {
  29.                             PORTD = ~_BV(i+1);
  30.                                 PORTC = SEG_CODE[DSY_Buffer[i]];
  31.                                  _delay_ms(80);
  32.                         }
  33.            }
  34.     }
  35. }



本帖子中包含更多资源

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

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

本版积分规则

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

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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