00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "femtoos_code.h"
00028
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define pinLEDbeacon PA0
00054 #define pinLEDsignal PA1
00055 #define pinLAMP PA2
00056 #define pinSWITCH PB0
00057
00058 void appBoot(void)
00059 { DDRA |= 0x07;
00060 PORTA &= 0xF7;
00061 DDRB &= 0xFE;
00062 PORTB &= 0xFE; }
00063
00064
00065 #define setChannel(channel,state) if (!state) { PORTA |= (1 << (channel)); } else { PORTA &= ~(1 << (channel)); }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 volatile Tuint08 uiLedMode;
00082 volatile Tuint08 uiDelayMode;
00083 volatile Tuint08 uiDelayTimer;
00084
00085
00086 void appTick16(void)
00087 { if (uiDelayTimer == 0) { uiDelayMode = 0; } else { uiDelayTimer--; } }
00088
00089
00090 #if (preTaskDefined(ReadSwitch))
00091
00092 void appLoop_ReadSwitch(void)
00093 { Tuint08 uiSwitchOldState = PINB & (1<<pinSWITCH);;
00094 Tuint08 uiSwitchNewState;
00095 while (true)
00096 { uiSwitchNewState = PINB & (1<<pinSWITCH);
00097 if (uiSwitchOldState != uiSwitchNewState)
00098 { uiSwitchOldState = uiSwitchNewState;
00099 Tuint08 uiLM = uiLedMode;
00100 if (uiLM==0)
00101 { uiDelayMode = 0;
00102 uiDelayTimer = 0; }
00103 else if (uiLM < 3)
00104 { if (uiDelayMode++ > 4) uiDelayMode=4;
00105 switch (uiDelayMode)
00106 { case 1 : { uiDelayTimer = 2; } break;
00107 case 2 : { uiDelayTimer = 15; } break;
00108 case 3 : { uiDelayTimer = 60; } break;
00109 default: { uiDelayTimer = 255; } break; } } }
00110 taskDelayFromNow(200); } }
00111
00112 #endif
00113
00114
00115 #if (preTaskDefined(DriveLed))
00116
00117 static void LedOff()
00118 { if (uiDelayMode > 0)
00119 { uiLedMode=0;
00120 setChannel(pinLEDbeacon,false);
00121 setChannel(pinLEDsignal,false);
00122 taskDelayFromNow(5000); } }
00123
00124 static void LedFlash()
00125 { if (uiDelayMode > 0)
00126 { Tuint08 uiDM = uiDelayMode;
00127 uiLedMode=3;
00128 setChannel(pinLEDbeacon,false);
00129 while (uiDM-- > 0)
00130 { setChannel(pinLEDsignal,true);
00131 taskDelayFromNow(200);
00132 setChannel(pinLEDsignal,false);
00133 taskDelayFromNow(200); } } }
00134
00135 static void LedOn()
00136 { if (uiDelayMode > 0)
00137 { uiLedMode=2;
00138 setChannel(pinLEDbeacon,false);
00139 setChannel(pinLEDsignal,true);
00140 taskDelayFromNow(5000); } }
00141
00142 static void LedBeacon()
00143 { if (uiDelayMode == 0)
00144 { uiLedMode=1;
00145 setChannel(pinLEDbeacon,true);
00146 setChannel(pinLEDsignal,false);
00147 taskDelayFromNow(200); } }
00148
00149 void appLoop_DriveLed(void)
00150 { while (true)
00151 { LedFlash();
00152 LedBeacon();
00153 LedOn();
00154 LedOff(); } }
00155
00156 #endif
00157
00158
00159 #if (preTaskDefined(DriveLamp))
00160
00161 void appLoop_DriveLamp(void)
00162 { while (true)
00163 { setChannel(pinLAMP,uiDelayMode>0)
00164 taskDelayFromNow(150); } }
00165
00166 #endif
00167