- Labornetzteil AliExpress         
Ergebnis 1 bis 2 von 2

Thema: LC-Display sendet seltsame Daten

  1. #1
    Benutzer Stammmitglied
    Registriert seit
    23.08.2007
    Ort
    Bielefeld
    Beiträge
    39

    LC-Display sendet seltsame Daten

    Anzeige

    LiFePo4 Akku selber bauen - Video
    Hallo,

    mit dem PIC16F887 steuer ich ein Graphik-LCD an (http://www.tigal.com/files/download/...glcd128x64.pdf).

    Die Punktansteuerung funktioniert auch ohne weiteres. Doch wenn ich eine Page auslesen möchte, liefert das Display völlig falsche Werte.
    So sendet das Display 1 statt 2 als Bytewert (also immer um eins versetzt):

    Hier ist meine Readfunktion:
    Code:
    char read(){
      TDB = 0xFF; //Databus-Pins: Input
      RS = 1;  //Control-wires: RS: H ; R/W: H
      RW = 1;
      Delay_ms(1); //Wait 1 ms
      E = 1; //ENABLE: H
      Delay_ms(5); //Wait 5 ms
      input = DB;  //Read Databus
      E = 0;  //ENABLE: L
      RS = 0;
      RW = 0;
      Delay_ms(1); //Wait 1 ms
      TDB = 0;  //Databus-Pins: Output
      DB = 0; //Control-wires: RS: L / R/W: L / Databus: L
    
      return input;
    }
    Mache ich irgendwelche Dinge falsch?

    MfG Sebastian

  2. #2
    Benutzer Stammmitglied
    Registriert seit
    23.08.2007
    Ort
    Bielefeld
    Beiträge
    39
    Hallo,

    ich habe das Problem gefunden. Hier nochmal mein kompletter Code für EasyPIC6 - GLCD:
    main.c
    Code:
    #include "glcd.h"
    int q = 0;
    
    void main() {
      ANSEL  = 0;            // Configure AN pins as digital
      ANSELH = 0;
      C1ON_bit = 0;          // Disable comparators
      C2ON_bit = 0;
         glcd_init();
         glcd_delete_display();
        while(1)
        {
                glcd_draw_point(68,q,1);
                q = q+1;
                Delay_ms(500);
                if(q == 63){
                     q = 0;
                     
                }
        }
    
         while(1);//Endlosschleife
    
    }
    glcd.c
    Code:
    #include "glcd.h"
      char page = 0;
      char b = 0;
      char n = 0;
      char input = 0;
    void glcd_init(){
    /*Initialize the display.*/
     Delay_ms(250);
      TCS1 = 0; //Pin: output
      TCS2 = 0;
      TRS  = 0;
      TRW = 0;
      TE = 0;
      TDB = 0;
      //Values:
      CSE = 0;
      CSZ = 0;
      RS = 0;
      RW = 0;
      E = 0;
      DB = 0;
       glcd_display_select(1);//Choose IC1
       glcd_display_off();
       glcd_display_on();
       glcd_display_select(2);//Choose IC2
       glcd_display_off();
       glcd_display_on();
    
    }
    void glcd_draw_point(char x, char y, char filled){
    /*
    x : x-chord
    y: y-chord
    filled: 1: filled or 0: unfilled
    */
          page = y / 8;
          b = glcd_read_page(x, page);
          n = page * 8;
          n = y - n;
          n = 1 << n;
          if(filled > 0 ){
                    glcd_draw(x, page, (b | n));
          }else{
                n = !n;
                glcd_draw(x, page, (b & n));
          }
    
    }
    
    void  glcd_display_select(char controller){
    /*Chip select*/
           if(controller == 1){
               CSE = 0;
               CSZ = 1;
           }else{
                CSE = 1;
                CSZ = 0;
           }
    }
    void glcd_draw(char x, char page, char byte){
    /*Write byte to DDRAM(x |page).*/
         if(x>=64){
                   glcd_display_select(2);
                   glcd_setAddress(x-64);
          }else{
                glcd_display_select(1);
                glcd_setAddress(x);
          }
         glcd_setPage(page);
         glcd_write(byte);
    }
    void glcd_display_off(){
    /*Switch the display off*/
         RS = 0;
         RW = 0;
         DB = 62;
         glcd_execute();
    }
    void glcd_display_on(){
    /*Switch the display on*/
         RS = 0;
         RW = 0;
         DB = 63;
         glcd_execute();
    }
    void glcd_execute(){
          //Executes the comand on DB
          E = 1;
          //Delay_ms(0);
          E = 0;
          Delay_ms(1);
    }
    void glcd_setAddress(char address){
    //Set the Address in DDRAM
           RS = 0;
           RW = 0;
           DB = 64 + address;
           glcd_execute();
    }
    void glcd_setPage(char page){
    //Set the Page in DDRAM
           RS = 0;
           RW = 0;
           DB =  184 + page;
           glcd_execute();
    }
    void glcd_write(char byte){
    //Write byte into the display
         DB = byte;
         RS = 1;
         RW = 0;
         glcd_execute();
    }
    void glcd_delete_display(){
    //Delete all points
         b = 0;
         while(b < 8){
           n = 0;
           while(n < 128){
                   glcd_draw(n, b, 0);
                   n++;
           }
           b++;
         }
    }
    char glcd_read_page(char x, char page){
    //Returns read page
           if(x>=64){
                  glcd_display_select(2);
                  glcd_setAddress(x-64);
         }else{
                  glcd_display_select(1);
                  glcd_setAddress(x);
         }
         glcd_setPage(page);
         return glcd_read();
    }
    char glcd_read(){
    //Read the ddram
      TDB = 0xFF; //Databus-Pins: Input
      RS = 1;  //Control-wires: RS: H / R/W: H
      RW = 1;
      E = 1;        ///Dummy-Read
        Delay_ms(1); //Wait 1 ms
      E = 0;
        Delay_ms(1); //Wait 1 ms
      Delay_ms(1); //Wait 1 ms
      E = 1; //ENABLE: H
      Delay_ms(1); //Wait 1 ms
      input = DB;  //Read Databus
      E = 0;  //ENABLE: L
      RS = 0;
      RW = 0;
      TDB = 0;  //Databus-Pins: Output
    
      return input;
    }
    glcd.h:
    Code:
    #define TCS1 TRISB.F0
    #define TCS2 TRISB.F1
    #define TRS TRISB.F2
    #define TRW TRISB.F3
    #define TE TRISB.F4
    #define TDB TRISD
    #define TRST TRISB.F5
    #define CSE PORTB.F0
    #define CSZ PORTB.F1
    #define RS PORTB.F2
    #define RW PORTB.F3
    #define E PORTB.F4
    #define DB PORTD
    #define RST PORTB.F5
    
    void glcd_init();
    void glcd_draw_point(char x, char y, char filled);
    void glcd_draw(char x, char page, char byte);
    void glcd_display_select(char controller);
    void glcd_display_on();
    void glcd_display_off();
    void glcd_execute();
    void glcd_setAddress(char address);
    void glcd_setPage(char page);
    void glcd_write(char byte);
    void glcd_delete_display();
    char glcd_read();
    char glcd_read_page(char x, char page);
    MfG Sebastian

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Solar Speicher und Akkus Tests