Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
USB

USB

Ratings: (0)|Views: 1 |Likes:
Published by PHONG279
communication with PIC and Labview
communication with PIC and Labview

More info:

Published by: PHONG279 on Jan 22, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/22/2013

pdf

text

original

 
Lab_PIC.txtprogram basico;//ojo datos del dispositivo{ BufferInSize = 64; //BufferOutSize = 64;VENDOR_ID = $1234;PRODUCT_ID = $0001;}uses USBdsc;constdac_confi=0x1000; //configurado ganancia de 2;VAR//no usado uso mi rutina spi mas rapido;{SoftSpi_SDI : sbit at Rb5_bit;var SoftSpi_SDO : sbit at RC0_bit;var SoftSpi_CLK : sbit at Ra5_bit; var SoftSpi_SDI_Direction : sbit at TRISb5_bit;var SoftSpi_SDO_Direction : sbit at TRISC0_bit;var SoftSpi_CLK_Direction : sbit at TRISa5_bit;} dac_sdo:sbit at latc.0;dac_ck:sbit at lata.5 ;dac_cs:sbit at lata.4;dato_dac,d_t:word;leido: byte;var cnt : char;var readbuff : array[9] of char; absolute 0x500; // Buffers should be in USB RAM,please consult datasheetvar writebuff : array[9] of char; absolute 0x540;led:sbit at latc.2;puntero:^word;cuenta:byte;//mi rutina de envio datos via spi;procedure envia_spi(b:byte);vari:byte;beginfor i:=7 downto 0 dobegindac_ck:=0;if testbit(b,i) then dac_sdo:=1else dac_sdo:=0;nop;dac_ck:=1;nop;end; // fordac_ck:=0;end;procedure envia_dac;begindato_dac:= dato_dac or dac_confi;dac_cs:=0;Page 1
 
Lab_PIC.txtenvia_SPI(hi(dato_dac));envia_SPi(lo(dato_dac));// Soft_SPI_Write(hi(dato_dac));// Soft_SPI_Write(lo(dato_dac));dac_cs:=1;end;procedure Interrupt();beginUSB_Interrupt_Proc(); // USB servicing is done insidethe interruptend;beginRCON:=0; //DESHABILITA PRIORIDAD INTERRUPCIONES//INTERRUPCIONESINTCON:=%0; //desgabilitadasINTCON2:=0;INTCON2.RBPU:=0;// HABILITA PULL UP PORTBINTCON3:=0;PIR1:=0;PIR2:=0;PIE1:=0;PIE2:=0;IPR1:=0;// PRIERODIDAD DE ALGUNAS INTERRUPCIONES.IPR2:=1;//USBUCON:=0;// CONVERSOR ANALOGOADCON0:=0; // PARA EL ADCADCON1:=%1011;// 4 pines analogos AN0-AN3//EL COMPARADORCMCON:=7; // APAGA EL COMPARADOR.//DETECTOR DE BAJO VOLTAGELVDCON:=0;//apaga pwmccp1con:=0;ccp1con:=0;//cinfiguracion de puertosTRISA:=0;// TODO SALIDATRISB:=$f0;// 4 salidas 4 entradastrisc:=0;//pines entradas analogas;trisa.0:=1;trisa.1:=1;Page 2
 
Lab_PIC.txttrisa.2:=1;trisa.3:=1;{//aun no implementado//configuracion pwmccp1con:=0;ccp2con:=0;//configura como PWMCCP1M3_bit:=1;CCP1M2_bit:=1;CCP1M1_bit:=1;CCP1M0_bit:=1;}// DAC setupdac_CS := 0; // CS pindac_CS := 1; // Set CS to inactiveADC_Init();// Soft_SPI_Init(); no utilizada uso mi propia rutina cuenta:=0;dato_dac:=0; //valor de inicio del DACenvia_dac;HID_Enable(@readbuff,@writebuff);while true dobegin//aqui programa principal while(HID_Read() = 0) do ;latb:=readbuff[0];// salida digital micro, envia labviewdato_dac:=readbuff[2] shl 8; //salidad adcdato_dac:=dato_dac or readbuff[1];envia_dac; puntero:=@writebuff[0]; //entradas analogas del microfor cuenta:=0 to 3 dobeginpuntero^:=ADC_Read(cuenta);inc(puntero);delay_us(100);end;writebuff[8]:=(swap(portb )and ($0f)); //entradas digitales del microwhile(HID_Write(@writebuff,9) = 0) do ;led:=not led; end;Page 3

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->