void main(void) { // M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts // Insert your main routine code here. //Start LCD LCD_Start(); LCD_Init(); value = 0; //0b0000 0000 where last four bits are 0, PRT0DR[3],PRT0DR[2], PRT0DR[1] while(1)//Control loop { mask = PRT0DR; //Collect PRT0DR[3] value if( (mask & 0b00001000) == 0) { //PRT0DR[3] is low value &= ~0b00000100; } else { //PRT0DR[3] is high value |= 0b00000100; } //Collect PRT0DR[2] value if( (mask & 0b00000100) == 0) { //PRT0DR[2] is low value &= ~0b00000010; } else { //PRT0DR[2] is high value |= 0b00000010; } //Collect PRT0DR[1] value if( (mask & 0b00000010) == 0) { //PRT0DR[1] is low value &= ~0b00000001; } else { //PRT0DR[1] is high value |= 0b00000001; } //Print to LCD LCD_Position(0,0); LCD_PrHexByte(value); }//End control loop }
void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ uint16 adc, compare; LCD_Start(); ADC_Start(); PWM_Start(); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ for(;;) { /* Place your application code here. */ // LCD_ClearDisplay(); LCD_Start(); adc = 0; ADC_StartConvert(); ADC_IsEndConversion(ADC_WAIT_FOR_RESULT); ADC_StopConvert(); adc = ADC_GetResult16(); if(adc > 255) { if(adc == 0xFFFF) /* underflow correction */ { adc = 0x00; } else adc = 0xFF; /* Overflow correction */ } LCD_Position(0,0); LCD_PrintHexUint8(adc); compare = (uint16)(1000 + ((float)((float)((float)adc / (float)255) * (float)1000))); LCD_Position(1,0); LCD_PrintDecUint16(compare); PWM_WriteCompare(compare); PWM_WritePeriod(compare + 39999); } }
void main() { //Iniitalize pulsewidth FanPWM_WritePulseWidth(255); //Start Fan PWM FanPWM_Start(); //Enable FanPWM interrupt FanPWM_EnableInt(); //Enable global interrupts M8C_EnableGInt; //Start tach timer TachTimer_Start(); //Enable Tach Timer interrupts TachTimer_EnableInt(); //Start LCD LCD_Start(); //Enable GPIO interrupts INT_MSK0 |= 0b00100000; //Initialize display LCD_Init(); LCD_Position(0,0); LCD_PrCString("Pulse Width: "); LCD_Position(0,13); LCD_PrHexByte(FanPWM_bReadPulseWidth()); while(1)//control loop { if(bDataAvailable == 1)//if data is available { //Clear it bDataAvailable = 0; //Calculate fan speed and write RPM and num cycles to lCD wSpeedRPM = ( ( (60/4) * 3000000 * cNumCycles )+ ((wFirstValue - wLastValue)/2) )/(wFirstValue - wLastValue); //Write to LCD LCD_Init(); LCD_Position(0,0); LCD_PrCString("RPM: ");//Begin writing at 0,5 LCD_Position(0,5); LCD_PrHexInt(wSpeedRPM); LCD_Position(1,0); LCD_PrCString("#Cycles: ");//Begin writing at 1,9 LCD_Position(1,9); LCD_PrHexByte(cNumCycles); } }//end control loop }
/******************************************************************************* * Function Name: main ******************************************************************************** * Summary: * Main function performs following functions: * 1. Starts Character LCD and print project info * 2. Starts SPI Master component * 3. Configures the DMA transfer for RX and TX directions * 4. Displays the results on Character LCD * * Parameters: * None. * * Return: * None. * *******************************************************************************/ void main() { uint8 i = 0u; CyGlobalIntEnable; for(i=0u; i<8u; i++) { m_rxBuffer[i] = 0u; } LCD_Start(); LCD_Position(0u,0u); LCD_PrintString("SPI Master"); LCD_Position(1u,0u); LCD_PrintString("example"); CyDelay(3000u); Dma_M_Tx_Configuration(); Dma_M_Rx_Configuration(); CyDmaChEnable(M_TxChannel, 1u); CyDmaChEnable(M_RxChannel, 1u); LCD_Position(0u,0u); LCD_PrintString("Master Tx data:"); LCD_Position(1u,0u); for(i=0u; i<8u; i++) { LCD_PrintHexUint8(m_txBuffer[i]); } CyDelay(5000u); SPIM_Start(); while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)); LCD_ClearDisplay(); LCD_PrintString("Master Rx data:"); LCD_Position(1u,0u); for(i=0u; i<8u; i++) { LCD_PrintHexUint8(m_rxBuffer[i]); } CyDelay(5000u); LCD_ClearDisplay(); LCD_PrintString("SPI Master"); LCD_Position(1u,0u); LCD_PrintString("example complete."); for(;;) { } }
void init() { // LCD Init LCD_Start(); LCD_DisplayOn(); //LCD_PrintNumber(1); ADC_Start(); }
void main(){ CYGlobalIntDisable;//Disable interrupts to avoid triggering during setup. LCD_Start();// Start LCD. UART_Start();// Start UART. Rx_Int_Start();//Start the Interrupt. Rx_Int_SetVector(Rx_ISR);//Set the Vector to the ISR. LCD_PrintString("UART:RX ISR Demo");//Print to the LCD. UART_PutString("UART:RX ISR Demo");//Print to Serial Terminal. CyDelay(1000); LCD_ClearDisplay();//Clear the screen for RX Data. CYGlobalIntEnable;//Enable Interrupts,and let the Games begin! for(;;); }
void setup(void) { int moi = 0; M8C_EnableGInt; M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO); LCD_Init(); LCD_Start(); Timer8UsTrig_EnableInt(); Timer8UsTrig_Start(); Timer8Main_EnableInt(); Timer8Main_Start(); Timer16UsEcho_EnableInt(); backlight(1); for (moi = 0; moi < 9999; moi++); }
void main(void) { M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts //Start LCD LCD_Start(); LCD_Init(); //Allow interrupts from GPIO and Sleep INT_MSK0 |= 0b01100000; while(1)//Control loop { }//End control loop }
void main(void) { int result; float voltage; int status; M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts // Insert your main routine code here. //Start PGA in high power mode PGA_Start(PGA_HIGHPOWER); //Start ADCINC in high power mode ADCINC_Start(ADCINC_HIGHPOWER); //Start LCD LCD_Start(); //Run the ADC continuously ADCINC_GetSamples(0); SleepTimer_Start(); SleepTimer_SetInterval(SleepTimer_1_HZ); SleepTimer_EnableInt(); while (1) { SleepTimer_SyncWait(1, SleepTimer_WAIT_RELOAD); // Wait for data to be ready while (ADCINC_fIsDataAvailable() == 0); // Get Data and clear flag result=ADCINC_iClearFlagGetData(); voltage = result * SCALE_FACTOR; LCD_Position(0, 0); LCD_PrCString(" "); LCD_Position(0, 0); LCD_PrHexInt(result); LCD_Position(1, 0); LCD_PrCString(" "); LCD_Position(1, 0); LCD_PrString(ftoa(voltage, &status)); } }
int main() { CyGlobalIntEnable; LCD_Start(); adc_Start(); adc_StartConvert(); for(;;) { if(adc_IsEndConversion(adc_RETURN_STATUS)) { int16 result = adc_GetResult16(POTCHAN); int16 mv = adc_CountsTo_mVolts(POTCHAN,result); LCD_Write7SegNumber_0(mv,0,1); } } }
void main_play_ttc(){ LCD_Start(); // initialize lcd LCD_ClearDisplay(); UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); struct tic_tac_toe lolz; ttc_init(&lolz,4,3); disp_grid_init_ttc(&disp,lolz.grid); // init the board disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); int x,y,z; int Values; while (lolz.game_not_won == 0){ //Values = read_from_8255(Values); Values = Pin3_Read(); if (Values >= 0 && Values <= 63){ //integer value z = Values / 16; x = Values % 4; //get row value y = Values / 4 - z*4; // LCD_ClearDisplay(); LCD_PrintNumber(Values); LCD_PrintString(" x"); LCD_PrintNumber(x); LCD_PrintString(" y"); LCD_PrintNumber(y); LCD_PrintString(" z"); LCD_PrintNumber(z); } if (ttc_get_grid(&lolz,x,y,z) == 0){ // has not been accessed ttc_step(&disp,&lolz,x,y,z); // step & print disp_grid_transmit(&disp); } } LCD_ClearDisplay(); LCD_Position(0,0); //move to bot row LCD_PrintString("GAME OVER!"); }
void main_play_tta_ai(){ LCD_Start(); // initialize lcd LCD_ClearDisplay(); UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); int x,y,z; uint8 Values; struct tic_tac_ai tta; tta_init(&tta,4,3,true,false); //first bool for player 1, second bool for player 2 disp_grid_init_ttc(&disp, tta.game.grid); disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); while (tta.game.game_not_won == 0){ Values = read_from_8255(Values); //read and print if (Values >= 0 && Values <= 63){ //integer value z = Values / 16; x = Values % 4; //get row value y = Values / 4 - z*4; // // LCD_ClearDisplay(); // LCD_PrintNumber(Values); // LCD_PrintString(" x"); // LCD_PrintNumber(x); // LCD_PrintString(" y"); // LCD_PrintNumber(y); // LCD_PrintString(" z"); // LCD_PrintNumber(z); } tta_step(&disp,&tta,x,y,z); //increment a turn disp_grid_transmit(&disp); } LCD_ClearDisplay(); LCD_PrintString("GAME OVER!"); disp_grid_draw_win(&disp,27,9,tta.game.player); // draw tic disp_grid_transmit(&disp); }
void main(void) { M8C_EnableGInt; LCD_Start(); // Start LCD LCD_Position(0,0); LCD_PrCString("PSoC I2C Slave"); EzI2Cs_SetRamBuffer(1, 1, (char *)&Wert); // Start I²C Buffer, Size of 1 Byte, Allowing to Read/Write 1 Byte I2C_Init(); while(1) { LCD_Position(1,0); LCD_PrCString("Wert:"); LCD_Position(2,0); LCD_PrHexInt(Wert); } }
void main(void) { //Note: Button is on P1[0] and sequence in is on P0[0] //Enable global interrupts M8C_EnableGInt; //CPU_F |= 0b00000001; //Enable interrupts for GPIO (switch) INT_MSK0 |= 0b00100000; //Start LCD for debug LCD_Start(); LCD_Init(); LCD_Position(0,0); LCD_PrCString("Start..."); while(1) { } }
void main_test_disp(){ LCD_Start(); // initialize lcd uint8 current; for (;;){ LCD_ClearDisplay(); LCD_Position(0,0); //move back to top row current = Pin0_Read(); //next, read a new value LCD_PrintString("P0: "); LCD_PrintNumber(current); //print value I am getting LCD_Position(1,0); //move to bot row current = Pin3_Read(); //next, read a new value LCD_PrintString("P3: "); LCD_PutChar(current); //print ascii value LCD_PrintString(" HEX: "); LCD_PrintNumber(current); //print value I am getting waiter(4); } }
int main() { //Blinky(); CyGlobalIntEnable; /* Enable global interrupts. */ // Enable the interrupt component connected to hallEffectSensor hallEffect_ISR_Start(); hallEffect_ISR_SetVector(hallEffectSensor); // Start components hallTickCounter_Start(); hallTickTimer_Start(); PWM_GateVoltage_Start(); // Start clocks deBounce_Start(); PWM_clock_Start(); //testClock_Start(); // Start LCD LCD_Start(); LCD_ClearDisplay(); for(;;) { /* Place your application code here. */ /* CyDelay(1000); Blinky(); LCD_Position(0u,0u); LCD_PrintU32Number(i); i++; */ } }
int main() { CyGlobalIntEnable; /* Enable global interrupts. */ // Set up LCD screen LCD_Start(); LCD_ClearDisplay(); rx_isr_StartEx(rx_isr); // start RX interrupt (look for CY_ISR with RX_INT address) // for code that writes received bytes to LCD. UART_Start(); // initialize UART UART_ClearRxBuffer(); // Check status message UART_PutString("AT\r\n"); CyDelay(1000);\ LCD_ClearDisplay(); // Set name to VizDude UART_PutString("AT+NAME=VizDude\r\n"); CyDelay(1000);\ LCD_ClearDisplay(); // Set rate to 115200 Baud, 1 stop bit, no parity UART_PutString("AT+UART=115200,1,0\r\n"); CyDelay(1000);\ LCD_ClearDisplay(); /* Place your initialization/startup code here (e.g. MyInst_Start()) */ for(;;) { /* Place your application code here. */ } }
void main(void) { LCD_Start(); LCD_Init(); LCD_InitBG(LCD_SOLID_BG ); PWM8_Start(); M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts INT_MSK0 |= 0x20; PRT0IE |= 0x01; PRT0DM0 = 0x01; //DM0[0-3] = 1 PRT0DM1 = 0x01; //DM1[0-3] = 0 PRT0DM2 = 0x00; //DM1[0-3] = 0 PRT0IC1 = 0x01; PRT0IC0 = 0x00; while(1){ if(pulsewidth==255){ pwDir = 1; } PWM8_WritePulseWidth(pulsewidth); LCD_DrawBG(0,0,16,pulsewidth/5); LCD_DrawBG(1,0,16,72); } }
/******************************************************************************* * Function Name: main ******************************************************************************** * Summary: * Main function performs following functions: * 1. Starts Character LCD and print project info * 2. Starts SPI Master component * 3. Configures the DMA transfer for RX and TX directions * 4. Displays the results on Character LCD * * Parameters: * None. * * Return: * None. * *******************************************************************************/ int main() { uint8 i; LCD_Start(); LCD_Position(0u,0u); LCD_PrintString("SPI Master"); LCD_Position(1u,0u); LCD_PrintString("example"); CyDelay(2000u); DmaTxConfiguration(); DmaRxConfiguration(); SPIM_Start(); CyDmaChEnable(rxChannel, STORE_TD_CFG_ONCMPLT); CyDmaChEnable(txChannel, STORE_TD_CFG_ONCMPLT); while (0u == (SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)) { } LCD_ClearDisplay(); LCD_PrintString("Master Rx data:"); LCD_Position(1u,0u); for(i=0u; i<BUFFER_SIZE; i++) { LCD_PrintHexUint8(rxBuffer[i]); } for(;;) { } }
void main(void){ unsigned char op = 0xFF; //0xFF is the SPI command for Soft Reset. //Initialize SPIM Module on the PSoC. spiInit(); //Start the LCD component. LCD_Start(); LCD_PrintString("SPI Init'd."); CyDelay(700); LCD_ClearDisplay(); //Send that Soft Reset Command. SPI_SEL(0); spiTxBuffer(&op,1); SPI_SEL(1); //Wait for the ENC chip to come back. CyDelay(1); LCD_PrintString("ENC Reset."); CyDelay(700); LCD_ClearDisplay(); /************************************** We will now try to turn on the LEDs on the Magjack. Steps: 1.Write to the PHLCON register,and turn on the LEDs. 1.1 Since its a PHY register,Write the address of the PHLCON register to into the MIREGADR register.(Which is why we select Bank 2 first by writing to ECON1.) 1.2 Write the lower 8 bits of data to write into the MIWRL register. 1.3 Write the upper 8 bits of data to write into the MIWRH register. Writing to this register auto- matically begins the MII transaction, so it must be written to after MIWRL. 2.Check the LEDs to see if they light up :-P 3.Say so on the LCD. ************************************************/ //Write Control Register Command for ECON1 // 010 11111 = 0x5F op = 0x5F; SPI_SEL(0); spiTxBuffer(&op,1); //Write 0x02 as we want to select bank 2. op = 0x02; spiTxBuffer(&op,1); SPI_SEL(1); //Write Control Register Command for MIREGADR Register. // 010 10100 = 0x54 op = 0x54; SPI_SEL(0); spiTxBuffer(&op,1); //Select PHLCON Register. op = 0x14; spiTxBuffer(&op,1); SPI_SEL(1); //Write Control Register Command for MIWRL Register. // 010 10110 = 0x56 op = 0x56; SPI_SEL(0); spiTxBuffer(&op,1); //Turn on LEDB. op = 0x80; spiTxBuffer(&op,1); SPI_SEL(1); LCD_PrintString("LEDB ON."); CyDelay(700); LCD_ClearDisplay(); //Write Control Register Command for MIWRL Register. // 010 10111 = 0x57 op = 0x57; //Write to MIWRH Reg SPI_SEL(0); spiTxBuffer(&op,1); //Turn on LEDA. op = 0x38; spiTxBuffer(&op,1); SPI_SEL(1); LCD_PrintString("LEDA ON."); CyDelay(700); LCD_ClearDisplay(); /************************************** We will now try to read the Silicon Revision. Steps: 1.Read from EREVID Register 1.1 Write to ECON 1 to Select Bank 3 1.2 Read the EREVID Register. (Mine gave 0x04) **************************************/ op = 0x5F; //Write to ECON1 Reg SPI_SEL(0); spiTxBuffer(&op,1); op = 0x03; //Write 3 as we want to select bank 3. spiTxBuffer(&op,1); SPI_SEL(1); op = 0x12; //Read EREVID Register SPI_SEL(0); spiTxBuffer(&op,1); spiRxBuffer(&op,1); SPI_SEL(1); LCD_PrintString("Silicon Revision"); LCD_Position(1,0); LCD_PrintInt8(op); for(;;); }
void main() { //Enable global interrupts M8C_EnableGInt; //Start LCD LCD_Start(); //Init LCD LCD_Init(); //Iniitalize pulsewidth FanPWM_WritePulseWidth(255); //Write label to LCD LCD_Position(0,0); LCD_PrCString("Pulse Width: ");//Begin writing at 0,13 LCD_Position(0,13); LCD_PrHexByte(FanPWM_bReadPulseWidth()); //Start Fan PWM FanPWM_Start(); //Enable FanPWM interrupt FanPWM_EnableInt(); while(1)//control loop { //Wait for sleep timer while(INT_CLR0 & 0b01000000 == 0){}//Wait for posted sleep timer interrupt //Clear sleep timer interrupt INT_CLR0 &= ~0b01000000; //Read switch input 3 times (debounce) if(PRT1DR & 0b00000001 == 0b00000001) //First read { if(PRT1DR & 0b00000001 == 0b00000001) //Second read { if(PRT1DR & 0b00000001 == 0b00000001) //Third read - Button has been pressed { LCD_Position(1,0); LCD_PrCString("Waitiing..."); while(PRT1DR & 0b00000001 == 0b00000001){}//Wait for button to be released LCD_Position(1,0); LCD_PrCString(" "); //Decrement pulse width FanPWM_WritePulseWidth(FanPWM_bReadPulseWidth() - 1); //Update display LCD_Position(0,13); LCD_PrHexByte(FanPWM_bReadPulseWidth()); } } } }//end control loop }
int main() { CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ XBee_UART_Start(); I2C_Start(); LCD_Start(); // INITIALIZE VALUES Command_Received = 0; MAG_DataRdy_Flag = 0; ReadyForCommand_Flag = 1; IncomingData_Flag = 0; StatusError_Flag = 0; //WaitForDataRead_Flag = 0; Command_Buffer = 0; // INITIALIZE ISRs InitXBee_Isr(); //InitINT1_Isr(); // IF INT1 TRIGGERS WHEN NOT IN ACTIVE MODE, MOVE INITIATION CODE FOR SETTING ACTIVE. //INT1_isr_Start(); XBee_UART_ClearRxBuffer(); XBee_UART_ClearTxBuffer(); CyDelay(2000); LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("MAG DRIVER:"); LCD_Position(1,0); LCD_PrintString("[ERR]"); LCD_Position(1,7); LCD_PrintString("[I2C]"); uint8 status = 0; status = SetCtrlReg1Default(); status |= SetCtrlReg2Default(); if(status !=0) { LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintInt8(status); status = 0; } uint8 pin_status = 0; for(;;) { pin_status = INT1_Pin_Read(); pin_status |= MAG_DataRdy_Flag; if(pin_status) { MAG_DataRdy_Flag = pin_status; if(ReadyForCommand_Flag!=0) { Command_Received = CMD_I_RM_MAGDATA; ReadyForCommand_Flag = 0; } } if(Command_Received != 0) { LCD_ClearDisplay(); //XBee_UART_ClearTxBuffer(); //XBee_UART_ClearRxBuffer(); switch (Command_Received){ case CMD_I_RM_MAGDATA: // CMD_I_RM_MAGDATA = 34 { status = ReadMagData(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); //LED_out_Write(0); CyDelay(500); XBee_UART_PutArray(Global_ReadPtr,ARRAY_SIZE_MAG_DATA); CyDelay(1000); //WaitForDataRead_Flag = 0; MAG_DataRdy_Flag = 0; if(Command_Buffer!=0) { Command_Received = Command_Buffer; Command_Buffer = 0; //ReadyForCommand_Flag = 0; //Dont toggle flag } else { Command_Received = 0; ReadyForCommand_Flag = 1; LED_out_Write(0); } } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WM_OFFSET_ALL:// CMD_I_WM_OFFSET_ALL = 1 { if(IncomingData_Flag == 0) // IF THE OFFSET DATA TO WRITE HAS BEEN RECEIVED... { status = WriteOffsetCorrection(DataInPtr_Global); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); //Sends confirmation TWICE. Once after receiving CMD, and again after finishing WRITE LED_out_Write(0); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } } break; case CMD_I_RS_CTRL1://CMD_I_RS_CTRL1=35 { status = ReadCtrlReg1(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_CTRL2://CMD_I_RS_CTRL2 = 36 { status = ReadCtrlReg2(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_DRSTATUS://CMD_I_RS_DRSTATUS = 37 { status = ReadDrStatus(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_SYSMOD:// CMD_I_RS_SYSMOD = 38 { status = ReadSysMod(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_DIETEMP: // CMD_I_RS_DIETEMP = 39 { status = ReadDieTemp(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RS_WHOAMI: // CMD_I_RS_WHOAMI = 40 { status = ReadWhoAmI(Global_ReadPtr); if(status == 0) { CyDelay(500); XBee_UART_PutChar(Command_Received); LED_out_Write(0); CyDelay(500); XBee_UART_PutChar(Global_ReadBuffer[0]); Command_Received = 0; IncomingData_Flag = 0; ReadyForCommand_Flag = 1; } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_DEFAULT: // CMD_I_WS_CTRL1_DEFAULT = 41 { status = SetCtrlReg1Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODSTANDBY: // CMD_I_WS_CTRL1_MODSTANDBY = 42 { status = SetStandbyMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODSINGLE: // CMD_I_WS_CTRL1_MODSINGLE = 43 { status = SetSingleMeasurmentMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; //IF INT1 CONTINUES TO TRIGGER WHEN NOT IT ACTIVE MODE, DEACTIVATE/ACTIVATE ISR WHEN CHANGING MODES case CMD_I_WS_CTRL1_MODACTIVE: // CMD_I_WS_CTRL1_MODACTIVE = 44 { status = SetContinuousMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_MODTRIGGER: // CMD_I_WS_CTRL1_MODTRIGGER = 45 { status = SetTriggerMeasurmentMode(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_ENFAST: // CMD_I_WS_CTRL1_ENFAST = 46 { status = SetFastReadOn(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL1_NENFAST: //CMD_I_WS_CTRL1_NENFAST = 47 { status = SetFastReadOff(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_DEFAULT: //CMD_I_WS_CTRL2_DEFAULT = 48 { status = SetCtrlReg2Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_ENAUTORESET: // CMD_I_WS_CTRL2_ENAUTORESET = 49 { status = SetAutoResetOn(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_NENAUTORESET: // CMD_I_WS_CTRL2_NENAUTORESET = 50 { status = SetAutoResetOff(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_ENUSEROFFSET: // CMD_I_WS_CTRL2_ENUSEROFFSET = 51 { status = SetUserCorrectedData(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_NENUSEROFFSET: // CMD_I_WS_CTRL2_NENUSEROFFSET = 52 { status = SetRawData(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) StatusError_Flag = 1; LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_WS_CTRL2_RESETMAG: // CMD_I_WS_CTRL2_RESETMAG = 53 { status = ResetMag(); if(status == 0) //if the write was a success { CyDelay(1000); //LET MAGNETOMETER RESET PROCEDURE FINISH XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; case CMD_I_RESET_ALL://54 { // RESET I2C uint8 i2c_status = I2C_MasterClearStatus(); //LCD_ClearDisplay(); LCD_Position(1,7); LCD_PrintInt8(i2c_status); I2C_MasterClearReadBuf(); I2C_MasterClearWriteBuf(); // Reset MAG CTRL REGISTERS status = SetCtrlReg1Default(); status |= SetCtrlReg2Default(); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); StatusError_Flag = 1; } } break; default: //handles Set Sampling/Data rate CMDs, and Out of range errors { if((Command_Received >= (STARTOFRANGE_SET_SAMPLING_AND_RATE))&&(Command_Received < (STARTOFRANGE_SET_SAMPLING_AND_RATE + RANGESIZE_SET_SAMPLING_AND_RATE))) { uint8 offset = Command_Received-STARTOFRANGE_SET_SAMPLING_AND_RATE; offset *=DELTAVALS_SET_SAMP_AND_RATE; status = SetOverSampleAndDataRate(offset); if(status == 0) //if the write was a success { CyDelay(500); XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation LED_out_Write(0); //Turns off LED Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command } else { // will result is a halt of CMD processing and leaves LED lit (visual error signal) StatusError_Flag = 1; //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:STA"); CyDelay(1000); } } else // ERROR: CMD VALUE OUT OF RANGE (executed if not a CMD to set sampling/data rate) { //CLEAR EVERYTHING XBee_UART_ClearTxBuffer(); XBee_UART_ClearRxBuffer(); I2C_MasterClearReadBuf(); I2C_MasterClearWriteBuf(); Command_Received = 0; //Clears the Command IncomingData_Flag = 0; ReadyForCommand_Flag = 1; // Sets state as READY for next command XBee_UART_PutChar(CMD_O_CMDVALUEOUTOFRANGE); //Send error msg //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("E:RAN"); CyDelay(1000); LED_out_Write(0); //Turns off LED } } } //END OF SWITCH-CASE }//end of IF statement encasing switch-case /*else // if(Command_Received == 0) { if((MAG_DataRdy_Flag==1) && (WaitForDataRead_Flag==0)) { //May change CMD_O_MAGDATARDY to simply be the same as CMD_I_RM_MAGDATA. //XBee_UART_ClearTxBuffer(); //LCD_ClearDisplay(); LCD_Position(1,0); LCD_PrintString("DRDY2"); XBee_UART_PutChar(CMD_O_MAGDATARDY);// CMD_O_MAGDATARDY = 55 WaitForDataRead_Flag = 1; //Prevents constant resending of notification to MATLAB INT1_isr_Disable(); } }*/ }//END OF FOR LOOP }//END OF MAIN
int main() { CyDelay(200); uint16 Counts=0; // ADC value (0 to 4095) right shifted by 6 which gives // us 0 to 63 to be used to simulate actual temperature uint16 TempSet = 2400; // Temperature set default value (left justified) 24 deg uint16 DisplayTemp = 0; // The combined sum of desired temp and actual temp uint16 bleTemp = 0; // Temperature sent to BLE module uint16 bleTempSet = 0; // Temperature set value sent to BLE module uint8 button0 = 0; // Declare CapSense button name button0 uint8 button1 = 0; // Declare CapSense button name button1 uint8 firstpress0 = 0; // Detects a transition of button1 from 0 to 1 uint8 firstpress1 = 0; // Detects a transition of button1 from 0 to 1 int buttonPrevious = 1; CyGlobalIntEnable; ADC_Start(); // Starts the ADC component ADC_StartConvert(); // The ADC conversion process begins LCD_Start(); // Start the LCD component CapSense_Start(); CapSense_ScanAllWidgets(); LCD_WritePixel(LCD_COLON, TRUE); ResetTimer_Start(); sendBootload_StartEx(StartBootload_ISR); BLEIOT_Start(); /* Initialize temperuature values out of range so that main loop update is triggered */ BLEIOT_updateTemperature(10000); BLEIOT_updatePot(100); for(;;) { /* Turn BLE on/off with button press */ if(buttonPrevious && (Button_Read() == 0)) { if(BLEIOT_remote.bleState == BLEIOT_BLEOFF) { BLEIOT_updateBleState(BLEIOT_BLEON); } else { BLEIOT_updateBleState(BLEIOT_BLEOFF); } } buttonPrevious = Button_Read(); /* Local Thermostat Operation */ /* ADC */ // Read the ADC, shift right by 6 (i.e. divide by 64) // and store result in Counts Counts = ADC_GetResult16(POT_CHAN); Counts = Counts >> 6; /* CapSense */ if (!CapSense_IsBusy()) { // Check Button states and store CapSense_ProcessAllWidgets(); if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) { button0 = 1; } else { button0 = 0; } if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID)) { button1 = 1; } else { button1 = 0; } // Light LEDs Based on Capsense buttons LED_CS0_Write(~button0); LED_CS1_Write(~button1); // Check for button touchdown transitions if (button0 == 1) { if(firstpress0 == 0) // Touchdown event { firstpress0 = 1; // Remember button0 was pressed TempSet = TempSet + 100; // Increment Temp by 1 deg } } else { firstpress0 = 0; // Button released } if (button1 == 1) { if(firstpress1 == 0) // Touchdown event { firstpress1 = 1; // Remember button0 was pressed TempSet = TempSet - 100; // Decrement Temp by 1 deg } } else { firstpress1 = 0; // Button released } CapSense_ScanAllWidgets(); // Start Next Scan } /* Warning LEDs and Buzzer */ if((Counts * 100) < TempSet) // Temperature Cold { LED_Blue_Write(LED_ON); // Blue On LED_Green_Write(LED_OFF); // Green Off LED_Red_Write(LED_OFF); // Red Off PWM_Stop(); // Buzzer Off } else if ((Counts * 100) <= (TempSet + 500)) // Temperature OK { LED_Blue_Write(LED_OFF); // Blue Off LED_Green_Write(LED_ON); // Green On LED_Red_Write(LED_OFF); // Red Off PWM_Stop();// Buzzer Off } else // Tempearture too high { LED_Blue_Write(LED_OFF); // Blue Off LED_Green_Write(LED_OFF); // Green Off LED_Red_Write(LED_ON); // Red On PWM_Start(); // Buzzer On } /* LCD Display */ DisplayTemp = TempSet + Counts; LCD_Write7SegNumber_0(DisplayTemp, POS, MODE); /* BLE operation - do only if BLE is not off */ if(BLEIOT_remote.bleState != BLEIOT_BLEOFF) { /* Send new temperature data to the BLE module */ if(bleTemp != Counts) { bleTemp = Counts; BLEIOT_updatePot(bleTemp); } if(bleTempSet != TempSet) { bleTempSet = TempSet; /* Scale set temperature down to whole number of degrees */ BLEIOT_updateTemperature(TempSet / 100); } /* Get new data from the BLE module */ /* LED0 is used for temperature changes */ if(BLEIOT_getDirtyFlags() & BLEIOT_FLAG_LED0) { /* Update local variable copy and clear dirty flag */ BLEIOT_updateLed0(BLEIOT_remote.led0); if(BLEIOT_local.led0 == UP) { TempSet = TempSet + 100; // Increment Temp by 1 deg } else if (BLEIOT_local.led0 == DOWN) { TempSet = TempSet - 100; // Decrement Temp by 1 deg } } } /* End of !BLEOFF state operations */ } /* End of superloop */ } /* End of main */
void main_flashing_tta(){ // this is the function compatible with the cap sensor input. does not use 8051; connect directly LCD_Start(); // initialize lcd LCD_ClearDisplay(); UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); struct tic_tac_ai tta; tta_init(&tta,4,3,false,true); //first bool for player 1, second bool for player 2. true means is AI disp_grid_init_ttc(&disp, tta.game.grid); disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); int x,y,z, count; uint8 Values; uint8 Values_prev; Values_prev = Pin0_Read(); x = 0; y = 0; z = 0; //test value count = 0; uint8 red_flash; //the temporary location flasher uint8 other_val; other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val red_flash = 0x30; //map to color red tta_step(&disp,&tta,x,y,z); //AI Increment also while (tta.game.game_not_won == 0){ // Values = read_from_8255(Values); //read and print LCD_ClearDisplay(); LCD_Position(0,0); //move back to top row Values = Pin0_Read(); //next, read a new value LCD_PrintString("P0: "); LCD_PrintNumber(Values); //print value I am getting if (Values != Values_prev){ Values_prev = Values; //we don't want nonconsect if (Values != 0){ if (Values == 32){ tta_step(&disp,&tta,x,y,z); //increment a turn tta_step(&disp,&tta,x,y,z); //AI Increment also other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val } else{ disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val); if (Values == 16 && y != 0){ // up y--; } else if (Values == 8 && y != 3){ // down y++; } else if (Values == 4 && x != 0){ // left x--; } else if (Values == 2 && x != 3){ // right x++; } else if (Values == 1){ // level shift z++; z = z % 4; } other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val } } } if (count == 0){ //decide print count = 1; disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,red_flash); } else{ count = 0; disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val); } disp_grid_transmit(&disp); } LCD_ClearDisplay(); LCD_PrintString("GAME OVER!"); }
void main(void) { M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts M8C_EnableIntMask(INT_MSK1, INT_MSK1_DBB01); // Enable DBB01 Interrupt for TempCounter M8C_EnableIntMask(INT_MSK1, INT_MSK1_DBB11); // Enable DBB01 Interrupt for MotorDriver M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO); // Enable GPIO interrupt for Tout // Start the UART(with no parity), LCD, TempCounter and MotorDriver UART_Start(UART_PARITY_NONE); LCD_Start(); TempCounter_EnableInt(); // Enable interrupts for counter TempCounter_Start(); MotorDriver_EnableInt(); // Enable interrupts for counter // Start I2CHW I2CHW_Start(); I2CHW_EnableMstr(); I2CHW_EnableInt(); WriteI2C(slaveAddress, 0xAC, 1, 0x02); // Write to access config, sets mode to cooling(POL = 1), also turns 1-SHOT off, continuous conversions WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets initial high temp to be setTemp + tolerance WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets initial low temp to be setTemp - tolerance WriteI2C(slaveAddress, 0xEE, 0); // This tells the temperature IC to start converting the temperatures // Writes initial string to LCD. When LCD is updated, only the numbers will be changed LCD_Position(0,0); LCD_PrCString("CUR: 00 OFF "); LCD_Position(1,0); LCD_PrCString("SET: 00 FAN OFF "); // This is the command usage string UART_CPutString("#################### Heating/Cooling Stepper Motors ##################\r\n\ # S ##\r\n\ # S - Set the desired Temperature\r\n\ # ## - Desired temperature in celsius\r\n\ #\r\n\ # T ##\r\n\ # T - Set the desired tolerance\r\n\ # ## - Desired tolerance in celsius\r\n\ #\r\n\ # M X\r\n\ # M - Change the mode of the thermostat\r\n\ # X - C is for cool, H is for heat, F is for off\r\n\ #\r\n\ # F X S\r\n\ # F - Change the mode of the fan\r\n\ # X - A is for automatic fan control, M is for always on\r\n\ # S - Speed of the fan, H = high, M = medium, L = low\r\n\ #####################################################################\r\n"); while (1) { char *cmd; char *params; if (GetLine(buf, &strPos, 79)) // Only process the data if GetLine returns true { cmd = Lowercase(cstrtok(buf, " ")); // Lowercase the first word from the inputted string if (strlen(cmd) == 1 && cmd[0] == 's') // If the person entered s { int temp; params = cstrtok(0x00, " "); // Read next word // If next word isnt number or isnt 1 or 2 characters long, then return error if (!IsNumber(params) || strlen(params) < 1 || strlen(params) > 2 || csscanf(params, "%d", &temp) != 1) goto error; // If there is additional data at end of string or if number is not within 0-99, return error if (cstrtok(0x00, " ") != 0x00) goto error; if ( temp > 99 || temp < 0) goto error; setTemp = temp; WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets high temp to be setTemp + tolerance WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets low temp to be setTemp - tolerance updateLCD = TRUE; // Update the LCD } else if (strlen(cmd) == 1 && cmd[0] == 't') // If the person entered t { int tol; params = cstrtok(0x00, " "); // Read next word // If next word isnt number or isnt 1 or 2 characters long, then return error if (!IsNumber(params) || strlen(params) < 1 || strlen(params) > 2 || csscanf(params, "%d", &tol) != 1) goto error; // If there is additional data at end of string or if number is not within 0-10, return error if (cstrtok(0x00, " ") != 0x00) goto error; if (tol < 0 || tol > 10) goto error; tolerance = tol; WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets high temp to be setTemp + tolerance WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets low temp to be setTemp - tolerance updateLCD = TRUE; // Update the LCD } else if (strlen(cmd) == 1 && cmd[0] == 'm') // If the person entered m { char mode; params = cstrtok(0x00, " "); // Read next word // If next word isnt 1 character long, return error if (strlen(params) != 1 || csscanf(params, "%c", &mode) != 1) goto error; // If there is additional data at end of string, return error if (cstrtok(0x00, " ") != 0x00) goto error; mode = tolower(mode); // Lowercase the character switch (mode) { case 'h': thermostatMode = 1; // Set mode to heating WriteI2C(slaveAddress,0xAC, 1, 0x00); // Change access config on DS1621 to heating(POL = 0) break; case 'c': thermostatMode = 2; // Set mode to cooling WriteI2C(slaveAddress, 0xAC, 1, 0x02); // Change access config on DS1621 to cooling(POL = 1) break; case 'f': thermostatMode = 0; // Set mode to off break; default: goto error; // Invalid character entered, goto error } CheckFan(); // Check the fan to see if it should be on } else if (strlen(cmd) == 1 && cmd[0] == 'f') // If the person entered f { char mode; char speed; params = cstrtok(0x00, " "); // Read next word // If next word isnt 1 character long, then return error if (strlen(params) != 1 || csscanf(params, "%c", &mode) != 1) goto error; params = cstrtok(0x00, " "); // Read next word // If next word isnt 1 character long, then return error if (strlen(params) != 1 || csscanf(params, "%c", &speed) != 1) goto error; // If there is additional data at end of string, return error if (cstrtok(0x00, " ") != 0x00) goto error; speed = tolower(speed); // Lowercase the speed and mode characters entered mode = tolower(mode); switch (mode) { case 'm': fanMode = 0; // Set fan mode to manual break; case 'a': fanMode = 1; // Set fan mode to automatic break; default: // Otherwise go to error goto error; } MotorDriver_Stop(); // Stop the motor to change the period values switch (speed) { case 'l': fanSpeed = 0; // Set fan speed to low MotorDriver_WritePeriod(49999); // See report for where these numbers came from MotorDriver_WriteCompareValue(25000); break; case 'm': fanSpeed = 1; // Set fan speed to medium MotorDriver_WritePeriod(9999); // See report for where these numbers came from MotorDriver_WriteCompareValue(5000); break; case 'h': fanSpeed = 2; // Set fan speed to high MotorDriver_WritePeriod(1999); // See report for where these numbers came from MotorDriver_WriteCompareValue(1000); break; default: // Otherwise go to error if invalid input entered goto error; } CheckFan(); // Check the fan to see if it should be on } else goto error; } if (checkTemp) // Check the temperature { char buf[2]; ReadI2C(slaveAddress, 0xAA, 2, buf); // Read the temperature from IC, returns 2 bytes curTemp = buf[0]; // We just care about the first byte checkTemp = FALSE; // Turn flag off so it doesnt keep doing this } if (updateLCD) // Update the LCD { char buf[3]; NumToStr(buf, curTemp, 2); // Convert current temp to str LCD_Position(0, 5); LCD_PrString(buf); // Print it LCD_Position(0, 8); switch(thermostatMode) // Print thermostat mode { case 0: LCD_PrCString("OFF "); break; case 1: LCD_PrCString("HEAT"); break; case 2: LCD_PrCString("COOL"); break; } NumToStr(buf, setTemp, 2); // Convert set temp to str LCD_Position(1, 5); LCD_PrString(buf); // Print it LCD_Position(1, 12); if (fanMode == 1 && thermostatMode == 0) LCD_PrCString("OFF"); // Print current fan state else if (fanSpeed == 0) LCD_PrCString("LOW"); else if (fanSpeed == 1) LCD_PrCString("MED"); else if (fanSpeed == 2) LCD_PrCString("HI "); updateLCD = FALSE; } continue; error: UART_CPutString("# Invalid format entered. Valid formats are:\r\n\ # S ##\r\n\ # S - Set the desired Temperature\r\n\ # ## - Desired temperature in celsius\r\n\ #\r\n\ # T ##\r\n\ # T - Set the desired tolerance\r\n\ # ## - Desired tolerance in celsius\r\n\ #\r\n\ # M X\r\n\ # M - Change the mode of the thermostat\r\n\ # X - C is for cool, H is for heat, F is for off\r\n\ #\r\n\ # F X S\r\n\ # F - Change the mode of the fan\r\n\ # X - A is for automatic fan control, M is for always on\r\n\ # S - Speed of the fan, H = high, M = medium, L = low\r\n\ #####################################################################\r\n"); } }
void main_flashing_tta_psoc(){ // this is the function compatible with the cap sensor input. with 8051 interrupts LCD_Start(); // initialize lcd LCD_ClearDisplay(); UART_Start(); // initialize UART UART_PutChar(0x81); // init connection; set to 16x12 image struct disp_grid_81 disp; disp_grid_init(&disp,0x3F); // init our display grid matrix to white disp_grid_transmit(&disp); struct tic_tac_ai tta; tta_init(&tta,4,3,false,true); //first bool for player 1, second bool for player 2. true means is AI disp_grid_init_ttc(&disp, tta.game.grid); disp_grid_draw_tic(&disp,24,1,0x27); // draw tic disp_grid_draw_xia(&disp,26,16,0x30); // draw xia disp_grid_transmit(&disp); int x,y,z, count; uint8 Values; uint8 Values_prev; uint8 current; Values_prev = 0; x = 0; y = 0; z = 0; //test value count = 0; uint8 red_flash; //the temporary location flasher uint8 other_val; other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val red_flash = 0x30; //map to color red while (tta.game.game_not_won == 0){ LCD_ClearDisplay(); LCD_Position(1,0); //move to bot row LCD_PrintString("LAST:"); //first, we print last value LCD_PutChar(Values_prev); //print ascii value LCD_PrintString(" HEX: "); LCD_PrintNumber(Values_prev); //print value I am getting current = Pin3_Read(); //next, read a new value LCD_Position(0,0); //move back to top row LCD_PrintString("CURR:"); LCD_PutChar(current); //print ascii value LCD_PrintString(" HEX: "); LCD_PrintNumber(current); //print value I am getting waiter(3); if (current != 255) { Values = current; // update values as last non Values_prev = Values; } if (Values != 0){ if (Values == 54){ if (tta.game.grid[z*16 + y*4 + x] == 0){ // make sure we can place there tta_step(&disp,&tta,x,y,z); //increment a turn disp_grid_transmit(&disp); tta_step(&disp,&tta,x,y,z); //AI Increment also other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val } } else{ disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val); if (Values == 53 && y != 0){ // up y--; } else if (Values == 52 && y != 3){ // down y++; } else if (Values == 51 && x != 0){ // left x--; } else if (Values == 50 && x != 3){ // right x++; } else if (Values == 49){ // level shift z++; z = z % 4; } other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val } Values = 0; // reset values; count = 0; } if (count == 0){ //decide print count = 1; disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,red_flash); disp_grid_transmit(&disp); } // else{ // count = 0; // disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val); // disp_grid_transmit(&disp); // } } LCD_ClearDisplay(); LCD_PrintString("GAME OVER!"); disp_grid_draw_win(&disp,27,9,tta.game.player); // draw tic disp_grid_transmit(&disp); }
int main() { pedal_node_state = pedal_state_neutral; LCD_Start(); CAN_invertor_init(); ADC_SAR_Start(); ADC_SAR_StartConvert(); EEPROM_Start(); //isr_Start(); //Timer_Start(); CAN_timer_Start(); CAN_Init(); CAN_Start(); isr_start_StartEx(&isr_start_handler); Start_Reset_Write(1); /* source of interrupt (reset) */ isr_start_ClearPending(); isr_neutral_StartEx(&isr_neutral_handler); Neutral_Reset_Write(1); isr_neutral_ClearPending(); isr_calibration_StartEx(&isr_calibration_handler); CyGlobalIntEnable; //enable global interrupts //Initialize terminal terminal_init(); monitor_init(); pedal_restore_calibration_data(); //set min and max values pedal_set_CAN(); //Setup tunnel from pedal control to CAN pedal_set_monitor(); //Setup tunnel from pedal control to USB Monitor // Initialize global variables EEPROM_ERROR_LED_Write(0); should_calibrate = false; // terminal_registerCommand("newCmd", &newCmdRout); sendNMT(NMT_command_startRemoteNode); CyDelay(1000); pedal_node_state = pedal_state_driving; for(;;){ pedal_fetch_data(); } for(;;) { CyDelay(50); terminal_run(); // Refresh terminal if (pedal_node_state == pedal_state_neutral) { if (should_calibrate) { pedal_node_state = pedal_state_calibrating; } else if (should_turn_to_drive) { pedal_node_state = pedal_state_driving; //Start sending can message for invertor CAN_invertor_resume(); } } else if (pedal_node_state == pedal_state_driving) { if (should_turn_to_neutral) { pedal_node_state = pedal_state_neutral; //Stop sending messages for invertor CAN_invertor_pause(); } } //Clear all flags after handling should_calibrate = false; should_turn_to_drive = false; should_turn_to_neutral = false; uint8_t out_of_range_flag; double brake_percent = 0, throttle_percent = 0; double brake_percent_diff = 0, throttle_percent_diff = 0; uint8_t torque_plausible_flag; uint8_t brake_plausible_flag; pedal_fetch_data(); //Update ADC readings CAN_invertor_update_pedal_state(pedal_node_state); monitor_update_vechicle_state(pedal_node_state); //Update vecicle state monitor_status_update_vehicle_state(pedal_node_state); switch (pedal_node_state) { case pedal_state_neutral: LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("NEUTRAL"); break; case pedal_state_driving: LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("DRIVING"); //out_of_range_flag = pedal_get_out_of_range_flag(); if (out_of_range_flag != 0) { pedal_node_state = pedal_state_out_of_range; break; } torque_plausible_flag = pedal_is_pedal_reading_matched(&brake_percent_diff, &throttle_percent_diff); if (torque_plausible_flag != 0) { pedal_node_state = pedal_state_discrepency; break; } brake_plausible_flag = pedal_is_brake_plausible(&brake_percent, &throttle_percent); if (brake_plausible_flag != 0) { pedal_node_state = pedal_state_implausible; break; } break; case pedal_state_calibrating: //clock_StopBlock(); //stop clock to disable interrupt pedal_calibrate(); LCD_ClearDisplay(); //isr_ClearPending(); //clock_Start(); // isr_calibration_Enable(); pedal_node_state = pedal_state_neutral; break; case pedal_state_out_of_range: LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("Pedal out of"); LCD_Position(1,0); LCD_PrintString("range"); out_of_range_flag = pedal_get_out_of_range_flag(); if (out_of_range_flag == 0) { pedal_node_state = pedal_state_driving; } break; case pedal_state_discrepency: LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("Pedal discrepency"); torque_plausible_flag = pedal_is_pedal_reading_matched(&brake_percent_diff, &throttle_percent_diff); if (torque_plausible_flag == 0) { pedal_node_state = pedal_state_driving; } break; case pedal_state_implausible: LCD_ClearDisplay(); LCD_Position(0,0); LCD_PrintString("Pedal implausible"); brake_plausible_flag = pedal_is_brake_plausible(&brake_percent, &throttle_percent); if (throttle_percent < PEDAL_BRAKE_IMPLAUSIBLE_EXIT_THROTTLE_PERCENT) { pedal_node_state = pedal_state_driving; } break; } // CyDelay(100); } return 0; }
void main(void) { // Enable Global Interrupt M8C_EnableGInt; // Clear the flags FlagsElevator = 0; FlagsAileron = 0;// new for motorcontroll2 FlagUltrasoon = 0; // Start timers and enable interrupt Timer1_Start(); Timer1_EnableInt(); Timer2_Start();// new for motorcontroll2 Timer2_EnableInt();// new for motorcontroll2 Timer3_Start(); Timer3_EnableInt(); TriggerUltrasoon(); // Init motors PWM1_Start(); PWM2_Start(); #if (DEBUG_LCD) LCD_Start(); #endif while (TRUE) { float aileronNormalized, elevatorNormalized; float distance; float speed, direction; float motorLeft, motorRight; BOOL forward; aileronNormalized = EvaluateAileron(PulseWidthAileron); direction = fabs(aileronNormalized); elevatorNormalized = EvaluateElevator(PulseWidthElevator); speed = fabs(elevatorNormalized); forward = (elevatorNormalized >= 0); distance = EvaluateUltrasoonSensor(); if (distance < MIN_SAFE_DISTANCE) { if (forward) speed = 0; } motorLeft = speed; // default is straight forward motorRight = speed; if (aileronNormalized < 0) // turning left { motorRight = speed; motorLeft = speed * (1 - direction); } else if (aileronNormalized > 0) // turning right { motorLeft = speed; motorRight = speed * (1 - direction); } if (forward) { // ccw PRT1DR |= 0x08; // AIN1 PRT1DR &= ~0x02; // AIN2 PRT1DR |= 0x20; // BIN1 PRT1DR &= ~0x80; // BIN2 } else { //cw PRT1DR &= ~0x08; // AIN1 PRT1DR |= 0x02; // AIN2 PRT1DR &= ~0x20; // BIN1 PRT1DR |= 0x80; // BIN2 } // Denormalize to Engine motorLeft *= (MAX_POWER - MIN_POWER); motorLeft += MIN_POWER; motorRight *= (MAX_POWER - MIN_POWER); motorRight += MIN_POWER; PWM1_WritePulseWidth(motorLeft); PWM2_WritePulseWidth(motorRight); #if (DEBUG_LCD) LCD_Position(0,7); LCD_PrHexInt(motorLeft); LCD_Position(1,7); LCD_PrHexInt(motorRight); LCD_Position(0,12); LCD_PrCString(forward ? "F" : "B"); #endif } }
void main(void) { unsigned long temp_ulong; INT temp_int, temp_int2; BYTE temp_byte; AMUX4_0_InputSelect(AMUX4_0_PORT0_1); AMUX4_1_InputSelect(AMUX4_1_PORT0_0); INSAMP_Start(INSAMP_LOWPOWER); ADCINC_Start(ADCINC_HIGHPOWER); DAC9_Ia_Start(DAC9_Ia_HIGHPOWER); DAC6_VGND_Start(DAC6_VGND_MEDPOWER); DAC6_VGND_WriteStall (31); PWM8_Vout_DisableInt(); PWM8_Vout_Start(); PWM8_Heater_DisableInt(); PWM8_Heater_Start(); PWM8_NB_Out_DisableInt(); PWM8_NB_Out_Start(); ADCINC_GetSamples(0); SleepTimer_Start(); SleepTimer_SetInterval(SleepTimer_512_HZ); SleepTimer_EnableInt(); M8C_EnableGInt ; LCD_Start(); // Initialize LCD LCD_InitBG(LCD_SOLID_BG); while(1) { temp_ulong++; if ((ADC_IF & 1) == 1) { ADC_IF = ADC_IF & 254; Ri_Min = IIR_Int(Ri_Min_x1*2,Ri_Min,Ri_Filter_Strength); Ri_Delta = Ri_Max - Ri_Min; Ri_Mid = (Ri_Max + Ri_Min) / 2; } if ((ADC_IF & 2) == 2) { ADC_IF = ADC_IF & 253; Ri_Max = IIR_Int(Ri_Max_x1 * 2, Ri_Max, Ri_Filter_Strength); Ri_Delta = Ri_Max - Ri_Min; Ri_Mid = (Ri_Max + Ri_Min) / 2; } if ((ADC_IF & 4) == 4) { ADC_IF = ADC_IF & 251; ip = IIR_Int(ip_x1 * 2, ip, ip_Filter_Strength); } Ia_PID_Counter += Sleep_Counter; Heater_PID_Counter += Sleep_Counter; Heatup_Counter += Sleep_Counter; Vout_Lookup_Counter += Sleep_Counter; LCD_Counter += Sleep_Counter; Sleep_Counter = 0; if (Ia_PID_Counter > Ia_PID_Counter_Set) { Ia_PID_Counter = 0; Ia_PID(); } if (Heater_PID_Counter > Heater_PID_Counter_Set) { Heater_PID_Counter = 0; Heater_PID(); } if (Vout_Lookup_Counter > Vout_Lookup_Counter_Set) {} Vout_Lookup_Counter = 0; temp_int = ip - ip_to_Vout_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Vout_Lookup_Size - 1)) { temp_int = (ip_to_Vout_Lookup_Size - 1); } PWM8_Vout_WritePulseWidth(ip_to_Vout_Lookup[temp_int]); #ifdef NB_Out temp_byte = 23;//0.45v if (ip < 251) { // 251 =0.9797787392968 temp_byte = 46; //0.9v } else if (ip > 259) { //259 = 1.02295956968912 temp_byte = 0; //0v } PWM8_NB_Out_WritePulseWidth(temp_byte); #endif } if (LCD_Counter > LCD_Counter_Set) { LCD_Counter = 0; #ifdef LCD_Lambda_Text temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) { temp_int=(ip_to_Lambda_Lookup_Size - 1); } Lambda_x100 = ip_to_Lambda_Lookup[temp_int]; temp_int = Lambda_x100; LCD_Position(0,0); temp_int2 = temp_int / 100; Str1[9] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str1[11] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str1[12] = btoa(temp_int); LCD_PrString(Str1); #endif #ifdef LCD_AFR_Text temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) { temp_int = (ip_to_Lambda_Lookup_Size - 1); } Lambda_x100=ip_to_Lambda_Lookup[temp_int]; temp_int = (INT) Lambda_x100 * 147; LCD_Position(0,0); temp_int2 = temp_int / 1000; Str1[6] = btoa(temp_int2); temp_int = temp_int - (1000 * temp_int2); temp_int2 = temp_int / 100; Str1[7] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str1[9] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str1[10] = btoa(temp_int); LCD_PrString(Str1); #endif #ifdef LCD_Lambda_Graph temp_int = ip - ip_to_Lambda_Lookup_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (ip_to_Lambda_Lookup_Size-1)) { temp_int = (ip_to_Lambda_Lookup_Size - 1); } Lambda_x100 = ip_to_Graph_Lookup[temp_int]; LCD_DrawBG(0, 0, 16, Lambda_x100); #endif #ifdef LCD_Temperature_Text temp_int = Ri_Delta-Ri_Delta_to_Temperature_C_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) { temp_int = (Ri_Delta_to_Temperature_C_Size - 1); } LSU_Temperature_C = Ri_Delta_to_Temperature_C[temp_int] + Ri_Delta_to_Temperature_C_Offset; temp_int = LSU_Temperature_C; LCD_Position(1,0); temp_int2 = temp_int / 100; Str2[7] = btoa(temp_int2); temp_int = temp_int - (100 * temp_int2); temp_int2 = temp_int / 10; Str2[8] = btoa(temp_int2); temp_int = temp_int - (10 * temp_int2); Str2[9] = btoa(temp_int); LCD_PrString(Str2); #endif #ifdef LCD_Temperature_Graph temp_int = Ri_Delta - Ri_Delta_to_Temperature_C_Start; if (temp_int < 0) { temp_int = 0; } else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) { temp_int = (Ri_Delta_to_Temperature_C_Size - 1); } LSU_Temperature_C = Ri_Delta_to_Graph[temp_int]; LCD_DrawBG(1, 0, 16, LSU_Temperature_C); #endif } if (Heatup_Heater_Output < 255) { if (Heatup_Counter > Heatup_Counter_Set) { Heatup_Counter = 0; Heatup_Heater_Output++; } if ((Ri_Min > 50) && (Ri_Max < 475) && (Ri_Delta < Ri_Delta_Target)) { Heatup_Heater_Output = 255; Ri_Delta_Error_Sum = 0; } } }
/******************************************************************************* * Function name: DisplayConfig ******************************************************************************** * * Summary: * initialization display * *******************************************************************************/ void DisplayStart(void) { LCD_Start(); }