Advertisement
buckoka

Delay.c

Jul 21st, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. int Timer;
  2. int State;
  3. enum(No_State=0, Init_State, Wait_State, Delay_State, Off_State);
  4. #define TIMR0_TICK 10ms
  5. #define INIT_DELAY=1*60/(64*256*1us)
  6. #define Delay_2min=4*60/TMR0_TICK
  7. #define Delay_4min=4*60/TMR0_TICK
  8. //---------------------------------------------------------------------------------------------
  9. main()
  10. {
  11.         State=NoState;
  12.         Init
  13. Loop:
  14.         goto Loop;
  15. }
  16. //---------------------------------------------------------------------------------------------
  17. Interrupt()
  18. {
  19.                 if ( INTF ) {                               // 100Hz mains edge interrupt
  20.                 INTF=0;
  21.                 INTEDG=!INTEDG;                             // toggle int edge
  22.                 switch ( State )
  23.                 {
  24.                         No_State:
  25.                                     TMR0=0;                 // set up 16ms delay
  26.                                     Timer=INIT_DELAY;
  27.                                     State++;                // -> Init_State
  28.                                     break;
  29.                         Init_State:                         // delay INIT_DELAY
  30.                                     TMR0=0;
  31.                                     if ( (--Timer) == 0 )
  32.                                         State++;            // -> Wait_State
  33.                                     break;
  34.                         Wait_State:                         // reset 16ms timer
  35.                                     TMR0=0;
  36.                                     break;
  37.                         Delay_State:
  38.                         Off_State:
  39.                                     break;
  40.                 }
  41.                 };
  42.  
  43.                 if ( TMR0IF ) {                             // 16/10ms timer interrupt
  44.                 TMR0IF=0;
  45.                 switch ( State )
  46.                 {
  47.                         No_State:
  48.                         Init_State:
  49.                                     break;
  50.                         Wait_State:                         // mains timeout (16ms)
  51.                                     SSR=On;
  52.                                     if ( OPT == 1 )
  53.                                         Timer=Delay_4min;
  54.                                     else
  55.                                         Timer=Delay_2min;
  56.                                     State++;                // -> Delay_State
  57.                                     break;
  58.                         Delay_State:                        // delay Delay_Xmin
  59.                                     TMR0=TMR0_TICK;         // 10ms
  60.                                     if ( (--Timer) == 0 )
  61.                                     {
  62.                                             SSR=Off;
  63.                                             State++;        // -> Off_State
  64.                                     }
  65.                                     break;
  66.                         Off_State:
  67.                                     break;
  68.                 }
  69.                 };
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement