找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 239|回复: 8
打印 上一主题 下一主题
收起左侧

实物的LCD12864显示屏与仿真不一致?

[复制链接]
跳转到指定楼层
楼主
rt。算是从新手到焊板子一路冲过来了。这回板子也焊好了,也下载成功了。最后...显示屏显示的和仿真的不一致,这肯定是实物和仿真的器件不一致的问题了,估计的改代码之类的。但我现在毫无头绪。求教。 仿真图
实物图 附带上次提问后折磨了很久以后才弄得原理图
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1107719 发表于 2024-4-13 21:05 | 只看该作者
用的是hs12864-15c差点忘了带实物得编号了
回复

使用道具 举报

板凳
ID:1107719 发表于 2024-4-14 00:05 | 只看该作者
这个是怎么处理?是我换显示屏还是改代码?还是我焊接得有问题???
回复

使用道具 举报

地板
ID:1107719 发表于 2024-4-14 15:15 | 只看该作者
自顶一下。有没有人有头绪QAQ
回复

使用道具 举报

5#
ID:69038 发表于 2024-4-14 15:21 | 只看该作者
实物屏带字库,仿真屏无字库,两者时序指令不能通用,就是这么回事。。
要与仿真一致,就要换成无字屏。
要实物为主,就要改写代码。
回复

使用道具 举报

