uint8_t taste = 0;
#define ta1 0b00001110 //Switch definations You can also use tamul or tadiv
#define ta2 0b00001101
#define ta3 0b00001011
#define ta4 0b00000111
#define ta5 0b00011110
#define ta6 0b00011101
#define ta7 0b00011011
#define ta8 0b00010111
#define ta9 0b00101110
#define ta10 0b00101101
#define ta11 0b00101011
#define ta12 0b00100111
#define ta13 0b00111110
#define ta14 0b00111101
#define ta15 0b00111011
#define ta16 0b00110111
//...
uint8_t readtast (void)
{
uint8_t r = 0, i = 0;
DDRB = 0b00000001;
PORTB = 0b00001110;
r = PINC & 0b00001111;
if (r<0x0F)
{
i=r;
}
DDRB = 0b00000010;
PORTB = 0b00001101;
r = PINC & 0b00001111;
if (r<0x0F)
{
i=r+0x10;
}
DDRB = 0b00000100;
PORTB = 0b00001011;
r = PINC & 0b00001111;
if (r<0x0F)
{
i=r + 0x20;
}
DDRB = 0b00001000;
PORTB = 0b00000111;
r = PINC & 0b00001111;
if (r<0x0F)
{
i=r+0x30;
}
if ( i == 0b00001111)
{
i=0;
}
return i;
}
void dosome (uint8_t tasi)
{
switch (tasi)
{
case ta1:
asm ("nop");
// do something
break;
case ta2:
asm ("nop");
// do something other
break;
//...
}
}
int main(void)
{
DDRC = 0b00000000;
PORTC = 0b00001111;
DDRB = 0b00000000;
PORTB = 0b00001111;
//sei();
while (1)
{
//asm ("nop");
taste = readtast(); //Repeated action has to be avoid not in code yet
dosome(taste);
// Place your code here
}
}