

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


.MICRO "ATmega16" .TOOLCHAIN "GCC" .GCCPATH "C:\WinAVR" .GCCMAKE AUTO .TARGET "my_idea.hex" .SOURCE "my_idea.c"
.TRACE ; Activate micro trace
.POWER VDD=5 VSS=0 ; Power nodes .CLOCK 1meg ; Micro clock .STORE 250m ; Trace (micro+signals) storage time
; KEYBOARD SPECS, USING PORTA [ro-r3]=[PA0-PA3] [c0-c3]=[PA4-PA7] X1 KEY4x4 PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA
; 8 Pull down resistors, [R1-R4]=[r0=r3] [R5-R8]=[c0-c3] R1 PA0 VSS 10K R2 PA1 VSS 10K R3 PA2 VSS 10K R4 PA3 VSS 10K R5 PA4 VSS 10K R6 PA5 VSS 10K R7 PA6 VSS 10K R8 PA7 VSS 10K
; 4 LEDs to find which key has been pressed D1 VDD PB D2 VDD PB D3 VDD PB D4 VDD PB
#include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here
// Main program // int main(void) { unsigned char check1, check2, result; unsigned comb[] = {0x00,0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x ,0x88};
unsigned portcomb[] = {0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x E,0x0F}; int i;
while(1) { // for LEDs DDRB = 0x0F;
// checking for Column: DDRA = 0x0F; PORTA = 0x0F; check1 = PINA;
// checking for Row: DDRA = 0xF0; PORTA = 0xF0; check2 = PINA;
// result: result = ((check1 & 0xF0) | (check2 & 0x0F));
for (i=0;i<17;i++) { if(result==comb[i]) { PORTB=~(portcomb[i]); } }