int main(void){ //main function, execution starts here char c; AD1PCFGL = 0xFFFF; //digital pins //setup internal clock for 80MHz/40MIPS //7.37/2=3.685*43=158.455/2=79.2275 CLKDIVbits.PLLPRE=0; // PLLPRE (N2) 0=/2 PLLFBD=41; //pll multiplier (M) = +2 CLKDIVbits.PLLPOST=0;// PLLPOST (N1) 0=/2 while(!OSCCONbits.LOCK);//wait for PLL ready //uart //UART can be placed on any RPx pin //we need to configure it for RP14/RP15 to use the FTDI usb->serial converter //you could also output one (or both) of the two available UARTS to the I/O header //assign pin 14 to the UART1 RX input register //RX PR14 (input) U1RXR_I = 14; //assign UART1 TX function to the pin 15 output register //TX RP15 (output) RP15_O=U1TX_O; //InitializeUART1(); //setup UART U1BRG = 85;//86@80mhz, [email protected]=115200 U1MODE = 0; //clear mode register U1MODEbits.BRGH = 1; //use high percison baud generator U1STA = 0; //clear status register U1MODEbits.UARTEN = 1; //enable the UART RX IFS0bits.U1RXIF = 0; //clear the receive flag //setup LEDs SD_TRIS = 0; //set pin direction to output IO1_TRIS = 0; LD1_TRIS = 0; SD_O = 1; //set all pins high (LED on) LD1_O = 1; IO1_O=1; while(1){//never ending loop if(UART1RXRdy()==1){//check for data waiting c=UART1RX();//get the character if(c=='0'){ //LATA &=(~0b11100000000); LD1_O = 0; IO1_O=0; SD_O = 0; }else if(c=='1'){ LD1_O = 1; }else if(c=='2'){ IO1_O=1; }else if(c=='3'){ SD_O = 1; } UART1TX(c);//echo the character back } } }
// measure constantly void bpADCCprobe(void) { unsigned int temp; //bpWline(OUMSG_PS_ADCC); BPMSG1042; //bpWline(OUMSG_PS_ANY_KEY); BPMSG1250; //BPMSG1043; //bpWstring(OUMSG_PS_ADC_VOLT_PROBE); BPMSG1044; bpWvolts(0); // print dummy (0v) //bpWstring(OUMSG_PS_ADC_VOLTS); BPMSG1045; while(!UART1RXRdy()) // wait for keypress { AD1CON1bits.ADON = 1; // turn ADC ON temp=bpADC(BP_ADC_PROBE); AD1CON1bits.ADON = 0; // turn ADC OFF bpWstring("\x08\x08\x08\x08\x08"); // 5x backspace ( e.g. 5.00V ) //BPMSG1046; bpWvolts(temp); // print measurement //bpWstring(OUMSG_PS_ADC_VOLTS); BPMSG1045; // CvD: wait xx ms?? } UART1RX(); bpWline(""); // need a linefeed :D }
int16_t main(void) { char c = 'g'; /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize IO ports and peripherals */ InitApp(); hd44780_init(N_2LINE,FONT_8); //hd44780_setCursorPosition(0, 0); hd44780_write_char(' '); hd44780_write_char('G'); hd44780_write_char('K'); hd44780_write_string("hat DE Lieb"); while(1) { if(UART1RXRdy()==1){//check for data waiting c=UART1RX();//get the character if(c=='0') { T1CONbits.TON = ~T1CONbits.TON; /* enable Timer 1 and start the count */ if(!T1CONbits.TON) //if timer is off, turn off LED { UART1TX('T'); UART1TX('1'); UART1TX('-'); UART1TX('O'); UART1TX('F'); UART1TX('F'); UART1TX('\n'); UART1TX('\r'); MSLED_O = 0; } else { UART1TX('T'); UART1TX('1'); UART1TX('-'); UART1TX('O'); UART1TX('N'); UART1TX('\n'); UART1TX('\r'); MSLED_O=1; } } else { UART1TX(c);//echo the character back hd44780_write_char(c); } } } }
void binBB(void) { static unsigned char inByte; unsigned int i; BP_LEDMODE = 1; //light MODE LED binReset(); binBBversion(); //send mode name and version while (1) { inByte = getRXbyte(); if ((inByte & 0b10000000) == 0) {//if command bit cleared, process command if (inByte == 0) {//reset, send BB version binBBversion(); } else if (inByte == 1) {//goto SPI mode binReset(); #ifdef BP_USE_HWSPI binSPI(); //go into rawSPI loop #endif binReset(); binBBversion(); //say name on return } else if (inByte == 2) {//goto I2C mode binReset(); #ifdef BP_USE_I2C binI2C(); #endif binReset(); binBBversion(); //say name on return } else if (inByte == 3) {//goto UART mode binReset(); #ifdef BP_USE_HWUART binUART(); #endif binReset(); binBBversion(); //say name on return } else if (inByte == 4) {//goto 1WIRE mode binReset(); #ifdef BP_USE_1WIRE bin1WIRE(); #endif binReset(); binBBversion(); //say name on return } else if (inByte == 5) {//goto RAW WIRE mode binReset(); binwire(); binReset(); binBBversion(); //say name on return } else if (inByte == 6) {//goto OpenOCD mode binReset(); #ifndef BUSPIRATEV4 binOpenOCD(); #endif binReset(); binBBversion(); //say name on return } else if (inByte == 7) {//goto pic mode binReset(); #ifdef BP_USE_PIC binpic(); #endif binReset(); binBBversion(); //say name on return } else if (inByte == 0b1111) {//return to terminal UART1TX(1); BP_LEDMODE = 0; //light MODE LED WAITTXEmpty(); //wait untill TX finishes #ifndef BUSPIRATEV4 asm("RESET"); #endif #ifdef BUSPIRATEV4 //cannot use ASM reset on BPv4 binReset(); return; #endif //self test is only for v2go and v3 #ifndef BUSPIRATEV1A } else if (inByte == 0b10000) {//short self test binSelfTest(0); } else if (inByte == 0b10001) {//full self test with jumpers binSelfTest(1); #endif } else if (inByte == 0b10010) {//setup PWM //cleanup timers from FREQ measure T2CON = 0; //16 bit mode T4CON = 0; OC5CON = 0; //clear PWM settings BP_AUX_RPOUT = OC5_IO; //setup pin //get one byte i = getRXbyte(); if (i & 0b10) T2CONbits.TCKPS1 = 1; //set prescalers if (i & 0b1) T2CONbits.TCKPS0 = 1; //get two bytes i = (getRXbyte() << 8); i |= getRXbyte(); OC5R = i; //Write duty cycle to both registers OC5RS = i; OC5CON = 0x6; // PWM mode on OC, Fault pin disabled //get two bytes i = (getRXbyte() << 8); i |= getRXbyte(); PR2 = i; // write period T2CONbits.TON = 1; // Start Timer2 UART1TX(1); } else if (inByte == 0b10011) {//clear PWM T2CON = 0; // stop Timer2 OC5CON = 0; BP_AUX_RPOUT = 0; //remove output from AUX pin UART1TX(1); //ADC only for v1, v2, v3 } else if (inByte == 0b10100) {//ADC reading (x/1024)*6.6volts AD1CON1bits.ADON = 1; // turn ADC ON i = bpADC(BP_ADC_PROBE); //take measurement AD1CON1bits.ADON = 0; // turn ADC OFF UART1TX((i >> 8)); //send upper 8 bits UART1TX(i); //send lower 8 bits } else if (inByte == 0b10101) {//ADC reading (x/1024)*6.6volts AD1CON1bits.ADON = 1; // turn ADC ON while (1) { i = bpADC(BP_ADC_PROBE); //take measurement WAITTXEmpty(); UART1TX((i >> 8)); //send upper 8 bits //while(UART1TXRdy==0); UART1TX(i); //send lower 8 bits if (UART1RXRdy() == 1) {//any key pressed, exit i = UART1RX(); // /* JTR usb port; */; break; } } AD1CON1bits.ADON = 0; // turn ADC OFF }else if (inByte==0b10110){ //binary frequency count access
int main(void){ //main function, execution starts here char c = 'g'; /* * PIC pins start as analog inputs to protect any sensitive * externally connected components from unwanted pin output. * To use a pin for digital input and output, we need to * disable the analog functions on a pin by writing 1 to * the corresponding bits of the AD1PCFGL register. */ AD1PCFGL = 0xFFFF; //digital pins /* Initialize ports */ LATA = 0x0000; // set latch levels TRISA = 0x0000; // set IO as outputs LATB = 0x0000; // set latch levels TRISB = 0x0000; // set IO as outputs TRISBbits.TRISB6 = 1; //setup internal clock for 80MHz/40MIPS //7.37/2=3.685*43=158.455/2=79.2275 CLKDIVbits.PLLPRE=0; // PLLPRE (N2) 0=/2 PLLFBD=41; //pll multiplier (M) = +2 CLKDIVbits.PLLPOST=0;// PLLPOST (N1) 0=/2 while(!OSCCONbits.LOCK);//wait for PLL ready InitTimer1(); //uart //UART can be placed on any RPx pin //we need to configure it for RP14/RP15 to use the FTDI usb->serial converter //you could also output one (or both) of the two available UARTS to the I/O header //assign pin 14 to the UART1 RX input register //RX PR14 (input) U1RXR_I = 6; //assign UART1 TX function to the pin 15 output register //TX RP15 (output) RP7_O=U1TX_O; //InitializeUART1(); //setup UART U1BRG = 85;//86@80mhz, [email protected]=115200 U1MODE = 0; //clear mode register U1MODEbits.BRGH = 1; //use high percison baud generator U1STA = 0; //clear status register U1MODEbits.UARTEN = 1; //enable the UART RX IFS0bits.U1RXIF = 0; //clear the receive flag /* //setup LEDs // SD_TRIS = 0; //set pin direction to output // IO1_TRIS = 0; LD1_TRIS = 0; // SD_O = 1; //set all pins high (LED on) LD1_O = 0; // IO1_O=1; */ UART1TX(' ');//first character is discarded UART1TX('h'); UART1TX('e'); UART1TX('l'); UART1TX('l'); UART1TX('o'); while(FOREVER){//never ending loop /*Microchip code*/ if (timer_expired && Counter == FLASH_RATE ) { LATA = ~LATA; LATB = ~LATB; Counter = 0; timer_expired = 0; } // or do something else Nop(); Nop(); Nop(); //-----------end Microchip code-------------// // for(counterNum1 = 0;counterNum1<10000;counterNum1++) // { // counterNum1=counterNum1; // } //random delay) // LD1_O = 1 - LD1_O; if(UART1RXRdy()==1){//check for data waiting c=UART1RX();//get the character /*if(c=='0'){ //LATA &=(~0b11100000000); LD1_O = 0; IO1_O=0; SD_O = 0; }else if(c=='1'){ LD1_O = 1; }else if(c=='2'){ IO1_O=1; }else if(c=='3'){ SD_O = 1; }*/ UART1TX(c);//echo the character back } } }