logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[winavr][atmega8][C] lcd-nokia6100 + termometr

iksmodiw1 17 Lut 2010 11:30 2046 3
REKLAMA
  • #1 7707368
    iksmodiw1
    Poziom 11  
    Witam.

    Mam problem z wyświetlenie znaku na tym wyświetlaczu.Wszystko inne daje radę wyświetlić (kwadraty,koła i inne). Wszystko sie kompiluje, ale po wysłaniu do uC ekran jest czarny, nawet jak przed wyświetleniem znaku wypełniam ekran na biało.
    Zamieszczam kod funkcji. W czym może być problem?

    
    void LCDPutChar(char c, int  x, int  y, int size, int fColor, int bColor) { 
      
      extern const unsigned char FONT6x8[97][8]; 
      extern const unsigned char FONT8x8[97][8]; 
      extern const unsigned char FONT8x16[97][16]; 
       
     int    i,j; 
     unsigned int   nCols; 
     unsigned int   nRows; 
     unsigned int   nBytes; 
     unsigned char   PixelRow; 
     unsigned char   Mask; 
     unsigned int   Word0; 
     unsigned int   Word1; 
     unsigned char   *pFont; 
      
     unsigned char   *pChar; 
      unsigned char    *FontTable[] = {(unsigned char *)FONT6x8,  
             (unsigned char *)FONT8x8,  
             (unsigned char *)FONT8x16};  
      
      // get pointer to the beginning of the selected font table 
      pFont = (unsigned char *)FontTable[size];   
      
      // get the nColumns, nRows and nBytes 
      nCols = *pFont; 
      nRows = *(pFont + 1); 
      nBytes = *(pFont + 2); 
     
      // get pointer to the last byte of the desired character 
      pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1; 
      
      // Row address set  (command 0x2B) 
    	sendCMD(PASET); 
    	sendData(x); 
        sendData(x + nRows - 1); 
       
      // Column address set  (command 0x2A) 
     sendCMD(CASET); 
     sendData(y); 
     sendData(y + nCols - 1); 
      
     // WRITE MEMORY 
     sendCMD(RAMWR); 
      
      // loop on each row, working backwards from the bottom to the top 
      for (i = nRows - 1; i >= 0; i--) { 
       
        // copy pixel row from font table and then decrement row 
      PixelRow = *pChar--; 
      
        // loop on each pixel in the row (left to right) 
        // Note: we do two pixels each loop 
      Mask = 0x80; 
        for (j = 0; j < nCols; j += 2) { 
       
          // if pixel bit set, use foreground color; else use the background color 
          // now get the pixel color for two successive pixels 
          if ((PixelRow & Mask) == 0) 
        Word0 = bColor; 
       else 
        Word0 = fColor; 
       Mask = Mask >> 1; 
          if ((PixelRow & Mask) == 0) 
        Word1 = bColor; 
       else 
        Word1 = fColor; 
       Mask = Mask >> 1; 
        
          // use this information to output three data bytes 
         sendData((Word0 >> 4) & 0xFF); 
         sendData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF)); 
    	 sendData(Word1 & 0xFF); 
      }   
     } 
      // terminate the Write Memory command 
     sendCMD(NOP);   
    } 
    
    
  • REKLAMA
  • Pomocny post
    #2 7707723
    tmf
    VIP Zasłużony dla elektroda
    Problem w tym, ze zapewne tablica fontow siedzi we FLASH (chociaz z zalaczonego programu wcale to nie wynika). A skoro jest we FLASH to nie mozesz odwolywac sie do tych danych poprzez zwykla dereferencje wskaznika, bo AVRy maja architekture Harvardzka i rozlaczne przestrzenie adresowe. W efekcie do danych we FLASH musisz sie odwolywac poprzez specjalne funkcje (pgm_costam z naglowka pgmspace.h). A fonty zapewne siedza we FLASH, bo ATMega8 nie ma wystarczajaco SRAM, zeby je tam umiescic.
  • REKLAMA
  • #3 7708884
    iksmodiw1
    Poziom 11  
    Otóż poradziłem sobie już z tym. Już wyświetla znaki a nawet stringi. Tylko znak w lustrzanym odbiciu, więc przez to stringi tak samo i jeszcze w odwrotnej kolejności znaków. Zamieszczam kod. Co zmienić aby było dobrze ?
    void LCDPutChar(unsigned char c, int x, int y, int size, int fColor, int bColor) 
    {
      int i,j;
      unsigned int  nCols;
      unsigned int  nRows;
      unsigned int  nBytes;
      unsigned char PixelRow;
      unsigned char Mask;
      unsigned int  Word0;
      unsigned int  Word1;
      unsigned char *pFont;
      unsigned char *pChar;
      unsigned char *FontTable[] = {(unsigned char *)FONT6x8,
                                    (unsigned char *)FONT8x8,
                                    (unsigned char *)FONT8x16};
    
      // get pointer to the beginning of the selected font table
      pFont = (unsigned char *)FontTable[size];
    
      /* get the nColumns, nRows and nBytes */
      //nCols = *pFont;
      nCols  = pgm_read_byte(&*pFont);         // Array Flash
      //nRows = *(pFont + 1);
      nRows  = pgm_read_byte(&*(pFont + 1));   // Array Flash
      //nBytes = *(pFont + 2);
      nBytes = pgm_read_byte(&*(pFont + 2));   // Array Flash
    
      /* get pointer to the last byte of the desired character */
      pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
    
      // Row address set (command 0x2B)
      sendCMD(PASET);
      sendData(x);
      sendData(x + nRows - 1);
    
      // Column address set (command 0x2A)
      sendCMD(CASET);
      sendData(y);
      sendData(y + nCols - 1);
    
    
      // WRITE MEMORY
      sendCMD(RAMWR);
      // loop on each row, working backwards from the bottom to the top
      
      //for (i = nRows - 1; i >= 0; i--) 
      //for (j = 0; j < nCols; j += 2)	
      
      for (i = nRows - 1; i >= 0; i--)  													
      {
        /* copy pixel row from font table and then decrement row */
        //PixelRow = *pChar--;
    	PixelRow = pgm_read_byte(&*pChar--);  // Array Flash
    
        // loop on each pixel in the row (left to right)
        // Note: we do two pixels each loop
        Mask = 0x80;
        for (j = 0; j < nCols; j += 2)				
    	{
          // if pixel bit set, use foreground color; else use the background color
          // now get the pixel color for two successive pixels
          if ((PixelRow & Mask) == 0)
            Word0 = bColor;
          else
            Word0 = fColor;
          Mask = Mask >> 1;
    
          if ((PixelRow & Mask) == 0)
            Word1 = bColor;
          else
            Word1 = fColor;
          Mask = Mask >> 1;
    
          // use this information to output three data bytes
          sendData((Word0 >> 4) & 0xFF); 
          sendData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
    	  sendData(Word1 & 0xFF);
          
        }
      }
    
      // terminate the Write Memory command
      sendCMD(NOP);
    }
    
    void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int bColor) 
    {
      // loop until null-terminator is seen
      while (*pString != 0x00) 
      {
        // draw the character
        LCDPutChar(*pString++, x, y, Size, fColor, bColor);
    
        // advance the y position
        if (Size == SMALL)
        y = y - 6;
    
        else if (Size == MEDIUM)
        y = y - 8;
    
        else
        y = y - 8;
    
        // bail out if y exceeds 131
        if (y > 131) break;
      }
    }
    
    


    Dodano po 3 [godziny] 4 [minuty]:

    Już sobie poradziłem z tym problemem. Mam już w pełni działającą bibliotekę obsługującą ten wyświetlacz.
  • #4 7712646
    iksmodiw1
    Poziom 11  
    Podłączyłem termometr DS18B20 pod atmegę, znalazłem na forum kod do obsługi ds'a, ale przy próbie kompilacji wyskakuje taki błąd.

    c:/winavr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: nokia_6100_test.elf section .text will not fit in region text
    c:/winavr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: region text overflowed by 3402 bytes
    make.exe: *** [nokia_6100_test.elf] Error 1


    Więcej błędów nie ma, a nie mam pojęcia czym ten błąd jest spowodowany.

    Dobra już sobie poradziłem.
REKLAMA