' PSU Output control Copyright Cyrob 2018 ' CP0086 Firmware ' Release History ' 24/02/2018 V1.0 Phildem First blood ' 29/05/2018 V1.1 Phildem Final Adjust with hardware ' At start up, output is off, no delay ' A single push on bt switch toggle the output on off ' A long push enter progMode ' In progMode, each push increment the second counter (up to 255) ' A long push leave progMode ' IO abstraction symbol In_Bt = pinC.3 'Ctl Button activ Low symbol Out_Piezzo = C.4 'Sound Buzzer activ High symbol Out_Relay = C.2 'Output relay activ High symbol Out_LedB = C.0 'LedBlue activ Low symbol Out_LedG = C.1 'LedGreen activ Low ' States symbol kStateInit = 0 ' Startup Blue/Green Blink with snd symbol kStateOff = 1 ' Output Off Green led On symbol kStateOn = 2 ' Output On relay (Red led) On symbol kStateCountDown = 3 ' Countdow to on Green Pulse with Snd pulse symbol kStateProg = 4 ' Mode Program Blue Led On symbol kStateStop = 5 ' Push to stop Green led On ' Misc Constant symbol kTickVal = 50 ' Value of tick in mS symbol kLongPush = 20 ' NbTick for nong Push symbol kTickPerSec = 20 ' NbTick by second 'Variables symbol m_State = b0 ' State symbol m_Loop = b1 ' Loop var symbol m_NbTickOn = b2 ' Number of Tick bt on symbol m_Delay = b3 ' Number of seconds to goes on symbol m_SecTick = b4 ' Second Tick counter symbol m_CntDown = b5 ' Startup count down 'Program main: output Out_Piezzo ' Init Outputs output Out_Relay output Out_LedB output Out_LedG high Out_LedB ' Lock Power On high Out_LedG ' Lock Power On m_State = kStateInit ' Init Var m_NbTickOn = 0 m_Delay = 0 'Startup sequence for m_Loop = 1 to 5 low Out_LedB sound Out_Piezzo,(100,3) high Out_LedB low Out_LedG sound Out_Piezzo,(150,3) high Out_LedG next m_Loop sound Out_Piezzo,(120,20) sound Out_Piezzo,(50,20) m_State = kStateOff '------------------------------------------------------- SwLoop: ; Adjust relay vs state if m_State=kStateOn then high Out_Relay else low Out_Relay endif ; Adjust led vs state SELECT m_State CASE kStateOn CASE kStateCountDown high Out_LedB high Out_LedG CASE kStateProg low Out_LedB high Out_LedG ELSE high Out_LedB low Out_LedG ENDSELECT Pause kTickVal ; We do something only every Tick ; Look If bt Down if In_Bt=0 then if m_State=kStateOn then ; Stop asap m_State=kStateStop low Out_Relay endif inc m_NbTickOn if m_NbTickOn=kLongPush then if m_State=kStateProg then ; Leave ProgMode sound Out_Piezzo,(120,60,60,40) m_State=kStateOff else ; Enter ProgMode sound Out_Piezzo,(60,40,120,60) m_Delay=0 m_State=kStateProg endif endif if m_NbTickOn>kLongPush then m_NbTickOn=kLongPush ; Wait user relase bt endif elseif m_NbTickOn<>0 then ;Bt return up if m_NbTickOn