我的显示为什么不正常,错在了哪里啊?程序如下
#include <reg52.h>
#include <string.h>
#include "zf.h"
#include "io.h"
#define uchar unsigned char
#define uint unsigned int
uchar ye=0,lie=0;
#define DB P0
#define chr_width 7
#define chn_width 15
unsigned char disp_no;
unsigned char position,which;
/*****************************延时*************************/
void delay(uint i)
{
while(--i);
}
/****************12864液晶写数据命令地址函数*****************/
void writedacm(uchar dat,uchar log) //写数据 RS=1数据,RS=0命令
{
delay(8);
RW = 0;
if(log) RS=1;
else RS=0;
E = 1;
DB = dat;
E = 0;
}
/************************页列设置*************************/
void set_YL( uchar y, uchar x) //ye -> 0 : 7 页 lie -> 0 :63 列
{
y= y&0x07|0xb8;
writedacm(y,0);
x= x&0x3f|0x40;
writedacm(x,0);
}
/*************************12864液晶屏幕选择函数************/
void setPM(uchar PX) //选择屏幕( 0-左屏,1-右屏,2-全屏 )
{
switch(PX){
case 0 : CS1 = 0; CS2 = 1; break;
case 1 : CS1 = 1; CS2 = 0; break;
case 2 : CS1 = 0; CS2 = 0;
}
}
/******************左右屏设置*************************/
void chear() //清屏(0-清左屏1-清右屏,2-清全屏 ),
{ uchar i,j;
setPM(2);
for(i = 0;i <8;i++)
{ set_YL(i,0);
for(j = 0;j <64 ; j++)
writedacm(0x00,1);
}
}
//****************************************
void SetOnOff(uchar onoff) //1-开显示 0-关
{
if(onoff == 1){ setPM(2); writedacm(0x3f,0);}
if(onoff == 0){ setPM(2); writedacm(0x3e,0);}
}
/******************** 12864液晶复位函数******************/
void init_lcd()
{
Reset = 0; delay(2);
Reset = 1; delay(2);
chear(); //清屏
SetOnOff(1) ;
delay(100);
CS1=1; //刚开始关闭两屏
CS2=1;
delay(100);
writedacm(0x3e,0); //显示关
writedacm(0xb8,0); //定义Y坐标
writedacm(0xC0,0);
writedacm(0x40,0); //设定X坐标
writedacm(0x3f,0); //显示开
}
void DrawBmp(uchar x0,bit layer,uchar width,uchar *bmp)
{
uchar x,i=0,j=16; //RAMadr表示显存的物理地址
uchar page=0;
delay(10);
if (layer) page=2;
delay(10);
for (x=x0;x<(x0+width);x++)
{
delay(10);
setPM(0);//显示左半屏
writedacm(0xb8,0);//从第一行开始显示
writedacm(bmp,1);//写第一行字上半部分
i=i+1;
}
for (x=x0;x<(x0+width);x++)
{
delay(10);
setPM(0);
writedacm(0xb8+1,0);//从第一行开始显示
writedacm(bmp[j],1);//写第一行字下半部分
j=j+1;
}
}
#define welcome_hanzi 6
void disp_welcome(void)
{
unsigned char cyc_counter;
delay(10);
for(cyc_counter=0; cyc_counter<6; cyc_counter++)
{
delay(10);
DrawBmp(16+cyc_counter*chn_width,0,chn_width,chn_font+(cyc_counter+welcome_hanzi)*chn_width*2);
delay(10);
};
disp_no = 0x00;
}
/**********************主函数*****************************/
main()
{
init_lcd();
chear();
disp_welcome();
while(1);
}
/***********************************************************/
/*******************下面是字库摸******************************/
//汉字用的字号是五号字
unsigned char code chn_font[]={
/*
无(0) 池(1) 流(2) 压(3) 容(4) 量(5)
新(6) 乡(7) 安(8) 科(9) 电(10) 子(11) ----这里的6个汉字必须是连续的,给显示公司用
型(12) 号(13) 异(14) 充(15) 放(16) 次(17)
数(18) 生(19) 产(20) 额(21) 定(22) 编(23)
常(24) 满(25) 低(26) 温(27) 度(28) 非(29)
字(30) 日(31) 期(32) 镉(33) 镍(34) 锂(35)
*/
/*-- 文字: 无0 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x22,0x22,0x22,0x22,0x22,0xFE,0x22,0xE2,0x22,0x22,0x23,0x32,0x20,0x00,0x00,
0x20,0x20,0x10,0x08,0x06,0x01,0x00,0x1F,0x20,0x20,0x20,0x20,0x3C,0x00,
/*-- 文字: 池1 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x10,0x61,0x86,0x60,0x40,0xFC,0x20,0x20,0xFF,0x10,0x10,0xF8,0x10,0x00,0x00,0x02,
0x3E,0x01,0x00,0x00,0x1F,0x20,0x20,0x27,0x20,0x22,0x23,0x20,0x38,0x00,
/*-- 文字: 流2 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x10,0x61,0x02,0xC6,0x00,0xA4,0x34,0x2D,0xA6,0x24,0xA4,0x34,0x66,0x04,0x00,0x04,
0x3C,0x03,0x20,0x10,0x0F,0x00,0x00,0x3F,0x00,0x1F,0x20,0x20,0x38,0x00,
/*-- 文字: 压3 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x42,0x03,0x02,0x00,0x20,
0x18,0x07,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x11,0x16,0x10,0x10,0x00,
/*-- 文字: 容4 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x10,0x4C,0x44,0x24,0x94,0x44,0x25,0x26,0x44,0x84,0x14,0x24,0x4C,0x04,0x00,0x04,
0x04,0x02,0x01,0x3E,0x22,0x22,0x22,0x22,0x22,0x3F,0x01,0x02,0x02,0x00,
/*-- 文字: 量5 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBF,0x22,0x20,0x00,0x00,
0x20,0x28,0x2F,0x2A,0x2A,0x2A,0x3F,0x2A,0x2A,0x2A,0x2F,0x28,0x20,0x00,
/*-- 文字: 新6 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x20,0x24,0x2C,0x35,0xE6,0x34,0x2C,0x00,0xFE,0x24,0x24,0xE2,0x33,0x22,0x00,0x10,
0x09,0x15,0x21,0x1F,0x05,0x29,0x10,0x0F,0x00,0x00,0x3F,0x00,0x00,0x00,
/*-- 文字: 乡7 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0x00,0x10,0x18,0x94,0x52,0x31,0x10,0x08,0x04,0xC0,0x00,0x00,0x00,0x00,
0x20,0x20,0x21,0x21,0x11,0x11,0x09,0x05,0x03,0x01,0x00,0x00,0x00,0x00,
/*-- 文字: 安8 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x40,0x50,0x4C,0x44,0x44,0xC4,0x75,0x46,0x44,0xC4,0x44,0x54,0x4C,0x40,0x00,0x00,
0x20,0x20,0x20,0x13,0x12,0x0C,0x04,0x06,0x09,0x08,0x10,0x30,0x00,0x00,
/*-- 文字: 科9 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x14,0x14,0x94,0xFE,0x93,0x12,0x00,0x20,0xC4,0x18,0x00,0xFF,0x00,0x00,0x00,0x04,
0x03,0x00,0x3F,0x00,0x01,0x02,0x02,0x02,0x02,0x02,0x3F,0x01,0x01,0x00,
/*-- 文字: 电10 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0xF8,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
0x00,0x07,0x02,0x02,0x02,0x1F,0x22,0x22,0x22,0x22,0x23,0x20,0x38,0x00,
/*-- 文字: 子11 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xF2,0x52,0x4A,0x46,0x43,0x62,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 型12 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x12,0x92,0x7E,0x12,0x12,0xFE,0x12,0x00,0x7E,0x80,0x00,0xFF,0x00,0x00,0x00,
0x21,0x24,0x24,0x24,0x24,0x25,0x3E,0x24,0x24,0x24,0x25,0x30,0x20,0x00,
/*-- 文字: 号13 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x40,0x40,0x40,0x5E,0xD2,0x52,0x52,0x52,0x52,0x52,0x5F,0x42,0x40,0x40,0x00,0x00,
0x00,0x00,0x02,0x03,0x01,0x11,0x21,0x21,0x11,0x0F,0x00,0x00,0x00,0x00,
/*-- 文字: 异14 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0x00,0x3E,0xD2,0x52,0x52,0x52,0x52,0xD2,0x5F,0x42,0x70,0x00,0x00,0x22,
0x22,0x12,0x0A,0x07,0x02,0x02,0x02,0x02,0x3F,0x02,0x02,0x02,0x02,0x00,
/*-- 文字: 充15 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x04,0x44,0x44,0x64,0xD4,0x4D,0x46,0xC4,0x54,0x64,0xC4,0x06,0x04,0x00,0x00,
0x20,0x10,0x08,0x04,0x03,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x38,0x00,
/*-- 文字: 放16 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x08,0x08,0xF9,0x4E,0x48,0xC8,0x08,0x20,0xF8,0x0F,0x08,0xF8,0x0C,0x08,0x00,0x20,
0x18,0x07,0x10,0x10,0x0F,0x20,0x20,0x10,0x09,0x06,0x09,0x10,0x20,0x00,
/*-- 文字: 次17 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x02,0x8C,0x60,0x98,0x40,0x30,0x0F,0xE8,0x08,0x08,0x28,0x18,0x00,0x00,0x01,
0x01,0x1F,0x20,0x20,0x10,0x0C,0x03,0x00,0x03,0x04,0x08,0x30,0x10,0x00,
/*-- 文字: 数18 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x08,0x4A,0x2C,0x18,0xFF,0x2C,0x4A,0x28,0xF0,0x0F,0x08,0x88,0x7C,0x08,0x00,0x21,
0x21,0x15,0x17,0x09,0x0D,0x13,0x20,0x10,0x0B,0x04,0x0B,0x10,0x20,0x00,
/*-- 文字: 生19 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x18,0x10,0x00,0x00,0x20,
0x20,0x20,0x21,0x21,0x21,0x21,0x3F,0x21,0x21,0x21,0x21,0x30,0x20,0x00,
/*-- 文字: 产20 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x04,0xC4,0x44,0x4C,0x74,0x45,0x46,0x64,0x5C,0x44,0x44,0x44,0x44,0x00,0x20,
0x18,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 额21 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x4C,0x24,0xBC,0x55,0x56,0xB4,0x0C,0xFA,0x0A,0x0E,0xEA,0x0A,0xFB,0x02,0x00,0x02,
0x01,0x3E,0x12,0x12,0x1E,0x21,0x27,0x10,0x08,0x07,0x08,0x17,0x20,0x00,
/*-- 文字: 定22 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x10,0x2C,0xA4,0x24,0x24,0x25,0xE6,0x24,0x24,0x24,0x24,0x14,0x0C,0x00,0x20,
0x10,0x08,0x07,0x08,0x10,0x10,0x3F,0x22,0x22,0x22,0x22,0x20,0x20,0x00,
/*-- 文字: 编23 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x20,0xB8,0x67,0x30,0x00,0xFC,0xD4,0x54,0xD5,0x56,0xD4,0x54,0xDC,0x00,0x00,0x09,
0x1B,0x09,0x25,0x18,0x07,0x3F,0x02,0x1F,0x02,0x1F,0x22,0x3F,0x00,0x00,
/*-- 文字: 常24 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x20,0x18,0x08,0x0A,0xEC,0xA8,0xA8,0xAF,0xA8,0xA8,0xEC,0x0A,0x28,0x18,0x00,0x00,
0x00,0x00,0x1E,0x02,0x02,0x02,0x3F,0x02,0x02,0x12,0x1E,0x00,0x00,0x00,
/*-- 文字: 满25 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x10,0x61,0x86,0x60,0xA4,0xA4,0xA4,0xEF,0xA4,0xE4,0xAF,0xA4,0xB6,0x24,0x00,0x02,
0x3E,0x01,0x00,0x3F,0x08,0x04,0x03,0x0A,0x07,0x12,0x24,0x1F,0x00,0x00,
/*-- 文字: 低26 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x40,0x20,0xF8,0x07,0x00,0xFC,0x44,0x44,0x44,0xFC,0x42,0x43,0x62,0x40,0x00,0x00,
0x00,0x3F,0x00,0x00,0x1F,0x10,0x08,0x14,0x21,0x06,0x08,0x10,0x3C,0x00,
/*-- 文字: 温27 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x10,0x61,0x86,0x60,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7F,0x02,0x00,0x00,0x02,
0x3E,0x01,0x20,0x3F,0x21,0x21,0x3F,0x21,0x3F,0x21,0x21,0x3F,0x20,0x00,
/*-- 文字: 度28 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0xFC,0x04,0x14,0x14,0x7C,0x55,0x56,0x54,0x7C,0x14,0x16,0x04,0x00,0x20,
0x18,0x07,0x20,0x21,0x21,0x13,0x15,0x09,0x15,0x13,0x21,0x20,0x20,0x00,
/*-- 文字: 非29 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x08,0x48,0x48,0x48,0x48,0xFF,0x00,0x00,0xFF,0x48,0x48,0x48,0x4C,0x08,0x00,0x04,
0x04,0x04,0x04,0x04,0x3F,0x00,0x00,0x3F,0x04,0x04,0x04,0x06,0x04,0x00,
/*-- 文字: 字30 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x10,0x0C,0x14,0x14,0x14,0x15,0xD6,0x54,0x34,0x14,0x14,0x8C,0x00,0x00,0x01,
0x01,0x01,0x01,0x01,0x11,0x21,0x1F,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
/*-- 文字: 日31 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFF,0x02,0x00,0x00,0x00,
0x00,0x00,0x3F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3F,0x00,0x00,0x00,
/*-- 文字: 期32 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x00,0x04,0xFF,0x94,0x94,0xFF,0x04,0x00,0xFE,0x12,0x12,0x12,0xFF,0x02,0x00,0x22,
0x12,0x0B,0x06,0x02,0x07,0x2A,0x10,0x0F,0x01,0x11,0x21,0x1F,0x00,0x00,
/*-- 文字: 镉33 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x60,0x38,0xE7,0x24,0x24,0x00,0x82,0xBA,0xAA,0xAA,0xAA,0xBA,0x83,0x02,0x00,0x01,
0x01,0x3F,0x11,0x09,0x01,0x3F,0x04,0x06,0x1C,0x06,0x24,0x3F,0x00,0x00,
/*-- 文字: 镍34 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x60,0x38,0xE7,0x24,0x24,0x00,0xFE,0xAA,0xAB,0xAA,0xAA,0xFE,0x00,0x00,0x00,0x01,
0x01,0x1F,0x11,0x29,0x12,0x0A,0x06,0x02,0x3F,0x06,0x0A,0x12,0x22,0x00,
/*-- 文字: 锂35 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x60,0x38,0xE7,0x24,0x24,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0xFF,0x02,0x00,0x01,
0x01,0x3F,0x11,0x09,0x21,0x24,0x24,0x24,0x3F,0x24,0x24,0x24,0x20,0x00,
/*-- 文字: 记36 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x20,0x20,0x21,0xE6,0x00,0x00,0xC4,0x44,0x44,0x44,0x44,0x44,0x7E,0x04,0x00,0x00,
0x00,0x00,0x1F,0x08,0x04,0x1F,0x20,0x20,0x20,0x20,0x20,0x20,0x3C,0x00,
/*-- 文字: 录37 --*/
/*-- 宋体11; 此字体下对应的点阵为:宽x高=15x15 --*/
/*-- 高度不是8的倍数,现调整为:宽度x高度=15x16 --*/
0x20,0x20,0xA2,0xAA,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x3F,0xA2,0x20,0x20,0x00,0x10,
0x10,0x08,0x08,0x05,0x12,0x22,0x1F,0x01,0x02,0x05,0x08,0x18,0x08,0x00
};
|