LCD 7 segment

De LOAD.

Cette page a pour but d’héberger la doc des écrans LCD que L0ad a reçu en cadeau de fond de tiroir de la part de Georges T.
Fichier:ecran_lcd_7_seg_donation.jpg

La doc :
Fichier:LCD 7segment clover display S5080.pdf

Librairie (pour PIC mais facilement transposable)

/* librairie d'utilisation d'afficheur 7 segments LCD double
 * fonctions :
 * aff1(val, dp) => affiche val sur le digit de gauche, dp le point
 * aff2(val, dp) => affiche val sur le digit de droite, dp le point
 * aff_sct(void)  => effectue le rafraichissement de l'écran (efface puis raffiche), a appeler au moins toutes les 20ms
 */

#include <pic18f2550.h>

// definition des broches
#define aff1dp      LATAbits.LA2
#define aff1_a      LATBbits.LB1
#define aff1_b      LATBbits.LB0
#define aff1_c      LATBbits.LB4
#define aff1_d      LATBbits.LB5
#define aff1_e      LATBbits.LB6
#define aff1_f      LATBbits.LB2
#define aff1_g      LATBbits.LB3
#define aff2dp      LATAbits.LA2
#define aff2_a      LATCbits.LC2
#define aff2_b      LATCbits.LC1
#define aff2_c      LATCbits.LC0
#define aff2_d      LATAbits.LA5
#define aff2_e      LATAbits.LA4
#define aff2_f      LATCbits.LC7
#define aff2_g      LATCbits.LC6

char val1, dp1, val2, dp2, alterne;

void aff1(char val, char dp, char com)
{
    alterne = 0;
    val1 = val;
    dp1 = dp;
    if (dp)
        aff1dp = 1;
    else
        aff1dp = 0;
    switch (val)
    {
        case 0:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 0;
            break;
        case 1:
            aff1_a = 0;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 0;
            aff1_e = 0;
            aff1_f = 0;
            aff1_g = 0;
            break;
        case 2:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 0;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 0;
            aff1_g = 1;
            break;
        case 3:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 0;
            aff1_f = 0;
            aff1_g = 1;
            break;
        case 4:
            aff1_a = 0;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 0;
            aff1_e = 0;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 5:
            aff1_a = 1;
            aff1_b = 0;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 0;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 6:
            aff1_a = 1;
            aff1_b = 0;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 7:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 0;
            aff1_e = 0;
            aff1_f = 0;
            aff1_g = 0;
            break;
        case 8:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 9:
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 0;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 10:    //A
            aff1_a = 1;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 0;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 11:    //b
            aff1_a = 0;
            aff1_b = 0;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 12:    //C
            aff1_a = 1;
            aff1_b = 0;
            aff1_c = 0;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 0;
            break;
        case 13:    //d
            aff1_a = 0;
            aff1_b = 1;
            aff1_c = 1;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 0;
            aff1_g = 1;
            break;
        case 14:    //E
            aff1_a = 1;
            aff1_b = 0;
            aff1_c = 0;
            aff1_d = 1;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        case 15:    //F
            aff1_a = 1;
            aff1_b = 0;
            aff1_c = 0;
            aff1_d = 0;
            aff1_e = 1;
            aff1_f = 1;
            aff1_g = 1;
            break;
        default:
            aff1_a = 0;
            aff1_b = 0;
            aff1_c = 0;
            aff1_d = 0;
            aff1_e = 0;
            aff1_f = 0;
            aff1_g = 0;
            break;
    }
}

void aff2(char val, char dp, char com)
{
    alterne = 0;
    val2 = val;
    dp2 = dp;
    if (dp)
        aff2dp = 1;
    else
        aff2dp = 0;
    switch (val)
    {
        case 0:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 0;
            break;
        case 1:
            aff2_a = 0;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 0;
            aff2_e = 0;
            aff2_f = 0;
            aff2_g = 0;
            break;
        case 2:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 0;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 0;
            aff2_g = 1;
            break;
        case 3:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 0;
            aff2_f = 0;
            aff2_g = 1;
            break;
        case 4:
            aff2_a = 0;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 0;
            aff2_e = 0;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 5:
            aff2_a = 1;
            aff2_b = 0;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 0;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 6:
            aff2_a = 1;
            aff2_b = 0;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 7:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 0;
            aff2_e = 0;
            aff2_f = 0;
            aff2_g = 0;
            break;
        case 8:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 9:
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 0;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 10:    //A
            aff2_a = 1;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 0;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 11:    //b
            aff2_a = 0;
            aff2_b = 0;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 12:    //C
            aff2_a = 1;
            aff2_b = 0;
            aff2_c = 0;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 0;
            break;
        case 13:    //d
            aff2_a = 0;
            aff2_b = 1;
            aff2_c = 1;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 0;
            aff2_g = 1;
            break;
        case 14:    //E
            aff2_a = 1;
            aff2_b = 0;
            aff2_c = 0;
            aff2_d = 1;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        case 15:    //F
            aff2_a = 1;
            aff2_b = 0;
            aff2_c = 0;
            aff2_d = 0;
            aff2_e = 1;
            aff2_f = 1;
            aff2_g = 1;
            break;
        default:
            aff2_a = 0;
            aff2_b = 0;
            aff2_c = 0;
            aff2_d = 0;
            aff2_e = 0;
            aff2_f = 0;
            aff2_g = 0;
            break;
    }
}

void aff_sct(void)
{
    if (alterne == 1)        //clear LCD
    {
        aff1_a = 0;
        aff1_b = 0;
        aff1_c = 0;
        aff1_d = 0;
        aff1_e = 0;
        aff1_f = 0;
        aff1_g = 0;
        aff2dp = 0;
        aff2_a = 0;
        aff2_b = 0;
        aff2_c = 0;
        aff2_d = 0;
        aff2_e = 0;
        aff2_f = 0;
        aff2_g = 0;
        aff2dp = 0;
        alterne = 0;
    }
    else                //rafraichissement avec valeur memorise
    {
        aff1(val1, dp1, 0);
        aff2(val2, dp2, 0);
        alterne = 1;
    }
}
Outils personnels