#include <mega16.h>
#include <delay.h>
#include <sleep.h>
char keycode[4][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
char key;
char findcolumn (char input)
{
if (input==1)
return 0;
else if ((input>>1)==1)
return 1;
else if ((input>>2)==1)
return 2;
else
return 3;
}
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
char row,column;
column=findcolumn(PINA & 0x0F);//determine the column of the pressed key
delay_ms(20);
PORTA=0xEF; //make row 0, Low
if ((PINA & 0x0F)!=0x0F)
row=0;
else
{
PORTA=0xDF; //make row 1, Low
if ((PINA & 0x0F)!=0x0F)
row=1;
else
{
PORTA=0xBF; //make row 2, Low
if ((PINA & 0x0F)!=0x0F)
row=2;
else
{
PORTA=0x7F; //make row 3, Low
if ((PINA & 0x0F)!=0x0F)
row=3;
}
}
}
key=keycode[row][column];
if (key==5 | key==10 | key==15) //if key 5,10 or 15 is pressed then ...
{
PORTB.1=1;
delay_ms(1000);
PORTB.1=0;
}
PORTA=0x0F;
}
void main(void)
{
/*initialization*/
// Global enable interrupts
#asm("sei"
sleep_enable();
while (1)
{
// Place your code here
powerdown();
};
}
copyright:امیر رهآافروز
#include <delay.h>
#include <sleep.h>
char keycode[4][4]={{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
char key;
char findcolumn (char input)
{
if (input==1)
return 0;
else if ((input>>1)==1)
return 1;
else if ((input>>2)==1)
return 2;
else
return 3;
}
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
char row,column;
column=findcolumn(PINA & 0x0F);//determine the column of the pressed key
delay_ms(20);
PORTA=0xEF; //make row 0, Low
if ((PINA & 0x0F)!=0x0F)
row=0;
else
{
PORTA=0xDF; //make row 1, Low
if ((PINA & 0x0F)!=0x0F)
row=1;
else
{
PORTA=0xBF; //make row 2, Low
if ((PINA & 0x0F)!=0x0F)
row=2;
else
{
PORTA=0x7F; //make row 3, Low
if ((PINA & 0x0F)!=0x0F)
row=3;
}
}
}
key=keycode[row][column];
if (key==5 | key==10 | key==15) //if key 5,10 or 15 is pressed then ...
{
PORTB.1=1;
delay_ms(1000);
PORTB.1=0;
}
PORTA=0x0F;
}
void main(void)
{
/*initialization*/
// Global enable interrupts
#asm("sei"

sleep_enable();
while (1)
{
// Place your code here
powerdown();
};
}
copyright:امیر رهآافروز
دیدگاه