这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 16,LCD 分享:2*16字符型LCD程序

共2条 1/1 1 跳转至

16,LCD 分享:2*16字符型LCD程序

院士
2006-09-17 18:14:16     打赏
16,LCD 分享:2*16字符型LCD程序



关键词: 分享     字符型     程序    

院士
2006-12-22 22:43:00     打赏
2楼
问 #include<reg51.h>
//#include <intrins.h>
#define uchar unsigned char

bit bflag;
//sbit LIGHT=P0^4;
sbit P1_0=P1^0;
sbit P1_2=P1^2;
sbit RS=P2^0;//4jiao
sbit RW=P2^1;//5jiao
sbit E=P2^2;//6jiao

void lcd_clear(void);    /*清屏*/
void lcd_chekbusy(void);     /*测试忙*/
void lcd_wrcmd(uchar lcd_cmd);    /*写命令*/
void lcd_wrdata(uchar lcd_data);    /*写数据*/
void lcd_moveto(uchar position);    /*写要显示的地方*/
//void lcd_cursor ( uchar cursor_cmd );    /*光标控制*/
void lcd_init(void);    /*初始化*/

void delay(uchar x)
{    
    uchar i;
    do
    {    
    for(i=0;i<125;i++)
    {;}
    }
    while (x--);
}
    
void lcd_chekbusy(void)
{    
    uchar middle;
    do
    {    
        RS=0;
        RW=1;
        E=1;
        //delay(10);
        middle=P0;
        E=0;
        bflag=(0x80&middle);
    }
    while(bflag==1);
    bflag=1;
}

void lcd_wrcmd(uchar lcd_cmd)
{    
    //delay(1);
    RS=0;
    RW=0;
    E=1;
    P0=lcd_cmd;
    //delay(1);
    E=0;
    //lcd_chekbusy();
    //delay(1);
}

void lcd_wrdata(uchar lcd_data)    
{    
    //lcd_chekbusy();
    RS=1;
    RW=0;
    E=1;
    P0=lcd_data;
    E=0;
    //lcd_chekbusy();
}

void lcd_clear(void)
{    
    lcd_wrcmd (0x01);
}

void lcd_moveto(uchar position)        /*position为从左起算起1--16 */
{    
    uchar temp_1;
    //lcd_chekbusy();
    if (position<16)    
        temp_1=(position+0x80-1);
    else
        temp_1=((position-16)+0xc0);/////////////////已经修改
    lcd_wrcmd(temp_1);
    //lcd_chekbusy();
    //delay ( 1 );
}

void lcd_wrstr( uchar *pdispstrda ) /* 函数 */
{    uchar i;
    lcd_wrcmd(0x80); /*设置显示数据RAM*/
    for (i=0;i<=7;i++)
    {    
        lcd_wrdata(*pdispstrda);/* char of LCM */
        pdispstrda++;
    }
    lcd_wrcmd(0xc0); /*设置显示数据RAM*/
    for (i=0;i<=7;i++)
    {    
        lcd_wrdata(*pdispstrda);/* char of LCM */
        pdispstrda++;
    }
}

void lcd_wrchar(uchar lcd_add,uchar lcd_data)
{    
    lcd_moveto(lcd_add);
    lcd_wrdata(lcd_data);
}    

void lcd_init(void)
{    uchar i;
    delay(20);
    for(i=0;i<8;i++)
    {    lcd_wrcmd(0x30);    
        delay(5);
    }
    //lcd_chekbusy();
    lcd_wrcmd(0x38);
    lcd_chekbusy();
    lcd_wrcmd(0x0c);    
    lcd_chekbusy();
    lcd_wrcmd(0x06);    
    lcd_chekbusy();
    lcd_wrcmd(0x01);    
    lcd_chekbusy();
}

main()
{    
    uchar dis_string[16]={"this is a test"};
    uchar i,j,k;
    k=1;
    P0=0xff;
    P2=0xff;
    P1_2=1;
    P1_0=0;
    lcd_init();       
bee:
    lcd_moveto(1);
    j='A';
    for(i=0;i<16;i++)
    {    
        delay(1);
        lcd_wrdata(j);
        j++;
    };
    lcd_wrcmd(0xc0);
    for(i=0;i<16;i++)
    {    
        delay(1);
        lcd_wrdata(j);
        j++;
    }
    delay(250);
    lcd_wrstr(dis_string);
    lcd_clear();
    delay(1);
    lcd_wrchar(3,'G');
    delay(1);
    lcd_wrdata('O');
    delay(1);
    lcd_wrdata('O');
    delay(1);
    lcd_wrdata('D');
    P1_2=~P1_2;
goto bee;    
} 1: 楼主的LCD主控芯片是什么型号啊? 2: 应该是通用的1602 lcd吧 3: ts1620对不起,各位,忘说了.是内含hd44780的ts1620.

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]