حولت كود من لغة السي ل bascom
بس ما اشتغلش ؟
محتاج مساعدة ؟
-------------
كود c والموضوع كامل
http://www.qariya.info/vb/showthread.php?t=115437
------------
كود:
#define data PORTB.f0
#define command PORTB.f1
#define clock PORTB.f2
#define att PORTB.f3
#define ack PORTB.f4
unsigned char natg[6];char dd ;
void ps_clock(){ // Void For Make Plus 0 And 1 All The Time
clock=0;
delay_us(10);
clock=1;
delay_us(10);
}
void psinit(){
char x;
att=0;
command=1;
ps_clock();
for(x=0;x<7;x++){ /// 0x01
command=0;
ps_clock(); }
while(ack==1){}
command=0;
ps_clock();
command=1;
ps_clock();
for(x=0;x<4;x++){ ///// 0x42
command=0;
ps_clock(); }
command=1;
ps_clock();
command=0;
ps_clock();
while(ack==1){}
for(x=0;x<8;x++){ ///// 0x00
command=0;
ps_clock(); }
}
unsigned char psnatg(){
ps_clock(); // Void For Get Bit
dd = data;
return dd;
}
unsigned char get_ps_byte(){
char n;
unsigned char ps_byte = 0;
unsigned char temp_ps = 0;
// Void For Get Byte
for(n=0 ; n<8 ; n++){
temp_ps = psnatg();
ps_byte >>= 1;
if (temp_ps == 1) {
ps_byte += 0x80; // 128 // 10000000
}
}
return ps_byte;
}
char cc;
void main() {
trisb=17;trisd=0;portd=0;PORTB.f7=0;
while(1){
att=1;clock=1;command=1;
psinit(); // Initialize The PS2 Controller
command=0;
for(cc=0;cc<6;cc++){
while(ack==1){} // Recive BYTEs
natg[cc] = get_ps_byte(); }
att=1;
if(natg[0]==247||natg[0]==254){PORTB.f7=~PORTB.f7;delay_ms(250);}
if(natg[1]==239||natg[1]==223){PORTD.f1=~PORTD.f1;delay_ms(250);}
if(natg[2]==0||natg[2]==255){PORTD.f2=~PORTD.f2;delay_ms(250);}
if(natg[4]==0||natg[4]==255){PORTD.f3=~PORTD.f3;delay_ms(250);}
}
}
--------------------
كود باسكوم الى حولتو
كود:
$regfile = "m32def.dat"
$crystal = 8000000
Ddrb = &B11101110
Config Portd = Output
Portd = &B00000000
Pinb.7 = 0
Dataa Alias Pinb.0
Command Alias Portb.0
Clock Alias Portb.2
Att Alias Portb.3
Ackk Alias Pinb.4
Dim Dd As Byte
Dim Ps_byte As Byte
Dim Cc As Byte
Dim Natg(8) As Byte
Dim Z As Byte
Do
Att = 1
Clock = 1
Command = 1
Gosub Psinit
Command = 0
For Cc = 0 To 7 Step 1
While Ackk = 1
nop
Wend
Natg(cc) = Ps_byte
Next Cc
Att = 1
Z = 0
If Natg(z) = 247 Or Natg(z) = 254 Then
Toggle Portd.0
Waitms 250
End If
Z = 1
If Natg(z) = 239 Or Natg(z) = 223 Then
Toggle Portd.1
Waitms 250
End If
Z = 2
If Natg(z) = 0 Or Natg(z) = 255 Then
Toggle Portd.2
Waitms 250
End If
Z = 4
If Natg(z) = 0 Or Natg(z) = 255 Then
Toggle Portd.3
Waitms 250
End If
Loop
End
Psinit:
Dim X As Byte
Att = 0
Command = 1
Gosub Ps_clock
For X = 0 To 7 Step 1
Command = 0
Gosub Ps_clock
Next X
While Ackk = 1
nop
Wend
Command = 0
Gosub Ps_clock
Command = 1
Gosub Ps_clock
For X = 0 To 4 Step 1
Command = 0
Gosub Ps_clock
Next X
Command = 1
Gosub Ps_clock
Command = 0
Gosub Ps_clock
While Ackk = 1
nop
Wend
For X = 0 To 7 Step 1
Command = 0
Gosub Ps_clock
Next X
Return
Ps_clock:
Clock = 0
Waitus 10
Clock = 1
Waitus 10
Return
Psnatg:
Gosub Ps_clock
Dd = Dataa
Return
Get_ps_byte:
Dim N As Byte
Dim Temp_ps As Byte
Temp_ps = 0
Ps_byte = 0
For N = 0 To 7 Step 1
Temp_ps = Dd
Shift Ps_byte , Left , 1
If Temp_ps = 1 Then
Ps_byte = Ps_byte + &H80
End If
Next N
Return
لو حد فاهم فى اللغتين يراجع الكود يمكن انا غلطت فى حاجة ؟