Đèn Giao Thông /* * File: newmain.c * Author: * * Created on April 13, 2015, */ //den giao thong tai nga tu: //dung pic16f877a thach anh 4MH //led doan anot //thoi gian den 15s, den xanh 12s, den vang 3s #include CONFIG(WDTDIS&PWRTEN&UNPROTECT&BORDIS&LVPDIS); #define _XTAL_FREQ 4000000 int chuc_dec,donvi_dec,chuc_hex,donvi_hex,dem,count=16000; int chuc_dec1,donvi_dec1,chuc_hex1,donvi_hex1,dem1,count1=16000; #define MAX_TASKS #define DO1 RC0 #define XANH1 RC1 #define VANG1 RC2 #define DO2 RC3 #define XANH2 RC4 #define VANG2 RC5 typedef struct _sTask { void (*pTask)(void); unsigned int Delay; unsigned int Period; char RunMe; }sTask; sTask SCH_Tasks[MAX_TASKS]; char SCH_Delete_Task(const unsigned char Index); void SCH_Init(void); void interrupt SCH_Update(void); char SCH_Add_Task(void (*pFn)(void), unsigned int delay, unsigned int period); void SCH_Dispatch_Tasks(void); void SCH_Start(void); // void init_port(); void tach_so(int dem,int dem1); void dec_to_hex(); void quetled_7doan(); // void Task_T1(void); void Task_T2(void); void Task_T3(void); void Task_T4(void); void Task_T5(void); void main(void) { init_port(); TRISC = 0; SCH_Init(); SCH_Add_Task(Task_T1,0,30000); SCH_Add_Task(Task_T2,12000,30000); SCH_Add_Task(Task_T3,15000,30000); SCH_Add_Task(Task_T4,27000,30000); SCH_Add_Task(Task_T5,0,10); SCH_Start(); while(1) { SCH_Dispatch_Tasks(); } } char SCH_Delete_Task(const unsigned char Index) { if(SCH_Tasks[Index].pTask==0) return -1; SCH_Tasks[Index].pTask = 0; SCH_Tasks[Index].Delay = 0; SCH_Tasks[Index].Period = 0; SCH_Tasks[Index].RunMe = 0; return 0; } void SCH_Init(void) { unsigned char Index; for(Index=0;Index