⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd._c

📁 mega128的串口发送文件.可以发送0X55上位机使用串口调试工具就可以接收了.
💻 _C
字号:

//作者:张文2008.08.07
//液晶显示问题的说明
//液晶显示的时候用到LCD_SHOW()就可以了,不过开SPCR = 0x50  使用后关SPCR = 0x54;
//液晶的尺寸是256*192的. 
//void LCDSHOW(UINT8 page,UINT8 m,UINT8 n,UINT8 date)
//page 为0 2 4 8 10对应的是行
//m 对应的是 0x10  -- 0x17 每一行对应的数据的开始地址
//n 对应的是 两个字节的数据中的一个 一个汉字是32*32 //n==0的时候显示前半个数据.n=8对应的是后半个数据
//data 对应的是显示的数据,在显示的时候用的是查表的方法。
#include <iom64v.h>
#include <macros.h>

#include"lcd.h"
#define LCD_control	  PORTD
#define LCD_CS	  6
#define LCD_RST	  5
#define LCD_RS	  4 

//-------------------------------------------------------------------------------
unsigned char date[11]={0};   
//-------------------------------------------------------------------------------
//十进制数
//-------------------------------------------------------------------------------
const unsigned char data_hi[224]= {	  	 			 	//0123456789.
   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
   0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, //0	  
   0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
   0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,	//1
   0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
   0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,	//2
   0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
   0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,	//3
   0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
   0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,	//4
   0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
   0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,	//5
   0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
   0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,	//6
   0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
   0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,	//7
   0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
   0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,	//8
   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
   0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,	//9
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,	//.   10
   0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
   0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,  //v   11
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        //12
   
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  //"-"  //13
   0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
   
   
   
   }; 
//-------------------------------------------------------------------------------
// Delay Routine
//延时程序
//-------------------------------------------------------------------------------
void delayms(UINT32 m)    
{
    UINT32 j;
    UINT32 i;
    NOP();
    for(i=0; i<m; i++)
        for(j=0; j<109; j++)
        NOP();
}
//-------------------------------------------------------------------------------
// IO Routine
// LCD“命令字”发送
//-------------------------------------------------------------------------------
void SdCmd(UINT8 Command)                                     // send command
{
  SPI_SS |=1;  											  //屏蔽3548
	LCD_control &=~(1<<LCD_CS);                               // chip select
	LCD_control &=~(1<<LCD_RS);                               // for command
	SPI_SendByte(Command);
	LCD_control |=1<<LCD_CS;                                  // chip select
}
//-------------------------------------------------------------------------------
//LCD 数据发送
//-------------------------------------------------------------------------------
void SdData(UINT8 DData)                                       // send data
{
    SPI_SS |=1;	  											   //屏蔽3548
	LCD_control &=~(1<<LCD_CS);                           	   // chip select
	LCD_control |=1<<LCD_RS;                                   // for data
	SPI_SendByte(DData);
	LCD_control |=1<<LCD_CS;                                  // chip select
}	
//-------------------------------------------------------------------------------
//LCD 显示字符和数字
//    void LCDSHOW(UINT8 page,UINT8 m,UINT8 n,UINT8 date)
//    LCDSHOW( page, 0x15, 8, 12);	
//    M ()   N   
//-------------------------------------------------------------------------------
void LCDSHOW(UINT8 page,UINT8 m,UINT8 n,UINT8 date)
{
    
	UINT8 i,j;
	for(i=0;i<2;i++)              
	   {
	    SdCmd(0xb0+i+page);          
		SdCmd(m);                
        SdCmd(n);                 
        for(j=0;j<8;j++)
		   {
		   SdData(data_hi[j+8*i+8*2*date]);   //为什么要写两次呢?  0--7 +8*0  
           SdData(data_hi[j+8*i+8*2*date]);  //                     0-7  +8*1
		   }
	   }
}	   

//-------------------------------------------------------------------------------
//清屏 
//-------------------------------------------------------------------------------
void SdPage(void)
  {
  UINT8 i, j; 	
  SPCR = 0x50;
  for(i=0;i<12;i++)              // page data
    {
	WDR();
    SdCmd(0xb0|i );              // select page
    SdCmd(0x10);                 // column address start at 00 (Y7,Y6,Y5)
    SdCmd(0x00);                 // column address start at 00 (Y4,Y3,Y2,Y1)
    for(j=0;j<128;j++)
      {
      SdData(0X00);	  		     //清屏 
      SdData(0X00);
      }
   }			
  SPCR = 0x54; 
  }

