Bonjour, cliquez-ici pour vous inscrire et participer au forum.
  • Login:



+ Répondre à la discussion
Affichage des résultats 1 à 1 sur 1

Code C pour LCD T6963C et 16F877

  1. FandeMuse

    Date d'inscription
    mars 2006
    Localisation
    Vers Genève
    Âge
    23
    Messages
    90

    Code C pour LCD T6963C et 16F877

    Depuis peu, je me suis décider de controler un LCD graphique avec un 16F877 mais celui-ci a un driver Toshiba T6963C.Et quand je teste le programme un peu modifier car sinon il ne fonctionnait pas, il reste bloqué dans la fonction glcd_writebyte(), pourquoi n'en sort-il pas et continue ce qu'il a à faire.

    code : ex_glcd.c
    #include <16F877.h>
    #use delay(clock=4000000)
    #fuses HS,NOWDT,NOPROTECT,NOLVP
    #include <ex_glcd.h>
    #include <function.c>
    #byte data = 8
    #byte portd=8 //// /WR - - C4;/RD - - C5;C//D- - C6;/RST- - C7;DATA0-7 PORTD0-7 ////

    void main() {
    set_tris_a(0xff);set_tris_a(0x 00);set_tris_b(0xff);set_tris_ b(0x00);set_tris_d(0xff);set_t ris_d(0x00);set_tris_c(0xff);s et_tris_c(0x00);LCD=portd=data =0x00;
    set_tris_c(0x00); // graphic lcd control lines all output
    set_tris_b(0xff); //TRIS DATA bus,note:control bus always outputs

    glcd_init();
    glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
    glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDi sp_GRH));
    glcd_putc("hello");
    }
    code function.c
    #byte data = 8
    #byte portd=8 //// /WR - - C4;/RD - - C5;C//D- - C6;/RST- - C7;DATA0-7 PORTD0-7 ////

    const int TextHome = 0x78;
    const int TextArea = 0x1E; // how many bytes before a new line
    const int GraphicsHome = 0x00;
    const int GraphicsArea = 0x1E; // how many bytes before a new line

    const int AutoModeWrite = 0xB0;
    const int AutoModeRead = 0xB1;
    const int AutoModeReset = 0xB2;

    const int LCDModeSet = 0x80; // send this OR'd with the following
    const int LCDMode_OR = 0b0000;
    const int LCDMode_XOR = 0b0001;
    const int LCDMode_AND = 0b0010;
    const int LCDMode_TA = 0b0100; // TEXT ATTRIBUTE mode.
    const int LCDMode_RAM = 0b1000; // 1=CG RAM, 0=internal CG ROM

    const int LCDSetCursorPtr = 0x21; // cursor address
    const int LCDSetCursorSize = 0xA0; // 1 line cursor

    const int LCDDispMode = 0x90; // send this OR'd with the following
    const int LCDDisp_BLK = 0b0001;
    const int LCDDisp_CUR = 0b0010;
    const int LCDDisp_TXT = 0b0100;
    const int LCDDisp_GRH = 0b1000;

    struct lcd_pin_def
    {
    BOOLEAN unused1; // C0
    BOOLEAN unused2; // C1
    BOOLEAN unused3; // C2
    BOOLEAN unused4; // C3
    BOOLEAN w_bar; // C4 Write bar active low
    BOOLEAN r_bar; // C5 Read bar active low
    BOOLEAN cd; // C6 Command/Data BAR 1=command 0=data
    BOOLEAN reset_bar; // C7 Reset active low
    };
    struct lcd_pin_def LCD;

    #byte LCD = 7 // portC address on 16F877

    void glcd_init()
    {
    set_tris_a(0xff);set_tris_a(0x 00);set_tris_b(0xff);set_tris_ b(0x00);set_tris_d(0xff);set_t ris_d(0x00);set_tris_c(0xff);s et_tris_c(0x00);LCD=portd=data =0x00;
    set_tris_c(0x00); // graphic lcd control lines all output
    set_tris_b(0xff); //TRIS DATA bus,note:control bus always outputs

    LCD.w_bar = 1; // INITIAL STATES OF CONTROL PINS
    LCD.r_bar = 1; //
    LCD.cd = 1; // command

    LCD.reset_bar = 0; // perform a reset
    delay_us(10); // delay for a reset
    LCD.reset_bar = 1; // run

    glcd_WriteCmd2(TextHome, 0x40);
    glcd_WriteCmd2(TextArea, 0x41);
    glcd_WriteCmd2(GraphicsHome, 0x42);
    glcd_WriteCmd2(GraphicsArea, 0x43);

    // set address to 0
    glcd_WriteCmd2(0x0000, 0x24);
    glcd_WriteCmd2(0x0000, 0x24);

    // Clear all RAM of LCD (8k)
    glcd_WriteByte(1, AutoModeWrite);
    glcd_WriteByte(1, AutoModeReset);
    }

    void glcd_WriteByte(int cd2, int data)
    {
    int status = 0, temp = 0;
    set_tris_d(0xff);
    LCD.w_bar = 1;
    LCD.r_bar= 0;
    LCD.cd = 1;
    status = portd;

    while (status != 0x03) { // is LCD busy?
    LCD.r_bar= 0;
    portd = temp;
    LCD.r_bar = 1;
    status = temp & 0x03;
    }

    set_tris_d(0x00);
    LCD.cd = cd2; // Command/Data bar
    portd = data;
    LCD.r_bar = 1; // not read
    LCD.w_bar = 0; // write
    LCD.w_bar = 1; // release
    }

    void glcd_WriteByteAuto(int data)
    {
    int status = 0, temp = 0; // status bits ARE DIFFERENT BITS THAN NORMAL
    set_tris_b(0xff);
    LCD.w_bar = 1;
    LCD.r_bar = 1;
    LCD.cd = 1; // defaults
    status=portd;

    while (status != 0x08) { // is LCD busy?
    LCD.r_bar = 0;
    temp = portd;
    LCD.r_bar = 1;
    status = temp & 0x08;
    }

    set_tris_d(0x00); // All outputs
    LCD.cd = 0; // This is always data, cd=0
    portd = data; // Put data on data bus
    LCD.w_bar = 0; // write
    LCD.w_bar = 1; // release
    }

    void glcd_WriteCmd1(int data, int cmd)
    {
    glcd_WriteByte(0, data);
    glcd_WriteByte(1, cmd);
    }

    void glcd_WriteCmd2(int data, int cmd)
    {
    glcd_WriteByte(0, data & 0xff);
    glcd_WriteByte(0, data>>8);
    glcd_WriteByte(1, cmd);
    }

    int glcd_ReadByte(void)
    {
    int data = 0, status = 0, temp = 0;
    set_tris_b(0xff);
    LCD.w_bar = 1;
    LCD.r_bar = 1;
    LCD.cd = 1; // defaults
    status=portd;

    #asm nop #endasm

    while (status != 0x03) { // is LCD busy?
    LCD.r_bar = 0;
    temp = portd;
    LCD.r_bar = 1;
    status = temp & 0x03;
    }

    LCD.cd = 0; // Command/Data bar
    LCD.r_bar = 0; // read
    /////////////////////////////////////////////////////////
    #asm nop #endasm // THIS PAUSE IS VERY NESSESARY !!!//
    /////////////////////////////////////////////////////////
    data = portd;
    LCD.r_bar = 1;
    LCD.cd = 1;
    return data; // Return the read data
    }

    void glcd_putc(char c) {
    glcd_WriteCmd1(c - 0x20, 0xc0);
    }

    void glcd_gotoxy(int x, int y, int text) { // sets memory location to screen location x, y
    // location 1,1 is upper left corner; text = 1 (text area), text = 0 (graphics area)
    int location, home;
    int line;

    if (!text) {
    home = GraphicsHome;
    line = GraphicsArea;
    }
    else {
    home = TextHome;
    line = TextArea;
    }

    location = home + (((int)y - 1) * line) + x - 1;
    glcd_WriteCmd2(location, 0x24);
    }
    code : ex_glcd.h
    extern int glcd_ReadByte(void);
    extern void glcd_WriteByte(int cd, int data);
    extern void glcd_WriteByteAuto(int data);
    extern void glcd_WriteCmd2(int data, int cmd);
    extern void glcd_WriteCmd1(int data, int cmd);
    extern void glcd_gotoxy(int x, int y, int1 text);
    extern void glcd_init();

    Merci d'avance
     


    • Publicité




Poursuivez votre recherche :




Sur le même thème :




 

Discussions similaires

  1. lcd clavier 16 touches 16f877
    Par sdow dans le forum Électronique
    Réponses: 4
    Dernier message: 11/04/2011, 13h57
  2. LCD 128x64 T6963C sur PIC16F876
    Par nk36 dans le forum Électronique
    Réponses: 1
    Dernier message: 17/10/2007, 08h25
  3. Driver LCD 2*16 avec PIC 16F877
    Par misstik dans le forum Électronique
    Réponses: 2
    Dernier message: 20/07/2007, 22h54
  4. 16f877 et afficheur LCD
    Par 7ider5 dans le forum Électronique
    Réponses: 3
    Dernier message: 10/02/2007, 10h50
  5. Pic 16f877 + Lcd (m6222 + Lc7930 )
    Par Toufinet dans le forum Électronique
    Réponses: 1
    Dernier message: 23/05/2006, 01h27


Les tags pour cette discussion