Logs
Consultez les logs.
OK
Liste des données
Consultez la liste des données.
OK
Loading...
Formulaire
Saisissez vos données.
Enregistrer
Annuler

8051

Vues
625

Introduction


8051 est l'un des microcontrôleurs à usage général les plus populaires actuellement utilisés. Le succès du 8051 a engendré un certain nombre de clones, qui sont collectivement appelés la famille de microcontrôleurs MCS-51, qui comprend des puces de fournisseurs tels qu'Atmel, Philips, Infineon et Texas Instruments. Le 8051 est un microcontrôleur 8 bits, ce qui signifie que la plupart des opérations disponibles sont limitées à 8 bits. Il existe 3 tailles de base du 8051 : Court, Standard et Etendu. Les puces Short et Standard sont souvent disponibles sous forme DIP (boîtier double en ligne), mais les modèles Extended 8051 ont souvent un facteur de forme différent et ne sont pas compatibles drop-in. Toutes ces puces sont appelées 8051 car elles peuvent toutes être programmées en utilisant le langage d'assemblage 8051, et elles partagent toutes certaines caractéristiques (bien que les différents modèles aient tous leurs propres caractéristiques spéciales). Les variantes du 8051 peuvent également avoir un certain nombre de fonctionnalités spéciales spécifiques au modèle, telles que UART, ADC, AOP, I2C, CAN, SPI, ce qui en fait un microcontrôleur encore plus puissant. Les puces 8051 sont utilisées dans une grande variété de systèmes de contrôle, d'applications de télécommunications, de robotique ainsi que dans l'industrie automobile. Selon certaines estimations, les puces de la famille 8051 représentent plus de 50% du marché des puces embarquées.

image.png


Recommandations techniques


Pour tester les extraits de code dans ce tutoriel, vous aurez besoin des éléments suivants:

Un environnement de développement intégré Keil µVision.
Un simulateur de circuits électroniques Proteus.
Un émulateur de ports séries virtuels VSPE.
Un terminal série RealTerm.
Lien vers Keil µVision: https://www.keil.com/download/
Lien vers Proteus: https://www.labcenter.com/


Clignotement d'une diode LED



Inclusion d'un fichier header


Inclusion d'un fichier header:
 
//===============================================
// main.c
//===============================================
#include <reg52.h>
//===============================================

Définition d'un nouveau type


Définition d'un nouveau type:

//===============================================
// main.c
//===============================================
#include <reg52.h>
//===============================================
typedef unsigned int uint;
//===============================================

Définition d'un port


Définition d'un port:
 
//===============================================
// main.c
//===============================================
#include <reg52.h>
//===============================================
typedef unsigned int uint;
//===============================================
#define PORT P1
//===============================================

Déclaration d'une broche


Déclaration d'une broche: 

//===============================================
// main.c
//===============================================
#include <reg52.h>
//===============================================
typedef unsigned int uint;
//===============================================
#define PORT P1
//===============================================
sbit LED = PORT^0;
//===============================================

Création d'une fonction


Création d'une fonction: 

//===============================================
// main.c
//===============================================
#include <reg52.h>
//===============================================
typedef unsigned int uint;
//===============================================
#define PORT P1
//===============================================
sbit LED = PORT^0;
//===============================================
void GDelay_ms(uint _ms) {

}
//===============================================

Création d'un délai logiciel


Création d'un délai logiciel:

//===============================================
// 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++);
    }
}
//===============================================

Programme principal


Programme principal:

//===============================================
// 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() {

}
//===============================================

Initialisation d'un port


Initialisation d'un port: 

//===============================================
// 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;
}
//===============================================

Boucle principale


Boucle principale:

//===============================================
// 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) {

    }
}
//===============================================
 

Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode LED:
 
//===============================================
// 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);
    }
}
//===============================================

Définition d'une constante


Résultat:

image.png

Définition d'une constante:
 
//===============================================
// 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);
    }
}
//===============================================

Inversion d'une broche


Résultat:

image.png

Inversion d'une broche:

//===============================================
// 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);
    }
}
//===============================================


Programmation modulaire



Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode LED: 

//===============================================
// 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);
    }
}
//===============================================

Création d'un module de fichiers headers


Résultat:

image.png

Programme principal:

//===============================================
// 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);
    }
}
//===============================================

Création d'un module de fichiers headers: 

//===============================================
// GInclude.h
//===============================================
#ifndef _GInclude_
#define _GInclude_
//===============================================
#include <reg52.h>
//===============================================
typedef unsigned int uint;
//===============================================
#endif
//===============================================

Création d'un module de délai


Résultat:

image.png

Programme principal:

//===============================================
// main.c
//===============================================
#include "GDelay.h"
//===============================================
#define PORT P1
//===============================================
sbit LED = PORT^0;
//===============================================
void main() {
    PORT = 0xFF;
    while(1) {
        LED = !LED;
        GDelay_ms(500);
    }
}
//===============================================

Création d'un module de délai: 

//===============================================
// 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++);
    }
}
//===============================================

Création d'un module de clignotement d'une LED


