原创 7565R(MP3)液晶屏驱动

2008-12-11 21:53 3245 3 3 分类: MCU/ 嵌入式

7565R(MP3)液晶屏,屏幕分辨率:128*64,这种液晶屏的量很大,以前很多MP3上都是使用的它,以下是CVAVR版驱动。



void WriteData(unsigned char Rs,unsigned char SData)
 {    //写数据到模块Rs=05为命令,Rs=1为显示数据//8080时序
        delay_us(3);
        LCD_DATA_DDR = 0xff;
        LCD_DATA_PORT=SData;
        LCD_CS=0;
        LCD_RW=0;
        LCD_A0=Rs;
        //LCD_CS=0;
        LCD_RD=0;
        //LCD_DATA_PORT=SData;
        delay_us(3);
        LCD_RD=1;
        //LCD_CS=1;
        LCD_A0 =1;
        LCD_RW=1;
      //  LCD_CS=1;
        LCD_DATA_DDR = 0x00;
       // LCD_CS=1;
}



void REST_LCD(void)
     {
       char   m,n;
       for (m=0;m<9;m++)
         {
          WriteData(0,0xB0+m); //Set Page Address 0xB0-0xB7  Icon Address 0xB8
          WriteData(0,0x10);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,0x00);   //Set Column Address LSB 0x00-0x0F
          for(n=0;n<=132;n++)
             WriteData(1,0x00);
          } 
     }
    
void LCD_init(void)
    {
      LCD_RS=1;
      LCD_RS=0;             //复位
      delay_ms(100);       //Delay 1S
      LCD_RS=1;
      delay_ms(100);       //Delay 1S
      WriteData(LCD_COM,0xE2);   // Soft Reset
      delay_ms(10); 
      WriteData(LCD_COM,0xAE);
      delay_ms(10);     
      WriteData(LCD_COM,0xA2);   //LCD Bias Select 1/9////背景灰度
      delay_ms(10);     
      WriteData(LCD_COM,0xA1);   //ADC Select   SEG0-SEG131
      delay_ms(10);     
      WriteData(LCD_COM,0xC0);   //SHL Select   COM0-COM63
      delay_ms(10);     
      WriteData(LCD_COM,0x24);   //WriteData(0,0x24);   //Regulator Select 0x20-0x27
      delay_ms(10);     
      WriteData(LCD_COM,0x81);   //Set Reference Voltage Select Mode
      delay_ms(10);     
      WriteData(LCD_COM,0x1e);   //Set Reference Voltage Register 0x00-0x3F
      delay_ms(10);
      WriteData(LCD_COM,0xF8);   //
      delay_ms(10);     
      WriteData(LCD_COM,0x00);   //
      delay_ms(10);     
      WriteData(LCD_COM,0x2F);   //Power Control On VC、VR、VF ON
      delay_ms(10);     


    //  WriteData(LCD_COM,0x47);   //Initial DisPlay Line
      WriteData(LCD_COM,0x40);   //Initial DisPlay Line //起始地址
     //  WriteData(LCD_COM,0x50);   //Initial DisPlay Line //起始地址  //
      delay_ms(10);     
     
    //  WriteData(LCD_COM,0xc8);   //屏幕上下翻转
    //  delay_ms(10);
      //WriteData(LCD_COM,0xa7);   //屏幕负像显示
      //delay_ms(10);
     // WriteData(LCD_COM,0x40);   //屏幕左右翻转
     // delay_ms(10);
      WriteData(LCD_COM,0xa0);   //屏幕左右翻转
      delay_ms(10);
    
     // WriteData(LCD_COM,0xad);   //
     // delay_ms(10);
    
     // WriteData(LCD_COM,0xB0);   //Initial DisPlay Line
    //  delay_ms(10);   
     
      //WriteData(LCD_COM,0xA5);   //
     // delay_ms(10);  
      //初始化完成
      WriteData(LCD_COM,0xAE);
      delay_ms(10);          
      WriteData(LCD_COM,0xAF);   //DisPlay On
      delay_ms(10);     
      REST_LCD(); 
    }


