请教一下,在做AT89S51/52的ISP时需要注意那些事情? 电路按照S52的datasheet搭起来了,检查硬件也都好的,就是按下面的读写程序对单片机控制,读回来就是FFH,气死我了。 读写程序如下(Delphi 7):
procedure WriteByte(Port:word; bData : Byte; bTms : Byte); var iTckLow, iTdiVal, iTckHi : Byte; bVal:array[1..8] of Byte; i : integer; iScaletoW : Byte; begin iScaletoW := 1; for i := 1 to 8 do begin if ( bData and iScaletoW ) <> 0 then bVal := 1; iScaletoW := iScaletoW * 2; end;
if bTms <> 0 then //TCK = 0 PortOut(portadd1,$02) else PortOut(portadd1,$00); Pause(10);//Delay;
if bTms <> 0 then //TMS = 1 begin for i := 8 downto 1 do begin if bVal <> 0 then //TDI = 1 begin iTckLow := $02; iTdiVal := $42; iTckHi := $43; end else begin //TDI = 0 iTckLow := $02; iTdiVal := $02; iTckHi := $03; end; PortOut(portadd1,iTckLow); Pause(10);//Delay; PortOut(portadd1,iTdiVal); Pause(10);//Delay; PortOut(portadd1,iTckHi); Pause(10);//Delay;
end; end else //TMS = 0 begin for i := 8 downto 1 do begin if bVal <> 0 then //TDI = 1 begin iTckLow := $00; iTdiVal := $40; iTckHi := $41; end else //TDI = 0 begin iTckLow := $00; iTdiVal := $00; iTckHi := $01; end; PortOut(portadd1,iTckLow); Pause(10);//Delay; PortOut(portadd1,iTdiVal); Pause(10);//Delay; PortOut(portadd1,iTckHi); Pause(10);//Delay; end; end;
if bTms <> 0 then //TCK = 0 PortOut(portadd1,$02) else PortOut(portadd1,$00); Pause(10);//Delay;
end;
function ReadByte(Port:word; bTms : Byte):Byte; var iTckLo, iTckHi, iValue : Byte; i : integer; iValIn : Byte; begin iValIn := 0;
if bTms <> 0 then //TCK = 1 PortOut(portadd1,$03) else PortOut(portadd1,$01); Pause(10);//Delay;
if bTms <> 0 then //TMS = 1 begin for i := 8 downto 1 do begin iTckLo := $02; iTckHi := $03; PortOut(portadd1,iTckLo); //TCK TO 0 Pause(10);//Delay; iValue := PortIn(Port); Pause(10);//Delay; PortOut(portadd1,iTckHi); //TCK TO 1 Pause(10);//Delay; if ( iValue and $80 ) = 0 then case i of 8 : iValIn := iValIn or $80; 7 : iValIn := iValIn or $40; 6 : iValIn := iValIn or $20; 5 : iValIn := iValIn or $10; 4 : iValIn := iValIn or $08; 3 : iValIn := iValIn or $04; 2 : iValIn := iValIn or $02; 1 : iValIn := iValIn or $01; end; end; end else //TMS = 0 begin for i := 8 downto 1 do begin iTckLo := $00; iTckHi := $01; PortOut(portadd1,iTckLo); //TCK TO 0 Pause(10);//Delay; iValue := PortIn(Port); Pause(10);//Delay; PortOut(portadd1,iTckHi); //TCK TO 1 Pause(10);//Delay;
if ( iValue and $80 ) = 0 then case i of 8 : iValIn := iValIn or $80; 7 : iValIn := iValIn or $40; 6 : iValIn := iValIn or $20; 5 : iValIn := iValIn or $10; 4 : iValIn := iValIn or $08; 3 : iValIn := iValIn or $04; 2 : iValIn := iValIn or $02; 1 : iValIn := iValIn or $01; end; end; end; if bTms <> 0 then //TCK = 1 PortOut(portadd1,$03) else PortOut(portadd1,$01); Pause(10);//Delay;
Result := iValIn; end;
请各位高手不吝赐教,在下先谢过,谢谢!
|