; Test of a decimal keyboard ; ; Reads the keyboard on port B and displays the activated key on the LEDs ; in hex format.; ; The decimal keyboard is attached to port B: ; Bit 6: *=Bit0 7=Bit1 4=Bit2 1=Bit3 ; Bit 5: 0=Bit0 8=Bit1 5=Bit2 2=Bit3 ; Bit 4: #=Bit0 9=Bit1 6=Bit2 3=Bit3 ; ; Tests with this program showed that parallel operation of the LEDs and ; of the keyboard on the same port (B) is practically impossible due to ; insufficient driving currents of the port pins. No correct values are read. ; ; 8515-Definitions .NOLIST .INCLUDE "C:\avrtools\appnotes\8515def.inc" .LIST ; ; Registers used .def mpko=R15 ; Last keyboard status .def mpr=R16 ; Multi-function register .def mpk=R25 ; Multi-function register for keyboard-interrupt ; ; RAM-Adresses .equ taste=$0060 ; First Ram-adress, here the pressed key will be placed ; ; Reset-/Interrupt vector table, most of the inactive rjmp main reti ; Ext Int 0 reti ; Ext Int 1 reti ; TC1 Capture rjmp test ; TC1 Compare A reti ; Compare B reti ; TC1 Overflow reti ; TC0 Overflow reti ; Serial Transfer Complete reti ; Serial Rx Complete reti ; Data Register Empty reti ; Serial Tx Complete reti ; Analog Comparator ; Main program main: ldi mpr,HIGH(RAMEND) ; Stack Pointer Init for Interrupts out SPH,mpr ldi mpr,LOW(RAMEND) out SPL,mpr ; General control register clr mpr ; no SRAM, no Wait, no Sleep-Mode, out MCUCR,mpr ; Ext.Int not used ; Port B is output und keyboard-Input ldi mpr,0x70 ; all as Output out DDRB,mpr ldi mpr,0x00 ; all lamps on out PORTB,mpr sts Taste,mpr ; ; Timer/Counter 0 init ldi mpr,$00 ; Prescaler = 256 out TCCR0,mpr ; Timer 1 init ldi mpr,0b00000000 ; Disable Timer Output and PWM-Mode out TCCR1A,mpr ; in Timer Control Register 1A ldi mpr,0b00001011 ; No input noise canceling, clear counter after ; match, Prescaler = 64 ==> 62500 Hz = 16 µs out TCCR1B,mpr ; in Timer Control Register 1B ldi mpr,HIGH(625) ; Compare-value in Compare-Register A out OCR1AH,mpr ; High Byte first ldi mpr,LOW(625) out OCR1AL,mpr ; Low Byte last ldi mpr,0xFF ; No Interrupt on Compare B out OCR1BH,mpr ; High Byte first out OCR1BL,mpr ; Low Byte last ; Interrupt start clr mpr ; External interrupts disable out GIMSK,mpr ; to General Interrupt mask register ldi mpr,0b01000000 ; Timer 1: Overflow Int Off, Compare A Int on, out TIMSK,mpr ; Compare B Int Off, Input Int Off, Timer 0: Int Off sei ; interrupt enable ; Incefinite Loop, all execution is interrupt-driven loop: rjmp loop ; Interrupt Routine for TC1 Compare Match B tc1ci: in mpk,SREG ; save Status-Register push mpk ldi mpk,0b11110000 ; Upper Nibble to output, lower to input out DDRB,mpk ; on Port B ldi mpk,0x0F ; Upper Nibble to zero, lower nibble sets Pullup resistors out PORTB,mpk in mpk,PINB ; Read result from keyboard cp mpk,mpko ; Compare with older value breq tc1cir ; ne change: return mov mpko,mpk ; Copy new status to old status sts taste,mpk ; New LED-Status tc1cir: ldi mpk,0xFF ; Port B to all output out DDRB,mpr lds mpk,taste ; pressed key to LEDs out PORTB,mpk pop mpk ; Return from Interrupt out SREG,mpk ; restore Status-Register reti tc0ci: ldi mpr,0xFF out PORTB,mpr reti tc2ci: ldi mpr,0xAA out PORTB,mpr reti test: ; LDI mpk,0x0F ; OUT DDRB,mpk ; LDI mpk,0xF0 ; OUT PORTB,mpk reti