• 專注電子技術學習與研究
    當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

    1602液晶顯示漢字

    作者:huqin   來源:本站原創   點擊數:  更新時間:2014年04月04日   【字體:

    此為變態法,操作有待提高

    程序代碼如下:
    #include <reg51.h>
    #include <intrins.h>
    #define uchar unsigned char
    #define uint unsigned int
    uchar code line1[] = {"welcome!"};
    uchar p[]= //自定義字模數組
    {
    0x00,0x0f,0x04,0x0f,0x05,0x07,0x00,0x00,
    0x0f,0x12,0x1f,0x15,0x1f,0x15,0x1f,0x15, //確
    0x04,0x02,0x0e,0x02,0x02,0x03,0x02,0x00,
    0x04,0x04,0x04,0x04,0x04,0x0a,0x11,0x00, //認
    0x00,0x0f,0x09,0x06,0x06,0x06,0x09,0x00,
    0x1f,0x0a,0x0e,0x0e,0x0a,0x1f,0x02,0x02 //取
    };
    sbit E=P2^7;
    sbit RW=P2^5;
    sbit RS=P2^6;
    busying ()
    {
    bit result;
    RS = 0;
    RW = 1;
    E = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    result = (bit)(P0&0x80);
    E = 0;
    return result;
    }
    writeorder (uchar cmd)
    {
    while (busying());
    RS = 0;
    RW = 0;
    E = 0;
    _nop_();
    _nop_();
    P0 = cmd;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    E = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    E = 0;
    }
    writedata (uchar dat)
    {
    while (busying());
    RS = 1;
    RW = 0;
    E = 0;
    _nop_();
    _nop_();
    P0 = dat;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    E = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    E = 0;
    }
    delay(uchar i)
    {
    while(i--)
    {
    uchar j=250;
    while(j--)
    {
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    }
    }
    }
    initial ()
    {
    delay (150);
    writeorder (0x38); //工作方式:8位、2行、5x7
    delay(5);
    writeorder (0x06); //輸入方式:光標右移、屏幕不動
    delay(5);
    writeorder (0x0c); //顯示狀態:顯示開、有光標、不閃爍
    delay(5);
    writeorder (0x01); //清屏
    delay(5);
    }
    newbyte (void) //設置自定義字符
    {
    uchar i,j,k=0;
    uchar temp=0x40;
    for(j=0;j<6;j++)
    {
    for(i=0;i<8;i++)
    {
    writeorder(temp+i);
    writedata(p[k]);
    k++;
    }
    temp += 8;
    }
    }
    main (void)
    {
    uchar i=0;
    initial ();
    newbyte ();
    writeorder (0x85); //設置第一行顯示位置
    writedata (0x00);
    writedata (0x01);
    writedata (0x02);
    writedata (0x03);
    writedata (0x04);
    writedata (0x05);
    writeorder (0xc4); //設置第二行顯示位置
    while(line1[i] != '\0')
    { // 顯示字符"welcome!"
    writedata(line1[i]);
    i++;
    }
    while (1);
    }

    關閉窗口

    相關文章

    亚洲一区二区制服在线|在绩专区欧美自拍日韩|青春娱乐网97超碰人人射|在线观看国产网址你懂的