打印
[PIC®/AVR®/dsPIC®产品]

PIC18驱动LCD 5110屏幕不显示东西是怎么回事啊?

[复制链接]
1143|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
如题,屏幕会亮但是没有显示,求大神看看程序!
#define uint unsigned int
#define uchar unsigned char
#define res     PORTCbits.RC5
#define sce     PORTCbits.RC4        //片选PORTAbits.RA0
#define dc      PORTCbits.RC3         //1些数据,0写指令
#define sdin    PORTCbits.RC6         //数据
#define sclk    PORTCbits.RC7         //时钟
void LCD_init(void);
void init(void);
void LCD_write_byte(unsigned char dt,unsigned char command);
void delay(uint x);
void LCD_set_XY(unsigned char X,unsigned char Y);
void LCD_clear(void);
void LCD_write_char(unsigned char x,unsigned char y,unsigned char c);
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);

void main(void)
{
    init();
    LCD_init();//初始化LCD模块
    LCD_clear();//清屏
    while(1)
    {
          LCD_write_english_string(0,0," Welcome to  ");
        LCD_write_english_string(0,1," Amy  studio ");
        LCD_write_english_string(0,2,"amy-studio.com");
        LCD_write_english_string(0,3," Nokia5110 LCD");
    }
//    while(1)
  //  {
//        asm("CLRWDT");
//    }
}

void init(void)  //单片机初始化
{
    asm("CLRWDT");
    ADCON1=0x06;
    TRISC=0x00;
    PORTB=0x00;
}

void LCD_write_byte(unsigned char dt,unsigned char command)
{
    unsigned char i;
    sce = 0;        //片选
    dc = command;   //1写数据,0写指令
    for(i=0;i<8;i++) //循环传送8个bit
    {
        if(dt&0x80)
            sdin=1;
        else
            sdin=0;
        dt=dt<<1;
        sclk = 0;
        asm("CLRWDT");
        asm("CLRWDT");
        sclk=1;     //在时钟上升沿采样
    }
    dc=1;
    sce=1;
    sdin=1;
}

void LCD_init(void)     //LCD初始化
{
    res=0;
    delay(10);
    res=1;
    sce=0;      //sce为高时,串行口被初始化。sce为高时忽略始时钟信号。
    delay(10);
    sce=1;
    LCD_write_byte(0x21,0);//0b0010 0001LCD功能设置:芯片活动,水平寻址,使用扩展指令
    LCD_write_byte(0xc6,0);//设置VOP值
    LCD_write_byte(0x06,0);//温度校正
    LCD_write_byte(0x13,0);//1:48
    LCD_write_byte(0x20,0);//LCD功能设置:新品活动,水平寻址,使用基本指令
    LCD_clear();
    LCD_write_byte(0x0c,0);//设定显示配置:普通模式
   
    sce=0;
}

void LCD_set_XY(unsigned char X,unsigned char Y)// 位置选择
{
    LCD_write_byte(0x40|Y,0);
    LCD_write_byte(0x80|X,0);
}

void LCD_clear(void)    //清屏
{
    unsigned char t;
    unsigned char k;
    LCD_set_XY(0,0);
    for(t=0;t<6;t++)
    {
        for(k=0;k<84;k++)
        {
            LCD_write_byte(0x00,1);
            asm("CLRWDT");
        }
    }
}

void LCD_write_char(unsigned char x,unsigned char y,unsigned char c)//写数据
{
    unsigned char line;
    c -= 32;
    LCD_set_XY(x*6,y);
    for(line=0;line<6;line++)
        LCD_write_byte(font6x8[c][line],1);
}

void delay(uint x)//延时程序
{
    uint a,b;
    for(a=x;a>0;a--)
        for(b=110;b>0;b--);
}

void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
    LCD_set_XY(X,Y);
    while(*s)
    {
        LCD_write_char(X,Y,*s);
        s++;
    }
}
沙发
15907726754|  楼主 | 2016-1-13 22:07 | 只看该作者
沉下去了!!!

使用特权

评论回复
板凳
JY-DX-JY| | 2016-1-14 12:56 | 只看该作者
多半时序的问题。

使用特权

评论回复
地板
mzb2012| | 2016-1-14 22:06 | 只看该作者
1.确保硬件焊接,没问题
2.对于PIC单片机 LAT是输出口,PORT是输入口,建议更改
3.时序可参考我项目的例程,欧了





使用特权

评论回复
5
你没找死啊| | 2017-9-11 23:45 | 只看该作者
mzb2012 发表于 2016-1-14 22:06
1.确保硬件焊接,没问题
2.对于PIC单片机 LAT是输出口,PORT是输入口,建议更改
3.时序可参考我项目的例程 ...

还有呢?中文显示要如何写?

使用特权

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

本版积分规则

9

主题

65

帖子

1

粉丝