void test(UINT8 data,UINT8 page)
{
   UINT8 k,j,i;
   SPCR = 0x50;

   date[0]=(data&0xf0)>>4;
   date[1]=data&0x0f;
   
   for(k=0;k<2;k++)
	     {
		     LCDSHOW( page, 0x10+k/2, (0x08*k)&0x0f, date[k]);  
		}
 SPCR = 0x54;		
}



//-------------------------------------------------------------------------------
//LCD初始化
//-------------------------------------------------------------------------------
void LCD_init_initialize(void)
 {
	LCD_control&=~(1<<LCD_RST);      // reset the LCD module
    delayms(5);

	LCD_control|=1<<LCD_RST;
    delayms(5);     // wait for the init routine to finish

//  SdCmd(0xae);    // Display off **hardware reset default**
    SdCmd(0x48);    // Display Duty Ratio = 1/96
    SdCmd(0x60);    // (two byte instruction)
    SdCmd(0xa1);    // ADC = 1, reverse (flip x-direction)
    SdCmd(0xc8);    // SHL = 1, reverse (flip y-direction)
    SdCmd(0x44);    // COM0Reg = 16
    SdCmd(0x10);    // (two byte instruction)
    SdCmd(0x40);    // Display Start Line = 0
    SdCmd(0x00);    // (two byte instruction)
    SdCmd(0xab);    // Osc on strat
    SdCmd(0x66);    // DC-DC StepUp = 5x boosting

    SdCmd(0x27);    // 1+(Rb/Ra) = 7.2 (highest value)
    SdCmd(0x81);    // ElecVol = 32 (middle value)
    SdCmd(0x20);    // (two byte instruction)
    SdCmd(0x54);    // LCD bias = 1/9 (adjusted for better control)
//  SdCmd(0x4c);    // N-line inversion = frame inversion **hardware reset default**
//  SdCmd(0x00);    // (two byte instruction) **hardware reset default**

    SdCmd(0x93);    // FRC=4 PWM=15

    SdCmd(0x88);    // white mode (two byte instruction)
    SdCmd(0x00);    // 1st Frame Pulse width = 00h
                    // 2nd Frame Pulse width = 00h
    SdCmd(0x89);    // white mode (two byte instruction)
    SdCmd(0x00);    // 3rd Frame Pulse width = 00h
                    // 4th Frame Pulse width = 00h

    SdCmd(0x8a);    // light gray mode (two byte instruction)
    SdCmd(0x00);    // 1st Frame Pulse width = 08h
                    // 2nd Frame Pulse width = 08h
    SdCmd(0x8b);    // white mode (two byte instruction)
    SdCmd(0x00);    // 3rd Frame Pulse width = 08h
                    // 4th Frame Pulse width = 08h

    SdCmd(0x8c);    // dark gray mode (two byte instruction)
    SdCmd(0xff);    // 1st Frame Pulse width = 0Bh
                    // 2nd Frame Pulse width = 0Bh
    SdCmd(0x8d);    // white mode (two byte instruction)
    SdCmd(0xff);    // 3rd Frame Pulse width = 0Bh
                    // 4th Frame Pulse width = 0Bh

    SdCmd(0x8e);    // dark gray mode (two byte instruction)
    SdCmd(0xff);    // 1st Frame Pulse width = 0Eh (set to reduce crosstalk)
                    // 2nd Frame Pulse width = 0Eh (set to reduce crosstalk)
    SdCmd(0x8f);    // white mode (two byte instruction)
    SdCmd(0xff);    // 3rd Frame Pulse width = 0Eh (set to reduce crosstalk)
                    // 4th Frame Pulse width = 0Eh (set to reduce crosstalk)

    SdCmd(0x2C);    // power ctl = DC-DC ON
    delayms(1); 
    SdCmd(0x2f);    // power ctl = Voltage Regulator ON
    delayms(1);
    SdCmd(0x2f);    // power ctl = Voltage follower ON
    delayms(1);

    SdCmd(0xaf);    // display ON
 }
//------------------------------------------------------------------------------- 
void LCD_init(void)                      					   //模块复位与初始化  
 {   
    UINT8 csdbuff[16],ret;
	SPCR = 0x50; 
	DDRD|=1<<LCD_CS;
	DDRD|=1<<LCD_RS;
	DDRD|=1<<LCD_RST;
	
    LCD_init_initialize();	 								   //LCD初始化 
	SdPage();    											   // 清屏
	SPCR = 0x54;
 }

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -