How to interface PC keyboard to uC...

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Hi again,

i am trying to capture signal using capture mode...but the problem is how should i capture i mean it is showing 7F all the time is there any problem in it?
Rich (BB code):
void Capture_init()
{
   TRISC0 =1;    //Make PS2 CLK and DATA Pins as Input
   TRISC1 =1;
CCP2CON=0x04;    //Capture Every Falling Edge
   T1CON=0x04;      //Timer1 1:1 Prescale, Internal Clock
   TMR1H=0;
       TMR1L=0;
       CCP2IF=0;        //Clear the Interrupt Flag
 
}
Rich (BB code):
unsigned char Scan_Data()
{
    unsigned char Data=0,temp; 
    while(CCP2IF==0);   //Wait for First Falling Edge
    CCP2IF=0;     //Clear the Flag--Bcoz this is Start Pulse 
    for(char i=0;i<7;i++)                       
    {
 
        while(CCP2IF==0); //Capture the next 7 bits of data 
        CCP2IF=0;
        temp=RC0;
        temp<<=i;
        Data|=temp;
    }
 
    CCP2CON=0;
        __delay_ms(100);
        return(Data);        //return the data
}
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I would actually expect you to post a schematic drawing after this. Preferably drawn in a suited program. Not more software. Remember: First comes the hardware, then comes the software.
Now i have corrected that problem...
the problem was i have connected the led directly to uC pin the R was connected with GND due to which voltage drop was happening....
can u help me with PS2 code above?
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
First RRitesh, I know you have been on this site http://www.computer-engineering.org/ps2protocol/ Here we can read that PS/2 use a synchronous serial protocol Did you absorb ANY of that!! So then using asynchronous aproach. Do you not think that is most likely to fail. If you have no idea of what you do, then you will not be able to create anything either. Spending a lot of time using Google and then posting any code you think may work. And then asking for help will not either work. For crying out loud. Can you not just for once. Gather information, then based on that information. DO SOME CODING ON YOUR OWN. Even how painful you must think it is to actually read the datasheet, and then convert that information into code. Start simple by just setting up the PIC to use synchronous serial protocol. Then read any data from the latter port, convert it a alphanumeric hex string. And then send it to LCD
http://www.youtube.com/watch?v=ICr3ygRsJvE


Hi again,

This code is is for SPI in slave mode clk from PS2...WILL THIS BE OK?





Rich (BB code):
 void initialise_SPI(void); 
  unsigned char spi_r(void);


void main (){ 
  unsigned char temp ; 
  init_io(); 
  initialise_SPI(); 
  while(1) 
  {temp=spi_r(); 
  PORTD=temp; 
  } 
  }  
 void init_io(void){  
   TRSID=0X00;
  TRISC = 0b00011000;    
  
  } 
 void initialise_SPI(){  
  SSPSTAT=0b01000000;    
  SSPCON=0b00100100;    
  SSPEN = 1; 
  } 
  
 unsigned char spi_r(){ 
  unsigned char temp; 
  while(!SSPIF); 
  temp=SSPBUF;  
  return temp; 
 }
 
Top