'**************************************************************** '* Name : MainTest.BAS * '* Author : John Barrat * '* Notice : Copyright (c) 2004 John Barrat * '* : All Rights Reserved * '* Date : 16/02/2005 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** #DEFINE TASK_DEBUG #DEFINE INT_ENABLED '#DEFINE REMRESET_ENABLED #DEFINE LVD_HANDLER Prog_Shut_Down #DEFINE RX_HANDLER ReceiveUSART #IFDEF RX_HANDLER #DEFINE GET_RX_RECORD #ENDIF #DEFINE TX_HANDLER TransmitUSART #IFDEF INT_ENABLED #DEFINE INT0_HANDLER Scheduler_Intr #DEFINE IOC_HANDLER KeyScan_Intr #IFDEF IOC_HANDLER #DEFINE TMR1_HANDLER KeyRepTMR ' This is the routine to manage Timer1 #DEFINE TMR1_FREQ 50 ' Set Timer to 50 Hz (20mS) #ENDIF #ENDIF Include "SWCBoardVer3.INC" Symbol LCD_NoChars = 16 Symbol RB_MinMsgLen = 5 ' Number of Received Chars before Checking for message Dim MsgArry As String * 32 ' General purpose message array for LCD and Serial Messages ' Set up the maximum tasks for task rate Symbol ImmdTasks = 4 ' Must be a power of 2 (i.e. 2, 4, 8 etc) Symbol Rate1Tasks = 6 ' 2Hz - No restrictions on the others Symbol Rate2Tasks = 6 ' 1 Hz Symbol Rate3tasks = 6 ' 1 Min Symbol Rate4Tasks = 5 ' 1 Hour Symbol CoDTasks = 2 ' Change of Day ' Menu Setup Values Symbol MnuMTNum $01 ' The number of Main Menu Items Symbol MnuMCNum $01 ' The number of Config Menu Items (1 is for Config Confirmation) ' Variables ------------------------------------------------------------------------------------ Dim DispORptr As Word ' Address of a routine to be run by Execute Dim TB1 As Byte ' Temporary Byte Variable Dim MainMode As Byte ' Bits 4-7 Pump & temp modes, 0 - 2 default disp param (8 Max) Symbol D_Over_Ride MainMode.3 ' Aliase to Display Override. Dim OR_Count As Byte ' Holds the number of current procedures forcing Disp Over Ride Dim RTC_NotSet As Bit ' Flag indicating RTC Chip not set up. Dim Sensor_Acq As Bit ' Flag indicating Sensor Acquistion State True = Acquiring Dim AdjMode As Bit ' Flag indicating that displayed value can be altered Dim PSIMode As Bit ' PSI = True Bar = False ' Prime start up position first time off EData 01, 00 ' Set Contrast to Full and Normal mode Symbol OW_EEP_St = 2 ' Includes ------------------------------------------------------------------------------------- Include "Constants_P+.inc" Include "Int_Ctrl_18F_P+.inc" ' Include "TaskMan_P+.inc" ' Task Manager 'Include "Utils_P+.inc" Include "LCD_P+.inc" ' ' The following INCs must be added after TASKMAN_INC Include "RTC_P+.inc" ' Must be after TASKMAN_INC Include "Menu_P+.inc" ' Must be after LCD_INC Include "I_Schedule_P+.inc" ' Interrupt Scheduler Include "RX_Buff_P+.inc" Include "Remote_IF_P+.inc" Symbol Main_EEP_St 0 Symbol SavedMode Main_EEP_St ' Location in EEP for the last saved operational state Symbol SvdContrast SavedMode + 1 ' Location in EEP for last saved LCD contrast GoTo Main_Init '----------------------------------------------------------------------------------------------- ' Updating routines - these routines can be placed on the task list using ADDTask and REMTask '----------------------------------------------------------------------------------------------- Disp_Time_L2: ' Displays Time at the end of the bottom line TkRow = 2: TkCol = 13 GoSub DispTime Return DispRTC_L2: ' Displays Time and Date on the Bottom Line TkRow = 2: GoSub DispTimeDate Return '----------------------------------------------------------------------------------------------- ' Menu control subroutines '----------------------------------------------------------------------------------------------- ' This routine is called on returning from a menu to the default display RestoreDefaultDisp: Cls: MnuHold = False Select Case MainMode & $F8 ' Chose routine to run from Display Mode bits in MainMode Case 0 ADDTask DispTick, Rate1 ' Add the routine to toggle the Tick indicator ADDTask DispTimeDate, Rate3 ' Add the routine to update the display on the minute TkRow = 1 ' set the Row to print Time & Date GoSub DispTimeDate ' refresh display now - we might have to wait for a minute. ' Add other Cases here End Select Return ' This routine is called on leaving the Default display RemoveDefaultDisp: Select Case MainMode & $F8 ' Choose routine to run from Display Mode bits in MainMode Case 0 REMTask DispTimeDate, Rate3 REMTask DispTick, Rate1 ' Add other Cases here End Select Return ' This routine will invoke the menu control routines according to the Value of ActPtr ProcMainMenu: On ActPtr GoToL Menu_Clock GoSub ActionFail [10] Return ' This routine will invoke the Set control routines according to the Value of ActPtr ProcMainSet: On ActPtr GoToL Set_Clock GoSub ActionFail [20] Return ' This routine will invoke the IncDec control routines according to the Value of ActPtr ProcMainIncDec: On ActPtr GoToL IncDec_Clock GoSub ActionFail [30] Return CancelMainMenu: On ActPtr GoToL Can_Menu_Clock Can_Menu_Def: Return ' Configuration Menu --------------------------------------------------------------------------- ProcCfgMenu: On ActPtr GoToL Menu_Cfg_Chk, Can_Menu_Def Cls : GoSub ActionFail [11] Return ProcCfgSet: On ActPtr GoToL Set_Cfg_Chk, Can_Menu_Def Cls : GoSub ActionFail [21] Return ProcCfgIncDec: On ActPtr GoToL IncDec_Cfg_Chk, Can_Menu_Def Cls : GoSub ActionFail [31] Return ' Default button Actions ----------------------------------------------------------------------- ' These routines will be invoked when SET, INC or DEC buttons are pressed when the display ' is not in any of the Menu modes and is displaying its default display. DefltDec: Dec LCD_Contrast GoSub LCD_Adjust_Contrast Return DefltInc: Inc LCD_Contrast GoSub LCD_Adjust_Contrast Return DefltSet: Return ' End of menu control subroutines--------------------------------------------------------------- ' Other non-real time routines ----------------------------------------------------------------- Disp_Ver_No: ' Displays the current Software version number Cls Print CStr mVer, " ", CStr VerNo Return ' Saves the master control mode in EEPROM SaveMode: EWrite SavedMode, [MainMode] ' Saves Control mode and default display in EEPROM Return SaveContrast: EWrite LCD_Contrast, [SvdContrast] ' Saves current Contrast setting in EEPROM Return ' End of Main program Subroutines ************************************************************** Main_Init: ' Board version 3 only #IFDEF SPCV3 LCD_Contrast = ERead SvdContrast ' Retrieve saved contrast setting GoSub LCD_Adjust_Contrast ' Set up the contrast (Board Version 3 only) #ENDIF ' Get the last updated Pump and Heat Control and Default display settings MainMode = ERead SavedMode ' Read the Control Byte and save it in Mainmode GoSub Interrupt_Init ' Set up Interrupt vectors GoSub Disp_Ver_No ' Show version number GoSub TaskMan_Init ' Clear all tasks on startup GoSub Menu_Init ' Reset Menu DelayMS 2000 ' Leave Version details up for 2 seconds Cls ' Clear screen - Remove Ver number GoSub CheckRTC ' See if clock has previously been set If RTC_Cont = False Then ' Clock not set so force user to MenuAct = $50 ' the Date & Time Set up menu and MnuHold = True ' disable Menu Button until clock setup is complete RTC_NotSet = True ' Set Not Set Flag - used by Menu_Clock GoSub Menu_Clock ' Process as a normal menu item - no menu timeout Else GoSub RTC_Init ' Initialise RTC RTC_NotSet = False ' Clear RTC_NotSet Flag If RTC_Cont = False Then ' Initialisation failed - Something wrong with GoSub ActionFail [1] ' the clock chip so set error code and report it EndIf GoSub RestoreDefaultDisp ' Set up the default display EndIf GoSub USARTBuffInit ' Set up Serial Port GoSub RemoteInit ' Start monitoring Serial IF GoTo InitScheduler ' Start up Scheduler 'Program Shutdown ****************************************************************************** Prog_Shut_Down: GoSub SaveMode ' Save Mode and Display defaults #IFDEF SPCV3 GoSub SaveContrast ' Save Contrast #ENDIF End ' Config Check Routines ************************************************************************ ' These routines ask the user to confirm they want to continue with config or return to normal Menu_Cfg_Chk: Print mConfig ' Print "Config" on top line Cursor 2,1: Print mYes ' on bottom line print "Yes" above the SET Cursor 2,5: Print mNo ' "No" over DEC button SetHold = True: IncDecHold = False ' Allow Set and IncDec buttons (Set off until with no config menu) MnuHold = True ' Disable use of Menu button Return IncDec_Cfg_Chk: If DecButton = Pressed Then Set_Cfg_Exit ' User wants to leave Config Return Set_Cfg_Chk: MnuHold = False ' Allow use of Menu button REMTask DecMenuTimer, Rate1 ' Remove Display timeout task from task list Cls ' Clear Screen MenuAct = $20 ' Skip the first Menu Item (Check Config) GoTo ProcCfgMenu ' and process the first config item 'Return Show_Cfg_OK: Print At 2,1, mOK ' Move to bottom line Print "OK" adjacent to SET button Show_Cfg_Arrow: Print At 2,15, mChevRh ' Set cursor over the "Menu" Button and print ">" Return ' Config Exit Routines ************************************************************************* ' Offers the option to exit - Alternatively Menu button takes user back to first Config Menu Menu_Cfg_Exit: Print mExit, " ", mConfig ' Print "Exit Config" above SetHold = False: MnuHold = False ' Allow Set button and Menu Button IncDecHold = True ' disable Inc/Dec buttons GoTo Show_Cfg_OK ' Print "OK" above Set Button and Arrow above Menu ' and return through Show_Cfg_OK Set_Cfg_Exit: ' User wants to leave Config mode MenuAct = $00: ConfigMode = False ' Reset MenuAct to normal, clear Config mode Flag GoTo RestoreDefaultDisp ' and Return to the default display ' Clock Setup Routines ************************************************************************* Menu_Clock: ' Title top line and display Daylight saving option and show the current Time in the RTC Array Print mSet, " ", mClock ' Title "Set Clock" SetHold = False: TB1 = 0 ' Allow SET button, Reset TB1 IncDecHold = False ' Allow INC/DEC buttons If RTC_NotSet = False Then ' Test to see if RTC Set up TkRow = 2: TkCol = 13 ' place Time at end of bottom row ADDTask DispTick, Rate1 ' Add updating task ADDTask Disp_Time_L2, Rate3 ' If set up show updating Time on Bottom line EndIf GoSub TSetup: GoSub Disp_DS_Mode ' Get Time/Date ready for editing & Display DS State ' SubMenuCnt = 7 ' Set up the Submenu Count Return Disp_DS_Mode: CLL 2 ' Clear bottom line Print CStr mDS, " " ' and print "D-S " If DSTime = True Then Print CStr mOn Else Print CStr mOff ' determine current D-S state EndIf GoSub Disp_Time_L2 ' Display updated time imediately Return Set_Clock: GoSub IncSubMenu ' Move pointer to the next sub menu ' First depression of SET button starts the Clock Update cycle TB1 = MenuAct & $0F ' Put Submenu number in Temp Var TB1 If TB1 = $1 Then GoSub Can_Menu_Clock ' remove updating display from task list Cls ' Clear LCD Print mSet ' Display "Set " GoSub TSetup ' Get TimeDate ready for editing IncDecHold = False ' Allow Use of IncDec buttons EndIf If TB1 = $6 Then GoSub RTCUpDate ' Reached the end of Set Clock cycle so update RTC Cursor 1,1 ' Cursor to top line to report If RTC_Cont = False Then ' Test to see if update successful GoSub ActionFail [1] ' No Set Error code to RTC update problem and Report MnuHold = True ' Try again Else CLL 1: GoSub ActionOK ' Clear top line OK to Report Update Completed If RTC_NotSet = True Then Main_Init ' If 1st time clock set restart as RTC now set MnuHold = False ' Allow use of menu button EndIf MenuAct = MenuAct & $F0 ' Reset MenuAct Cls GoTo Menu_Clock ' Back to top menu Else MsgArry = " " GoSub StrRTCUnit [TB1] ' Use TB1 pointer to index the parameter and display Print At 1,4, MsgArry ' "Hours", "Mins ", "Day ", "Month", "Year " Cursor 2,1: GoSub DispTimeDate2 ' Show edited time/date on line 2 EndIf Return IncDec_Clock: If TB1 = 0 Then ' Still in DS mode so GoSub ToggleDS ' Change Daylight saving GoSub RTCUpDate ' Save new setting in RTC GoSub Disp_DS_Mode ' and redisplay setting Else GoSub ClkAdjust ' Push return address and jump to routine CLL 2: GoSub DispTimeDate2 ' Display updated time & date EndIf Return ClkAdjust: RTC_Cont = DecButton ' Set the Inc/Dec Direction ' branch to clock adjust routines determined by MenuAct returning through selected routine On TB1 - 1 GoToL StepHour, StepMin, StepDay, StepMonth, StepYear GoTo BeepErr ' If we have reached here there is a error Return through the BeepErr Can_Menu_Clock: REMTask Disp_Time_L2, Rate3 ' Remove Time Display task used by Clock menu REMTask DispTick, Rate1 ' and the updating tick indicator Return Stop PName: CData "MainTest ",0 VerNo: CData "1.0.1.0",0 Include "SPC_Messages_P+.bas"