//=============================================== // main.c //=============================================== #include <reg52.h> //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { } } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { LED = 0; GDelay_ms(500); LED = 1; GDelay_ms(500); } } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define LED_ON (0) #define LED_OFF (!LED_ON) //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { LED = LED_ON; GDelay_ms(500); LED = LED_OFF; GDelay_ms(500); } } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { LED = !LED; GDelay_ms(500); } } //===============================================
//=============================================== // main.c //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { LED = !LED; GDelay_ms(500); } } //===============================================
//=============================================== // main.c //=============================================== #include "GInclude.h" //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== void main() { PORT = 0xFF; while(1) { LED = !LED; GDelay_ms(500); } } //===============================================
//=============================================== // GInclude.h //=============================================== #ifndef _GInclude_ #define _GInclude_ //=============================================== #include <reg52.h> //=============================================== typedef unsigned int uint; //=============================================== #endif //===============================================
//=============================================== // main.c //=============================================== #include "GDelay.h" //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void main() { PORT = 0xFF; while(1) { LED = !LED; GDelay_ms(500); } } //===============================================
//=============================================== // GDelay.h //=============================================== #ifndef _GDelay_ #define _GDelay_ //=============================================== #include "GInclude.h" //=============================================== void GDelay_ms(uint _ms); //=============================================== #endif //=============================================== // GDelay.c //=============================================== #include "GDelay.h" //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //===============================================
#include "GDelay.h" #include "GLed.h" //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(500); } } //===============================================
//=============================================== // GLed.h //=============================================== #ifndef _GLed_ #define _GLed_ //=============================================== #include "GInclude.h" //=============================================== void GLed_init(); void GLed_update(); //=============================================== #endif //=============================================== // GLed.c //=============================================== #include "GLed.h" //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(500); } } //=============================================== // GLed.c //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(1); } } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(1); } } //=============================================== // GLed.c //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== static uint gTime = 0; //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(1); } } //=============================================== // GLed.c //=============================================== #define PORT P1 //=============================================== sbit LED = PORT^0; //=============================================== static uint gTime = 0; //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { if(++gTime == 500) { LED = !LED; gTime = 0; } } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GDelay_ms(1); } } //=============================================== // GDelay.c //=============================================== void GDelay_ms(uint _ms) { uint i, j; for(i = 0;i < _ms; i++) { for(j = 0; j < 125; j++); } } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { if(++gTime == 500) { LED = !LED; gTime = 0; } } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; TR0 = 1; } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; TR0 = 1; while(TF0 == 0); } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; TR0 = 1; while(TF0 == 0); TR0 = 0; } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; TR0 = 1; while(TF0 == 0); TR0 = 0; TF0 = 0; } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); while(1) { GLed_update(); GTimer_1ms(); } } //=============================================== // GTimer.c //=============================================== void GTimer_1ms() { TMOD = 0x01; TH0= 0xFC; TL0 = 0x66; TR0 = 1; while(TF0 == 0); TR0 = 0; TF0 = 0; } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { if(++gTime == 500) { LED = !LED; gTime = 0; } } //===============================================
//=============================================== // GInterrupt.c //=============================================== void GInterrupt_init() { IT0 = 1; } //===============================================
//=============================================== // GInterrupt.c //=============================================== void GInterrupt_init() { IT0 = 1; EX0 = 1; } //===============================================
//=============================================== // GInterrupt.c //=============================================== void GInterrupt_init() { IT0 = 1; EX0 = 1; EA = 1; } //===============================================
//=============================================== // GInterrupt.c //=============================================== static void GInterrupt_update() interrupt 0 { } //===============================================
//=============================================== // main.c //=============================================== void main() { GPort_init(); GInterrupt_init(); while(1); } //=============================================== // GPort.c //=============================================== void GPort_init() { PORT = 0xFF; } //=============================================== void GPort_update() { PORT = ~PORT; } //=============================================== // GInterrupt.c //=============================================== void GInterrupt_init() { IT0 = 1; EX0 = 1; EA = 1; } //=============================================== void GInterrupt_update() interrupt 0 { GPort_update(); } //===============================================
//=============================================== // GTimer.c //=============================================== void GTimer_init() { TMOD = 0x01; TH0 = 0x4B; TL0 = 0xFD; ET0 = 1; EA = 1; TR0 = 1; } //===============================================
//=============================================== // GTimer.c //=============================================== static void GTimer_reload() { TH0 = 0x4B; TL0 = 0xFD; } //===============================================
//=============================================== // GTimer.c //=============================================== static void GTimer_update() interrupt 1 { GTimer_reload(); } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); GTimer_init(); while(1); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //=============================================== // GTimer.c //=============================================== void GTimer_init() { TMOD = 0x01; TH0 = 0x4B; TL0 = 0xFD; ET0 = 1; EA = 1; TR0 = 1; } //=============================================== static void GTimer_reload() { TH0 = 0x4B; TL0 = 0xFD; } //=============================================== static void GTimer_update() interrupt 1 { GTimer_reload(); GLed_update(); } //===============================================
//=============================================== // main.c //=============================================== void main() { GLed_init(); GTimer_init(); while(1); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //=============================================== // GTimer.c //=============================================== void GTimer_init() { T2CON = 0x00; TH2 = 0x4B; TL2 = 0xFD; RCAP2H = 0x4B; RCAP2L = 0xFD; TF2 = 0; ET2 = 1; EA = 1; TR2 = 1; } //=============================================== static void GTimer_update() interrupt 5 { TF2 = 0; GLed_update(); } //===============================================
//=============================================== // GInclude.h //=============================================== #define OSC_FREQ (11059200UL) #define OSC_PER_INST (12) //=============================================== // GSeos.c //=============================================== #define PRELOAD(ms) (65536 - ((OSC_FREQ * ms) / (OSC_PER_INST * 1000))) #define PRELOAD_H(ms) (PRELOAD(ms) / 256) #define PRELOAD_L(ms) (PRELOAD(ms) % 256) //=============================================== void GSeos_init(uchar _ms) { T2CON = 0x00; TH2 = PRELOAD_H(_ms); TL2 = PRELOAD_L(_ms); RCAP2H = PRELOAD_H(_ms); RCAP2L = PRELOAD_L(_ms); TF2 = 0; ET2 = 1; TR2 = 1; } //===============================================
//=============================================== // GSeos.c //=============================================== void GSeos_start() { EA = 1; } //===============================================
//=============================================== // GSeos.c //=============================================== void GSeos_goToSleep() { PCON |= 0x01; } //===============================================
//=============================================== // GSeos.c //=============================================== static void GSeos_update() interrupt 5 { TF2 = 0; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSeos_init(1); GLed_init(); GSeos_start(); while(1) { GSeos_goToSleep(); } } //=============================================== // GSeos.c //=============================================== void GSeos_init(uchar _ms) { T2CON = 0x00; TH2 = PRELOAD_H(_ms); TL2 = PRELOAD_L(_ms); RCAP2H = PRELOAD_H(_ms); RCAP2L = PRELOAD_L(_ms); TF2 = 0; ET2 = 1; TR2 = 1; } //=============================================== void GSeos_start() { EA = 1; } //=============================================== void GSeos_goToSleep() { PCON |= 0x01; } //=============================================== static void GSeos_update() interrupt 5 { TF2 = 0; GLed_update(); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSeos_init(1); GLed_init(); GSeos_start(); while(1) { GSeos_goToSleep(); } } //=============================================== // GSeos.c //=============================================== static void GSeos_update() interrupt 5 { TF2 = 0; GLed_update(); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { if(++gTime == 500) { LED = !LED; gTime = 0; } } //===============================================
//=============================================== // GInclude.h //=============================================== #define OSC_FREQ (11059200UL) #define OSC_PER_INST (12) //=============================================== // GSch.c //=============================================== #define PRELOAD(ms) (65536 - ((OSC_FREQ * ms) / (OSC_PER_INST * 1000))) #define PRELOAD_H(ms) (PRELOAD(ms) / 256) #define PRELOAD_L(ms) (PRELOAD(ms) % 256) //=============================================== #define SCH_MAX_TASKS (1) //=============================================== typedef struct _sGTask sGTask; //=============================================== struct _sGTask { void (*m_pTask)(); uint m_delay; uint m_period; uchar m_runMe; }; //=============================================== sGTask gTaskMap[SCH_MAX_TASKS]; //=============================================== void GSch_init(uchar _ms) { uchar lIndex; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { GSch_deleteTask(lIndex); } T2CON = 0x00; TH2 = PRELOAD_H(_ms); TL2 = PRELOAD_L(_ms); RCAP2H = PRELOAD_H(_ms); RCAP2L = PRELOAD_L(_ms); TF2 = 0; ET2 = 1; TR2 = 1; } //===============================================
//=============================================== // GSch.c //=============================================== static void GSch_deleteTask(uchar _index) { gTaskMap[_index].m_pTask = 0x0000; gTaskMap[_index].m_delay = 0; gTaskMap[_index].m_period = 0; gTaskMap[_index].m_runMe = 0; } //===============================================
//=============================================== // GSch.c //=============================================== void GSch_addTask(void (*_pTask)(), const uint _delay, const uint _period) { uchar lIndex = 0; while((gTaskMap[lIndex].m_pTask != 0) && (lIndex < SCH_MAX_TASKS)) lIndex++; if(lIndex == SCH_MAX_TASKS) return; gTaskMap[lIndex].m_pTask = _pTask; gTaskMap[lIndex].m_delay = _delay; gTaskMap[lIndex].m_period = _period; gTaskMap[lIndex].m_runMe = 0; } //===============================================
//=============================================== // GSch.c //=============================================== void GSch_start() { EA = 1; } //===============================================
//=============================================== // GSch.c //=============================================== static void GSch_goToSleep() { PCON |= 0x01; } //===============================================
//=============================================== // GSch.c //=============================================== void GSch_dispatchTasks() { uchar lIndex; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { if(gTaskMap[lIndex].m_runMe > 0) { (*gTaskMap[lIndex].m_pTask)(); gTaskMap[lIndex].m_runMe -= 1; if(gTaskMap[lIndex].m_period == 0) { GSch_deleteTask(lIndex); } } } GSch_goToSleep(); } //===============================================
//=============================================== // GSch.c //=============================================== static void GSch_update() interrupt 5 { uchar lIndex; TF2 = 0; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { if(gTaskMap[lIndex].m_pTask != 0) { if(gTaskMap[lIndex].m_delay == 0) { gTaskMap[lIndex].m_runMe += 1; if(gTaskMap[lIndex].m_period != 0) { gTaskMap[lIndex].m_delay = gTaskMap[lIndex].m_period; } } else { gTaskMap[lIndex].m_delay -= 1; } } } } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 200); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // GSch.c //=============================================== void GSch_init(uchar _ms) { uchar lIndex; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { GSch_deleteTask(lIndex); } T2CON = 0x00; TH2 = PRELOAD_H(_ms); TL2 = PRELOAD_L(_ms); RCAP2H = PRELOAD_H(_ms); RCAP2L = PRELOAD_L(_ms); TF2 = 0; ET2 = 1; TR2 = 1; } //=============================================== void GSch_addTask(void (*_pTask)(), const uint _delay, const uint _period) { uchar lIndex = 0; while((gTaskMap[lIndex].m_pTask != 0) && (lIndex < SCH_MAX_TASKS)) lIndex++; if(lIndex == SCH_MAX_TASKS) return; gTaskMap[lIndex].m_pTask = _pTask; gTaskMap[lIndex].m_delay = _delay; gTaskMap[lIndex].m_period = _period; gTaskMap[lIndex].m_runMe = 0; } //=============================================== void GSch_start() { EA = 1; } //=============================================== static void GSch_update() interrupt 5 { uchar lIndex; TF2 = 0; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { if(gTaskMap[lIndex].m_pTask != 0) { if(gTaskMap[lIndex].m_delay == 0) { gTaskMap[lIndex].m_runMe += 1; if(gTaskMap[lIndex].m_period != 0) { gTaskMap[lIndex].m_delay = gTaskMap[lIndex].m_period; } } else { gTaskMap[lIndex].m_delay -= 1; } } } } //=============================================== void GSch_dispatchTasks() { uchar lIndex; for(lIndex = 0; lIndex < SCH_MAX_TASKS; lIndex++) { if(gTaskMap[lIndex].m_runMe > 0) { (*gTaskMap[lIndex].m_pTask)(); gTaskMap[lIndex].m_runMe -= 1; if(gTaskMap[lIndex].m_period == 0) { GSch_deleteTask(lIndex); } } } GSch_goToSleep(); } //=============================================== static void GSch_deleteTask(uchar _index) { gTaskMap[_index].m_pTask = 0x0000; gTaskMap[_index].m_delay = 0; gTaskMap[_index].m_period = 0; gTaskMap[_index].m_runMe = 0; } //=============================================== static void GSch_goToSleep() { PCON |= 0x01; } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GChenillard_init(); GSch_addTask(GChenillard_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // GChenillard.c //=============================================== void GChenillard_init() { DATA_PORT = 0xFF; } //=============================================== void GChenillard_update() { if(gCount <= 7) GChenillard_updateM0(); else if(gCount <= 16) GChenillard_updateM1(); else if(gCount <= 26) GChenillard_updateM2(); else if(gCount <= 36) GChenillard_updateM3(); } //=============================================== static void GChenillard_updateM0() { if(gCount == 0) {gData = 0x01; gCount = 1;} else if(gCount == 1) {gData = 0x02; gCount = 2;} else if(gCount == 2) {gData = 0x04; gCount = 3;} else if(gCount == 3) {gData = 0x08; gCount = 4;} else if(gCount == 4) {gData = 0x10; gCount = 5;} else if(gCount == 5) {gData = 0x20; gCount = 6;} else if(gCount == 6) {gData = 0x40; gCount = 7;} else if(gCount == 7) {gData = 0x80; gCount = 8;} DATA_PORT = ~gData; } //=============================================== static void GChenillard_updateM1() { if(gCount == 8) {gData = 0x01; gCount = 9;} else if(gCount == 9) {gData = 0x03; gCount = 10;} else if(gCount == 10) {gData = 0x06; gCount = 11;} else if(gCount == 11) {gData = 0x0C; gCount = 12;} else if(gCount == 12) {gData = 0x18; gCount = 13;} else if(gCount == 13) {gData = 0x30; gCount = 14;} else if(gCount == 14) {gData = 0x60; gCount = 15;} else if(gCount == 15) {gData = 0xC0; gCount = 16;} else if(gCount == 16) {gData = 0x80; gCount = 17;} DATA_PORT = ~gData; } //=============================================== static void GChenillard_updateM2() { if(gCount == 17) {gData = 0x01; gCount = 18;} else if(gCount == 18) {gData = 0x03; gCount = 19;} else if(gCount == 19) {gData = 0x07; gCount = 20;} else if(gCount == 20) {gData = 0x0E; gCount = 21;} else if(gCount == 21) {gData = 0x1C; gCount = 22;} else if(gCount == 22) {gData = 0x38; gCount = 23;} else if(gCount == 23) {gData = 0x70; gCount = 24;} else if(gCount == 24) {gData = 0xE0; gCount = 25;} else if(gCount == 25) {gData = 0xC0; gCount = 26;} else if(gCount == 26) {gData = 0x80; gCount = 27;} DATA_PORT = ~gData; } //=============================================== static void GChenillard_updateM3() { if(gCount == 27) {gData = 0x01; gCount = 28;} else if(gCount == 28) {gData = 0x03; gCount = 29;} else if(gCount == 29) {gData = 0x07; gCount = 30;} else if(gCount == 30) {gData = 0x0F; gCount = 31;} else if(gCount == 31) {gData = 0x1E; gCount = 32;} else if(gCount == 32) {gData = 0x3C; gCount = 33;} else if(gCount == 33) {gData = 0xF0; gCount = 34;} else if(gCount == 34) {gData = 0xE0; gCount = 35;} else if(gCount == 35) {gData = 0xC0; gCount = 36;} else if(gCount == 36) {gData = 0x80; gCount = 0;} DATA_PORT = ~gData; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); G7SegRun_init(); GSch_addTask(G7SegRun_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // G7SegRun.c //=============================================== void G7SegRun_init() { G7Seg_write(gData); } //=============================================== void G7SegRun_update() { G7Seg_write(gData); if(++gData > 9) gData = 0; } //=============================================== // G7Seg.c //=============================================== static code uchar gDigitMap[] = { 0x3F, 0x06, 0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F }; //=============================================== void G7Seg_write(uchar _data) { DATA_PORT = ~gDigitMap[_data]; } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); G7SegRun2_init(); GSch_addTask(G7Seg2_update, 0, 10); GSch_addTask(G7SegRun2_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // G7SegRun2.c //=============================================== void G7SegRun2_init() { G7Seg2_write(gData); } //=============================================== void G7SegRun2_update() { G7Seg2_write(gData); gData += 10; if(gData > 99) gData = 0; } //=============================================== // G7Seg2.c //=============================================== static code uchar gDigitMap[] = { 0x3F, 0x06, 0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F }; //=============================================== static void G7Seg2_writeOff() { CMD_PIN_0 = 0; CMD_PIN_1 = 0; } //=============================================== static void G7Seg2_writeCmd(uchar _cmd) { if(_cmd == 0) { CMD_PIN_0 = 1; } else if(_cmd == 1) { CMD_PIN_1 = 1; } } //=============================================== static void G7Seg2_writeData(uchar _cmd, uchar _data) { uchar lPort = DATA_PORT; uchar lData = ~gDigitMap[_data]; G7Seg2_writeOff(); lPort &= 0x80; lData &= 0x7F; lPort |= lData; DATA_PORT = lPort; G7Seg2_writeCmd(_cmd); } //=============================================== void G7Seg2_write(uchar _data) { gDataValue = _data; } //=============================================== void G7Seg2_update() { uchar lData = gDataValue; if(gCmdSelect == 0) { lData = lData%10; G7Seg2_writeData(1, lData); gCmdSelect = 1; } else if(gCmdSelect == 1) { lData = (lData/10)%10; G7Seg2_writeData(0, lData); gCmdSelect = 0; } } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); G7SegRun3_init(); GSch_addTask(G7Seg3_update, 0, 10); GSch_addTask(G7SegRun3_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // G7SegRun3.c //=============================================== void G7SegRun3_init() { G7Seg3_write(gData); } //=============================================== void G7SegRun3_update() { G7Seg3_write(gData); gData += 1000; if(gData > 9999) gData = 123; } //=============================================== // G7Seg3.c //=============================================== static code uchar gDigitMap[] = { 0x3F, 0x06, 0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F }; //=============================================== static void G7Seg3_writeOff() { CMD_PIN_0 = 0; CMD_PIN_1 = 0; CMD_PIN_2 = 0; CMD_PIN_3 = 0; } //=============================================== static void G7Seg3_writeCmd(uchar _cmd) { if(_cmd == 0) { CMD_PIN_0 = 1; } else if(_cmd == 1) { CMD_PIN_1 = 1; } else if(_cmd == 2) { CMD_PIN_2 = 1; } else if(_cmd == 3) { CMD_PIN_3 = 1; } } //=============================================== static void G7Seg3_writeData(uchar _cmd, uchar _data) { uchar lPort = DATA_PORT; uchar lData = ~gDigitMap[_data]; G7Seg3_writeOff(); lPort &= 0x80; lData &= 0x7F; lPort |= lData; DATA_PORT = lPort; G7Seg3_writeCmd(_cmd); } //=============================================== void G7Seg3_write(uint _data) { gDataValue = _data; } //=============================================== void G7Seg3_update() { uint lData = gDataValue; if(gCmdSelect == 0) { lData = lData%10; G7Seg3_writeData(3, lData); gCmdSelect = 1; } else if(gCmdSelect == 1) { lData = (lData/10)%10; G7Seg3_writeData(2, lData); gCmdSelect = 2; } else if(gCmdSelect == 2) { lData = (lData/100)%10; G7Seg3_writeData(1, lData); gCmdSelect = 3; } else if(gCmdSelect == 3) { lData = (lData/1000)%10; G7Seg3_writeData(0, lData); gCmdSelect = 0; } } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GClock_setHour(20); GClock_setMinute(30); GClock_setSecond(55); GSch_addTask(GClock_update, 0, 10); GSch_addTask(GClock_updateDP, 1, 500); GSch_addTask(GClock_updateSecond, 3, 1000); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // GClock.c //=============================================== static code uchar gDigitMap[] = { 0x3F, 0x06, 0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F }; //=============================================== static void GClock_writeOff() { CMD_PIN_0 = 0; CMD_PIN_1 = 0; CMD_PIN_2 = 0; CMD_PIN_3 = 0; } //=============================================== static void GClock_writeCmd(uchar _cmd) { if(_cmd == 0) { CMD_PIN_0 = 1; } else if(_cmd == 1) { CMD_PIN_1 = 1; } else if(_cmd == 2) { CMD_PIN_2 = 1; } else if(_cmd == 3) { CMD_PIN_3 = 1; } } //=============================================== static void GClock_writeData(uchar _cmd, uchar _data) { uchar lPort = DATA_PORT; uchar lData = ~gDigitMap[_data]; GClock_writeOff(); lPort &= 0x80; lData &= 0x7F; lPort |= lData; DATA_PORT = lPort; GClock_writeCmd(_cmd); } //=============================================== void GClock_setHour(uchar _hour) { gData.m_hour = _hour; } //=============================================== void GClock_setMinute(uchar _minute) { gData.m_minute = _minute; } //=============================================== void GClock_setSecond(uchar _second) { gData.m_second = _second; } //=============================================== void GClock_update() { uchar lData; if(gData.m_update == 0) { lData = (gData.m_hour/10)%10; GClock_writeData(0, lData); gData.m_update = 1; } else if(gData.m_update == 1) { lData = gData.m_hour%10; GClock_writeData(1, lData); gData.m_update = 2; } else if(gData.m_update == 2) { lData = (gData.m_minute/10)%10; GClock_writeData(2, lData); gData.m_update = 3; } else if(gData.m_update == 3) { lData = gData.m_minute%10; GClock_writeData(3, lData); gData.m_update = 0; } } //=============================================== void GClock_updateDP() { DP_PIN = !DP_PIN; } //=============================================== void GClock_updateSecond() { gData.m_second++; if(gData.m_second == 60) { gData.m_second = 0; gData.m_minute++; } if(gData.m_minute == 60) { gData.m_minute = 0; gData.m_hour++; } if(gData.m_hour == 24) { gData.m_hour = 0; } } //===============================================
//=============================================== // main.c //=============================================== void main() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 500); GSch_start(); while(1) { GSch_dispatchTasks(); } } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GProcess_init(); while(1) { GProcess_run(); } } //=============================================== // GProcess.c //=============================================== void GProcess_init() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 500); GSch_start(); } //=============================================== void GProcess_run() { GSch_dispatchTasks(); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GProcess_init(); while(1) { GProcess_run(); } } //=============================================== // GProcess.c //=============================================== void GProcess_init() { gAction = 0; if(gAction == 0) GSchRun_init(); } //=============================================== void GProcess_run() { if(gAction == 0) GSchRun_run(); } //=============================================== // GSchRun.c //=============================================== void GSchRun_init() { GSch_init(1); GLed_init(); GSch_addTask(GLed_update, 0, 500); GSch_start(); } //=============================================== void GSchRun_run() { GSch_dispatchTasks(); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GProcess_init(); while(1) { GProcess_run(); } } //=============================================== // GProcess.c //=============================================== void GProcess_init() { gAction = 0; if(gAction == 0) GSchRun_init(); } //=============================================== void GProcess_run() { if(gAction == 0) GSchRun_run(); } //=============================================== // GSchRun.c //=============================================== void GSchRun_init() { GSch_init(1); GSchTask_init(); GSch_start(); } //=============================================== void GSchRun_run() { GSch_dispatchTasks(); } //=============================================== // GSchTask.c //=============================================== void GSchTask_init() { GLed_init(); GSch_addTask(GLed_update, 0, 500); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // main.c //=============================================== void main() { GProcess_init(); while(1) { GProcess_run(); } } //=============================================== // GProcess.c //=============================================== void GProcess_init() { gAction = 0; if(gAction == 0) GSchRun_init(); } //=============================================== void GProcess_run() { if(gAction == 0) GSchRun_run(); } //=============================================== // GSchRun.c //=============================================== void GSchRun_init() { GSch_init(1); GSchTask_init(); GSch_start(); } //=============================================== void GSchRun_run() { GSch_dispatchTasks(); } //=============================================== // GSchTask.c //=============================================== void GSchTask_init() { gAction = 0; if(gAction == 0) GSchTask_initLedFlash(); } //=============================================== static void GSchTask_initLedFlash() { GLed_init(); GSch_addTask(GLed_update, 0, 500); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // GSchTask.c //=============================================== void GSchTask_init() { gAction = 0; if(gAction == 0) GSchTask_initLedFlash(); } //=============================================== static void GSchTask_initLedFlash() { GLed_init(); GSch_addTask(GLed_update, 0, 500); } //=============================================== // GLed.c //=============================================== void GLed_init() { PORT = 0xFF; } //=============================================== void GLed_update() { LED = !LED; } //===============================================
//=============================================== // GSchTask.c //=============================================== void GSchTask_init() { gAction = 1; if(gAction == 0) GSchTask_initLedFlash(); else if(gAction == 1) GSchTask_init7Seg(); } //=============================================== static void GSchTask_init7Seg() { G7SegRun_init(); GSch_addTask(G7SegRun_update, 0, 500); } //=============================================== // G7SegRun.c //=============================================== void G7SegRun_init() { G7Seg_write(gData); } //=============================================== void G7SegRun_update() { G7Seg_write(gData); if(++gData > 9) gData = 0; } //=============================================== // G7Seg.c //=============================================== static code uchar gDigitMap[] = { 0x3F, 0x06, 0x5B,0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F }; //=============================================== void G7Seg_write(uchar _data) { DATA_PORT = ~gDigitMap[_data]; } //===============================================