void  CLR_Hang(unsigned char hang)
         {
          char i;
          switch(hang)
              {
               case 0:      ////
                     WriteData(0,0xB7); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 1:
                    WriteData(0,0xB5); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B5和B4为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 2:
                   WriteData(0,0xB3); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B3和B2为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 3:
                    WriteData(0,0xB1); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B1和B0为同一个汉字的上下页B7为上页,B6为下页
                      break;
             
               default:
                     WriteData(0,0xB1); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                      break;
               }
          WriteData(0,0x10);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,0x00);   //Set Column Address LSB 0x00-0x0F
          for(i=0;i<132;i++)
                WriteData(1,0x00);   //All DisPlay
          switch(hang)
              {
               case 0:      ////
                     WriteData(0,0xB6); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 1:
                    WriteData(0,0xB4); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B5和B4为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 2:
                   WriteData(0,0xB2); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B3和B2为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 3:
                    WriteData(0,0xB0); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B1和B0为同一个汉字的上下页B7为上页,B6为下页
                      break;
             
               default:
                     WriteData(0,0xB0); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                      break;
               }
          WriteData(0,0x10);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,0x00);   //Set Column Address LSB 0x00-0x0F
          for(i=0;i<132;i++)
                WriteData(1,0x00);   //All DisPlay
         }


void LCD_write_string(unsigned char X,unsigned char Y,unsigned char Fan,char flash *s)
  {
    unsigned char TempFan,MMChar;
    unsigned int strchar; 
    ASIIChar = 0;
    MMChar = 0;
    LCD_set_xy( X, Y );
    while (*s)
      {
        if(Fan<16)
         {
           if(Fan == MMChar)
            TempFan = 1;
           else
            TempFan = 0;
          }
        else
         TempFan = 0;
        if(*s<128)
         {
          //strchar = *s;
           LCD_write_char(*s,TempFan);
         //s ++;
         }
       else
        {
         strchar = *s;
         strchar = strchar<<8;
         s++;
         strchar |= *s;
         LCD_write_HZ(strchar,TempFan);
       //   s++;
        }
       s++; 
       MMChar++;
      }
  }



void LCD_set_xy( unsigned char x, unsigned char y )
  {
    unsigned char ytemp;
    charX = x;
    charY = y;
    switch(x)
              {
               case 0:      ////
                      PAGN = 0xB7; //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                       break;
               case 1:
                      PAGN = 0xB5; //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B5和B4为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 2:
                     PAGN = 0xB3; //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B3和B2为同一个汉字的上下页B7为上页,B6为下页
                      break;
               case 3:
                     PAGN = 0xB1; //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B1和B0为同一个汉字的上下页B7为上页,B6为下页
                      break;
               default:
                     PAGN = 0xB1;; //Set Page Address 0xB0-0xB7  Icon Address 0xB8     B7和B6为同一个汉字的上下页B7为上页,B6为下页
                      break;
         
              }
             
              ytemp = y;
             if(ytemp>15)
               ytemp = 15;
             ColumnH = (ytemp/2)+0x10;
             ytemp = ytemp%2;
             if(ytemp == 0)
              ColumnL = 0x00;
             else
               ColumnL = 0x08;
  }
 
void LCD_write_char( unsigned int str_char, unsigned char Fan_char)
     {
       ////-----------------
       unsigned char chari;
       unsigned int  charadd,strdata,CharTemp;
       charadd = 0;
       //Fan_char = 1;
          for(;;)
            {
             strdata= ASIIC[charadd*18];
             strdata = strdata<<8;
             strdata |= ASIIC[charadd*18+1];
             if(strdata != 0)
              {
                if(str_char == strdata)
                 break;
                else
                 charadd++;
               }
             else
              charadd = 0;
            }
          LCD_set_xy(charX, charY);
          WriteData(0,PAGN); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     ////BO和B7为同一个汉字的页
          WriteData(0,ColumnH);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,ColumnL);   //Set Column Address LSB 0x00-0x0F
          if((ColumnH == 0x10)&&(ColumnL == 0))
            WriteData(1,0);   //All DisPlay
            CharTemp = charadd;
            CharTemp =CharTemp*18+2;
          for(chari=0;chari<8;chari++)
             {
             //   if(Fan_char == 0)
                  WriteData(1,ASIIC[CharTemp+chari]);   //All DisPlay
              //  else
              //   WriteData(1,~ASIIC[CharTemp+chari]);   //All DisPlay
             }
          WriteData(0,PAGN-1); //Set Page Address 0xB0-0xB7  Icon Address 0xB8
          WriteData(0,ColumnH);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,ColumnL);   //Set Column Address LSB 0x00-0x0F
          if((ColumnH == 0x10)&&(ColumnL == 0))
            WriteData(1,0);   //All DisPlay
          for(chari=0;chari<8;chari++)
             {
                if(Fan_char == 0)
                  WriteData(1,ASIIC[CharTemp+8+chari]);   //All DisPlay 
                else
                 WriteData(1,ASIIC[CharTemp+8+chari]|0x03);   //All DisPlay  
             } 
          charY = charY+1; 
     }


