Ejemplo n.º 1
0
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  char TextString[256];
  unsigned int UniqueID = CSpinEdit1->Value;
  int StartPercent, cnt;

  CGauge1->Progress = 0;
    
  //config data pins as output
  OutputPort(nAddress+2, InputPort(nAddress+2)&0xDF);

  //Enable buffers
  SetOE(1);

  //Start programming
  SetMOSI(0);
  SetSCK(0);
  SetReset(0);
  Sleep(1);
  SetReset(1);
  for (cnt=0; cnt<50; cnt++)
  {
    CGauge1->AddProgress(1);
    Sleep(75);
  }

  StartPercent = CGauge1->PercentDone;
  for (cnt=0; cnt<16; cnt++)
  {
    SetMOSI((bool)(UniqueID&(0x8000>>cnt)));
    SetSCK(1);
    Sleep(1);
    SetSCK(0);
    Sleep(1);
    CGauge1->AddProgress(((100-StartPercent)*cnt)/32);
  }
  unsigned int ControlValue = 0xAC5A;
  for (cnt=0; cnt<16; cnt++)
  {
    SetMOSI((bool)(ControlValue&(0x8000>>cnt)));
    SetSCK(1);
    Sleep(1);
    SetSCK(0);
    Sleep(1);
    CGauge1->AddProgress(((100-StartPercent)*cnt)/32);
  }
  Sleep(100);
  
  //Start reset
  SetMOSI(0);
  SetSCK(0);

  SetReset(0);
  Sleep(1);
  SetReset(1);

  //Disable buffers
  SetOE(0);
}
/////////////////////////////////////////////////////////////////////////////////
/// SPIWrite.
/// Propósito: Envia um caractere através do pino MOSI<br>
/// Entradas: char dado, dado que será enviado<br>
/// Saídas: Nenhuma
///
/// \param [in] dado char que será enviado através do pino MOSI
/////////////////////////////////////////////////////////////////////////////////
void SPIWrite(char dado){	  
	int i;
	for(i=7; i>=0; i--){				// para os 8 bits do caractere
		if(dado & (1 << i ))            // faz um AND com uma máscara 
										// que se move até percorrer os 8 bits
			SetMOSI();					// seta o pino
		else 						    // ou
			ClearMOSI();				// zera o pino

		DelaySPI(10);					// aguarda e gera pulsos de clock
		SetSCK();                       // para o dispositivo slave SPI
		DelaySPI(10);
		ClearSCK();
		DelaySPI(10);
	}
}
Ejemplo n.º 3
0
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  //config data pins as output
  OutputPort(nAddress+2, InputPort(nAddress+2)&0xDF);

  //Enable buffers
  SetOE(1);

  //Start reset
  SetMOSI(0);
  SetSCK(0);

  SetReset(0);
  Sleep(1);
  SetReset(1);

  //Disable buffers
  SetOE(0);
}