74LS148 是带优先级的8-3编码芯片,对于外部的8路数据输入线,只要有1路或几路被置为0,编码芯片即会按由高到低的优先级进行编码,并由A2~A0引脚输出3位二进制数,而且GS引脚下会自动变为0。在没在任何输入法,8路数据线均为高电平,GS自动变为1。
另一组中断扩展,使用了四路输入的74LS21与门芯片,本例中,无论哪一个按键都会触发INT0中断,中断程序通过读(PINC)高4位即可知道是哪一个按键触发中断。
以下是Ptoteus 运行截图:
以下是Atmel Stduio
以下是程序清单:
- /*
- * GccApplication19.c
- *
- * Created: 2014-11-18 20:30:06
- * Author: Administrator
- */
- #define F_CPU 6000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include <stdint.h>
- #define LED_BLINK() PORTB ^=_BV(PB0)
- int main(void)
- {
- DDRA = 0xFF; PORTA = 0xFF;
- DDRB = 0xFF; PORTB = 0xFF;
- DDRC = 0xF0; PORTC = 0xFF;
- DDRD = 0x00; PORTD = 0xFF;
- MCUCR = 0x0a; //INT0,INT1中断下降沿触发
- GICR = 0xC0;
- sei();
-
- while(1)
- {
- LED_BLINK();
- _delay_ms(100);
- //TODO:: Please write your application code
- }
- }
- ISR(INT0_vect)
- {
- PORTC = PINC << 4 | 0x0F;
- }
- ISR(INT1_vect)
- {
- uint8_t bidx = (PIND>>4) & 0x07;
- PORTA = ~_BV(bidx);
- }
|