void MyWIFI_Init(void) { // Configure Pins for MRF24J40MB mPORTESetBits(RST_WIFI); mPORTESetPinsDigitalOut(RST_WIFI); mPORTBSetBits(WIFI_HIB); mPORTBSetPinsDigitalOut(WIFI_HIB); mPORTBClearBits(WIFI_WP); // Has to be pulled low mPORTBSetPinsDigitalOut(WIFI_WP); /* // Configure the INT4 controller for WIFI // Set RD11/INT4 as input mPORTDSetPinsDigitalIn(BIT_11); // Clear corresponding bits in INTCON for falling edge trigger INTCONCLR = _INTCON_INT4EP_MASK; // Set up interrupt prioirty and sub-priority INTSetVectorPriority(INT_EXTERNAL_4_VECTOR, My_INT_EXTERNAL_4_PRIORITY); INTSetVectorSubPriority(INT_EXTERNAL_4_VECTOR, My_INT_EXTERNAL_4_SUB_PRIORITY); // Clear the interrupt flags INTClearFlag(INT_INT4); // Enable INT4 INTEnable(INT_INT4, INT_ENABLED); */ }
int main(void) { // === config the uart, DMA, SPI =========== PT_setup(); // == SPI == //enable SPI at 10 MHz clock to meet digital potentiometer specifications SpiChnOpen(spiChn, SPI_OPEN_ON | SPI_OPEN_MODE16 | SPI_OPEN_MSTEN | SPI_OPEN_CKE_REV , spiClkDiv); // === setup system wide interrupts ==================== INTEnableSystemMultiVectoredInt(); // === set up i/o port pin =============================== //Port B bits, 3,7,8, and 9 are used to select digital output //Port B bit 4 is used as chip select for treble digital potentiometer //Port B bit 13 is used as a select signal for output effect selection multiplexer //Additional functionality would use the TFT to display which output was being //selected mPORTBSetPinsDigitalOut(BIT_4 | BIT_3|BIT_7 | BIT_8 | BIT_9 |BIT_13); //Set port as output //Port A Bits 0,2,and 3 are used to configure digital potentiometers (chip selects). Port A bit 4 is used //for multiplexing whether to have input from Digital effector chip, distortion, //or pure tonestack sound mPORTASetPinsDigitalOut(BIT_0 | BIT_2 | BIT_3 | BIT_4); // === now the threads =================================== // init the threads PT_INIT(&pt_cmd); PT_INIT(&pt_time); //==Digipot spi stuff // SCK2 is pin 26 // SDO1 (MOSI) is in PPS output group 1, could be connected to RB5 which is pin 14 PPSOutput(2, RPB5, SDO1); // control CS for DAC //mPORTBSetPinsDigitalOut(BIT_4); //CS mPORTBSetBits(BIT_4 | BIT_6); //=== mPORTASetBits(BIT_0 | BIT_2 | BIT_3 | BIT_4); //CS pins active high mPORTAClearBits(BIT_4); mPORTBClearBits(BIT_13); mPORTBSetBits(BIT_13); // schedule the threads while(1) { //cmd used as command center for all effects PT_SCHEDULE(protothread_cmd(&pt_cmd)); } } // main
void InitializeSystem() { SYSTEMConfigWaitStatesAndPB(CLOCK_FREQ); mOSCSetPBDIV(OSC_PB_DIV_4); // Set to get 20MHz PB clock //mOSCSetPBDIV(OSC_PB_DIV_2); CheKseg0CacheOn(); mJTAGPortEnable(0); // Initialize the pins to all digital output and driven to ground. // Exception is RE7 and RE6 which are switch inputs PORTSetPinsDigitalIn(IOPORT_E, BIT_6); PORTSetPinsDigitalIn(IOPORT_E, BIT_7); mPORTASetPinsDigitalOut(0xFFFF); mPORTBSetPinsDigitalOut(0xFFFF); mPORTCSetPinsDigitalOut(0xFFFF); mPORTDSetPinsDigitalOut(0xFFFF); mPORTESetPinsDigitalOut(0xFF3F); mPORTFSetPinsDigitalOut(0xFFFF); mPORTGSetPinsDigitalOut(0xFFFF); mPORTAClearBits(0xFFFF); mPORTBClearBits(0xFFFF); mPORTCClearBits(0xFFFF); mPORTDClearBits(0xFFFF); mPORTEClearBits(0xFF3F); mPORTESetBits(0x000F); // LED latches need to be set high for off mPORTFClearBits(0xFFFF); mPORTGClearBits(0xFFFF); INTEnableSystemMultiVectoredInt(); #ifdef SANITY_CHECK mLED_Green_On(); #endif //LCD_Initialize(); //WIFI_Initialize(); //SPRINKLER_Initialize(); //RTCC_Initialize(); //SERIALUSB_Initialize(); SDCARD_Initialize(); TCPIP_Initialize(); }
/* TIMER 2 Interrupt Handler - configured to 50us periods */ void __ISR(_TIMER_2_VECTOR, ipl3) Timer2Handler(void) { // clear the interrupt flag mT2ClearIntFlag(); counterTrigger--; if(counterTrigger==5){ mPORTBSetBits(BIT_8 | BIT_9| BIT_10 | BIT_11); //Sends trigger signal to the four sensors } if(counterTrigger == 0){ mPORTBClearBits(BIT_8 | BIT_9| BIT_10 | BIT_11); //Shut down trigger signal } delayFront++; delayBack++; delayRight++; delayLeft++; }
//===================== Main ======================= // void main(void) { SYSTEMConfig( SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0; PT_setup(); INTEnableSystemMultiVectoredInt(); // initialize the threads PT_INIT(&pt_blink); PT_INIT(&pt_capture); // initialize the display tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_BLACK); tft_setRotation(0); //240x320 vertical display // initialize the comparator CMP1Open(CMP_ENABLE | CMP_OUTPUT_ENABLE | CMP1_NEG_INPUT_IVREF); // initialize the timer2 OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_64, 0xffffffff); // initialize the input capture, uses timer2 OpenCapture1( IC_EVERY_RISE_EDGE | IC_FEDGE_RISE | IC_INT_1CAPTURE | IC_TIMER2_SRC | IC_ON); ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_3 | IC_INT_SUB_PRIOR_3 ); INTClearFlag(INT_IC1); // initialize the input/output I/O mPORTBSetPinsDigitalOut(BIT_3); mPORTBClearBits(BIT_3); PPSOutput(4, RPB9, C1OUT); //set up output of comparator for debugging PPSInput(3, IC1, RPB13); //Either Pin 6 or Pin 24 idk //round-robin scheduler for threads while(1) { PT_SCHEDULE(protothread_blink(&pt_blink)); PT_SCHEDULE(protothread_capture(&pt_capture)); } } //main
// This thread is responsible for all the code not involving the TFT Display, it handled discharging and charging the capacitor and calculating the // capacitance of the capacitor. static PT_THREAD(protothread_cap(struct pt *pt)){ PT_BEGIN(pt); while(1){ // Discharge Capacitor // Set pin as output mPORTBSetPinsDigitalOut(BIT_3); // Drive RB3 low so capacitor can discharge into the pin mPORTBClearBits(BIT_3); // Yield until discharge is complete PT_YIELD_TIME_msec(2); // 2ms is given for the capacitor to discharge and for the display to update if needed Comp1Setup(); // Charge Capacitor // Set RB3 as an input to detect capacitor's current charge mPORTBSetPinsDigitalIn(BIT_3); // Set up the timer for charging the capcitor capTimerSetup(); // Set up the input capture to capture when the capacitor voltage reaches the reference voltage IC1setup(); // Yield while waiting for event from comparator PT_YIELD_UNTIL(pt, charged); CloseTimer2(); // Reset thread wait variable charged = 0; // Calculate capacitance in nF capacitance = (((charge_time*-1)/1000000)/(log(1-(VREF / VDD)) * RESISTOR))*1000000000; CMP1Close(); PT_YIELD_TIME_msec(20); } PT_END(pt); }
//===================== Capture ==================== // // Discharges capacitor, displays and begins measurement of C1INA static PT_THREAD (protothread_capture(struct pt *pt)) { PT_BEGIN(pt); while(1) { // sets pin 7 to an output mPORTBSetPinsDigitalOut(BIT_3); mPORTBClearBits(BIT_3); tft_setCursor(10, 50); tft_setTextColor(ILI9340_YELLOW); tft_setTextSize(3); tft_writeString("Capacitance: "); //sets up for the capacitor reading char buffer[20]; tft_setCursor(10, 90); tft_fillRect(10,90, 300, 100, ILI9340_BLACK); sprintf(buffer,"%.1f nF",cap); tft_setTextColor(ILI9340_WHITE); //displays the capacitor value if it is above the threshold of 1 nF if(cap < 1.0*(1-ERROR)) tft_writeString("No capacitor"); else tft_writeString(buffer); cap = 0.0; PT_YIELD_TIME_msec(1); //Clear timer and sets pin 7 as input WriteTimer2(0); mPORTBSetPinsDigitalIn(BIT_3); PT_YIELD_TIME_msec(100); } PT_END(pt); } // capture
void TURN_OFF_LED(short lednumber) { switch(lednumber) { case 0: {} case 1: {} case 2: { mPORTDClearBits(1 << lednumber); break; } case 3: {} case 4: { mPORTBClearBits(1 << (lednumber+1)); } default: { break; } } }
void __ISR(_I2C_1_VECTOR, ipl3) _SlaveI2CHandler(void) { unsigned char temp; static unsigned int dIndex; // check for MASTER and Bus events and respond accordingly if (IFS1bits.I2C1MIF) { mI2C1MClearIntFlag(); return; } if (IFS1bits.I2C1BIF) {//bus collision, reset I2C state machine I2Cstate = 0; mI2C1BClearIntFlag(); return; } // handle the incoming message if ((I2C1STATbits.R_W == 0) && (I2C1STATbits.D_A == 0)) { // reset any state variables needed by a message sequence // perform a dummy read temp = SlaveReadI2C1(); I2C1CONbits.SCLREL = 1; // release the clock I2Cstate = 0; } else if ((I2C1STATbits.R_W == 0) && (I2C1STATbits.D_A == 1)) {//data received, input to slave WDTCount = 0; WriteTimer1(0); // writing data to our module I2CDataIn = SlaveReadI2C1(); I2C1CONbits.SCLREL = 1; // release clock stretch bit if (I2Cstate == 0 && I2CDataIn != ADDR_CLR_I2C_STATE) { I2Cstate = 1; I2C_request = I2CDataIn; } else if (I2Cstate == 1) { switch (I2C_request) { case ADDR_M3_PWM: M3_Dir = I2CDataIn >> 7 & 0x01;//take top bit if (((Status2 & M3_CUR) && (config1 & CUR_SENSE_EN)) || (config1 & MOTOR_HALT)) { M3_PWM = 0; } else { if (I2CDataIn & 0x80) { mPORTBClearBits(BIT_13); M3_PWM = (((int) ((~I2CDataIn) + 1)) << 4); } else { mPORTBSetBits(BIT_13); M3_PWM = ((int) I2CDataIn) << 4; } } SetDCOC4PWM(M3_PWM); break; case ADDR_M4_PWM: M4_Dir = I2CDataIn >> 7 & 0x01;//take top bit if (((Status2 & M4_CUR) && (config1 & CUR_SENSE_EN)) || (config1 & MOTOR_HALT)) { M4_PWM = 0; } else { if (I2CDataIn & 0x80) { mPORTBClearBits(BIT_14); M4_PWM = (((int) ((~I2CDataIn) + 1)) << 4); } else { mPORTBSetBits(BIT_14); M4_PWM = ((int) I2CDataIn) << 4; } } SetDCOC5PWM(M4_PWM); break; case ADDR_M5_PWM: M5_Dir = I2CDataIn >> 7 & 0x01;//take top bit if (((Status2 & M5_CUR) && (config1 & CUR_SENSE_EN)) || (config1 & MOTOR_HALT)) { M5_PWM = 0; } else { if (I2CDataIn & 0x80) { mPORTBClearBits(BIT_15); M5_PWM = (((int) ((~I2CDataIn) + 1)) << 4); } else { mPORTBSetBits(BIT_15); M5_PWM = ((int) I2CDataIn) << 4; } } SetDCOC3PWM(M5_PWM); break; case ADDR_M6_PWM: M6_Dir = I2CDataIn >> 7 & 0x01;//take top bit if (((Status2 & M6_CUR) && (config1 & CUR_SENSE_EN)) || (config1 & MOTOR_HALT)) { M6_PWM = 0; } else { if (I2CDataIn & 0x80) { mPORTBClearBits(BIT_11); M6_PWM = (((int) ((~I2CDataIn) + 1)) << 4); } else { mPORTBSetBits(BIT_11); M6_PWM = ((int) I2CDataIn) << 4; } } SetDCOC2PWM(M6_PWM); break; case ADDR_M7_PWM: M7_Dir = I2CDataIn >> 7 & 0x01;//take top bit if (((Status2 & M7_CUR) && (config1 & CUR_SENSE_EN)) || (config1 & MOTOR_HALT)) { M7_PWM = 0; } else { if (I2CDataIn & 0x80) { mPORTBClearBits(BIT_7); M7_PWM = (((int) ((~I2CDataIn) + 1)) << 4); } else { mPORTBSetBits(BIT_7); M7_PWM = ((int) I2CDataIn) << 4; } } SetDCOC1PWM(M7_PWM); break; case ADDR_Config1: config1 = I2CDataIn; if (config1 & MOTOR_HALT) { SetDCOC1PWM(0); SetDCOC2PWM(0); SetDCOC3PWM(0); SetDCOC4PWM(0); SetDCOC5PWM(0); } else { SetDCOC1PWM(M7_PWM); SetDCOC2PWM(M6_PWM); SetDCOC3PWM(M5_PWM); SetDCOC4PWM(M3_PWM); SetDCOC5PWM(M4_PWM); } break; default: break; } I2Cstate = 0; } } else if ((I2C1STATbits.R_W == 1) && (I2C1STATbits.D_A == 0)) {
int main(void) { int a = 0; unsigned char data_mix = 0, data_mix_old = 0; SDEV_TYPE1 S1 = {0}, *S1_p = &S1; char comm_buffer[MAXSTRLEN]; int update_rate = 4; int eresult = 0, records = 0, file_errors = 0; // Init remote device data S1.obits.out_byte = 0xff; // Enable multi-vectored interrupts INTEnableSystemMultiVectoredInt(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //STEP 1. Configure cache, wait states and peripheral bus clock // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); srand(ReadCoreTimer()); // Seed the pseudo random generator // SCLK1 pin 25 - SD pin 5 PORTSetPinsDigitalOut(IOPORT_B, BIT_14); // Clock output // SCLK2 pin 26 - PIC pin 18 PORTSetPinsDigitalOut(IOPORT_B, BIT_15); // Clock output PPSInput(2, SDI1, RPB8); //Assign SDI1 to pin 17 - SD pin 7 PORTSetPinsDigitalIn(IOPORT_B, BIT_8); // Input for SDI1 PPSInput(3, SDI2, RPB13); //Assign SDI2 to pin 24 PORTSetPinsDigitalIn(IOPORT_B, BIT_13); // Input for SDI2 PPSOutput(2, RPB11, SDO1); // Set 22 pin as output for SDO1 - SD pin 2 PPSOutput(2, RPB5, SDO2); // Set 14 pin as output for SDO2 PORTSetPinsDigitalOut(IOPORT_B, BIT_2); // CS line pin 6 - SD pin 1 mPORTBSetBits(BIT_2); // deselect SDCARD PORTSetPinsDigitalOut(IOPORT_B, BIT_3); // select pin enable for SPI slaves bit 2 to 74hc138 mPORTBSetBits(BIT_3); // deselect Slave1 bit2 PORTSetPinsDigitalOut(IOPORT_A, BIT_3); // spare digital output mPORTASetBits(BIT_3); // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Diag Led pins PORTSetPinsDigitalOut(IOPORT_A, BIT_0 | BIT_1); // bi-color LED PORTSetPinsDigitalOut(IOPORT_B, BIT_0 | BIT_1); // programming inputs /device select outputs address for SPI slaves bits [0..1] 74hc138 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // STEP 3. initialize the port pin states = outputs low mPORTASetBits(BIT_0 | BIT_1); mPORTBClearBits(BIT_0 | BIT_1); RTC_Init(); // Start Timer5 for background processes and 1ms soft timers Blink_Init(); // Start Timer4 background blink driver blink_led(RED_LED, LED_ON, FALSE); init_spi_ports(); ps_select(0); // select the pic18 slave1 on spi port 2, select 0 // send some text to clean the buffers SpiStringWrite("\r\n \n\r"); eresult = f_mount(&FatFs, "0:", 1); if (eresult) { sprintf(comm_buffer, "\r\n Mount error %i ", eresult); SpiStringWrite(comm_buffer); /* Register work area to the logical drive 1 */ blink_led(GREEN_LED, LED_OFF, FALSE); blink_led(RED_LED, LED_ON, FALSE); } else { Show_MMC_Info(); blink_led(RED_LED, LED_OFF, FALSE); blink_led(GREEN_LED, LED_ON, TRUE); } /* Create destination file on the drive 1 */ eresult = f_open(&File[0], "0:logfile.txt", FA_CREATE_ALWAYS | FA_WRITE); while (1) { // loop and move data V.Timer1 = update_rate; while (V.Timer1); /* loop back testing */ data_mix_old = data_mix; // save the old data data_mix = rand(); // make new data if (S1_p->char_ready || !S1_p->ibits.in_bits.eject) { S1_p->rec_data = S1_p->rec_tmp; // led1_green(); } else { // led1_off(); } S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); if (S1_p->ibits.in_bits.card_detect) { S1_p->obits.out_bits.eject_led = OFF; SD_NOTRDY = STA_NOINIT; } else { S1_p->obits.out_bits.eject_led = ~S1_p->obits.out_bits.eject_led; } for (S1_p->chan_no = 0; S1_p->chan_no < 4; S1_p->chan_no++) { S1_p->adc_data[S1_p->chan_no] = SpiADCRead(S1_p->chan_no); } a = 0; if (((records % 100)) == 0 && !eresult) { if (S1_p->char_ready) { snprintf(comm_buffer, 64, "\r\n %x , %i, %x , %i , %i , %i , %i ", S1_p->rec_data, records, S1_p->ibits.in_byte, S1_p->adc_data[0], S1_p->adc_data[1], S1_p->adc_data[2], S1_p->adc_data[3]); } else { snprintf(comm_buffer, 64, "\r\n %x , %i , %i , %i , %i , %i ", S1_p->ibits.in_byte, records, S1_p->adc_data[0], S1_p->adc_data[1], S1_p->adc_data[2], S1_p->adc_data[3]); } S1_p->rec_tmp = SpiStringWrite(comm_buffer); } if (SpiSerialReadOk() || !S1_p->ibits.in_bits.eject) { S1_p->char_ready = TRUE; if ((S1_p->rec_tmp == 'f') || !S1_p->ibits.in_bits.eject) { if (S1_p->ibits.in_bits.card_detect) { // no disk blink_led(0, LED_ON, FALSE); S1_p->obits.out_bits.eject_led = OFF; S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); SpiStringWrite("\r\n Insert Disk! y/n "); while (!SpiSerialReadReady() && S1_p->ibits.in_bits.card_detect) S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); V.Timer1 = update_rate; while (V.Timer1); if (!S1_p->ibits.in_bits.card_detect) { SpiStringWrite("/\r\n Mounting Disk "); S1_p->obits.out_bits.eject_led = ON; S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); eresult = f_mount(&FatFs, "0:", 1); if (eresult) { sprintf(comm_buffer, "\r\n Mount error %i ", eresult); SpiStringWrite(comm_buffer); /* Register work area to the logical drive 1 */ blink_led(GREEN_LED, LED_OFF, FALSE); blink_led(RED_LED, LED_ON, FALSE); } else { Show_MMC_Info(); blink_led(RED_LED, LED_OFF, FALSE); blink_led(GREEN_LED, LED_ON, TRUE); } /* Create destination file on the drive 1 */ eresult = f_open(&File[0], "0:logfile.txt", FA_CREATE_ALWAYS | FA_WRITE); SpiStringWrite("\r\n Mount Complete "); S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); if (S1_p->ibits.in_bits.card_detect) SD_NOTRDY = STA_NOINIT; } } else { // Eject current disk blink_led(0, LED_ON, FALSE); S1_p->obits.out_bits.eject_led = OFF; S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); f_close(&File[0]); SpiStringWrite("\r\n Eject Disk? y/n "); while (!SpiSerialReadReady() && !S1_p->ibits.in_bits.card_detect) S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); V.Timer1 = update_rate; while (V.Timer1); if (S1_p->ibits.in_bits.card_detect) { SpiStringWrite("\r\n Ejecting Disk "); S1_p->obits.out_bits.eject_led = ON; S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); if (f_mount(0, "0:", 0)) SpiStringWrite("\r\n UMount error "); /* Unregister work area from the logical drive 1 */ SpiStringWrite("\r\n Ejection Complete "); eresult = 1; S1_p->ibits.in_byte = SpiPortWrite(S1_p->obits.out_byte); if (S1_p->ibits.in_bits.card_detect) SD_NOTRDY = STA_NOINIT; } } } } else { S1_p->char_ready = FALSE; } V.Timer1 = update_rate; while (V.Timer1); // only GREEN if the data sent and received match or eject button is pressed if (S1_p->ibits.in_bits.eject && (S1_p->rec_data != data_mix_old)) { // blink_led(0, LED_ON, TRUE); } else { // blink_led(0, LED_ON, FALSE); } if (!eresult) { a = f_puts(comm_buffer, &File[0]); blink_led(RED_LED, LED_OFF, FALSE); blink_led(GREEN_LED, LED_ON, TRUE); records++; } else { file_errors++; if ((file_errors % 100) == 0) { SpiStringWrite("\r\n not logged "); blink_led(GREEN_LED, LED_OFF, FALSE); blink_led(RED_LED, LED_ON, FALSE); } } if (a == (-1)) { if ((file_errors % 100) == 0) { sprintf(comm_buffer, "\r\n File Write error %i ", a); SpiStringWrite(comm_buffer); blink_led(GREEN_LED, LED_OFF, FALSE); blink_led(RED_LED, LED_ON, FALSE); } } f_sync(&File[0]); } }
static PT_THREAD (protothread_cmd(struct pt *pt)) { PT_BEGIN(pt); while(1) { // send the prompt via DMA to serial sprintf(PT_send_buffer,"cmd>"); // by spawning a print thread PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) ); //spawn a thread to handle terminal input // the input thread waits for input // -- BUT does NOT block other threads // string is returned in "PT_term_buffer" PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input) ); // returns when the thread dies // in this case, when <enter> is pushed // now parse the string sscanf(PT_term_buffer, "%s %d", cmd, &value); if (cmd[0]=='d' ) { //set mux to DSP chip mPORTAClearBits(BIT_4); mPORTBClearBits(BIT_13); mPORTASetBits(BIT_4); mPORTBClearBits(BIT_3 | BIT_7 | BIT_8 | BIT_9); if(((value << 6) & (0x0040))){ mPORTBSetBits(BIT_3); } //select sound effect mPORTBSetBits(value << 6); } if (cmd[0] == 's'){ //distortion //set mux to Distortion mPORTAClearBits(BIT_4); mPORTBClearBits(BIT_13); } if (cmd[0] == 'n'){ //normal: only tone stack //set mux to channel 0 mPORTAClearBits(BIT_4); mPORTBClearBits(BIT_13); mPORTBSetBits(BIT_13); } //pots if (cmd[0] == 't'){ //treble // CS low to start transaction mPORTBClearBits(BIT_4); // start transaction deliverSPICh1Datum(value); // CS high mPORTBSetBits(BIT_4); // end transaction } if (cmd[0] == 'b'){ //bass // CS low to start transaction mPORTAClearBits(BIT_0); // start transaction deliverSPICh1Datum(value); // CS high mPORTASetBits(BIT_0); // end transaction } if (cmd[0] == 'v'){ //level // CS low to start transaction mPORTAClearBits(BIT_2); // start transaction deliverSPICh1Datum(value); // CS high mPORTASetBits(BIT_2); // end transaction } if (cmd[0] == 'm'){ //mid // CS low to start transaction mPORTAClearBits(BIT_3); // start transaction deliverSPICh1Datum(value); // CS high mPORTASetBits(BIT_3); // end transaction } // never exit while } // END WHILE(1) PT_END(pt); } // thread 3
void switchMonitorOff() { mPORTBClearBits(BIT_14); }