打印

RA8806-240128 液晶不显示,为什么,求高手,程序如下

[复制链接]
2581|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
baochongyou|  楼主 | 2013-5-9 16:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

#include<iom16v.h>       
#include<macros.h>
#define uint unsigned  int
#define uchar unsigned char
#define   cs1   PORTD |= (1 << PD0)
#define   cs0  PORTD &= ~(1 <<PD0)
#define   rd1   PORTD |= (1 << PD1)                                                                                
#define   rd0  PORTD &= ~(1 <<PD1)
#define   wr1   PORTD |= (1 << PD2)
#define   wr0  PORTD &= ~(1 <<PD2)
//#define   BINT1   PORTD |= (1 << PD3)
//#define  BINT0  PORTD &= ~(1 <<PD3)
#define   rs1   PORTD |= (1 << PD4)
#define   rs0  PORTD &= ~(1 <<PD4)
#define   rst1   PORTD |= (1 << PD5)
#define   rst0  PORTD &= ~(1 <<PD5)
#define   Read_BUSY     PIND & (1 << PD7)
#define   BUS          PORTB
//#define   Read_lcd_data     PINC & (0XFF)
#define   Read_BUS     PINB

//----------------------------------1us延时子程序-----------------------------
void delay_us(uint delay_counter)//延时1us
{
   do
   {
      delay_counter--;
   }while(delay_counter>1);
}
void delay_nms(unsigned int delay_counter)//延时1ms
{
   while(delay_counter!=0)
   {
     delay_us(1000);
      delay_counter--;
   }
}
//$$$$$$$$$$$$$$$$$$$$$//lcd$$$$$$$$$$$$$$$$$$$$$$$$$$$

