//this loop services user input and passes it to be processed on <enter> int main(void){ CLKDIVbits.RCDIV0=0; //clock divider to 0 AD1PCFG = 0xFFFF; // Default all pins to digital OSCCONbits.SOSCEN=0; //Oscilator setup, registar-OSCON bits-SOSCEN MODE_LED_DIR = 0; //Mode LED set as output VREG_DIR =0; //VREG is set as output VREG_EN = 1; //Sets the VREG pin to 1, turns on the Voltage regulators. MODE_LED = 1; //Turns the MOD LED 0N InitializeUART1(); //Initialize UART1 initADC(); //Initialise ADC unsigned int voltage; /////FOREVER///LOOP////////// while(1) { if(UART1RX() == 'a') //Checks if the recived byte is 'a' if so it sends the two RAW bytes form ADC { voltage = getADC(); //reads the ADC pin UART1TX(voltage>>8); //seds the top byte of ADC to UART UART1TX(voltage); //sends the bottom byte of ADC to UART } }
U8 InitializeMicroAPI(void) { InitializePorts(); InitializeClock(); InitializeSPI(); InitializeUART1(k115200); InitializeInterrupts(); GpioSet(NSSpin); InitializeTimers(); RealTimeClockOn(); StartIntervalTimer(); return 0; }
void Initialize(void) { #if defined (BUSPIRATEV2) unsigned char i; #endif volatile unsigned long delay = 0xffff; // volatile unsigned long delay = 0xffff; // TBLPAG = 0; // we need to be in page 0 (somehow this isn't set) #if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A) CLKDIVbits.RCDIV0 = 0; //clock divider to 0 AD1PCFG = 0xFFFF; // Default all pins to digital #elif defined (BUSPIRATEV4) INTCON1bits.NSTDIS = 1; CLKDIV = 0x0000; // Set PLL prescaler (1:1) BP_LEDUSB_DIR = 0; // output CORCONbits.PSV = 1; // JTR PIC24 fixup ?? PSV not being initialized. May have been done by c_init though. PSVPAG = 0; // OSCCONbits.SOSCEN = 0; AD1PCFGL = 0x7FD8; //BUSPIRATEV4 has five analog pins b0, b1, b2, b5, b15 AD1PCFGH = 0x2; // usb_register_sof_handler(0); #endif OSCCONbits.SOSCEN = 0; while (delay--); //set pin configuration using peripheral pin select #if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A) BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=4; BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP3R=U1TX_IO; #elif defined (BUSPIRATEV4) && defined (BPV4_DEBUG) BP_TERM_RX = BP_TERM_RX_RP; //Inputs UART1 RX RPINR18bits.U1RXR=11;//AUX2 BP_TERM_TX_RP = BP_TERM_TX; // Outputs UART1 TX RPOR1bits.RP2R=U1TX_IO;//AUX1 #endif //put startup values in config (do first) bpConfig.termSpeed = 8; //default PC side port speed, startup in 115200, or saved state (later).... bpConfig.displayMode = HEX; bpInit(); //put startup values in config (do first)clean up, exit in HI-Z #if defined (BUSPIRATEV2) || defined (BUSPIRATEV1A) InitializeUART1(); //init the PC side serial port #endif #if defined (BUSPIRATEV4) && !defined (BPV4_DEBUG) initCDC(); usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); usb_start(); #endif #if defined (BUSPIRATEV4) && defined (BPV4_DEBUG) InitializeUART1(); //init the PC side serial port #endif #if defined (BUSPIRATEV2) //find the Bus Pirate revision //pullup on, do it now so it can settle during the next operations CNPU1bits.CN6PUE = 1; CNPU1bits.CN7PUE = 1; #endif //#ifndef BUSPIRATEV4 // Get the chip type and revision bpConfig.dev_type = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_TYPE); bpConfig.dev_rev = bpReadFlash(DEV_ADDR_UPPER, DEV_ADDR_REV); //#endif #if defined (BUSPIRATEV2) //now check the revision //Version | RB3 | RB2 //2go, 3a | 1 | 1 //v3b | 1 | 0 //v3.5 | 0 | 0 i=PORTB; //get settings i=i>>2; //remove unused i&=(~0b11111100); //clear others if (i==0b11) { bpConfig.HWversion = 'a'; } else if(i==0b10){ bpConfig.HWversion = 'b'; }else if(i==0){ bpConfig.HWversion = '5'; } //pullup off CNPU1bits.CN6PUE = 0; CNPU1bits.CN7PUE = 0; #else bpConfig.HWversion = 0; #endif bpConfig.quiet = 0; // turn output on (default) modeConfig.numbits = 8; #ifdef BP_USE_BASIC initpgmspace(); #endif TBLPAG = 0; // we need to be in page 0 (somehow this isn't set) #ifndef BUSPIRATEV4 bpWBR; //send a line feed versionInfo(); //prints hardware and firmware version info (base.c) #endif }