Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Lab_PIC.

txt program basico; //ojo datos del dispositivo { BufferInSize = 64; // BufferOutSize = 64; VENDOR_ID = $1234; PRODUCT_ID = $0001; } uses USBdsc; const dac_confi=0x1000;

//configurado ganancia de 2;

VAR //no usado uso {SoftSpi_SDI : var SoftSpi_SDO var SoftSpi_CLK mi rutina spi mas rapido; sbit at Rb5_bit; : sbit at RC0_bit; : 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; please consult datasheet var 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); var i:byte; begin for i:=7 downto 0 do begin dac_ck:=0; if testbit(b,i) then dac_sdo:=1 else dac_sdo:=0; nop; dac_ck:=1; nop; end; // for dac_ck:=0; end; procedure envia_dac; begin dato_dac:= dato_dac or dac_confi; dac_cs:=0; Page 1

// Buffers should be in USB RAM,

Lab_PIC.txt envia_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(); begin USB_Interrupt_Proc(); the interrupt end; begin RCON:=0; //DESHABILITA PRIORIDAD INTERRUPCIONES //INTERRUPCIONES INTCON:=%0; //desgabilitadas INTCON2:=0; INTCON2.RBPU:=0;// HABILITA PULL UP PORTB INTCON3:=0; PIR1:=0; PIR2:=0; PIE1:=0; PIE2:=0; IPR1:=0;// PRIERODIDAD DE ALGUNAS INTERRUPCIONES. IPR2:=1; //USB UCON:=0; // CONVERSOR ANALOGO ADCON0:=0; // PARA EL ADC ADCON1:=%1011;// 4 pines analogos AN0-AN3 //EL COMPARADOR CMCON:=7; // APAGA EL COMPARADOR. //DETECTOR DE BAJO VOLTAGE LVDCON:=0; //apaga pwm ccp1con:=0; ccp1con:=0; //cinfiguracion de puertos TRISA:=0;// TODO SALIDA TRISB:=$f0;// 4 salidas 4 entradas trisc:=0; //pines entradas analogas; trisa.0:=1; trisa.1:=1; Page 2

// USB servicing is done inside

Lab_PIC.txt trisa.2:=1; trisa.3:=1; {//aun no implementado //configuracion pwm ccp1con:=0; ccp2con:=0; //configura como PWM CCP1M3_bit:=1; CCP1M2_bit:=1; CCP1M1_bit:=1; CCP1M0_bit:=1; } // DAC setup dac_CS := 0; dac_CS := 1; // CS pin // Set CS to inactive

ADC_Init(); // Soft_SPI_Init();

no utilizada uso mi propia rutina

cuenta:=0; dato_dac:=0; //valor de inicio del DAC envia_dac; HID_Enable(@readbuff,@writebuff); while true do begin //aqui programa principal while(HID_Read() = 0) do ;

latb:=readbuff[0];// salida digital micro, envia labview dato_dac:=readbuff[2] shl 8; //salidad adc dato_dac:=dato_dac or readbuff[1]; envia_dac; puntero:=@writebuff[0]; //entradas analogas del micro for cuenta:=0 to 3 do begin puntero^:=ADC_Read(cuenta); inc(puntero); delay_us(100); end; writebuff[8]:=(swap(portb )and ($0f)); //entradas digitales del micro while(HID_Write(@writebuff,9) = 0) do ; led:=not led;

end; Page 3

Lab_PIC.txt end.

Page 4

You might also like