#define Clock 0.25 // µS at 16Mhz
#define Ualim 5.00
#define ADC_Coeff 4.096/1024.0
// DAC 16 bits SPI ali=+5V output max==Vref=2.5V en DIP 8
#define MAX541
#ifdef MAX541
// VOut pin 1
// VRef pin 3 ... +2,5V
// VDD pin 8
// VSS pin 7
#define MAX541_CS LATCbits.LATC4 // CS out to pin 4
#define MAX541_SI LATCbits.LATC1 // SI out to pin 6
#define MAX541_SCK LATCbits.LATC3 // SCK out to pin 5
#endif
#ifdef MAX541
void Out_MAX541(unsigned int V);
[COLOR="#0000CD"][I]void Out_MAX541(unsigned int V)
{
unsigned int i,j;
MAX541_CS=0; // CS pin 4
MAX541_SCK=0;// SCK pin 5
MAX541_SI=0; // SI pin 6
Nop();Nop();Nop();Nop();
j=32768;
// instruction byte
for (i=0;i<16;i++)
{
if ((V & j)==j)
MAX541_SI=1;
else
MAX541_SI=0;
Nop();Nop();
MAX541_SCK=0;
Nop();Nop();Nop();Nop();
MAX541_SCK=1;
Nop();Nop();Nop();Nop();
j=j>>1;
MAX541_SCK=0;
}
Nop();
MAX541_CS=1;
}
#endif[/I][/COLOR]
void Raz_Receipt()
{ptecr=buffer;
ptlec= ptecr;
CptCars=0;
buffer[0]=0;
c=0;
receive=0;
}
void main(void)
{
#ifdef OSCILLATEUR_INTERNE
OSCCON=0x60; // Select8 MHz internal clock
OSCTUNE=0;
#ifdef WithPLL
OSCTUNEbits.PLLEN=1; // 1= avec PLL => 64Mhz ou 40Mhz
#else
OSCTUNEbits.PLLEN=0; // 0 =sans PLL => 16Mhz ou 10Mhz
#endif
#endif
................
Init_Hardware() ;
............
Init_UART1();
OUT_RS232
................
// init sortie DAC à 0V
Sd=0;
[B]Out_MAX541(Sd);[/B]
LATC=0;
Volt=Ualim;
k=fprintf(_H_USART,"Alim du Montage =5.0 -> %s%c",fltToa(Volt,CRam1,4),9);
CRLF();
....................
// test si saisie consigne DAC MAX
if ((CptCars>6) && (c==13)&& (buffer[0]=='M'))
{
SaisieOk=0;
for (i=1;i<6;i++)
{
SaisieOk=SaisieOk+isdigit(buffer[i]);
}
if(SaisieOk!=5)
{
strcpypgm2ram(txt,RS_Str[5]); k=PutStr_RS(txt);
Delay_mS(1000);
Raz_Receipt();
}
else
{
buffer[6]=0; //terminateur de string
Sd=atoi(buffer+1); // numerique
[B]Out_MAX541(Sd);[/B]
Volt= (float)(Sd) *2.50/65536.0;
k=fprintf(_H_USART,"\r\nBuffer= %s Out Max541 %05u soit %s V \r\n ",buffer,Sd,fltToa(Volt,CRam1,3));
Raz_Receipt();
}
..............
}