-1

i'm trying to make a calculator which needs two keyboards with ATMEGA16A i have wrote a code for getting input from the keyboard and it's working on PORTB but the same code (with just changing B to C)doesn't work on PORTC!!

please help me i'm getting crazy :(

 while(y[1]== 0 || y[0] ==24) 
        {
            getB(y);
            if(y[1]== 0 || y[0] ==24)
            {
                getC(y);
            }
        }

    int* getB(int *y)
{
    int key;
    DDRB = 0x0F;
    PORTB = 0xF0;
    delay_ms(5);
    key = PINB;
    DDRB = 0xF0;
    PORTB = 0x0F;
    delay_ms(5);       
    key = key | PINB;
    delay_ms(10); 
    if(key != 0xFF) {keyboardB(y);}
    return y;
}

int* keyboardB(int* y)
{
    DDRB = 0x0F;

    PORTB.0 = 1;
    PORTB.1 = 0;
    PORTB.2 = 0;
    PORTB.3 = 0;
    if(PINB.5 == 1){y[0] = 14; y[1] = 1; lcd_puts("*");while(PINB.5 == 1){PORTD.0 = 1;}PORTD.0 = 0;return y;}
    if(PINB.4 == 1){y[0] = 15; y[1] = 1; lcd_puts("/");while(PINB.4 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.6 == 1){y[0] = 13; y[1] = 1; lcd_puts("-");while(PINB.6 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.7 == 1){y[0] = 12; y[1] = 1; lcd_puts("+");while(PINB.7 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    //=================================================
    PORTB.0 = 0;
    PORTB.1 = 1;
    PORTB.2 = 0;
    PORTB.3 = 0;
    if(PINB.5 == 1){y[0] = 9; y[1] = 1; lcd_puts("9");while(PINB.5 == 1){PORTD.0 = 1;}PORTD.0 = 0;return y;}
    if(PINB.4 == 1){y[0] = 11; y[1] = 1; lcd_puts("=");while(PINB.4 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.6 == 1){y[0] = 6; y[1] = 1; lcd_puts("6");while(PINB.6 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.7 == 1){y[0] = 3; y[1] = 1; lcd_puts("3");while(PINB.7 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    //=================================================
    PORTB.0 = 0;
    PORTB.1 = 0;
    PORTB.2 = 1;
    PORTB.3 = 0;
    if(PINB.5 == 1){y[0] = 8; y[1] = 1; lcd_puts("8");while(PINB.5 == 1){PORTD.0 = 1;}PORTD.0 = 0;return y;}
    if(PINB.4 == 1){y[0] = 0; y[1] = 1; lcd_puts("0");while(PINB.4 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.6 == 1){y[0] = 5; y[1] = 1; lcd_puts("5");while(PINB.6 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.7 == 1){y[0] = 2; y[1] = 1; lcd_puts("2");while(PINB.7 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    //=================================================
    PORTB.0 = 0;
    PORTB.1 = 0;
    PORTB.2 = 0;
    PORTB.3 = 1;
    if(PINB.4 == 1)     //Mode
    {
        //delay_ms(1000);
        //if(PINB.4 == 1) {while(PINB.4 == 1){}y[0] = 10; y[1] = 1; return y;}
        //else {y[0] = 10; y[1] = 0; return y;}  //value of y[0] is not important
        y[0] = 24; y[1] = 1;while(PINB.4 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;
    }
    if(PINB.5 == 1){y[0] = 24; y[1] = 1;while(PINB.5 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.6 == 1){y[0] = 24; y[1] = 1;while(PINB.6 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
    if(PINB.7 == 1){y[0] = 24; y[1] = 1;;while(PINB.7 == 1){PORTD.0 = 1;}PORTD.0 = 0; return y;}
}
Mina
  • 1
  • 2
  • 1
    This can have many reasons: Is the second function of some pins on portc activated? (i.e. TWI)? Some typo in the PORTC-Code (It would have been better to post this one instead of the working PORTB-Code)? Of course the circuit may be erroneous (by design or by a bad connection). Some GPIO-Pins in PORTC may be defunct, you should measure their function one by one. You would have to provide all relevant code and probably the circuit itself – Ctx Jan 20 '16 at 15:51

1 Answers1

1

Most probably you did not deactivated the JTAG Port that uses some Pins on Port C. Look at the fuses and set them to deactivate the JTAG to be able to use the port in your application.

vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80