本帖最后由 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();
- }
- }
- }
|