Résultat:

image.png

Programme principal:

#include "GDelay.h"
#include "GLed.h"
//===============================================
void main() {
    GLed_init();
    while(1) {
        GLed_update();
        GDelay_ms(500);
    }
}
//===============================================

Création d'un module de clignotement d'une LED:

//===============================================
// 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;
}
//===============================================


Ajustement d'une base de temps



Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode 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;
}
//===============================================

Ajustement d'une base de temps


Ajustement d'une base de temps:
 
//===============================================
// main.c
//===============================================
void main() {
    GLed_init();
    while(1) {
        GLed_update();
        GDelay_ms(1);
    }
}
//===============================================

Création d'un compteur de temps


Résultat:

image.png

Création d'un compteur de temps:
 
//===============================================
// 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;
}
//===============================================

Utilisation d'un compteur de temps


Résultat:

image.png

Utilisation d'un compteur de temps:

//===============================================
// 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;
    }
}
//===============================================


Utilisation d'un délai matériel



Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode LED: 

//===============================================
// 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;
    }
}
//===============================================

Configuration du timer 0 en mode 1 sur 16-bit


Configuration du timer 0 en mode 1 sur 16-bit:
 
//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
}
//===============================================

Initialisation du timer 0 pour un délai de 1ms


Initialisation du timer 0 pour un délai de 1ms:
 
//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
    TH0= 0xFC;
    TL0 = 0x66;
}
//===============================================

Démarrage du timer 0


Démarrage du timer 0: 

//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
    TH0= 0xFC;
    TL0 = 0x66;
    TR0 = 1;
}
//===============================================

Attente d'un débordement du timer 0


Attente d'un débordement du timer 0:
 
//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
    TH0= 0xFC;
    TL0 = 0x66;
    TR0 = 1;
    while(TF0 == 0);
}
//===============================================

Arrêt du timer 0


Arrêt du timer 0: 

//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
    TH0= 0xFC;
    TL0 = 0x66;
    TR0 = 1;
    while(TF0 == 0);
    TR0 = 0;
}
//===============================================

Réinitialisation du flag de débordement du timer 0


Réinitialisation du flag de débordement du timer 0: 

//===============================================
// GTimer.c
//===============================================
void GTimer_1ms() {
    TMOD = 0x01;
    TH0= 0xFC;
    TL0 = 0x66;
    TR0 = 1;
    while(TF0 == 0);
    TR0 = 0;
    TF0 = 0;
}
//===============================================

Utilisation d'un délai matériel


Résultat:

image.png

Utilisation d'un délai matériel: 

//===============================================
// 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;
    }
}
//===============================================


Utilisation d'une interruption externe



Configuration de l'interruption externe 0 sur front descendant


Configuration de l'interruption externe 0 sur front descendant:
 
//===============================================
// GInterrupt.c
//===============================================
void GInterrupt_init() {
    IT0 = 1;
}
//===============================================

Autorisation de l'interruption externe 0


Autorisation de l'interruption externe 0:
 
//===============================================
// GInterrupt.c
//===============================================
void GInterrupt_init() {
    IT0 = 1;
    EX0 = 1;
}
//===============================================

Autorisation de toutes les interruptions


Autorisation de toutes les interruptions:
 
//===============================================
// GInterrupt.c
//===============================================
void GInterrupt_init() {
    IT0 = 1;
    EX0 = 1;
    EA  = 1;
}
//===============================================

Gestionnaire de l'interruption externe 0


Gestionnaire de l'interruption externe 0:

//===============================================
// GInterrupt.c
//===============================================
static void GInterrupt_update() interrupt 0 {

}
//===============================================

Clignotement d'un port sur front descendant


Résultat:

image.png

Clignotement d'un port sur front descendant:
 
//===============================================
// 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();
}
//===============================================


Utilisation de l'interruption d'un timer



Initialisation du timer 0 pour un délai de 50ms sur 16-bit


Initialisation du timer 0 pour un délai de 50ms sur 16-bit:
 
//===============================================
// GTimer.c
//===============================================
void GTimer_init() {
    TMOD = 0x01;
    TH0 = 0x4B;
    TL0 = 0xFD;
    ET0 = 1;
    EA = 1;
    TR0 = 1;
}
//===============================================

Rechargement du timer 0 pour un délai de 50ms


Rechargement du timer 0 pour un délai de 50ms:
 
//===============================================
// GTimer.c
//===============================================
static void GTimer_reload() {
    TH0 = 0x4B;
    TL0 = 0xFD;
}
//===============================================

Gestionnaire de l'interruption du timer 0


Gestionnaire de l'interruption du timer 0:

//===============================================
// GTimer.c
//===============================================
static void GTimer_update() interrupt 1 {
    GTimer_reload();
}
//===============================================

Inversion d'une broche toutes les 50ms avec le timer 0


Résultat:

image.png

Inversion d'une broche toutes les 50ms avec le timer 0:
 
//===============================================
// 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();
}
//===============================================

Inversion d'une broche toutes les 50ms avec le timer 2


Résultat:

image.png

