void main(){ OUTPUT_LOW(LCD_RW); //Che do ghi LCD_Init(); //Khoi tao LCD LCD_PutCmd(0x01); //Xoa man hinh ENABLE_INTERRUPTS(INT_TIMER0); //Kich hoat ngat ngoai SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_32); //Xung kich noi va chia truoc 32 ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc SET_TIMER0(100); //Bat dau dem tu 100, khi tran Timer0 duoc 1ms while (True){ //Duy tri hoat dong cua vi dieu khien if (dem > N_max){ dem = 0; LCD_PutCmd(0x01); } LCD_SetPosition(0x00); //Cot 1 dong 1 LCD_PutChar("Dem so:"); LCD_SetPosition(0x07); //Cot 8 dong 1 printf(LCD_PutChar,"%lu",dem); } }
/************************************************************* * 函数名称:LCD_DrawRec * 功 能:在指定位置画矩形 * 参 数: * x: 窗体中X坐标中始点 * y: 窗体中Y坐标中始点 * Length:条形的长 * High: 矩形的高 * Colour:矩形的颜色 * 返 回 值:无 *************************************************************/ void LCD_DrawRec(u16 x,u16 y,u16 Length,u16 High,u16 Colour) { u16 i; if(horizontal_or_vertical) //横屏显示时 { if(x+Length>320) Length=320-Length; if(High+y>240) High=240-High; LCD_SetPosition(x,y); LCD_WR_CMD(0X0044,((High+y-1)<<8)+y); LCD_WR_CMD(0X0046,x+Length); } else //竖屏显示时 { if(x+Length>240) Length=240-Length; if(High+y>320) High=320-High; LCD_SetPosition(x,y); LCD_WR_CMD(0X0044,((Length+x-1)<<8)+x); LCD_WR_CMD(0X0046,y+High); } LCD_WR_ADD(0x0022); for(i=0;i<Length*High;i++) { LCD_WR_DATA(Colour); } }
void main(){ float distance = 0; OUTPUT_LOW(LCD_RW); LCD_Init(); LCD_PutCmd(0x01); SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_4); SETUP_CCP1(CCP_CAPTURE_RE); ENABLE_INTERRUPTS(INT_CCP1); ENABLE_INTERRUPTS(GLOBAL); while (True){ Trigger(); while (echo == 0){ ; } distance = value*0.8/58; LCD_PutCmd(0x01); LCD_SetPosition(0x00); LCD_PutChar("Distance:"); LCD_SetPosition(0x40); printf(LCD_PutChar,"%.2fcm",distance); delay_ms(1000); } }
signed char DisplayMenu(const char *Menu[], char ItemCount, char Initial) { char SecondLine = 0; signed char SelectedItem = 0; signed char ret = 0; SelectedItem = Initial; while (1) { LCD_ClearDisplay(); if (SecondLine) { LCD_SetPosition(0, 1); if (SelectedItem == 0) LCD_PrintString(Menu[ItemCount]); else LCD_PrintString(Menu[SelectedItem - 1]); LCD_SetPosition(1, 0); LCD_PrintChar('*'); LCD_PrintString(Menu[SelectedItem]); LCD_SetPosition(1, 0); } else { LCD_PrintChar('*'); LCD_PrintString(Menu[SelectedItem]); LCD_SetPosition(1, 1); if (SelectedItem == ItemCount) LCD_PrintString(Menu[0]); else LCD_PrintString(Menu[SelectedItem + 1]); LCD_SetPosition(0, 0); } ret = GetInput(); if (ret < 0) { SelectedItem = ret; goto exit; } switch (ret) { case USER_INPUT_CLICK: goto exit; case USER_INPUT_BACK: SelectedItem = -1; goto exit; case USER_INPUT_CANCEL: SelectedItem = -2; goto exit; case USER_INPUT_INC: SecondLine = 1; if (SelectedItem == ItemCount) SelectedItem = ItemCount; else SelectedItem++; break; case USER_INPUT_DEC: SecondLine = 0; if (SelectedItem == 0) SelectedItem = 0; else SelectedItem--; break; } } exit: return (SelectedItem); }
signed char GetFloat(const char *prompt, const char *unit, double* Value, double Min, double Max, double Precision) { double Output; char WholePlaces; char FractionalPlaces; signed char ret = 0; if ((Max >= 10000) || (Min <= -10000)) WholePlaces = 5; else if (Max >= 1000 | Min <= -1000) WholePlaces = 4; else if (Max >= 100 | Min <= -100) WholePlaces = 3; else if (Max >= 10 | Min <= -10) WholePlaces = 2; else WholePlaces = 2; if (Precision >= 1.0) FractionalPlaces = 0; else if (Precision >= 0.1) FractionalPlaces = 1; else if (Precision >= 0.01) FractionalPlaces = 2; else if (Precision >= 0.001) FractionalPlaces = 3; else if (Precision >= 0.0001) FractionalPlaces = 4; Output = *Value; LCD_ClearDisplay(); LCD_PrintString(prompt); LCD_SetPosition(1, 0); LCD_PrintFloat(Output, WholePlaces, FractionalPlaces, 1); LCD_PrintString(unit); while (1) { LCD_SetPosition(1, 0); LCD_PrintFloat(Output, WholePlaces, FractionalPlaces, 1); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: //user has pressed the switch to accept. *Value = Output; return (0); case USER_INPUT_CANCEL: return -2; case USER_INPUT_BACK: return -1; case USER_INPUT_INC: //Rot+ Output += GetRotaryMultiplier() * Precision; if (Output > Max) Output = Max; break; case USER_INPUT_DEC: Output -= GetRotaryMultiplier() * Precision; if (Output < Min) Output = Min; break; } } return (0); }
signed char GetPresetNumber() { signed char inp; char pnum; signed char ptype; LCD_ClearDisplay(); LCD_PrintString("PRESET SLOT:\0"); LCD_SetPosition(1, 0); LCD_PrintString("PRESET 01\0"); pnum = 1; while (1) { LCD_SetPosition(1, 7); LCD_PrintLong((int) pnum, 2, 0); ptype = GetPresetType(pnum); switch (ptype) { case 0: LCD_PrintString("-EMPTY \0"); break; case 1: LCD_PrintString("-WAYPOINT \0"); break; case 2: LCD_PrintString("-ORBIT \0"); break; } inp = GetInput(); if (inp<0) return inp; switch (inp) { case USER_INPUT_DEC: if (pnum > 1) pnum--; break; case USER_INPUT_INC: if (pnum < 5) pnum++; break; case USER_INPUT_CLICK: return (pnum); case USER_INPUT_BACK: return (-1); case USER_INPUT_CANCEL: return (-2); } } return (-2); }
signed char DisplayChoices(const char *Menu[], char ItemCount, const char *Prompt, char Initial) { char SelectedItem = 0; signed char ret = 0; SelectedItem = Initial; while (1) { LCD_ClearDisplay(); LCD_PrintString(Prompt); LCD_SetPosition(1, 0); LCD_PrintChar('*'); LCD_PrintString(Menu[SelectedItem]); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: return (SelectedItem); case USER_INPUT_BACK: return (-1); case USER_INPUT_CANCEL: return (-2); case USER_INPUT_INC: if (SelectedItem == ItemCount) SelectedItem = ItemCount; else SelectedItem++; break; case USER_INPUT_DEC: if (SelectedItem == 0) SelectedItem = 0; else SelectedItem--; break; } } return (0); }
void main(){ Output_low(LCD_RW); //Che do ghi LCD_init(); //Khoi tao LCD lcd_putcmd(0x01); delay_ms(100); printf(lcd_putchar,"Nhiet do: "); while (true){ i2c_start(); //Tao dieu kien start de giao tiep //Dia chi thiet bi I2C(tra trang 9 cua Datasheet) sau khi da them bit 0 vao //0x48 (1001000 them bit 0 vao 10010000 = 0x90 i2c_write(0x90); i2c_write(0x00); //Gui lenh yeu cau doc nhiet do i2c_start(); //Tao lai dieu kien start //Dia chi thiet bi I2C(tra trang 9 cua Datasheet) sau khi da them bit 1 vao //0x48 (1001000 them bit 1 vao 10010001 = 0x91 i2c_write(0x91); //Thiet bi chu yeu cau duoc doc du lieu cua thiet bi to temp = i2c_read(0); //Gui lenh doc gia tri nhiet do i2c_stop(); //Tao dieu kien Stop, ket thuc giao tiep LCD_SetPosition(0x09); printf(lcd_putchar,"%u",temp); //Hien thi nhiet do doc duoc len LCD lcd_putchar(223); printf(lcd_putchar,"C"); delay_ms(1000); } }
signed char GetYesNo(const char *prompt, signed char Initial) { signed char answer; signed char inp; LCD_ClearDisplay(); LCD_PrintString(prompt); answer = Initial; while (1) { LCD_SetPosition(1, 0); if (answer) LCD_PrintString("<YES>\0"); else LCD_PrintString("<NO> \0"); inp = GetInput(); if (inp < 0) return inp; switch (inp) { case USER_INPUT_CLICK: //The User Pressed the button to select something... return (answer); case USER_INPUT_CANCEL: return -2; case USER_INPUT_BACK: return -1; case USER_INPUT_INC: //Rot + case USER_INPUT_DEC: //Rot - answer = !answer; break; default: break; } } return (0); }
signed char ShowVoltage() { double Batt; LCD_ClearDisplay(); bLock_BatteryVoltage = 1; Batt = BatteryVoltage; bLock_BatteryVoltage = 0; Batt *= Config.Volts_per_Count; LCD_PrintString("BATTERY VOLTAGE:\0"); LCD_SetPosition(1, 0); LCD_PrintFloat(Batt, 2, 2, 0); LCD_PrintString(" VOLTS\0"); return GetClick(); }
/** * Configures the SPI module, and writes some test text to the LCD. * Effectively tests the basic functionality of the display. * @return */ int LCD_TEST(void) { LCD_ConfigSPI(); LCD_InitiaizeLCD(); LCD_WriteData('L'); LCD_WriteData('i'); LCD_WriteData('n'); LCD_WriteData('e'); LCD_WriteData(' '); LCD_WriteData('1'); LCD_WriteCommand(LCD_CMD_RETURN_LINE2); LCD_WriteData('L'); LCD_WriteData('i'); LCD_WriteData('n'); LCD_WriteData('e'); LCD_WriteData(' '); LCD_WriteData('2'); LCD_SetPosition(0,0xA); LCD_WriteData('T'); LCD_WriteData('e'); LCD_WriteData('x'); LCD_WriteData('t'); LCD_WriteData(' '); LCD_WriteData('1'); LCD_SetPosition(1,0xA); LCD_WriteData('T'); LCD_WriteData('e'); LCD_WriteData('x'); LCD_WriteData('t'); LCD_WriteData(' '); LCD_WriteData('2'); return 0; }
/************************************************************* * 函数名称:LCD_DrawLine * 功 能:在指定位置画条长度为Length的线 * 参 数: * x: 窗体中X坐标中始点 * y: 窗体中Y坐标中始点 * Length:线的长度,长度大于屏幕时,截去 * Colour:线的颜色 * 返 回 值:无 *************************************************************/ void LCD_DrawLine(u16 x,u16 y,u16 Length,u16 Colour) { u16 i; if(horizontal_or_vertical) //横屏显示时 { if(x+Length>320) Length=320-Length; } else { if(x+Length>240) Length=240-Length; } LCD_SetPosition(x,y); for(i=0;i<Length;i++) LCD_WR_DATA(Colour); }
void main(void) { signed char ret = 0; signed char lastMenu = 0; char pnum = 0; SetupIO(); MOTOR_FORWARD = 0; MOTOR_REVERSE = 0; Move_shifted_position.ul = 0; Move_position[0].ul = 0; Move_position[1].ul = 0; //PID_SetPoint = 0; char idx; for (idx = 0; idx < 16; idx++) RotaryDetentIntervals[idx] = 0xFF; LoadSettings(); //FactoryDefault(); SetupHardware(); LCD_PowerUp(); LCD_ClearDisplay(); LCD_PrintString("CINEFLUX ORBIT\0"); LCD_SetPosition(1, 0); LCD_PrintString(VER); Wait_ms(2000); const char *COMMAND_0 = "ORBIT MODE\0"; const char *COMMAND_1 = "WAYPOINT MODE\0"; const char *COMMAND_3 = "RUN PRESET\0"; const char *COMMAND_2 = "REALTIME MODE\0"; const char *COMMAND_4 = "BATTERY VOLTAGE\0"; const char *COMMAND_5 = "GO TO SLEEP\0"; const char *COMMAND_6 = "EXTERNAL CTRL MODE\0"; const char*CommandMenu[7]; CommandMenu[0] = COMMAND_0; CommandMenu[1] = COMMAND_1; CommandMenu[2] = COMMAND_2; CommandMenu[3] = COMMAND_3; CommandMenu[4] = COMMAND_4; CommandMenu[5] = COMMAND_5; CommandMenu[6] = COMMAND_6; bFollowMode = 1; LCD_ClearDisplay(); LCD_PrintString("MOVE TO ZERO DEGREES\0"); LCD_SetPosition(1, 0); LCD_PrintString("THEN CLICK...\0"); GetClick(); bClear_MotorPosition = 1; while (bClear_MotorPosition) Idle(); Wait_ms(10); bFollowMode = 0; LCD_ClearDisplay(); while (1) { UI_Location = UI_LOC_MAINMENU; ret = DisplayMenu(CommandMenu, 6, lastMenu); labelProcessCommand: switch (ret) { case 0: case USER_INPUT_MACRO_ORBITMODE: lastMenu = 0; ret = CreateOrbitProgram(); if (ret == -2) RealtimeMode(); if (ret == -1) RealtimeMode(); if (ret<-2) goto labelProcessCommand; break; case 1: case USER_INPUT_MACRO_WAYMODE: lastMenu = 1; ret = CreateWaypointProgram(); if (ret<-2) goto labelProcessCommand; if (ret < 0) { ret = RealtimeMode(); if (ret<-2) goto labelProcessCommand; } break; case 3: lastMenu = 3; ret = GetPresetNumber(); if (ret == -1) break; if (ret == -2) break; if (ret<-2) goto labelProcessCommand; pnum = ret; ret = RunPreset(pnum); if (ret<-2) goto labelProcessCommand; break; case 2: case USER_INPUT_MACRO_REALMODE: lastMenu = 0; ret = RealtimeMode(); if (ret<-2) goto labelProcessCommand; break; case 4: lastMenu = 0; ret = ShowVoltage(); if (ret<-2) goto labelProcessCommand; break; case 5: case USER_INPUT_MACRO_SLEEP: lastMenu = 0; GoToSleep(); break; case 6: case USER_INPUT_MACRO_EXTMODE: lastMenu = 0; ret = ExtMode(); if (ret<-2) goto labelProcessCommand; break; case USER_INPUT_MACRO_RUNPRESET0: ret = RunPreset(1); if (ret<-2) goto labelProcessCommand; break; case USER_INPUT_MACRO_RUNPRESET1: ret = RunPreset(2); if (ret<-2) goto labelProcessCommand; break; case USER_INPUT_MACRO_RUNPRESET2: ret = RunPreset(3); if (ret<-2) goto labelProcessCommand; break; case USER_INPUT_MACRO_RUNPRESET3: ret = RunPreset(4); if (ret<-2) goto labelProcessCommand; break; case USER_INPUT_MACRO_RUNPRESET4: ret = RunPreset(5); if (ret<-2) goto labelProcessCommand; break; } } }
signed char CreateOrbitProgram() { UI_Location = UI_LOC_ORBITSETUP; signed char ret; const char *DIRECTION_1 = "CLOCKWISE\0"; const char *DIRECTION_0 = "COUNTER CLOCKWISE\0"; const char*DirectionMenu[2]; DirectionMenu[0] = DIRECTION_0; DirectionMenu[1] = DIRECTION_1; const char *SpeedMODE_0 = "MANUAL\0"; const char *SpeedMODE_1 = "PER ORBIT\0"; const char *SpeedMODE_2 = "FOR ALL ORBITS\0"; const char*SpeedModeMenu[3]; SpeedModeMenu[0] = SpeedMODE_0; SpeedModeMenu[1] = SpeedMODE_1; SpeedModeMenu[2] = SpeedMODE_2; const char *ENDMODE_0 = "BY ORBIT COUNT\0"; const char *ENDMODE_1 = "BY TOTAL TIME\0"; const char *ENDMODE_2 = "NEVER ENDING\0"; const char*EndModeMenu[3]; EndModeMenu[0] = ENDMODE_0; EndModeMenu[1] = ENDMODE_1; EndModeMenu[2] = ENDMODE_2; const char *COMMAND_0 = "RUN PROGRAM\0"; const char *COMMAND_1 = "SAVE PRESET\0"; const char*CommandMenu[2]; CommandMenu[0] = COMMAND_0; CommandMenu[1] = COMMAND_1; labelOrigin: LCD_ClearDisplay(); LCD_PrintString("MOVE TO START...\0"); LCD_SetPosition(1, 0); LCD_PrintString("THEN CLICK.\0"); bFollowMode = 1; ret = GetClick(); bFollowMode = 0; if (ret < 0) return ret; CurrentOrbitProgram.Origin_deg = (unsigned int) GetCurrentAngle(); labelDirection: ret = DisplayChoices(DirectionMenu, 1, "ROTATION DIRECTION:\0", CurrentOrbitProgram.IsClockWise); if (ret == -1) goto labelOrigin; if (ret == -2) return (-2); if (ret < 0) return ret; CurrentOrbitProgram.IsClockWise = ret; labelEndMode: ret = DisplayChoices(EndModeMenu, 2, "PROGRAM END MODE:\0", CurrentOrbitProgram.EndMode); if (ret == -1) goto labelDirection; if (ret == -2) return (-2); if (ret < 0) return ret; CurrentOrbitProgram.EndMode = ret; switch (CurrentOrbitProgram.EndMode) { case 0: //End based on Cycle Count. labelCycleCount : if (CurrentOrbitProgram.CycleCount_rev < 1) CurrentOrbitProgram.CycleCount_rev = 1; if (CurrentOrbitProgram.CycleCount_rev > 999) CurrentOrbitProgram.CycleCount_rev = 999; ret = GetFloat("ORBIT LIMIT:\0", "", &CurrentOrbitProgram.CycleCount_rev, 1, 999, 1.0); if (ret == -1) goto labelEndMode; if (ret == -2) return (-2); if (ret < 0) return ret; labelSpeedMode: if (CurrentOrbitProgram.CycleCount_rev > 1) ret = DisplayChoices(SpeedModeMenu, 2, "ORBIT SPEED:\0", CurrentOrbitProgram.SpeedMode); else ret = DisplayChoices(SpeedModeMenu, 1, "ORBIT SPEED:\0", CurrentOrbitProgram.SpeedMode); if (ret == -1) goto labelCycleCount; if (ret == -2) return (-2); if (ret < 0) return ret; switch (ret) { case 0: if (CurrentOrbitProgram.Speed_deg_sec < 0.01) CurrentOrbitProgram.Speed_deg_sec = 0.01; ret = GetFloat("SPEED\0", "\xDF/Sec\0", &CurrentOrbitProgram.Speed_deg_sec, 0.01, 90, 0.01); if (ret == -1) goto labelSpeedMode; if (ret == -2) return (-2); break; case 1: if (CurrentOrbitProgram.CycleTime_sec < 4) CurrentOrbitProgram.CycleTime_sec = 4; ret = GetTime("TIME PER ORBIT\0", &CurrentOrbitProgram.CycleTime_sec, 4, 86400, 0b1110); if (ret == -1) goto labelSpeedMode; if (ret == -2) return (-2); CurrentOrbitProgram.Speed_deg_sec = 360 / CurrentOrbitProgram.CycleTime_sec; break; case 2: if (CurrentOrbitProgram.CycleTime_sec < (4 * CurrentOrbitProgram.CycleCount_rev)) CurrentOrbitProgram.CycleTime_sec = 4 * CurrentOrbitProgram.CycleCount_rev; ret = GetTime("TIME FOR ALL ORBITS\0", &CurrentOrbitProgram.CycleTime_sec, 4 * CurrentOrbitProgram.CycleCount_rev, 86400, 0b1110); if (ret == -1) goto labelSpeedMode; if (ret == -2) return (-2); CurrentOrbitProgram.Speed_deg_sec = (360 * CurrentOrbitProgram.CycleCount_rev) / CurrentOrbitProgram.CycleTime_sec; break; } break; case 1://End based on runtime. labelProgramRuntime : ret = GetTime("TOTAL RUNTIME:\0", &CurrentOrbitProgram.ProgramRunTime_sec, 1, 86400, 0b1110); if (ret == -1) goto labelEndMode; if (ret == -2) return (-2); if (ret < 0) return ret; labelSpeedMode2: ret = DisplayChoices(SpeedModeMenu, 1, "ORBIT SPEED:\0", CurrentOrbitProgram.SpeedMode); if (ret == -1) goto labelProgramRuntime; if (ret == -2) return (-2); if (ret < 0) return ret; switch (ret) { case 0: if (CurrentOrbitProgram.Speed_deg_sec < 0.01) CurrentOrbitProgram.Speed_deg_sec = 0.01; ret = GetFloat("SPEED\0", "\xDF/Sec\0", &CurrentOrbitProgram.Speed_deg_sec, 0.01, 90, 0.01); if (ret == -1) goto labelSpeedMode2; if (ret == -2) return (-2); break; case 1: if (CurrentOrbitProgram.CycleTime_sec < 4) CurrentOrbitProgram.CycleTime_sec = 4; ret = GetTime("TIME PER ORBIT:\0", &CurrentOrbitProgram.CycleTime_sec, 4, 86400, 0b1110); if (ret == -1) goto labelSpeedMode2; if (ret == -2) return (-2); CurrentOrbitProgram.Speed_deg_sec = 360 / CurrentOrbitProgram.CycleTime_sec; break; } CurrentOrbitProgram.CycleCount_rev = (CurrentOrbitProgram.Speed_deg_sec * CurrentOrbitProgram.ProgramRunTime_sec) / 360; break; case 2: //NO END AT ALL labelSpeedMode3 : ret = DisplayChoices(SpeedModeMenu, 1, "ORBIT SPEED:\0", CurrentOrbitProgram.SpeedMode); if (ret == -1) goto labelEndMode; if (ret == -2) return (-2); if (ret < 0) return ret; switch (ret) { case 0: if (CurrentOrbitProgram.Speed_deg_sec < 0.01) CurrentOrbitProgram.Speed_deg_sec = 0.01; ret = GetFloat("SPEED\0", "\xDF/Sec\0", &CurrentOrbitProgram.Speed_deg_sec, 0.01, 90, 0.01); if (ret == -1) goto labelSpeedMode3; if (ret == -2) return (-2); if (ret < 0) return ret; break; case 1: if (CurrentOrbitProgram.CycleTime_sec < 4) CurrentOrbitProgram.CycleTime_sec = 4; ret = GetTime("TIME PER ORBIT:\0", &CurrentOrbitProgram.CycleTime_sec, 4, 86400, 0b1110); if (ret == -1) goto labelSpeedMode3; if (ret == -2) return (-2); if (ret < 0) return ret; CurrentOrbitProgram.Speed_deg_sec = 360 / CurrentOrbitProgram.CycleTime_sec; break; } break; } labelActions: ret = DisplayChoices(CommandMenu, 1, "ACTION:\0", 0); if (ret == -1) goto labelCycleCount; if (ret == -2) return (-2); if (ret < 0) return ret; if (ret == 0) { return RunOrbitProgram(); } ret = GetPresetNumber(); if (ret == -1) goto labelActions; if (ret == -2) return (-2); if (ret < 0) return ret; CurrentOrbitProgram.Type = 2; SavePreset(ret, (unsigned char *) &CurrentOrbitProgram); goto labelActions; }
signed char RunOrbitProgram() { signed char retCode = 0; UI_Location = UI_LOC_ORBITRUN; signed char ret; double EndPos; double OriginPos; double TimeRemaining; double DistanceRemaining; double MPos; LCD_ClearDisplay(); LCD_PrintString("MOVING TO START\0"); OriginPos=(double)CurrentOrbitProgram.Origin_deg; MoveToAngle(OriginPos, 90); while (bMove_InProgress) { Idle(); ret = GetInput_nonblocking(); if (ret == USER_INPUT_CANCEL) { retCode = -2; goto labelFinished; } if (ret < 0) { retCode = ret; goto labelFinished; } } double Distance = CurrentOrbitProgram.CycleCount_rev * 360; if (CurrentOrbitProgram.EndMode == 2) Distance = 7776000; if (!CurrentOrbitProgram.IsClockWise) Distance = -Distance; bLock_Motor_Position = 1; OriginPos = Motor_Position; bLock_Motor_Position = 0; OriginPos *= Config.Degrees_Per_Count; EndPos = OriginPos + Distance; LCD_ClearDisplay(); LCD_PrintString("RUNNING: T-HH:MM:SS\0"); if (CurrentOrbitProgram.EndMode == 2) { LCD_ClearDisplay(); LCD_PrintString("ORBIT RUNNING\0"); LCD_SetPosition(1, 0); LCD_PrintString("INFINITE RUNTIME\0"); } double SpdConvert = 1 / CurrentOrbitProgram.Speed_deg_sec; ret = GetInput_nonblocking(); Move(Distance, CurrentOrbitProgram.Speed_deg_sec); while (bMove_InProgress) { bLock_Motor_Position = 1; MPos = Motor_Position; bLock_Motor_Position = 0; MPos *= Config.Degrees_Per_Count; DistanceRemaining = EndPos - MPos; if (DistanceRemaining < 0) DistanceRemaining = -DistanceRemaining; TimeRemaining = DistanceRemaining*SpdConvert; DistanceRemaining *= 0.002778; if (!(CurrentOrbitProgram.EndMode == 2)) { LCD_SetPosition(0, 11); PrintTime(TimeRemaining, 0b1110, 0); LCD_SetPosition(1, 0); LCD_PrintFloat(DistanceRemaining, 5, 2, 0); LCD_PrintString(" REV REMAIN\0"); } ret = GetInput_nonblocking(); if (ret == USER_INPUT_CANCEL) { retCode = -2; goto labelFinished; } if (ret < 0) { retCode = ret; goto labelFinished; } Idle(); } labelFinished: bMove_InProgress = 0; bFollowMode = 0; bSpeedMode = 1; Speed_SetToThis = 0; Speed_SetPending = 1; LCD_ClearDisplay(); LCD_PrintString("STOPPING...\0"); while (Speed_SetPending); while (Speed_IsAccelerating){ Idle(); } bMove_InProgress = 0; bFollowMode = 0; bSpeedMode=0; return retCode; }
void main(void) { signed char ret = 0; signed char lastMenu = 0; char pnum = 0; SetupIO(); MOTOR_FORWARD = 0; MOTOR_REVERSE = 0; Move_shifted_position.ul = 0; Move_position[0].ul = 0; Move_position[1].ul = 0; //PID_SetPoint = 0; char idx; for (idx = 0; idx < 16; idx++) RotaryDetentIntervals[idx] = 0xFF; //LoadSettings(); FactoryDefault(); SetupHardware(); LCD_PowerUp(); LCD_ClearDisplay(); LCD_PrintString("CINEFLUX ORBIT\0"); LCD_SetPosition(1,0); LCD_PrintString(VER); Wait_ms(2000); const char *COMMAND_0 = "ORBIT MODE\0"; const char *COMMAND_1 = "WAYPOINT MODE\0"; const char *COMMAND_3 = "RUN PRESET\0"; const char *COMMAND_2 = "REALTIME MODE\0"; const char *COMMAND_4 = "BATTERY VOLTAGE\0"; const char *COMMAND_5 = "GO TO SLEEP\0"; const char *COMMAND_6 = "EXTERNAL CTRL MODE\0"; const char*CommandMenu[7]; CommandMenu[0] = COMMAND_0; CommandMenu[1] = COMMAND_1; CommandMenu[2] = COMMAND_2; CommandMenu[3] = COMMAND_3; CommandMenu[4] = COMMAND_4; CommandMenu[5] = COMMAND_5; CommandMenu[6] = COMMAND_6; bFollowMode = 1; LCD_ClearDisplay(); LCD_PrintString("MOVE TO ZERO DEGREES\0"); LCD_SetPosition(1, 0); LCD_PrintString("THEN CLICK...\0"); GetClick(); bClear_MotorPosition = 1; while (bClear_MotorPosition) Idle(); Wait_ms(10); bFollowMode = 0; LCD_ClearDisplay(); while (1) { ret = DisplayMenu(CommandMenu, 6, lastMenu); switch (ret) { case 0: lastMenu = 0; if (!CreateOrbitProgram() == 0) RealtimeMode(); break; case 1: lastMenu = 1; if (!CreateWaypointProgram() == 0) RealtimeMode(); break; case 3: lastMenu = 2; ret = GetPresetNumber(); if (ret == -1) break; if (ret == -2) break; pnum = ret; switch (GetPresetType(pnum)) { case 1: LoadPreset(pnum, (unsigned char *) &CurrentPath); if (!RunWaypointProgram() == 0) RealtimeMode(); break; case 2: LoadPreset(pnum, (unsigned char *) &CurrentOrbitProgram); if (!RunOrbitProgram() == 0) RealtimeMode(); break; } break; case 2: lastMenu = 2; RealtimeMode(); break; case 4: lastMenu = 0; ShowVoltage(); break; case 5: lastMenu = 0; GoToSleep(); break; case 6: lastMenu = 0; ExtMode(); break; } } }
void main(){ int temp1, temp2,temp3; // Bien duoc do ra tu EEPROM int keypad[10],i, position; int B_ENTER, B_EXIT, E0; temp1 = read_eeprom(add_setup_temp_1); temp2 = read_eeprom(add_setup_temp_2); temp3 = read_eeprom(add_setup_temp_3); nhietdo_setup = temp1*10 + temp2 + temp3*0.1; //Gia tri nhiet do setup Output_low(LCD_RW); LCD_Init(); TRISB = 0xFF; TRISE = 0xFF; LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); while (true){ //Doc gia tri nhiet do tu cam bien DS18B20 temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); OF_RELAY(temp_float, nhietdo_setup); E0 = input(SETUP_EXIT); if (E0 == 0){ //while (input(SETUP_EXIT)==0) ; LCD_PutCmd(0x01); LCD_SetPosition(0x00); printf(lcd_putchar,"SETUP TEMP: "); delay_ms(1000); i = 0; position = 64; //Khi chua nhan nut EXIT hay ENTER B_EXIT = input(SETUP_EXIT); B_ENTER = input(ENTER); while ((B_ENTER==1) | (B_EXIT == 1)){ int value; B_EXIT = input(SETUP_EXIT); B_ENTER = input(ENTER); value = READ_BUTTON(); //Chi cho nhap va hien thi 3 so if ((value >= 0) && (value < 10) && (i<=2)){ LCD_SetPosition(position); printf(lcd_putchar,"%d",value); delay_ms(1000); keypad[i] = value; i++; position++; } else //Khi da nhap du 3 so va nhan nut ENTER if ((value == 100) && (i>=3)){ write_eeprom(add_setup_temp_1,keypad[0]); write_eeprom(add_setup_temp_2,keypad[1]); write_eeprom(add_setup_temp_3,keypad[2]); temp1 = read_eeprom(add_setup_temp_1); temp2 = read_eeprom(add_setup_temp_2); temp3 = read_eeprom(add_setup_temp_3); nhietdo_setup = temp1*10 + temp2 + temp3*0.1; //Gia tri nhiet do setup LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); break; } else if (value == 50){ //Khi da nhan nut EXIT thi thoat khoi vong lap LCD_PutCmd(0x01); LCD_SetPosition(0x00); //Chuyen vi tri con tro sang dong 1 printf(lcd_putchar,"Setup: %.1f",nhietdo_setup); lcd_putchar(223); printf(lcd_putchar,"C"); temp_float = ds18b20_read(); LCD_SetPosition(0x40); //Chuyen vi tri con tro sang dong 2 printf(lcd_putchar,"Measure: %.1f",temp_float); lcd_putchar(223); printf(lcd_putchar,"C"); break; } } } } }
signed char GetTime(const char *prompt, double *Time, double Min, double Max, char Precision) { char Seconds, Minutes, Hours; int Milliseconds; double Tm = *Time; signed char ret = 0; ConvertTimeToDiscrete(Tm, &Hours, &Minutes, &Seconds, &Milliseconds); if (!(Precision & 0b1000)) Hours = 0; if (!(Precision & 0b0100)) Minutes = 0; if (!(Precision & 0b0010)) Seconds = 0; if (!(Precision & 0b0001)) Milliseconds = 0; Tm = ConvertTimeFromDiscrete(Hours, Minutes, Seconds, Milliseconds); if (Tm < Min) Tm = Min; if (Tm > Max) Tm = Max; labelHours: if (!(Precision & 0b1000)) goto labelMinutes; LCD_ClearDisplay(); LCD_PrintString(prompt); LCD_PrintString("<H>"); LCD_SetPosition(1, 0); LCD_PrintString(" \0"); while (1) { LCD_SetPosition(1, 0); PrintTime(Tm, Precision, 0b1000); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: //user has pressed the switch to accept. goto labelMinutes; case USER_INPUT_BACK: //user has pressed back return (-1); case USER_INPUT_CANCEL: //user has pressed Cancel return (-2); case USER_INPUT_INC: //Rot+ Tm += 3600; if (Tm > Max) Tm = Max; break; case USER_INPUT_DEC: Tm -= 3600; if (Tm < Min) Tm = Min; break; } } labelMinutes: if (!(Precision & 0b0100)) goto labelSeconds; LCD_ClearDisplay(); LCD_PrintString(prompt); LCD_PrintString("<M>"); LCD_SetPosition(1, 0); LCD_PrintString(" \0"); while (1) { LCD_SetPosition(1, 0); PrintTime(Tm, Precision, 0b0100); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: //user has pressed the switch to accept. goto labelSeconds; case USER_INPUT_BACK: //user has pressed back goto labelHours; case USER_INPUT_CANCEL: //user has pressed Cancel return (-2); case USER_INPUT_INC: //Rot+ Tm += 60; if (Tm > Max) Tm = Max; break; case USER_INPUT_DEC: Tm -= 60; if (Tm < Min) Tm = Min; break; } } labelSeconds: if (!(Precision & 0b0010)) goto labelMilliseconds; LCD_ClearDisplay(); LCD_PrintString(prompt); LCD_PrintString("<S>"); LCD_SetPosition(1, 0); LCD_PrintString(" \0"); while (1) { LCD_SetPosition(1, 0); PrintTime(Tm, Precision, 0b0010); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: //user has pressed the switch to accept. goto labelMilliseconds; case USER_INPUT_BACK: //user has pressed back goto labelMinutes; case USER_INPUT_CANCEL: //user has pressed Cancel return (-2); case USER_INPUT_INC: //Rot+ Tm += 1; if (Tm > Max) Tm = Max; break; case USER_INPUT_DEC: Tm -= 1; if (Tm < Min) Tm = Min; break; } } labelMilliseconds: if (!(Precision & 0b0001)) goto labelFinished; LCD_ClearDisplay(); LCD_PrintString(prompt); LCD_PrintString("<ms>"); LCD_SetPosition(1, 0); LCD_PrintString(" \0"); while (1) { LCD_SetPosition(1, 0); PrintTime(Tm, Precision, 0b0001); ret = GetInput(); if (ret < 0) return ret; switch (ret) { case USER_INPUT_CLICK: //user has pressed the switch to accept. goto labelFinished; case USER_INPUT_BACK: //user has pressed back goto labelSeconds; case USER_INPUT_CANCEL: //user has pressed Cancel return (-2); case USER_INPUT_INC: //Rot+ Tm += 0.1; if (Tm > Max) Tm = Max; break; case USER_INPUT_DEC: Tm -= 0.1; if (Tm < Min) Tm = Min; break; } } labelFinished: *Time = Tm; return 0; }