void LCD_write_HZ( unsigned int str_char,unsigned char Fan_char)
     {
       ////-----------------
       unsigned char chari;
       unsigned int  charadd,strdata,CharTemp;
       charadd = 0;
          for(;;)
            {
             strdata= HZ_font16[charadd*34];
             strdata = strdata<<8;
             strdata |= HZ_font16[charadd*34+1];
             if(strdata != 0)
              {
                if(str_char == strdata)
                 break;
                else
                 charadd++;
               }
             else
              charadd = 0;
            }
          LCD_set_xy(charX, charY);
          WriteData(0,PAGN); //Set Page Address 0xB0-0xB7  Icon Address 0xB8     ////BO和B7为同一个汉字的页
          WriteData(0,ColumnH);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,ColumnL);   //Set Column Address LSB 0x00-0x0F
          if((ColumnH == 0x10)&&(ColumnL == 0))
            WriteData(1,0);   //All DisPlay
            CharTemp = charadd;
            CharTemp =CharTemp*34+2;
          for(chari=0;chari<16;chari++)
             {
                if(Fan_char == 0)
                  WriteData(1,HZ_font16[CharTemp+chari]);   //All DisPlay
                else
                 WriteData(1,~HZ_font16[CharTemp+chari]);   //All DisPlay
              }
          WriteData(0,PAGN-1); //Set Page Address 0xB0-0xB7  Icon Address 0xB8
          WriteData(0,ColumnH);   //Set Column Address MSB 0x10-0x1F
          WriteData(0,ColumnL);   //Set Column Address LSB 0x00-0x0F
          if((ColumnH == 0x10)&&(ColumnL == 0))
            WriteData(1,0);   //All DisPlay
          for(chari=0;chari<16;chari++)
          {
                if(Fan_char == 0)
                   WriteData(1,HZ_font16[CharTemp+16+chari]);   //All DisPlay 
                else
                  WriteData(1,~HZ_font16[CharTemp+16+chari]);   //All DisPlay 
          }
          charY = charY+2; 
     }
    
    
