??? 08/20/08 19:01 Modified: 08/20/08 19:45 Read: times |
#157591 - Back to Topic-here is what I tried for days.. Responding to: ???'s previous message |
I tried the Asim Khan's circuit for AT89S51. The software said no response from uC. I read the datasheet and made my own circuit on bread board. Here is the schematics(drawn in paint)and the code Visual C++ 2005. plz see and give your suggestion :)
![]() ( http://img388.imageshack.us/img388/6940/at89s51gc8.jpg ) Code: void delay(DWORD nTimeMs) { MSG msg; DWORD endTick; endTick = GetTickCount() + nTimeMs; while(GetTickCount() < endTick) { if(PeekMessage(&msg, NULL, 0, 0, TRUE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return; } BYTE WriteRead(DWORD Bits, int TClck = 1); BYTE WriteRead(DWORD Bits, int TClck) { char ByteToSend = NULL ; //DWORD Bits = 0xAC530000; char BitCount = 0 ; const DWORD One = 1 ; BYTE DataIn = NULL ; BYTE DataRec = NULL ; //char str[100]; for(BitCount=31;BitCount>=0;BitCount--) { ByteToSend = ((One<<BitCount) & Bits)?1:0; // Get Current Bit ByteToSend <<= 3; // Shift Current Bit to data.3 = pin 5 Out32(888,ByteToSend); ByteToSend |= 16; // Turn On CLOCK IN. Data.4 is pin 6. Out32(888,ByteToSend); delay(TClck); // 1 ms delay if(BitCount<=7) { DataIn = Inp32(889); //Read From Status Register DataIn &= 64; DataRec <<= 1; if(DataIn) DataRec |=1; } ByteToSend &= 0xEF; // Brink down CLOCK IN Out32(888,ByteToSend); delay(TClck); } return DataRec; } void Write(DWORD Bits, int TClck = 1); void Write(DWORD Bits, int TClck) { char ByteToSend = NULL ; //DWORD Bits = 0xAC530000; char BitCount = 0 ; const DWORD One = 1 ; //BYTE DataIn = NULL ; //BYTE DataRec = NULL ; //char str[100]; for(BitCount=31;BitCount>=0;BitCount--) { ByteToSend = ((One<<BitCount) & Bits)?1:0; // Get Current Bit ByteToSend <<= 3; // Shift Current Bit to data.3 = pin 5 Out32(888,ByteToSend); ByteToSend |= 16; // Turn On CLOCK IN. Data.4 is pin 6. Out32(888,ByteToSend); delay(TClck); // 1 ms delay ByteToSend &= 0xEF; // Brink down CLOCK IN Out32(888,ByteToSend); delay(TClck); } } void CMy8051Dlg::OnBnClickedButton2() { WriteRead(0xAC530000); Write(0xAC800000); Write(0x400000AA); BYTE dat = WriteRead(0x20000000); char str[20]; sprintf_s(str,20,"%x",dat); MessageBox(str); } There was no output at MISO during the sending of 4th byte of Programming Enable.I checked for correctness of output signals(sck and MOSI) at lpt using an LED (with 500 ms delay). It blinked fine.My LPT is 5.02V, checked with multimeter. I have Mellinium Motherboard and 2.02Ghz P4 processor (GenuineIntel). I even tried the ACE-electronics SW(i just had to change the connection at lpt pins according their signal pins) but programming did not happen. Pls tell me where something is wrong? esp with the circuit? |