Inversion d'une broche toutes les 50ms avec le timer 2:

//===============================================
// 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();
}
//===============================================


Système d'exploitation embarqué simple (sEOS)



Initialisation du système sEOS


Initialisation du système sEOS:
 
//===============================================
// 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;
}
//===============================================

Démarrage du système sEOS


Démarrage du système sEOS:
 
//===============================================
// GSeos.c
//===============================================
void GSeos_start() {
    EA = 1;
}
//===============================================

Mise en veille du système sEOS


Mise en veille du système sEOS:
 
//===============================================
// GSeos.c
//===============================================
void GSeos_goToSleep() {
    PCON |= 0x01;
}
//===============================================

Gestionnaire des tâches du système sEOS


Gestionnaire des tâches du système sEOS: 

//===============================================
// GSeos.c
//===============================================
static void GSeos_update() interrupt 5 {
    TF2 = 0;
}
//===============================================

Inversion d'une broche toutes les 1ms


Résultat:

image.png

Inversion d'une broche toutes les 1ms:
 
//===============================================
// 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;
}
//===============================================

Inversion d'une broche toutes les 500ms


Résultat:

image.png

Inversion d'une broche toutes les 500ms:
 
//===============================================
// 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;
    }
}
//===============================================


Ordonnanceur multitâche temps réel (Scheduler)



Initialisation du système SCH


Initialisation du système SCH:
 
//===============================================
// 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;
}
//===============================================

Suppression d'une tâche du système SCH


Suppression d'une tâche du système SCH: 

//===============================================
// 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;
}
//===============================================

Ajout d'une tâche dans le système SCH


Ajout d'une tâche dans le système SCH: 

//===============================================
// 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;
}
//===============================================

Démarrage du système SCH


Démarrage du système SCH:
 
//===============================================
// GSch.c
//===============================================
void GSch_start() {
    EA = 1;
}
//===============================================

Mise en veille du système SCH


Mise en veille du système SCH:
 
//===============================================
// GSch.c
//===============================================
static void GSch_goToSleep() {
    PCON |= 0x01;
}
//===============================================

Répartiteur des tâches du système SCH


Répartiteur des tâches du système SCH:

//===============================================
// 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();
}
//===============================================
 

Mise à jour des tâches du système SCH


Mise à jour des tâches du système SCH:
 
//===============================================
// 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;
            }
        }
    }
}
//===============================================

Inversion d'une broche toutes les 200ms


Résultat:

image.png

Inversion d'une broche toutes les 200ms:
 
//===============================================
// 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;
}
//===============================================

Inversion d'une broche toutes les 500ms


Résultat:

image.png

Inversion d'une broche toutes les 500ms:

//===============================================
// main.c
//===============================================
void main() {
    GSch_init(1);
    GLed_init();
    GSch_addTask(GLed_update, 0, 500);
    GSch_start();
    while(1) {
        GSch_dispatchTasks();
    }
}
//===============================================


Utilisation d'une diode LED



Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode LED: 

//===============================================
// 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;
}
//===============================================

Réalisation d'un chenillard à diode LED


Résultat:

image.png

Réalisation d'un chenillard à diode 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;
}
//===============================================


Utilisation d'un afficheur 7-segment



Réalisation d'un compteur de 0 à 9


Résultat:

image.png

Réalisation d'un compteur de 0 à 9: 

//===============================================
// 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];
}
//===============================================

Réalisation d'un compteur de 0 à 99


Résultat:

image.png

Réalisation d'un compteur de 0 à 99: 

//===============================================
// 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;
    }
}
//===============================================

Réalisation d'un compteur de 0 à 9999


Résultat:

image.png

Réalisation d'un compteur de 0 à 9999:

//===============================================
// 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;
    }
}
//===============================================

Réalisation d'une horloge numérique


Résultat:

image.png

Réalisation d'une horloge numérique: 

//===============================================
// 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;
    }
}
//===============================================


Programmation par sélection de projet



Clignotement d'une diode LED


Résultat:

image.png

Clignotement d'une diode LED:
 
//===============================================
// 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;
}
//===============================================

Intégration d'un sélecteur de processus


Résultat:

image.png

Intégration d'un sélecteur de processus:
 
//===============================================
// 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;
}
//===============================================

Intégration d'un sélecteur de processus SCH


Résultat:

image.png

Intégration d'un sélecteur de processus SCH:
 
//===============================================
// 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;
}
//===============================================

Intégration d'un sélecteur de tâches SCH


Résultat:

image.png

Intégration d'un sélecteur de tâches SCH:
 
//===============================================
// 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;
}
//===============================================

Sélection d'un projet SCH


Résultat:

image.png

Sélection d'un projet SCH: 

//===============================================
// 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;
}
//===============================================

Clignotement d'une diode LED par SCH


Résultat:

image.png

Clignotement d'une diode LED par SCH:

//===============================================
// 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;
}
//===============================================

Réalisation d'un compteur de 0 à 9 par SCH


Résultat:

image.png

Réalisation d'un compteur de 0 à 9 par SCH:

//===============================================
// 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];
}
//===============================================