6#
ID:1107719 发表于 2024-4-14 15:21 | 只看该作者
#include<reg52.h>
#include<intrins.h>
#include <math.h> //Keil library
#include <stdio.h> //Keil library
#define LCD_databus P0 //LCD12864的8位数据口
#define uint unsigned int
#define uchar unsigned char
int heat=000,spurs=000;
uint c=1;
sbit EN=P2^2; //低电平写入高电平读取
sbit RS=P2^0; //高电平数据输入命令输入
sbit RW=P2^1; //高电平读取低电平写入
sbit CS2=P2^3; //
sbit CS1=P2^4;
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit key5=P1^4;
sbit key6=P1^5;
sbit key7=P1^6;
sbit key8=P1^7;
sbit BEEP=P3^0;  
char xiaoshu=0;
uchar f2;
uchar m2;
uchar x2;
uchar D,M;
uchar count;
char fen=0;
char miao=0;
unsigned char code time[][16]=
{
        0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//"0",
        0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//"1",
        0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//"2",
        0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//"3",
        0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//"4",
        0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//"5",
        0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//"6",
        0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//"7",
        0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//"8",
        0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//"9",
        0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//"V",10
        0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//"S",11
        0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//":",12
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//".",13
        0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//"T"14
        0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//"N"15
        0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//"D"16
        0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//"R"17
        0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//"H"18
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空格"19
};       
uchar code HZ[][32]=
{
        0x00,0x08,0x08,0x08,0x08,0x08,0x09,0xFE,
        0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
        0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,
        0x41,0x41,0x41,0x41,0x41,0x40,0x40,0x00,//"主"         0
        0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0x00,
        0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0xFF,0x08,0x10,0x88,0x47,0x20,0x18,
        0x07,0x00,0x07,0x18,0x20,0x40,0x80,0x00,// "队",         1
        0x10,0x0C,0x84,0x44,0x3C,0x54,0x95,0x96,
        0x94,0x54,0x34,0x14,0x04,0x14,0x0C,0x00,
        0x04,0x04,0x02,0x02,0xFD,0x45,0x44,0x44,
        0x44,0x45,0xFD,0x02,0x02,0x06,0x02,0x00,//“客”        2
        0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
        0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"一", 3
        0x00,0x10,0x18,0x16,0x10,0x90,0xF0,0x9F,
        0x90,0x90,0x92,0x94,0x10,0x18,0x10,0x00,
        0x40,0x20,0x90,0x88,0x46,0x41,0x23,0x14,
        0x08,0x14,0x22,0x21,0x40,0xC0,0x40,0x00,//"发"          4
        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,//"空白"   5
        0xFF,0xF7,0xF7,0xF7,0xF7,0xF7,0xF6,0x01,
    0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xFF,0xFF,
    0xBF,0xBF,0xBE,0xBE,0xBE,0xBE,0xBE,0x80,
    0xBE,0xBE,0xBE,0xBE,0xBE,0xBF,0xBF,0xFF,//"主"反色         6
        0xEF,0xF3,0x7B,0xBB,0xC3,0xAB,0x6A,0x69,
    0x6B,0xAB,0xCB,0xEB,0xFB,0xEB,0xF3,0xFF,
    0xFB,0xFB,0xFD,0xFD,0x02,0xBA,0xBB,0xBB,
    0xBB,0xBA,0x02,0xFD,0xFD,0xFD,0xFD,0xFF,//“客”反色   7
        0x08,0x08,0x08,0x08,0x88,0x78,0x0F,0x08,
    0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
    0x20,0x50,0x48,0x46,0x41,0x41,0x41,0x41,
    0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,//"左"           8
        0x08,0x08,0x08,0x08,0xC8,0x38,0x0F,0x08,
    0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
    0x08,0x04,0x02,0x01,0xFF,0x41,0x41,0x41,
    0x41,0x41,0x41,0x41,0xFF,0x00,0x00,0x00,//“右”          9
};
void delay_10us(uint n) //延时n个10us@12M晶振
{
        uint i;
        for(i=n;i>0;i--)
        {
        _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
        }
}
void delay_50us(uint z)
{
        uint x,y; for(x=z;x>0;x--)
        for(y=19;y>0;y--);
}
void delay_ms(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
        for(y=110;y>0;y--);
}
void delay(uint i)
{
while(--i);
} /**?延时函数?**/
void delay_1ms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<110;i++);
}
void Read_busy()//读“忙”函数-----数据线的最高位DB71则busy
{
        P0=0x00;
        RS=0;
        RW=1;
        EN=1;
        while(P0 & 0x80);
        EN=0;
}
void write_LCD_command(uchar value) //写命令函数
{       
        Read_busy(); //对LCD的每次读写都要读忙
        RS=0; //选择命令
        RW=0; //读操作
        LCD_databus=value;
        EN=1; //EN由1----0锁存有效数据
        _nop_();
        _nop_();
        EN=0;
}
void write_LCD_data(uchar value)//写数据函数
{
        Read_busy();
        RS=1; //选择数据
        RW=0;
        LCD_databus=value;
        EN=1; //EN由1----0锁存有效数据
        _nop_();
        _nop_();
        EN=0;
}
void Set_page(uchar page) //设置“页”LCD12864共8页,一页是8行点阵点
{
        page=0xb8|page; //页的首地址为0xB8
        write_LCD_command(page);
}
void Set_line(uchar startline) //设置显示的起始行
{
        startline=0xC0|startline; //起始行地址为0xC0
        write_LCD_command(startline); //设置从哪行开始:共0--63;一般从0 行开始显示
}
void Set_column(uchar column) //设置显示的列
{
        column=column &0x3f; //列的最大值为64
        column= 0x40|column; //列的首地址为0x40
        write_LCD_command(column); //规定显示的列的位置
}
void SetOnOff(uchar onoff) //显示开关函数:0x3E是关显示,0x3F是开显示
{
        onoff=0x3e|onoff; //onoff:1---开显示;0---关显示
        write_LCD_command(onoff);
}
void SelectScreen(uchar screen) //选择屏幕
{
        switch(screen)
        {
                case 0: CS1=0;CS2=0;break; //全屏
                case 1: CS1=0;CS2=1;break;//左半屏
                case 2: CS1=1;CS2=0;break;//右半屏
                default:break;
        }
}
void ClearScreen(uchar screen) //清屏函数
{
        uchar i,j;
        SelectScreen(screen); //0--全屏;1---左半屏;2---右半屏
        for(i=0;i<8;i++) //控制页数0-7,共8页
        {
                Set_page(i);
                Set_column(0);
                for(j=0;j<64;j++) //控制列数0-63,共64列
                {
                        write_LCD_data(0x00); //写入0,地址指针自加1
                }
        }
}                 
void init_LCD() //LCD的初始化
{
        SetOnOff(1); //开显示
        SelectScreen(0);//
        ClearScreen(0); //清屏
        Set_line(0); //开始行:0
}
void Display_ASCII(uchar screen,uchar page,uchar column,uchar a[][16],uchar h) //屏幕,页面,列(起始位置),二维数组,索引
{
        uchar i;
        SelectScreen(screen);
        Set_page(page);
        Set_column(column*8); //因为LCD屏幕上的每个字通常是8*8像素,所以需要乘以8以得到正确像素位置
        for(i=0;i<8;i++) //显示字符上半部分:8*8
        {
                write_LCD_data(*(a[h]+i));
        }
        Set_page(page+1); //显示字符下半部分:8*8
        Set_column(column*8);
        for(i=0;i<8;i++)
        {
        write_LCD_data
        (*(a[h]+i+8));
        }
}
void Display_HZ(uchar screen,uchar page,uchar column,uchar a[][32],uchar h)
{
        uchar i;
        SelectScreen(screen);
        Set_page(page); //写上半页:16*8
        Set_column(column*16); //控制列
        for(i=0;i<16;i++) //控制16列的数据输出
        {
                write_LCD_data(*(a[h]+i)); //汉字的上半部分
        }
        Set_page(page+1); //写下半页:16*8
        Set_column(column*16); //控制列
        for(i=0;i<16;i++) //控制16列的数据输出
        { write_LCD_data(*(a[h]+16+i)); //汉字的下半部分
        }
}

