I want to use timers of ATmega 32 ( PD4 and PD5 ) for pwm

mean while i'm using Port D for keypad

the available ports for me is PA7 and PC7

i want to know how can i change my code of keypad init. to make PD4 and PD5 not used by KeyPad to use them for servo and buzzer as pwm

like moving R1 to PC7 and R1 to PA7

note : all other ports are used by LCD and Leds and seven segment

those are the initialization of Keypad in my code

 #define F_CPU 8000000UL            /* Define CPU Frequency e.g. here 8MHz */
    #include <avr/io.h>            /* Include AVR std. library file */
    #include <util/delay.h>            /* Include inbuilt defined Delay header file */

    //Keypad Information
    #define R0 0
    #define R1 1
    #define R2 2
    #define R3 3
    #define C0 4
    #define C1 5
    #define C2 6
    #define C3 7

    #define keypadPORT PORTD
    #define keypadPIN PIND
    #define keypadDDR DDRD

     //Keypad functions and global variables
char getkey();
int keypadRow[] = {R0, R1, R2, R3}; //rows of the keypad
int keypadCol[] = {C0, C1, C2, C3};//column

    unsigned char Key_Pressed(void)
        unsigned char row,col,key_num;
        while (1)
            for (col=0;col<4;col++)
                DDRD = (0b00010000<<col);
                PORTD = (~(0b00010000<<col));

                for (row=0;row<4;row++)
                    if (!(PIND & (1<<row)))
                        key_num = row*4+col+1;
                        return key_num;
  • \$\begingroup\$ i don't see any keypad init code that you are talking about ...... did you leave out a part of your code? \$\endgroup\$ – jsotola Mar 24 at 3:18
  • \$\begingroup\$ Yes those are the initialization functions for starting keypad to work, they are for determining which key is pressed and using them later in if statement \$\endgroup\$ – Hassan Khaled Bosha Mar 24 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.