// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Initiates an async read operation void ee_readAHandler(void) { switch(_asyncStep) { // send a start signal case ASYNC_NEXT_START: _asyncStep = ASYNC_NEXT_DEVICE; i2cSendStartAsync(ee_readAHandler); break; // send SLA+R case ASYNC_NEXT_DEVICE: if (i2cGetStatus() != TW_START) { _asyncError(); break; } _asyncStep = ASYNC_NEXT_NACK; i2cSendByteAsync(_device | I2C_READ, ee_readAHandler); break; // setup TWI module to NACK the response case ASYNC_NEXT_NACK: if (i2cGetStatus() != TW_MR_SLA_ACK) { _asyncError(); break; } _asyncStep = ASYNC_NEXT_READ; i2cNackA(ee_readAHandler); break; // capture the received data case ASYNC_NEXT_READ: if (i2cGetStatus() != TW_MR_DATA_NACK) { _asyncError(); break; } // read received data _data = i2cGetReceivedByte(); i2cSendStop(); // mark transaction as complete _eeComplete(_data); // increment the address pointer incrementAddress(); break; } }
int main(int argc, char * argv[]) { int i; int x; HANDLE hComm; DWORD CMS; int oscal[READ_DATA_LENGTH]; int configWord[READ_DATA_LENGTH]; int command[]={1,0,0,1,1,1,1,1,1,1,1,1,1,1}; //prikaz, ktery bude zapsan do pameti int config[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1}; //konfiguracni slovo pri loadConfigurationData ?? nema vyznam int delka; delka=5; int pole[5]={0,0,1,0,0}; pole[0]=7; printf("Vitejte v programu pro cteni OSCAL z PIC16F630 s pouzitim naseho genialniho PROGRAMATORU Vasek1.\n"); hComm = CreateFile("COM4",GENERIC_WRITE,0,0,OPEN_EXISTING, FILE_FLAG_OVERLAPPED,0); setZeros(hComm); programVerifyMode(hComm); printf("Now entered Program/Verify mode...\n"); //read OSCAL //incrementAddress(hComm, 1023); //readDataFromProgramMemory(hComm, oscal, READ_DATA_LENGTH); //printf("Prectena hodnota OSCAL: "); //printData(oscal); //read CONFIG WORD loadConfigurationData(hComm, config); incrementAddress(hComm, 7); readDataFromProgramMemory(hComm, configWord, READ_DATA_LENGTH); printf("Prectena hodnota CONFIGWORD: "); printData(configWord); // loadDataToProgramMemory(hComm, command); // beginProgramingInternal(hComm); setZeros(hComm); CloseHandle(hComm); printf("\n"); printf("Pro ukonceni programu napiste cislo a stiskene ENTER...\n"); scanf("%i", &x); return 0; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Performs an asynchronous page read void ee_readBytesHandler(void) { // setting the current page in the device requires setting up the // device for a 'write' operation, but aborting the write before // sending any data to the chip. a re-start is initiated with the // device which starts the sequential read switch (_asyncStep) { // send start signal case ASYNC_MULTI_START: _asyncStep = ASYNC_MULTI_DEVICE; i2cSendStartAsync(ee_readBytesHandler); break; // send device address with write case ASYNC_MULTI_DEVICE: if (i2cGetStatus() != TW_START) { _asyncError(); break; } _asyncStep = ASYNC_MULTI_ADDRMSB; i2cSendByteAsync(_device & I2C_WRITE, ee_readBytesHandler); break; // send address MSB case ASYNC_MULTI_ADDRMSB: if (i2cGetStatus() != TW_MT_SLA_ACK) { _asyncError(); break; } _asyncStep = ASYNC_MULTI_ADDRLSB; i2cSendByteAsync(_address >> 8, ee_readBytesHandler); break; // send address LSB case ASYNC_MULTI_ADDRLSB: if (i2cGetStatus() != TW_MT_DATA_ACK) { _asyncError(); break; } _asyncStep = ASYNC_MULTI_READ; i2cSendByteAsync(_address & 0xff, ee_readBytesHandler); break; // prepare appropriate reply for recceived byte(s) case ASYNC_MULTI_READ: _asyncStep = ASYNC_MULTI_NEXT; if (_bufferLen) i2cAckA(ee_readBytesHandler); else i2cNackA(ee_readBytesHandler); break; // get the byte and case ASYNC_MULTI_NEXT: if (_bufferLen > 0) { _bufferLen--; *_pbuffer++ = i2cGetReceivedByte(); _asyncStep = ASYNC_MULTI_READ; // increment the address pointer incrementAddress(); } else _asyncStep = ASYNC_MULTI_STOP; break; // end the transaction case ASYNC_MULTI_STOP: if (i2cGetStatus() != TW_MT_DATA_ACK) { _asyncError(); break; } i2cSendStop(); _eeComplete(0); break; } }