void display_pl_long(unsigned long Data,unsigned char Dispw,unsigned char Dhide,unsigned char FANG,unsigned char Dkhz) 
      { 
       unsigned long Temm;
       unsigned long Temp;
       unsigned char Fangtemp,Fang;
       Fangtemp = 0;
      
       Temm = Data*1000; 
       switch(Dispw)
          {
           
            case  10:
                      
                       if(Temm/4200000001 != 0)
                         LCD_write_char('^', 0);
                       else
                         LCD_write_char(0x20, 0);
                       //  Fangtemp = 1;
                       Temm = Temm%4290000000;
                       Temp = Temm;
                       Temp = Temp/1000000000;
                      
                       if(FANG<16)
                        {
                          if(Fangtemp == FANG)
                             Fang = 1;
                          else
                             Fang = 0;
                        }
                      else
                       Fang = 0;
                     
                       if(Temp != 0)  Dhide = PASS;
 
                       if(Dhide != OK)
                         LCD_write_char(Temp+0x30, Fang);
                       else
                         LCD_write_char(0x20, 0);
                       Fangtemp= Fangtemp+1;
            case  9:
                       Temm = Temm%1000000000;
                        Temp = Temm;
                       Temp = Temp/100000000;
                       
                         if(FANG<16)
                        {
                          if(Fangtemp == FANG)
                             Fang = 1;
                          else
                             Fang = 0;
                        }
                      else
                       Fang = 0;
                     
                       if(Temp != 0)  Dhide = PASS;
                        
                       if(Dhide != OK)
                         LCD_write_char(Temp+0x30, Fang);
                       else
                         LCD_write_char(0x20, 0);
                        Fangtemp= Fangtemp+1;
           
            case  8:
                       Temm = Temm%100000000;
                        Temp = Temm;
                       Temp = Temp/10000000;
                        if(FANG<16)
                        {
                          if(Fangtemp == FANG)
                             Fang = 1;
                          else
                             Fang = 0;
                        }
                      else
                       Fang = 0;
                     
                       if(Temp != 0)  Dhide = PASS;
                       if(Dhide != OK)
                          LCD_write_char(Temp+0x30, Fang);
                       else
                          LCD_write_char(0x20, 0);
                        Fangtemp= Fangtemp+1;
           
            case  7:
                       Temm = Temm%10000000;
                        Temp = Temm;
                       Temp = Temp/1000000;


                       if(FANG<16)
                        {
                          if(Fangtemp == FANG)
                             Fang = 1;
                          else
                             Fang = 0;
                        }
                      else
                       Fang = 0;
                      
                       if((Temp != 0)||(Dkhz == MHz))  Dhide = PASS;
                       if(Dhide != OK)
                        LCD_write_char(Temp+0x30, Fang);
                       else
                          LCD_write_char(0x20, 0);
                       Fangtemp= Fangtemp+1;
                         
                       if(Dkhz == MHz)
                         LCD_write_char('.', 0);
                  
            case  6:
                       Temm = Temm%1000000;
                       Temp = Temm;
                       Temp = Temp/100000;
                       if(FANG<16)
                        {
                          if(Fangtemp == FANG)
                             Fang = 1;
                          else
                             Fang = 0;
                        }
                      else
                       Fang = 0;
                       LCD_write_char(Temp+0x30, Fang);
                       Fangtemp= Fangtemp+1;
           
            case  5:
                       Temm = Temm%100000;
                       Temp = Temm;
                       Temp = Temp/10000;
                       Temm = Temm%10000;
                       if(Fangtemp == FANG)
                          Fang = 1;
                       else
                         Fang = 0;
                          Fangtemp= Fangtemp+1;
                       LCD_write_char(Temp+0x30, Fang);
                   
            case  4:
                       Temm = Temm%10000;
                       Temp = Temm;
                       Temp = Temp/1000;
                       Temm = Temm%1000;
                      if(Fangtemp == FANG)
                          Fang = 1;
                       else
                         Fang = 0;
                          Fangtemp= Fangtemp+1;
                       LCD_write_char(Temp+0x30, Fang);
                       if(Dkhz == KHz)
                         LCD_write_char('.', 0);
                       Temp = Temm;
                       Temp = Temp/100;
                       Temm = Temm%100;
                       //lcd_putchar(Temp+0x30);
                       LCD_write_char(Temp+0x30, Fang);
                        Fang = 0;
                      
                       Temp = Temm;
                       Temp = Temp/10;
                       Temm = Temm%10;
                       //lcd_putchar(Temp+0x30);
                       LCD_write_char(Temp+0x30, Fang);
                       //lcd_putchar(Temm+0x30);
                       LCD_write_char(Temm+0x30, 0);
                       if(Dkhz == MHz)
                         //lcd_putchar('M');
                         LCD_write_char('M', 0);
                       if(Dkhz == KHz)
                         //lcd_putchar('K');
                         LCD_write_char('K', 0);
                       //lcd_putchar('H');
                       LCD_write_char('K', 0);
                       //lcd_putchar('z');
                       LCD_write_char('z', 0);
                       break;
             default:
                       Temm = Temm%1000000000;
                       break; 
          }  
    }
      https://static.assets-stash.eet-china.com/album/old-resources/2008/12/7/5eb6445b-7f7a-4393-921b-a4d8108d4a3b.rar

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条