ButterflyMP3

pcd8544.c

Go to the documentation of this file.
00001 
00034 #include <avr/io.h>
00035 #include <avr/pgmspace.h>
00036 #include <avr/interrupt.h>
00037 #include "types.h"
00038 #include "pcd8544.h"
00039 
00040 
00041 //extern        uint8 frameBuffer[fbCols][fbRows];      
00042 extern          uint8 fbXY[];                   
00043 
00044 /*** lcdByte ******************************************************************
00045  *      
00046  *      Send one byte to the LCD
00047  *      
00048  *      shift out given byte, MSB fisrt; dc is 1 (data) or 0 (command) 
00049  *      (lcdModeData/lcdModeCmd) and is set in calling function
00050  *      
00051  **************************************************************************///{
00052 void lcdByte(uint8 data) {      // 
00053         uint8 i;
00054         
00055         lcdResume;
00056         
00057         for(i=0; i<8; i++) {            // clock out the byte, MSB first
00058                 if(bit_is_set(data, 7))
00059                         lcdPort |= (unsigned char) _BV(SDIN);
00060                 else
00061                         lcdPort &= (unsigned char)~_BV(SDIN);
00062                 
00063                 // clock out the bit
00064                 lcdPort &= (unsigned char) ~_BV(SCLK);
00065                 lcdPort |= (unsigned char) _BV(SCLK);
00066 
00067                 data <<= 1;
00068         }
00069         
00070         lcdSuspend;
00071 }
00072 //}
00073 //      void lcdByte(uint8 data)
00074 
00075 /*** lcdDot *******************************************************************
00076  *      
00077  *      Draw a dot to the frame buffer
00078  *      
00079  **************************************************************************///{
00080 void lcdDot(uint8 x, uint8 yLine, uint8 color) {
00081         uint8 yBit;                     // 00LL LBBB
00082         
00083         // f x is more than screen x-res, wrap
00084         while(x>=fbCols)
00085                 x               -= fbCols;
00086         // if yLine is more than screen y-res, wrap
00087         while(yLine>=(fbRows*8))
00088                 yLine   -= (fbRows*8);
00089         
00090         
00091         // separate line number (0-5) from atual pixel in line (0-7)
00092         //      this is done by divide
00093         yBit    = yLine & 7;    // 0b0000 0bbb
00094         yLine   = yLine >> 3;   // yline / 8 ; 0b00l ll00 => 0b0000 0lll
00095 
00096 // if color is diff from frameBuffer, toggle; if color is toggle (2) expression is always true
00097 //      if( color ^ (frameBuffer[x][yLine] & _BV(yBit))>>yBit ) {
00098 //              frameBuffer[x][yLine] ^= _BV(yBit);
00099 //      }
00100 }
00101 //}
00102 //      void lcdDot(uint8 x, uint8 yLine, uint8 color)
00103 
00104 /*** lcdCh *******************************************************************
00105  *      
00106  *      Write predefined fonts to screen at set location
00107  *      
00108  **************************************************************************///{
00109 void lcdCh(uint8* fontSet, uint8 ch) {
00110         uint8 i;
00111         uint8 k = pgm_read_byte(fontSet);
00112         uint8 x = pgm_read_byte(fontSet+1);
00113         //uint8 y = pgm_read_byte(fontSet+2);
00114 
00115         lcdModeData;
00116         
00117         if(ch < k) {
00118                 
00119                 
00120                 for(i=0; i<x; i++) {
00121                         lcdByte(pgm_read_byte(fontSet+(x*ch+3)+i));
00122                 //      lcdByte(0);
00123                 /*
00124                         for(j=0; j<y; j++) {
00125                                 k=0;
00126                                 if(pgm_read_byte(fontSet+(x*ch+3)+i) & _BV(j)) {
00127                                         k=1;
00128                                 }
00129                                 
00130                                 lcdDot(fbXY[0],fbXY[1]+j,k);
00131                         }
00132                 */      fbXY[0]++;
00133                 }
00134         }
00135         else {
00136                 //for(j=0; j<y; j++) {
00137                 //      lcdDot(fbXY[0],fbXY[1]+j,0);            // show empty if out of range
00138                 //}
00139 
00140                 for(i=0; i<x; i++) {
00141                    lcdByte(0);
00142                    fbXY[0]++;
00143                 }
00144         }
00145 }
00146 //}
00147 //      void lcdCh(uint8* fontSet, uint8 ch)
00148 
00149 /*** lcdWrite *****************************************************************
00150  *      
00151  *      Translate input to selected font, Write to display at set location
00152  *      
00153  **************************************************************************///{
00154 void lcdWrite(uint8* fontSet, uint8* buf, uint8 is_pstr, uint8 len) {
00155         uint8 i=0, offset, ch;
00156 
00157         // check if string is in flash/sram and read appropriately
00158         if(is_pstr) {
00159                 ch = pgm_read_byte(buf+i);
00160         }
00161         else {
00162                 ch = buf[i];
00163         }
00164 
00165         lcdXY(fbXY[0],fbXY[1]);
00166         do {
00167                 if(ch > 32) {
00168                         offset = 33;
00169                         
00170                         if( (ch>96) && (ch<123) ) {
00171                                 #ifdef LOwERCASE_STRINGS
00172                                 offset = 33;
00173                                 #else
00174                                 offset = 65;
00175                                 #endif
00176                         }
00177                         else if(ch>122) {
00178                                 offset = 60;
00179                         }
00180         
00181                         lcdCh(fontSet, (ch-offset));
00182                 }
00183                 else {
00184                         lcdCh(fontSet, 255);    // empty (not recognized)
00185                 }
00186                 fbXY[0]++;      // char spacing
00187                 lcdByte(0);
00188                 i++;
00189                 
00190                 // check if string is in flash/sram and read appropriately
00191                 if(is_pstr) {
00192                         ch = pgm_read_byte(buf+i);
00193                 }
00194                 else {
00195                         ch = buf[i];
00196                 }
00197 
00198         } while((ch != '\0') && (i<=len));
00199    
00200 }
00201 //}
00202 //      void lcdWrite(uint8* fontSet, uint8* buf, uint8 is_pstr)
00203 
00204 /*** fbClr ********************************************************************
00205  *      
00206  *      Clear the frame buffer
00207  *      
00208  **************************************************************************///{
00209 void fbClr(void) {
00210         /*      
00211         uint8 x, yLine;
00212 
00213         for(yLine=0; yLine<fbRows; yLine++) {
00214                 for(x=0; x<fbCols; x++) {
00215                         frameBuffer[x][yLine] = 0x00;
00216                 }
00217         }*/
00218         lcdClr();
00219 }
00220 //}
00221 //      void fbClr(void)
00222 
00223 /*** lcdClr *******************************************************************
00224  *      
00225  *      Clears the LCD. Call this first to get rid of junk data on the screen.
00226  *      
00227  **************************************************************************///{
00228 void lcdClr(void) {
00229         uint16 i;
00230 
00231         lcdModeData;
00232         for(i=0; i<504; i++) {
00233                 lcdByte(0x00);
00234         }
00235 }
00236 
00237 /*** lcdClrLine *******************************************************************
00238  *      
00239  *      Clears an 8x84 line on the LCD. 
00240  *      
00241  **************************************************************************///{
00242 void lcdClrLine(uint8 lineNo) {
00243         uint16 i;
00244 
00245    lcdXY(0,lineNo);
00246 
00247         lcdModeData;
00248         for(i=0; i<84; i++) {
00249                 lcdByte(0x00);
00250         }
00251 }
00252 
00253 //}
00254 //      void lcdClr(void)
00255 
00256 /*** lcdInit ******************************************************************
00257  *      
00258  *      Initialize the LCD, get it ready to be used; returns in cmd mode
00259  *      
00260  **************************************************************************///{
00261 void lcdInit(void) {
00262         // set the direction on these pins to output
00263         lcdPortD |= (unsigned char)(_BV(SCLK) | _BV(SDIN) | _BV(DC) | _BV(SCE_) | _BV(RES_));
00264         // set RES: disable reset; IC ready to run
00265         lcdPort  |= (unsigned char)(_BV(SCLK) | _BV(SDIN) | _BV(DC) | _BV(SCE_) | _BV(RES_));
00266         // set all (high); RESET complete, LCD in suspend
00267 
00268         //      lcdReset;
00269         lcdClr();
00270 
00271         // init settings
00272         lcdModeCmd;             // set command mode
00273         lcdByte(0x21);  // extended instruction set
00274         
00275 //      lcdByte(0x90);  // set VOP
00276         lcdByte(0xC8);  // set VOP
00277         lcdByte(0x06);  // set temperature co-eff
00278         lcdByte(0x13);  // bias (1:48)
00279         
00280         lcdByte(0x20);  // normal instruction set: PD= 0, V= 0
00281 //      lcdByte(0x22);  // normal instruction set: PD= 0, V= 1
00282         lcdByte(0x0c);  // normal mode: d=1, e=0
00283 }
00284 //}
00285 //      void lcdInit(void)
00286 
00287 /*** lcdXY ********************************************************************
00288  *      
00289  *      Set cursor to location x:y (0-83:0-47).
00290  *      
00291  **************************************************************************///{
00292 void lcdXY(uint8 x, uint8 y) {
00293         lcdModeCmd;
00294         lcdByte(x|0x80);        // 0b1xxx xxxx
00295         lcdByte(y|0x40);        // 0b0100 0xxx
00296 }
00297 //}
00298 //      void lcdXY(uint8 x, uint8 y)
00299 
00300 
00301 /*--------------------------------------------------------------------------------------------------
00302 
00303   Name         :  lcdLine
00304 
00305   Description  :  Draws a line between two points on the display.
00306 
00307   Argument(s)  :  x1, y1 -> Absolute pixel coordinates for line origin.
00308                   x2, y2 -> Absolute pixel coordinates for line end.
00309                   mode   -> Off, On or Xor. See enum.
00310 
00311   Return value :  None.
00312 
00313 --------------------------------------------------------------------------------------------------*/
00314 /*
00315 void lcdLine ( uint8 x1, uint8 y1, uint8 x2, uint8 y2, uint8 mode )
00316 {
00317     int dx, dy, stepx, stepy, fraction;
00318 
00319     dy = y2 - y1;
00320     dx = x2 - x1;
00321 
00322     if ( dy < 0 )
00323     {
00324         dy    = -dy;
00325         stepy = -1;
00326     }
00327     else
00328     {
00329         stepy = 1;
00330     }
00331 
00332     if ( dx < 0 )
00333     {
00334         dx    = -dx;
00335         stepx = -1;
00336     }
00337     else
00338     {
00339         stepx = 1;
00340     }
00341 
00342     dx <<= 1;
00343     dy <<= 1;
00344 
00345     lcdDot( x1, y1, mode );
00346 
00347     if ( dx > dy )
00348     {
00349         fraction = dy - (dx >> 1);
00350         while ( x1 != x2 )
00351         {
00352             if ( fraction >= 0 )
00353             {
00354                 y1 += stepy;
00355                 fraction -= dx;
00356             }
00357             x1 += stepx;
00358             fraction += dy;
00359             lcdDot( x1, y1, mode );
00360         }
00361     }
00362     else
00363     {
00364         fraction = dx - (dy >> 1);
00365         while ( y1 != y2 )
00366         {
00367             if ( fraction >= 0 )
00368             {
00369                 x1 += stepx;
00370                 fraction -= dy;
00371             }
00372             y1 += stepy;
00373             fraction += dx;
00374             lcdDot( x1, y1, mode );
00375         }
00376     }
00377 
00378   //  UpdateLcd = TRUE;
00379 }
00380 */
00381 
 All Files Functions Variables Typedefs Enumerations Enumerator Defines