Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PS/2 keyboard with ATMEGA 32

Status
Not open for further replies.

djc

Advanced Member level 1
Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
Hi

Can anybody please guide me that how to write c code for PS/2 keyboard interfacing with AVR ATMEGA 32. I am using mikroC PRO for AVR compiler and EASY AVR5 developement kit. It doesn't have PS/2 socket so I bought one socket connected to keyboard connector and wires from PS/2 socket to respective pins of PORT C. I tried to use library for USART and PS/2 and TERA TERM hyperterminal program on Windows 7. Serial cable from development kit is connected to computer. I tried to change baud rate in example code provided to 9600 but i am geting no output. I followed same procedure for PIC 32 on PIC development board with mikroC PRO for PIC. There it's working fine. Please guide me.

Thanking You
 

HI
Sure, it's just an example given in the ps2 library.
Code:
unsigned short keydata = 0, special = 0, down = 0;


sbit PS2_Data         at PINC.B0;
sbit PS2_Clock_Input  at PINC.B1;
sbit PS2_Clock_Output at PORTC.B1;

sbit PS2_Data_Direction   at DDRC.B0;
sbit PS2_Clock_Direction  at DDRC.B1;

void main() {
  //PS_2_Data_Direction = 0;  //Data pin as input
  
  DDRC = 0x02;              //PORTC_1 as output
  
  UART1_Init(9600);        // Initialize UART module at 19200 bps
  Ps2_Config();             // Init PS/2 Keyboard
  Delay_ms(100);            // Wait for keyboard to finish


  do {
    if (Ps2_Key_Read(&keydata, &special, &down)) {
      if (down && (keydata == 16)) {// Backspace
       UART1_Write(0x08);
      }
      else if (down && (keydata == 13)) {// Enter
        UART1_Write('r');              // send carriage return to usart terminal
        //Usart_Write('n');             // uncomment this line if usart terminal also expects line feed
                                         // for new line transition
      }
      else if (down && !special && keydata) {
      if (down && !special && keydata) {
         UART1_Write(keydata);       //   and send data via UART
         }

      }
    }
    Delay_ms(10);            // debounce
   } while (1);
}
 

hi
20Mhz crystal i m using. Do you need any other information ? Is crysal any problem? I am using EASY AVR5 development kit.

Tanking you
 

djc send some data before do while loop if its sending then i then it may be mikroc pro ps2 bug for atmega like softuart bug in mikroc
 

Hi,
Thanx zia. Yes you are right. There must be some bug. Because there is no routine given to send the data on USART in library. I am trying to send the the like single character but it's not working. Can you please guide me regarding this.
 

hi
Please tell me the logic to write the C code to interface ps2 keyboard with ATMEGA 32 or any controller. I tried to read sevral posts but couldn't understand anythng. Please guide me on this. Where can i find good material about it, regarding logic and working of keyboard and all related material.
 


Thank you Istvan. Will try doing that. Thanx for the post.
 

HI Istvan,

I read your files however couldn't get anything. Moreover I dont want to use ps2 libraries. Please tell me some other solution.
 

hi djc i think the accurate data through serial is not transmitted due to crystal stability problem. check the transmissitted signal on oscilloscope or decrese baud rate it will work. such like using softuart using u=internal crytal doesnot work.
 

Hi zia,
So you are suggesting that baud rate should be decreased in the above code with 20 Mhz crystal. OK will try doing that too. Hope it will work.
Thank you
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top