PS2接口协议解析及应用
CLK =1;
DATA =1; //send 1 to P1 then read P1
if(CLK ==1)
{
delay_us(30);
}
if(CLK==1 && DATA==1) //send data
{
DATA =0; //start bit 0
delay_us(10);
CLK =0;
delay_us(5);
temp =x;
for(i=0;i<8;i++) //send 8 bits LSB first
{
CLK =1;
delay_us(5);
char_temp = temp & 0x01;
if ( char_temp == 0x01)
{
DATA =1;
}
else
{
DATA =0;
}
//DATA=(bit)(temp&0x01);
//LSB
delay_us(10);
CLK = 0;
delay_us(5);
temp = temp>>1;
}
CLK = 1; //send check bit