[Atmel] 用AtmelStudio6.2跑mega16例程(62)74C922扩展按键

[复制链接]
 楼主| ddllxxrr 发表于 2014-12-1 19:49 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2014-12-1 19:50 编辑

74C922为16按键,键盘扩展芯片。工作电压3-5V可直接跟单片机相连。

本例十分简单在按下键时,数码管显示哪个键子被按下。

Proteus仿真截图:

Atmel Studio6.2编译通过截图:


程序清单:






  1. /*
  2. * GccApplication25.c
  3. *
  4. * Created: 2014-12-1 19:10:48
  5. *  Author: Administrator
  6. */

  7. #define F_CPU 6000000UL
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. #include <stdint.h>

  11. #define BEEP() PORTD ^= _BV(PD7)

  12. #define  Key_Pressed ((PINA&0x80) == 0x80)

  13. #define Key_NO (PINA&0x0F)

  14. const uint8_t SEG_CODE[] = {0x3F,0x06,0x5b,0x4F,0x66,0x6d,0x70,0x07,
  15. 0x7F,0x6F,0x77,0x7c,0x39,0x5E,0x79,0x71};

  16. void Sounder()
  17. {
  18.         uint8_t i;
  19.         for(i=0;i<100;i++)
  20.         {
  21.                 _delay_us(190); BEEP();
  22.         }
  23. }



  24. int main(void)
  25. {
  26.     DDRA = 0x00;PORTA = 0xFF;
  27.         DDRC = 0xFF;PORTC = 0x00;
  28.         DDRD = 0xFF;PORTD = 0xFF;
  29.        
  30.        
  31.         while(1)
  32.     {
  33.         //TODO:: Please write your application code
  34.                 if(Key_Pressed)
  35.                 {
  36.                      PORTC = SEG_CODE[Key_NO];
  37.                          Sounder();
  38.                 }
  39.     }
  40. }









本帖子中包含更多资源

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

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

本版积分规则

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

2403

主题

6994

帖子

68

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

2403

主题

6994

帖子

68

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