打印
[Atmel]

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

[复制链接]
739|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 ddllxxrr 于 2014-12-1 19:50 编辑

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

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

Proteus仿真截图:

Atmel Studio6.2编译通过截图:


程序清单:






/*
* GccApplication25.c
*
* Created: 2014-12-1 19:10:48
*  Author: Administrator
*/

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

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

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

#define Key_NO (PINA&0x0F)

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

void Sounder()
{
        uint8_t i;
        for(i=0;i<100;i++)
        {
                _delay_us(190); BEEP();
        }
}



int main(void)
{
    DDRA = 0x00;PORTA = 0xFF;
        DDRC = 0xFF;PORTC = 0x00;
        DDRD = 0xFF;PORTD = 0xFF;
       
       
        while(1)
    {
        //TODO:: Please write your application code
                if(Key_Pressed)
                {
                     PORTC = SEG_CODE[Key_NO];
                         Sounder();
                }
    }
}









相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2398

主题

6950

帖子

67

粉丝