void main(void) { M8C_EnableGInt; // Uncomment this line to enable Global Interrupts CPU_F |= 0b00000001; INT_MSK1 |= 0b00000001; //Insert your main routine code here. //Enable PWM PWM_Start(); PWM_EnableInt(); //Enable LCD for debugging LCD_Start(); LCD_Init(); while(1)//Control loop { LCD_Position(0,0); LCD_PrHexByte(PWM_bReadPulseWidth()); LCD_Position(1,0); LCD_PrHexByte(ten_ms_counter); LCD_Position(0,6); LCD_PrHexByte(PWM_bReadCounter()); }//End Control Loop }
void main(void) { // Insert your main routine code here. LCD_Start(); LCD_Init(); LCD_Position(1,4); DBB00_WritePulseWidth(pulseWidth); DBB00_Start(); DBB00_EnableInt(); LCD_PrHexByte(DBB00_bReadPulseWidth()); INT_MSK0 |= 0x40; M8C_EnableGInt; while(1){ prt1 = PRT1DR; prt1 &= 0x01; if(prt1 == 0x01){ dBounce++; if(dBounce == 3){ pulseWidth--; DBB00_WritePulseWidth(pulseWidth); dBounce = 0; } } else { dBounce = 0; } LCD_Position(0,4); LCD_PrHexByte(dBounce); LCD_Position(1,4); LCD_PrHexByte(DBB00_bReadPulseWidth()); } }
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 }
void ButtonDown() { //Not needed //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 { while(PRT1DR & 0b00000001 == 0b00000001){}//Wait for button to be released //Decrement pulse width FanPWM_WritePulseWidth(FanPWM_bReadPulseWidth() - 1); //Update display LCD_Init(); LCD_Position(0,0); LCD_PrCString("Pulse Width: "); LCD_Position(0,13); LCD_PrHexByte(FanPWM_bReadPulseWidth()); } } } }
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 updateLCD() { //Clear LCD LCD_Init(); //Print month if(blinkState == 0 && state == 2) { //Do not print } else { //Print month LCD_Position(0,0); LCD_PrHexByte(month); } LCD_Position(0,2); LCD_PrCString("/"); //Print day if(blinkState == 0 && state == 3) { //Do not print } else { //Print day LCD_Position(0,3); LCD_PrHexByte(day); } LCD_Position(0,5); LCD_PrCString("/"); //Print year if(blinkState == 0 && state == 4) { //Do not print } else { //Print year LCD_Position(0,6); LCD_PrHexByte(year); } }
void RegTimeView_Update(void) { BYTE startMin10, startMin, endMin10, endMin, startHour10, startHour, endHour10, endHour; Config conf; Persist_LoadConfig(&conf); if(Keypad_IsKeyStored()) { switch(Keypad_GetKey()) { case 0x88: // "1" // start h up if(conf.registerStart.hour < 23) { conf.registerStart.hour++; } Persist_SaveConfig(&conf); break; case 0x84: // "2" // start min up if(conf.registerStart.min < 59) { conf.registerStart.min++; } Persist_SaveConfig(&conf); case 0x48: // "4" // start h down if(conf.registerStart.hour > 0) { conf.registerStart.hour--; } Persist_SaveConfig(&conf); break; case 0x44: // "5" // start min down if(conf.registerStart.min > 0) { conf.registerStart.min--; } Persist_SaveConfig(&conf); break; case 0x28: // "7" // end h up if(conf.registerEnd.hour < 23) { conf.registerEnd.hour++; } Persist_SaveConfig(&conf); break; case 0x24: // "8" // end min up if(conf.registerEnd.min < 59) { conf.registerEnd.min++; } Persist_SaveConfig(&conf); break; case 0x18: // "*" // end h down if(conf.registerEnd.hour > 0) { conf.registerEnd.hour--; } Persist_SaveConfig(&conf); break; case 0x14: // "0" // end min down if(conf.registerEnd.min > 0) { conf.registerEnd.min--; } Persist_SaveConfig(&conf); break; case 0x11: // "D" MainView_Callback(); return; break; } } decToBcd(&startHour10, &startHour, conf.registerStart.hour); startHour = (startHour10 << 4) | startHour; decToBcd(&startMin10, &startMin, conf.registerStart.min); startMin = (startMin10 << 4) | startMin; decToBcd(&endHour10, &endHour, conf.registerEnd.hour); endHour = (endHour10 << 4) | endHour; decToBcd(&endMin10, &endMin, conf.registerEnd.min); endMin = (endMin10 << 4) | endMin; LCD_Position(0, 0); LCD_PrCString("Inicio: "); LCD_PrHexByte(startHour); LCD_PrCString(":"); LCD_PrHexByte(startMin); LCD_Position(1,0); LCD_PrCString("Fin: "); LCD_PrHexByte(endHour); LCD_PrCString(":"); LCD_PrHexByte(endMin); }
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 }