void dingshiqi()
{
        TMOD=0X01; //T1 jishu T0 jishi
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;
        ET0=1;
        TR0=0;
}
void Key1()//改变发球
{
        if(key1==0)
        {
                delay_ms(10);
                if(key1==0)
                {
                        while(!key1) //
                        {
                                while(!key1)
                                {}
                                 c=c^1;//异或算法,改变c从而改变主客场发球                         
                                                                 
                        }
                }
        }
}
void Key2() //持续检查按钮增加heat
{
        if(key2==0)
        {
                delay_ms(10);
                if(key2==0)
                {
                        while(!key2)
                        { while(!key2)
                        { }
                        heat++;
                        }
                }
        }
}
void Key3() //持续检查减少heat
{
        if(key3==0)
        {
                delay_ms(10);
                if(key3==0)
                {
                        while(!key3)
                        {
                                while(!key3)
                                {}
                                if (heat==0)
                                {}
                                else
                                {
                                heat--;
                                D=heat;
                                }
                        }
                }
        }
}
void Key4() //增加spurs
{
        if(key4==0)
        {
                delay_ms(10);
                if(key4==0)
                {
                        while(!key4)
                        {
                                while(!key4)
                                { }
                                spurs++;
                        }
                }
        }
}
void Key5()  //减少spurs
{
        if(key5==0)
        {
                delay_ms(10);
                if(key5==0)
                {
                        while(!key5)
                        {
                                while(!key5){ }
                                if (spurs==0)
                                {}
                                else
                                {
                                        spurs--;
                                        M=spurs;
                                }
                        }
                }
        }
}
void Key6()//中断计时
{
        if(key6==0)
        {
                delay_ms(10);
                if(key6==0)
                {
                        while(!key6)
                        {
                                while(!key6)
                                { }
                                        TR0=0;
                        }
                }
        }
}
void Key7()  //开始计时
{
        if(key7==0)
        {
        delay_ms(10);
        if(key7==0)
                {
                        while(!key7)
                        {
                                while(!key7)
                                {}
                                TR0=1;
                        }
                }
        }
}
void Key8()         //重置
{
   if(key8==0)
        {
        delay_ms(10);
        if(key8==0)
                {
                        while(!key8)
                        {
                                while(!key8)
                                {}
                                fen=0;miao=0;xiaoshu=0;
                        }
                }
        }
}
void main(void)
{
        uchar A,B,C,E,F;
        uchar G,H,I,J;
        A=1;
        init_LCD();
        dingshiqi();         
        D=heat;
        M=spurs;
        while(1)
        {
               
                Key1();
                Key2();
                Key3();
                Key4();
                Key5();
                Key6();
                Key7();
                Key8();
                B=heat/10%10;
                C=heat%10;
                E=spurs/10%10;
                F=spurs%10;
                G=fen/10;
                H=fen%10;
                I=miao/10;
                J=miao%10;
               
               

                if(heat>D)        //发球
                {
                        if(heat!=D)
                        {
                                   if(heat%2==0)
                                 {
                                         Display_HZ(1,0,1,HZ,9);//"右"
                                         Display_HZ(1,2,1,HZ,5);//"空白"
                                 }
                                if(spurs%2==1)
                                {
                                         Display_HZ(1,0,1,HZ,8);//"左"
                                         Display_HZ(1,2,1,HZ,5);//"空白"
                                }
                        c=1;
                        D=heat;
                        M=spurs;
                        }
                }       
                if(spurs>M)
                {
                        if(spurs!=M)
                        {
                                   if(spurs%2==0)
                                 {
                                         Display_HZ(1,0,1,HZ,5);//"空白"
                                         Display_HZ(1,2,1,HZ,9);//"右"
                                 }
                                if(spurs%2==1)
                                {
                                         Display_HZ(1,0,1,HZ,5);//"空白"
                                         Display_HZ(1,2,1,HZ,8);//"左"
                                }
                        c=0;
                        D=heat;
                        M=spurs;
                        }
                }
                if(c==1)
                {         
                       
                                 if(heat%2==0)
                                {
                                        Display_HZ(1,0,1,HZ,9);//"右"
                                        Display_HZ(1,2,1,HZ,5);//"空白"
                                }
                                if(heat%2==1)
                                {
                                        Display_HZ(1,0,1,HZ,8);//"左"
                                        Display_HZ(1,2,1,HZ,5);//"空白"       
                                }

                        Display_HZ(1,0,0,HZ,6);//“主”反色
                        Display_HZ(1,2,0,HZ,2);//“客”
                }
                if(c==0)
                {
                       
                                   if(spurs%2==0)
                                 {
                                         Display_HZ(1,0,1,HZ,5);//"空白"
                                         Display_HZ(1,2,1,HZ,9);//"右"
                                 }
                                if(spurs%2==1)
                                {
                                         Display_HZ(1,0,1,HZ,5);//"空白"
                                         Display_HZ(1,2,1,HZ,8);//"右"
                                }
               
                        Display_HZ(1,0,0,HZ,0);//“主”               
                        Display_HZ(1,2,0,HZ,7);//“客”反色
                }
                if((heat==0)&&(spurs==0))
                {
                        D=heat;
                        M=spurs;
                }
       
               
                if(A==1)         //比分
                {
                        Display_ASCII(1,0,4,time,B);
                        Display_ASCII(1,0,5,time,C);//bifen
                        Display_ASCII(1,2,4,time,E);
                        Display_ASCII(1,2,5,time,F);
                        if(((heat>=21)&&(heat-spurs>1))||((spurs>=21)&&(spurs-heat>1))||((spurs==29)&&(heat==30))||((heat==29)&&(spurs==30)))
                        {
                                A=2;       
                                heat=0;spurs=0;
                                B=0;C=0;E=0;F=0;
                        }
                }
                if(A==2)
                {
                        Display_ASCII(1,0,7,time,B);
                        Display_ASCII(2,0,0,time,C);//bifen
                        Display_ASCII(1,2,7,time,E);
                        Display_ASCII(2,2,0,time,F);
                        if(((heat>=21)&&(heat-spurs>1))||((spurs>=21)&&(spurs-heat>1))||((spurs==29)&&(heat==30))||((heat==29)&&(spurs==30)))
                        {
                                A=3;       
                                heat=0;spurs=0;
                                B=0;C=0;E=0;F=0;
                        }
                }
                if(A==3)
                {
                                Display_ASCII(2,0,2,time,B);
                                Display_ASCII(2,0,3,time,C);//bifen
                                Display_ASCII(2,2,2,time,E);
                                Display_ASCII(2,2,3,time,F);
                                if(((heat>=21)&&(heat-spurs>1))||((spurs>=21)&&(spurs-heat>1))||((spurs==29)&&(heat==30))||((heat==29)&&(spurs==30)))
                        {
                                A=4;       
                                heat=0;spurs=0;
                                B=0;C=0;E=0;F=0;
                        }  
                } //三局分数展示,追分机制 。

                Display_ASCII(1,4,4,time,G); //时间
                Display_ASCII(1,4,5,time,H);
                Display_ASCII(1,4,6,time,12);
                Display_ASCII(1,4,7,time,I);
                Display_ASCII(2,4,0,time,J);
                Display_ASCII(2,4,1,time,13);
                Display_ASCII(2,4,2,time,xiaoshu);
       
        }
}
void timer0() interrupt 1 //3定时器1的中断号1定时器0的中断号0外部中断1 2外部中 断2 4串口中断
{
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        count++;
        if(count==2)
        {
                count=0;
                xiaoshu++;
                if(xiaoshu==10)
                { xiaoshu=1; miao++; } //计时时间小数
                if(miao==10)
                        {
                                miao=0;
                                fen++;
                        } //分钟
        }
}

以上是源代码
回复

使用道具 举报

7#
ID:1107719 发表于 2024-4-14 16:10 | 只看该作者
zhuls 发表于 2024-4-14 15:21
实物屏带字库,仿真屏无字库,两者时序指令不能通用,就是这么回事。。
要与仿真一致,就要换成无字屏。
...

嘶...如果要改的话,具体要怎么改?买个无字屏的话要买怎样的?如果要改时许的话又要怎样??也算是第一次从代码到仿真再到实物了。这个我还真没留意。
回复

使用道具 举报

8#
ID:69038 发表于 2024-4-14 16:29 | 只看该作者
12864LCD常用的无字库屏是KS0108驱动,常用的有字库屏是ST7290驱动。
相应代码本坛都能搜到。
回复

使用道具 举报

9#
ID:619259 发表于 2024-4-14 22:49 | 只看该作者
仿真屏为左半屏和右半屏驱动,工程屏不是呵。结论:此屏非彼屏。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表