想让两个字上下之间没有间隙,我该怎么办啊?
- #include <reg51.h>
- sbit e=0xb0;//1011 0000
- sbit rw=0xb1;//1011 0001
- sbit rs=0xb2;//1011 0010
- sbit cs2=0xb3;//1011 0011
- sbit cs1=0xb4;//1011 0100
- sbit busy=0xa7;//1010 0111
- //PCtoLCD2002完美版 阴码,逐列式,顺向
- //汉字当前点阵大小16*16,字宽19,字高19
- char code an[]= {
- 0x0A,0x10,0x32,0x10,0x22,0x10,0x23,0x90,0x2E,0xA0,0x62,0x60,
- 0x22,0x40,0x23,0xA0,0x22,0x20,0x2A,0x10,0x32,0x10,0x00,0x00,/*"安",0*/
- };
- char code ke[]= {
- 0x28,0xC0,0x2B,0x00,0x3F,0xF0,0x4A,0x00,0x49,0x00,0x00,0x80,
- 0x24,0x80,0x12,0x80,0x00,0x80,0x7F,0xF0,0x01,0x00,0x00,0x00,/*"科",0*/
- };
- void pulse()//puse=使能脉冲
- {
- e=1;
- e=0;
- }
- void busy_check(char right)
- {
- P2=0xff;//数据口全部高电平
- if (right==1)
- {
- P3=0x13;//0001 0011 CS1=1;CS2=0;RS=0;RW=1;RW=1;左半屏
- while(!busy);
- }
- if (right==0)
- {
- P3=0x0b;//0000 1011 CS1=0;CS2=1;RS=0;RW=1;RW=1;右半屏
- while(!busy);
- }
- }
- void cmd_w(char cmd,char right)
- {
- busy_check(right);
- if (right==1)
- {
- P3=0x10;//0001 0000 CS1=1
- }
- if (right==0)
- {
- P3=0x08;//0000 1000 CS2=0
- P3=0x08;//0000 1000 CS2=0
- }
- P2=cmd;
- pulse();//使能脉冲
- }
- void data_w(char dat,char right)
- {
- busy_check(right);
- if (right==1)
- {
- P3=0x14;//0001 0100 CS1=1; RS=1;
- }
- if (right==0)
- {
- P3=0x0c;//0000 1100 CS2=1; RS=1;
- }
- P2=dat;
- pulse();
- }
- void lcd_init()
- {
- unsigned int i;
- cmd_w(0x3e+1,0);//显示开关 0011 1111
- cmd_w(0xc0+0,0);//修改显示起始行 1100 0000
- cmd_w(0xb8+0,0);//修改页地址 1011 1000
- cmd_w(0x40+0,0);//修改列地址 0100 0000
- cmd_w(0x3e+1,1);
- cmd_w(0xc0+0,1);
- cmd_w(0xb8+0,1);
- cmd_w(0x40+0,1);
- for(i=0;i<256;i++)
- {
- data_w(0x00,0);
- }
- cmd_w(0xb8+4,0);//左边 页地址+4
- cmd_w(0x40+8,0);//左边 列地址+8
- for(i=0;i<256;i++)
- {
- data_w(0x00,0);
- }
- for(i=0;i<256;i++)
- {
- data_w(0x00,1);
- }
- cmd_w(0xb8+4,1);//右边 页地址+4
- cmd_w(0x40+8,1);//右边 列地址+8
- for(i=0;i<256;i++)
- {
- data_w(0x00,1);
- }
- }
- char chang(char a)//chang(zhi[i])
- {
- char temp,i;
- for(i=0;i<8;i++)
- {
- temp<<=1;//左移1位
- temp|=(a&0x01);//temp=temp|(a&0x01)
- a>>=1;//右移1位
- }
- return(temp);
- }
- void hanzi_w(char hang,char lie,char zhi[24])
- {
- unsigned char i;
- if(lie<4)//汉字上半部分;左半屏
- {
- cmd_w(0xb8+1*hang,0);
- cmd_w(0x40+1*lie,0);
- for(i=0;i<24;i=i+2)
- data_w(chang(zhi[i]),0);
- }
- else//汉字上半部分;右半屏
- {
- cmd_w(0xb8+1*hang,1);
- cmd_w(0x40+1*(lie-4),1);
- for(i=0;i<24;i+=2)
- data_w(chang(zhi[i]),1);
- }
- if(lie<4)//汉字下半部分;左半屏
- {
- cmd_w(0xb8+1*hang+1,0);
- cmd_w(0x40+1*lie,0);
- for(i=1;i<24;i+=2)
- data_w(chang(zhi[i]),0);
- }
- else//汉字下半部分;右半屏
- {
- cmd_w(0xb8+1*hang+1,1);
- cmd_w(0x40+1*(lie-4),1);
- for(i=1;i<24;i+=2)
- data_w(chang(zhi[i]),1);
- }
- }
- void delay(unsigned char a)
- {
- unsigned char i,j;
- for(i=0;i<a;i++)
- for(j=0;j<200;j++)
- ;
- }
- void main()
- {
- //unsigned char i;
- lcd_init();
- hanzi_w(0,0,an);
- hanzi_w(2,0,ke);
- while(1)
- {
- delay(3);
- cmd_w(0xc0+1,0);
- cmd_w(0xc0,1);
- //i++;
- //if(i==64)
- //i=0;
- }
- }
复制代码
|