miss_夏 2015-04-24 02:09 采纳率: 0%
浏览 2755

KS0108的LCD12864实际显示数据虚读是怎样的

KS0108的LCD12864仿真时成功,但是实际显示时却不能成功,只是亮着,看前辈说要虚读一次,有能详细明白的一点吗

  • 写回答

2条回答 默认 最新

  • miss_夏 2015-04-24 02:11
    关注

    #include
    #include
    #include
    #include"lcd12864.h"
    #include"cncode.h"
    #include"encode.h"

    uchar xdata dispbuf[8][128];//1024Byte用于存放显示数据

    void LcdInit() //lcd初始化
    {
    cs1 = 1;
    cs2 = 1;
    WriteCmd(DISP_OFF);
    WriteCmd(DISP_Y);
    WriteCmd(DISP_ON);
    }

    void WriteCmd(uchar cmd) //lcd写命令
    {
    WaiteBusy();
    e=0;
    rw = 0;
    rs = 0;
    DBPort = cmd;
    e = 1;
    nop();
    nop();
    e = 0;
    }

    void WriteData(uchar wdata) //lcd写数据
    {
    WaiteBusy();
    rs = 1;
    rw = 0;
    DBPort = wdata; //数据送入总线
    e = 1;
    nop();
    nop();
    e = 0;
    }

    /*从LCD读取状态*/
    uchar getState(void)

    {
    uchar temp; //定义状态变量
    DBPort = 0xFF; //黑屏0xff
    e=0; //准备读取
    rs=0; //选择命令寄存器
    rw=1; //选择读取方式
    e=1; //使能输出
    nop();
    e=0; //停止读取
    temp = DBPort; //读取数据端口总线
    return temp; //返回
    }

    void WaiteBusy()
    {
    uchar temp; //状态信息变量(用于判断是否忙)
    while(1)
    {
    temp = getState(); //读取LCD状态
    temp &= 0x80; //与运算,检查第7位busy信号
    if(temp == 0) //若状态值为0,则循环结束
    break;
    }
    }

    void DisPlay16(unsigned char line, unsigned char column , unsigned char LorR , unsigned char addr)
    {
    unsigned char i;
    unsigned char j;

    cs1 = 0;
    cs2 = 0;
    if(LorR == 0)
    {
        cs1 = 1;
    }
    else
    {
        cs2 = 1;
    }
    
    for(i=0; i<2 ;i++)     //每个字符占2页,所以写2次
    {
        for(j=0; j<16 ;j++)  //连续16次(上下半字各16个编码)
        {
            WriteCmd(DISP_PAGE|(i+line));    //写入显示页地址
            WriteCmd(DISP_X|(j+column));      //写入显示列地址
            WriteData(Hzk[addr*32 + j + 16*i]);  //每页写入16个字节的汉字编码数据
        }
    }
    cs1 = 0;
    cs2 = 0;
    

    }

    void DisPlay8(unsigned char line, unsigned char column , unsigned char LorR , unsigned char addr)
    {
    unsigned char i;
    unsigned char j;

    cs1 = 0;
    cs2 = 0;
    if(LorR == 0)
    {
        cs1 = 1;
    }
    else
    {
        cs2 = 1;
    }
    
    for(i=0; i<2 ;i++)     //每个字符占2页,所以写2次
    {
        for(j=0; j<8 ;j++)    //连续8次(上下半字各8个编码)
        {
            WriteCmd(DISP_PAGE|(i+line));   //写入显示页地址
            WriteCmd(DISP_X|(j+column));     //写入显示列地址
            WriteData(Ezk[addr*16 + j + 8*i]);  //每页写入8个字节编码数据
        }
    }
    cs1 = 0;
    cs2 = 0;    
    

    }

    void DisPlay8_not(unsigned char line, unsigned char column , unsigned char LorR , unsigned char addr)
    {
    unsigned char i;
    unsigned char j;

    cs1 = 0;
    cs2 = 0;
    if(LorR == 0)
    {
        cs1 = 1;
    }
    else
    {
        cs2 = 1;
    }
    
    for(i=0; i<2 ;i++)
    {
        for(j=0; j<8 ;j++)
        {
            WriteCmd(DISP_PAGE|(i+line));
            WriteCmd(DISP_X|(j+column));
            WriteData(~Ezk[(addr*16 + j + 8*i)]);
        }
    }
    cs1 = 0;
    cs2 = 0;    
    

    }

    /****************************************
    函数功能:将显示缓冲区所有数据送到12864显示
    ****************************************/
    void Show()
    {
    uchar i,j;
    LcdInit();
    for(j=0;j<8;j++)
    {

    cs1=0;
    cs2=1;
    WriteCmd(DISP_PAGE+j);
    WriteCmd(DISP_X);
    for(i=64;i<128;i++)
    WriteData(dispbuf[j][i]);

    }
    }

    void ClearBuff()//清空显存,0x00
    {
    uchar i,j;
    for(j=0;j<8;j++)
    {
    for(i=0;i<128;i++)
    dispbuf[j][i] = 0x00;
    }

    }
    void ClearScreen() //清屏
    {
    uchar i,j;

    for(j=0;j<8;j++)
    {       
        cs1=1;
        cs2=1;
        WriteCmd(DISP_PAGE+j);
        WriteCmd(DISP_X);
        for(i=64;i<128;i++)
            WriteData(0x00);    
    }
    

    }
    /*********************************************
    函数功能:drawflag = 1:在12864任意位置画点
    drawflag = 0:在12864任意位置清除点

    *********************************************/
    void DrawPixel(uchar x,uchar y,bit drawflag)
    {
    uchar a,b;
    a = y/0x08; //根据所在行位置,将该字节对应位置1(显)
    b = y&0x07; //根据所在行位置,将该字节对应位置0(擦除)
    if(drawflag)
    dispbuf[a][x] |= BIT(b);
    else
    dispbuf[a][x] &= ~BIT(b);

    }

    /********************************************************************************
    **函数功能描述:画直函数,采用非浮点型变量计算,显著提高了运算速度
    **输 入:x0,y0,x1,y1:起始,结束点(坐标)

            ***注意坐标不要越界***
            x:0-127
            y:0-63
    

    **输 出:无

    坐标如图所示

    |(0,0) (127,0)|
    | |
    | |
    | |
    | |
    | |
    | |

    |(0,63) (127,63)|

    *******************************************************************************/

    void Line(uchar x0,uchar y0,uchar x1,uchar y1)
    {

    //使用Bresenham算法画直线
    char dx,dy,x_increase,y_increase;
    int error;
    uchar x,y;
    uchar i;
    dx = x1-x0;
    dy = y1-y0;
    if(dx>=0)//判断x增长方向
    x_increase = 1;
    else
    x_increase = -1;
    if(dy>=0)//判断y增长方向
    y_increase = 1;
    else
    y_increase = -1;

    x = x0;
    y = y0;
    dx = cabs(dx);
    dy = cabs(dy);
    if(dx > dy)
    {
        error = -dx;
        for(i=0;i<dx+1;i++)
        {
            DrawPixel(x,y,1);
            x += x_increase;
            error += 2*dy;
            if(error >= 0)
            {
                y += y_increase;
                error -= 2*dx;
            }
        }
    }
    else
    {
        error = -dy;
        for(i=0;i<dy+1;i++)
        {
            DrawPixel(x,y,1);
            y += y_increase;
            error += 2*dx;
            if(error >= 0)
            {
                x += x_increase;
                error -= 2*dy;
            }
        }
    }
    

    }

    /*****************************************************
    函数功能:指定的位置按传入的数据画一条长度为len(len= *****************************************************/
    void DrawVerticalLine(uchar x,uchar y,uchar len,uchar d)
    {
    uchar i;
    for(i=0;i {
    if(d&0x01)
    DrawPixel(x,y+i,1);
    d >>= 1;
    }
    }

    #define CLK_X 95//时钟中心点坐标
    #define CLK_Y 31

    //秒针结束点坐标,起点坐标(x0,y0)=(31,31);
    uchar code secondpointerx[]=//x1
    {
    //0-15秒
    CLK_X+ 0,CLK_X+ 2,CLK_X+ 4,CLK_X+ 7,CLK_X+ 9,CLK_X+11,CLK_X+13,CLK_X+14,CLK_X+16,CLK_X+18,
    CLK_X+19,CLK_X+20,CLK_X+21,CLK_X+21,CLK_X+21,CLK_X+22,
    //16-30秒
    CLK_X+22,CLK_X+21,CLK_X+21,CLK_X+20,CLK_X+19,CLK_X+18,CLK_X+16,CLK_X+14,CLK_X+13,CLK_X+11,
    CLK_X+ 9,CLK_X+ 7,CLK_X+ 4,CLK_X+ 2,CLK_X+ 0,
    //31-45秒
    CLK_X- 2,CLK_X- 4,CLK_X- 7,CLK_X- 9,CLK_X-11,CLK_X-13,CLK_X-14,CLK_X-16,CLK_X-18,CLK_X-19,
    CLK_X-20,CLK_X-21,CLK_X-21,CLK_X-21,CLK_X-22,
    //46-59秒
    CLK_X-22,CLK_X-21,CLK_X-21,CLK_X-20,CLK_X-19,CLK_X-18,CLK_X-16,CLK_X-14,CLK_X-13,CLK_X-11,
    CLK_X- 9,CLK_X- 7,CLK_X- 4,CLK_X- 2,

    };
    uchar code secondpointery[]=//y1
    {
    //0-15秒
    CLK_Y-22,CLK_Y-22,CLK_Y-21,CLK_Y-21,CLK_Y-20,CLK_Y-19,CLK_Y-18,CLK_Y-16,CLK_Y-14,CLK_Y-13,
    CLK_Y-11,CLK_Y- 9,CLK_Y- 7,CLK_Y- 4,CLK_Y- 2,CLK_Y- 0,
    //16-30秒
    CLK_Y+ 2,CLK_Y+ 4,CLK_Y+ 7,CLK_Y+ 9,CLK_Y+11,CLK_Y+13,CLK_Y+14,CLK_Y+16,CLK_Y+18,CLK_Y+19,
    CLK_Y+20,CLK_Y+21,CLK_Y+21,CLK_Y+22,CLK_Y+22,
    //31-45秒
    CLK_Y+22,CLK_Y+21,CLK_Y+21,CLK_Y+20,CLK_Y+19,CLK_Y+18,CLK_Y+16,CLK_Y+14,CLK_Y+13,CLK_Y+11,
    CLK_Y+ 9,CLK_Y+ 7,CLK_Y+ 4,CLK_Y+ 2,CLK_Y+ 0,
    //46-59秒
    CLK_Y- 2,CLK_Y- 4,CLK_Y- 7,CLK_Y- 9,CLK_Y-11,CLK_Y-13,CLK_Y-14,CLK_Y-16,CLK_Y-18,CLK_Y-19,
    CLK_Y-20,CLK_Y-21,CLK_Y-21,CLK_Y-22,

    };

    //分针结束点坐标,起点坐标(x0,y0)=(31,31);
    uchar code minpointerx[]=//x1
    {
    //0-15分
    CLK_X+ 0,CLK_X+ 2,CLK_X+ 4,CLK_X+ 6,CLK_X+ 8,CLK_X+ 9,CLK_X+11,CLK_X+12,CLK_X+14,CLK_X+15,
    CLK_X+16,CLK_X+17,CLK_X+18,CLK_X+19,CLK_X+20,CLK_X+20,
    //16-30分
    CLK_X+20,CLK_X+19,CLK_X+18,CLK_X+17,CLK_X+16,CLK_X+15,CLK_X+14,CLK_X+12,CLK_X+11,CLK_X+ 9,
    CLK_X+ 8,CLK_X+ 6,CLK_X+ 4,CLK_X+ 2,CLK_X+ 0,
    //31-45分
    CLK_X- 2,CLK_X- 4,CLK_X- 6,CLK_X- 8,CLK_X- 9,CLK_X-11,CLK_X-12,CLK_X-14,CLK_X-15,CLK_X-16,
    CLK_X-17,CLK_X-18,CLK_X-19,CLK_X-20,CLK_X-20,
    //46-59分
    CLK_X-20,CLK_X-19,CLK_X-18,CLK_X-17,CLK_X-16,CLK_X-15,CLK_X-14,CLK_X-12,CLK_X-11,CLK_X- 9,
    CLK_X- 8,CLK_X- 6,CLK_X- 4,CLK_X- 2,
    };
    uchar code minpointery[]=//y1
    {
    //0-15分
    CLK_Y-20,CLK_Y-20,CLK_Y-19,CLK_Y-18,CLK_Y-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,CLK_X-16,

    CLK_X-16,CLK_X-16,CLK_X-15,CLK_X-14,CLK_X-14,CLK_X-13,CLK_X-12,CLK_X-11,CLK_X- 9,CLK_X- 8,
    CLK_X- 6,CLK_X- 5,CLK_X- 3,CLK_X- 1,

    };
    uchar code hourpointery[]=//y1
    {
    CLK_Y-16,CLK_Y-16,CLK_Y-16,CLK_Y-15,CLK_Y-14,CLK_Y-14,CLK_Y-13,CLK_Y-12,CLK_Y-11,CLK_Y- 9,
    CLK_Y- 8,CLK_Y- 6,CLK_Y- 5,CLK_Y- 3,CLK_Y- 1,CLK_Y- 0,

    CLK_Y+1,CLK_Y+ 3,CLK_Y+ 5,CLK_Y+ 6,CLK_Y+ 8,CLK_Y+ 9,CLK_Y+11,CLK_Y+12,CLK_Y+13,CLK_Y+14,
    CLK_Y+14,CLK_Y+15,CLK_Y+16,CLK_Y+16,CLK_Y+16,

    CLK_Y+16,CLK_Y+16,CLK_Y+15,CLK_Y+14,CLK_Y+14,CLK_Y+13,CLK_Y+12,CLK_Y+11,CLK_Y+ 9,
    CLK_Y+ 8,CLK_Y+ 6,CLK_Y+ 5,CLK_Y+ 3,CLK_Y+ 1,CLK_Y+ 0,

    CLK_Y-1,CLK_Y- 3,CLK_Y- 5,CLK_Y- 6,CLK_Y- 8,CLK_Y- 9,CLK_Y-11,CLK_Y-12,CLK_Y-13,CLK_Y-14,
    CLK_Y-14,CLK_Y-15,CLK_Y-16,CLK_Y-16,
    };
    uchar code clkbmp[]=//时钟图
    {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x60,0x20,0x30,
    0x38,0xC8,0x0C,0x04,0x04,0x06,0x02,0x02,0x02,0x03,0x01,0x01,0x21,0xF1,0x01,0x07,
    0x21,0x91,0x51,0x21,0x01,0x03,0x02,0x02,0x02,0x06,0x04,0x04,0x0C,0xC8,0x38,0x30,
    0x20,0x60,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x80,0xE0,0x30,0x1C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,
    0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x01,0x03,0x06,0x1C,0x30,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,
    0x00,0xE0,0x3C,0x07,0x01,0x01,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x02,0x02,0x01,0x01,0x07,0x3C,0xE0,0x00,0x00,
    0xFE,0x83,0x80,0x00,0x40,0xA0,0xA0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xE0,
    0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xA0,0xA0,0x40,0x00,0x80,0x83,0xFE,0x00,
    0x3F,0xE0,0x00,0x00,0x00,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,
    0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x01,0x00,0x00,0xE0,0x3F,0x00,
    0x00,0x03,0x1E,0x70,0xC0,0xC0,0x20,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x20,0xC0,0xC0,0x70,0x1E,0x03,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x03,0x06,0x1C,0x30,0x60,0xC0,0x80,0x80,0x00,0x00,0x00,
    0x00,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,
    0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,
    0x00,0x00,0x80,0x80,0xC0,0x60,0x30,0x1C,0x06,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x02,0x06,
    0x0E,0x09,0x18,0x10,0x10,0x30,0x20,0x20,0x20,0x60,0x40,0x40,0x40,0x40,0x43,0x75,
    0x45,0x42,0x40,0x40,0x40,0x60,0x20,0x20,0x20,0x30,0x10,0x10,0x18,0x09,0x0E,0x06,
    0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    };

    void WriteClkBmp(uchar code *image) //送一幅64x64点阵图像到显存
    {
    uchar i,j;
    for(j=0;j<8;j++)
    {
    for(i=64;i<128;i++)
    dispbuf[j][i] = image[j*64+i-64];
    }
    }
    void TimeDisp(uchar hour,uchar min,uchar sec)
    {
    uchar hp;
    hp = hour*5+min/12;
    WriteClkBmp(clkbmp);
    Line(CLK_X,31,secondpointerx[sec],secondpointery[sec]);//秒针
    Line(CLK_X,31,minpointerx[min],minpointery[min]);//分针
    Line(CLK_X,31,hourpointerx[hp],hourpointery[hp]);//时针
    }

    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境