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

📄 xianshi.c

📁 LCM的控制芯片是ST7541,与单片机相连
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************/
//    program :       714A.c
//    discription   :   IC     ST7541
//                          Dots   128*128
//                          VDD   3.0
//                          Duty   1/128 
//                          Bias    1/11
//                          Vop     11.57V
//     interface :      8 parallel
//     Write by  :     ywq
//     Date       :     2006-7-20
/***************************************************/



#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

uchar code map[];

sbit cs=P3^0;
sbit reset=P3^1;
sbit A0=P3^2;
sbit wr=P3^3;
sbit rd=P3^4;
uchar code number_2[];
uchar code num2;
uchar code number_3[];
uchar code num3;

void delay(uint d)   
{
  uint i,j;
  for(i=0;i<d;i++)
  	for(j=0;j<1000;j++);
}



void write_command(uchar d)
{
   cs=0;
   rd=1;  //not read  command 
   A0=0;  //command
   wr=0;
   P1=d;  //write command 
   wr=1;
   cs=1;  
}

void write_data(uchar d)
{
   cs=0;
   rd=1;  
   A0=1; //data
   wr=0;
   P1=d; //write data
   wr=1;
   cs=1;
}
void clear()
{
 int i,j;
 for(i=0;i<16;i++)
 {
  write_command(0xb0+i);   //set page adress
  write_command(0x10);     //Set column address MSB
  write_command(0x00);     //Set column address LSB
  for(j=0;j<128;j++)
  {
   write_data(0x00);
   write_data(0x00);
  }
 }
}