void softrst()
{
delay_nms(2);
cs0;
rd1;
rst0;
delay_nms(200);
rst1;
delay_nms(200);
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  

unsigned char LCD_CmdRead(unsigned char Addr)
{   
unsigned char Data;   
LCD_CmdWrite( Addr);
DDRB=0x00;       
wr1;
delay_us(2);
cs0;
delay_us(2);
rs0;
delay_us(2);  
rd0;
Data=Read_BUS;
//PORTA =Data;
delay_nms(1);
delay_us(2);
      rd1;       
          delay_us(2);
            rs1;
                delay_us(2);
            cs1;       
return Data;
}
uchar LCD_StasRead(void)
{
                uchar Data;
                DDRB=0xff;
                PORTB =0xff;
                DDRB=0x00;
                cs0;
                delay_us(2);                                
                rs1;
                delay_us(2);                                                               
            rd0;       
                delay_us(2);
                wr1;                                        
                Data = Read_BUS;
                PORTA =Data;
                delay_nms(2);
                 delay_us(2);
                 rd1;
                 delay_us(2);                               
                cs1;
            return Data;
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

void LCD_CmdWrite(unsigned char cmdaddr)//8080
{  
DDRB=0xFF;  
/////////////////BUS=cmdaddr;
rs1;
delay_us(2);
cs0;
delay_us(2);
rd1;  
delay_us(2);
BUS=cmdaddr;
wr0;
delay_nms(2);
delay_us(2);
wr1;
delay_us(2);
rs0;
delay_us(2);
cs1;
}
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
void LCD_DataWrite(unsigned char wrdata)
{  
     DDRB=0xFF;  
         DDRD=0x7F;
while(Read_BUSY==0);
///////////////////BUS=wrdata;
rs0;
delay_us(2);
cs0;
delay_us(2);
rd1;
delay_us(2);
BUS=wrdata;
wr0;
delay_nms(2);
delay_us(2);
wr1;
delay_us(2);
rs1;
delay_us(2);
cs1;
}
//******************消除雪花模式******************
void clearsnow(void)       //在文本方式下,无法使用消除雪花模式,在图形模式下可以用
{  unsigned char temp;

temp=LCD_CmdRead(0x01);
temp |=0x80;
//temp |=0x88;
LCD_CmdWrite(0x01);
LCD_DataWrite(temp);  
}
//******************不消除雪花模式--正常模式******************
void noclearsnow(void)

{  unsigned char temp;     //在文本方式下,无法使用消除雪花模式
temp=LCD_CmdRead(0x01);
temp &=0x7f;
LCD_CmdWrite(0x01);  
LCD_DataWrite(temp);  
}

//******************X,Y坐标定位******************

void LCD_GotoXY(unsigned char xx,unsigned char yy) //123456
{  
LCD_CmdWrite(0x60);  
LCD_DataWrite(xx&0x3f);
delay_us(1);
LCD_CmdWrite(0x70);   
        LCD_DataWrite(yy & 0xff);
        delay_us(1);
}
//*************绘图模式**************************
void LCD_Graphic(void)
{   unsigned char temp;
temp=LCD_CmdRead(0x00);
temp &=0xf7;
LCD_CmdWrite(0x00);
LCD_DataWrite(temp);  
clearsnow();      //开启消除雪花功能
}
void Only_Show_Page1(void)   //将DDRAM1的数据显示于屏幕上。
{
        uchar temp;
        temp =LCD_CmdRead(0x12);
        temp &= 0xbf;
        temp &= 0xdf;
        temp |= 0x10;
        LCD_CmdWrite(0x12);
  LCD_DataWrite(temp);
}
//***********DDRAM2 显示**************************

void Only_Show_Page2(void)
{
unsigned char temp;
temp=LCD_CmdRead(0x12);
temp &=0xaf;
temp |=0x20;
LCD_CmdWrite(0x12);
LCD_DataWrite(temp);  
}
//***********DDRAM1和DDRAM2 双图层显示***************
void Show_Two_Layer(void)
{
unsigned char temp;      
temp=LCD_CmdRead(0x12);
temp &=0xbf;
temp |=0x30;
LCD_CmdWrite(0x12);
LCD_DataWrite(temp);  
}
//***********DDRAM1和DDRAM2 OR方式显示***************
void OR_Two_Layer(void)
{
unsigned char temp;      
temp=LCD_CmdRead(0x12);
temp &=0xf3;
LCD_CmdWrite(0x12);
LCD_DataWrite(temp);  
}
//***********存取DDRAM1*******************************
void Access_Page1(void)
{
unsigned char temp;      
temp=LCD_CmdRead(0x12);
temp &=0xfd;
temp |=0x01;
LCD_CmdWrite(0x12);
LCD_DataWrite(temp);  
}
//***********存取DDRAM2*******************************

void Access_Page2(void)
{
unsigned char temp;      
temp=LCD_CmdRead(0x12);
temp &=0xfe;
temp |=0x02;
LCD_CmdWrite(0x12);
LCD_DataWrite(temp);
}

void lcd_inital()
{  
LCD_CmdWrite(0x00);             //[00H] , Default --> 0x00
LCD_DataWrite(0x04);    //屏幕显示开启  disp_off输出high   
   
LCD_CmdWrite(0x01);             //[01H] , Default --> 0x00
LCD_DataWrite(0x04);

LCD_CmdWrite(0x03);             //[03H] , Default --> 0x00  
LCD_DataWrite(0x00);

LCD_CmdWrite(0x0f);             //[0FH] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x10);             //[10H] , Default --> 0x00
//////////////////////////////////LCD_DataWrite(0x00);
LCD_DataWrite(0x40);
LCD_CmdWrite(0x11);             //[11H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x12);             //[12H] , Default --> 0x11  
LCD_DataWrite(0x11);

LCD_CmdWrite(0x20);             //[20H] , Default --> 0x27
LCD_DataWrite(0X1D);

LCD_CmdWrite(0x21);             //[21H] , Default --> 0x27
LCD_DataWrite(0X1D);

LCD_CmdWrite(0x30);             //[30H] , Default --> 0xEF      
LCD_DataWrite(0X7F);

LCD_CmdWrite(0x31);             //[31H] , Default --> 0xEF
LCD_DataWrite(0X7F);

LCD_CmdWrite(0x40);             //[40H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x50);             //[50H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x60);             //[60H] , Default --> 0x00  
LCD_DataWrite(0x00);

LCD_CmdWrite(0x61);             //[61H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x62);             //[62H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x70);             //[70H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x71);             //[71H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x72);             //[72H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x80);             //[80H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0x90);             //[90H] , Default --> 0x00    需要调整
LCD_DataWrite(0x80);

LCD_CmdWrite(0xe0);             //[E0H] , Default --> 0x00
LCD_DataWrite(0x00);

LCD_CmdWrite(0xf0);             //[F0H] , Default --> 0x00
////////////////////////////////////////LCD_DataWrite(0x00);
LCD_DataWrite(0x80);
LCD_CmdWrite(0xf1);             //[F1H] , Default --> 0x00
LCD_DataWrite(0x00);
}

/////////////////清屏子程序//////////////////////////
void clear(void)
{  
unsigned char temp;  
//LCD_Graphic();     //选择绘图模式      
//////////////////////////////noclearsnow();      //关闭消除雪花功能
LCD_CmdWrite(0xe0);
LCD_DataWrite(0x00);
        temp = LCD_CmdRead(0xf0);
        temp |= 0X08;   //内存清除功能开启,将FNTR数据填满整个工作窗口。
        LCD_DataWrite(temp);
do{
        delay_us(1);
        }
        while(LCD_StasRead() & 0x80);
}
//*************文字模式**************************
void LCD_Text(void) //123456
{   
unsigned char temp;
temp=LCD_CmdRead(0x00);
//temp |=0x08;
temp |=0x0C;
LCD_CmdWrite(0x00);
LCD_DataWrite(temp);
//noclearsnow();      //关闭消除雪花功能
}
/////////////在指定的坐标处显示字符串////////////////////
void LCD_ShowStr(unsigned char xxx,unsigned char yyy,unsigned char *text)//123456
{  
LCD_Text();   //选择文本模式
LCD_CmdWrite(0x12);
LCD_DataWrite(0x31);
LCD_GotoXY(xxx,yyy);   //设定X,Y坐标位置  
LCD_CmdWrite(0xB0);  
while(*text != '\0')      
{
delay_nms(100);
LCD_DataWrite(*text);
++text;
delay_nms(1);
   }
}

void main()
{   
int tp;
    DDRD  = 0x7F;
        PORTD = 0x00;
        PORTB = 0x00;  
    DDRB  = 0xBF;
    DDRA=0xFF; //端口C设置
        PORTA = 0xFF;
    DDRC=0xFF; //端口C设?
        PORTC = 0xFF;
softrst();
lcd_inital();
////////////////Only_Show_Page2();  
//////////////Access_Page2();   
//clear();
//display_biao();
///////////////////Access_Page1();  
///////////clear();     
/////////////LCD_ShowStr(0x00,0x00,"温度");
///////////////////Only_Show_Page1();
/////////////OR_Two_Layer();
/////////////////Show_Two_Layer();
/////////////delay_nms(3000);
clear();
while(1)
{
//PORTA = 0xFF;
//delay_nms(100);
// LCD_ShowStr(0x00,0x00,"1234");
///////////////////////////////LCD_ShowStr(0x00,0x00,"温度湿度");
//////////////////////delay_nms(100);
  //////////////////////////Access_Page1();
///////////////////////////////////////////////Only_Show_Page1();
//LCD_GotoXY(0x03,0x40);  
//////////////////LCD_GotoXY(0x00,0x00);
/////////////////////LCD_CmdWrite(0xb0);
/////////////////////////LCD_DataWrite(0x02+0x30);
LCD_ShowStr(0x00,0x00,"温度湿度");
delay_nms(1000);
clear();
  }         
}

相关帖子

沙发
baochongyou|  楼主 | 2013-5-9 16:47 | 只看该作者
液晶一直显示蓝屏,这是为什么,求高手!!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