void initialization()
{
  reset=0;
  delay(10); 
  reset=1;
  delay(10);
 
  /*write_command(0xe2);// reset

  write_command(0x38);//modeset
  write_command(0xa0);//modsetp   50

  write_command(0x48);//duty=1/128
  write_command(0x80);
  
  write_command(0xa1);//ADC 
  
  write_command(0xc0);//SHL 

  write_command(0x40);//initial line register
  write_command(0x00);
  write_command(0x44);//initial com0 register
  write_command(0x00);

  write_command(0xab);//osc on
  
  write_command(0x20);//Rb/Ra ratio ,20~27
  
  write_command(0x81);// set reference voltage register
  write_command(0x20);// a ,ajustable ,00~3F   24

  write_command(0x57);//bias =1/11

  write_command(0xa6);//normal display 
  write_command(0xa4);//entire display off
    
  write_command(0x66);//DC-DC  5*  
 
  write_command(0x2c);//power control :VC on  
  delay(100);
  write_command(0x2e);//   VC, VR on
  delay(5);
  write_command(0x2f);//   VC, VR, VF on
 write_command(0x93);//frcpwm set
          write_command(0x4c);//N-line inversion 1st
            write_command(0x00);//frame inversion 2nd
 
 write_command(0x88);
 write_command(0x00);
 write_command(0x89);
 write_command(0x00);
 write_command(0x8a);
 write_command(0xdd);
 write_command(0x8b);
 write_command(0xdd);
 write_command(0x8c);
 write_command(0xaa);
 write_command(0x8d);
 write_command(0xaa);
 write_command(0x8e);
 write_command(0xff);
 write_command(0x8f);
 write_command(0xff);
 
// write_command(0xa1);
// write_command(0xc0);
 
 write_command(0xaf);//display on
 
 delay(10);*/
  write_command(0xe2);// reset

  write_command(0x38);//modeset
  write_command(0xd0);//modsetp

  write_command(0x48);//duty=1/128
  write_command(0x80);
  
  write_command(0xa0);//ADC 
  
  write_command(0xc0);//SHL 

  write_command(0x40);//initial line register
  write_command(0x00);
  write_command(0x44);//initial com0 register
  write_command(0x00);

  write_command(0xab);//osc on
  
  write_command(0x26);//Rb/Ra ratio ,20~27  26
  
  write_command(0x81);// set reference voltage register
  write_command(0x38);// a ,ajustable ,00~3F     25(样品)

  write_command(0x57);//bias =1/12          

  write_command(0xa6);//normal display 
  write_command(0xa4);//entire display off
    
  write_command(0x67);//DC-DC  5*     66
 
  write_command(0x2c);//power control :VC on  
  delay(100);
  write_command(0x2e);//   VC, VR on
  delay(5);
  write_command(0x2f);//   VC, VR, VF on
 write_command(0x97);//frcpwm set
           write_command(0x4c);//N-line inversion 1st
            write_command(0x00);//frame inversion 2nd  00
 
 write_command(0x88);
 write_command(0x00);
 write_command(0x89);
 write_command(0x00);
 write_command(0x8a);
 write_command(0xdd);
 write_command(0x8b);
 write_command(0xdd);
 write_command(0x8c);
 write_command(0xaa);
 write_command(0x8d);
 write_command(0xaa);
 write_command(0x8e);
 write_command(0xff);
 write_command(0x8f);
 write_command(0xff);
 
// write_command(0xa1);
// write_command(0xc0);
 
 write_command(0xaf);//display on
 
 delay(10);
  	
}
void test_characters()
{
 int i,j,k,num;
 uchar code character[]={
 				0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff,
 				
 			//	0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
 			
 			//	0XAA,0XAA,0XAA,0XAA,0XAA,0XAA,0XAA,0XAA,
 				0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,
 				
 			};
 for(num=0;num<2;num++)
 {
  for(i=0;i<16;i++)
  {
   write_command(0xb0+i);
   write_command(0x10);
   write_command(0x00);
   for(j=0;j<16;j++)
    for(k=0;k<8;k++)
    {
     write_data(character[8*num+k]);
     write_data(character[8*num+k]);
    }
  }
//  wait_key();
  delay(200);
 }
}
void test_number_2()
{
 int i,k,m;
 clear();
 for(i=0;i<2;i++)
 {
  write_command(0xb4+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[m]);
    write_data(number_2[m]);
   }
  write_command(0xb5+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[16+m]);
    write_data(number_2[16+m]);
   }
  write_command(0xb6+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[32+m]);
    write_data(number_2[32+m]);
   }
  write_command(0xb7+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[48+m]);
    write_data(number_2[48+m]);
   }
 }
}
void test_number_3()
{
 int i,k;
 clear();
 for(i=0;i<16;i++)
 {
  write_command(0xb0+i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<128;k++)
  
   {
    write_data(number_3[128*i]);
    write_data(number_3[128*i+k]);
   }
  
 /* for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[16+m]);
    write_data(number_2[16+m]);
   }
  write_command(0xb6+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[32+m]);
    write_data(number_2[32+m]);
   }
  write_command(0xb7+4*i);
  write_command(0x10);
  write_command(0x00);
  for(k=0;k<8;k++)
   for(m=0;m<16;m++)
   {
    write_data(number_2[48+m]);
    write_data(number_2[48+m]);
   }*/
 }
}
void test_frame()
{
 int i;
 clear();
 write_command(0xb0);
 write_command(0x00);
 write_command(0x10);
 write_data(0xff);
 write_data(0xff);
 for(i=0;i<126;i++)
 {
  write_data(0x01);
  write_data(0x01);
 }
 write_data(0xff);
 write_data(0xff);
 for(i=0;i<14;i++)
 {
  write_command(0xb1+i);
  write_command(0x00);
  write_command(0x10);
  write_data(0xff);
  write_data(0xff);
  write_command(0x0f);
  write_command(0x17);
  write_data(0xff);
  write_data(0xff);
 }
 write_command(0xb15);
 write_command(0x00);
 write_command(0x10);
 write_data(0xff);
 write_data(0xff);
 for(i=0;i<126;i++)
 {
  write_data(0x80);
  write_data(0x80);

⌨️ 快捷键说明

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