论坛风格切换切换到宽版
  • 2767阅读
  • 8回复

请教编程高手:LCD显示信号条的那个黑块怎么弄? [复制链接]

上一主题 下一主题
在线bg6qbv
 
发帖
5838
只看楼主 倒序阅读 0楼 发表于: 2008-08-12
请教编程高手:lcd显示信号条的那个黑块怎么弄?

自己编程序,发现显示信号条的黑块不知道用的什么字?

用的英文8x8字库(不是lcd带的)。

难道要用图形显示方式?
离线永远的FM
发帖
12119
只看该作者 1楼 发表于: 2008-08-12
哈哈老大也遇到这个问题啦!~我现在也在做这个东西,显示信号强度。
哪个黑块是自定义字符,具体如何做请高手来解答。。。。
离线代洪波
发帖
4809
只看该作者 2楼 发表于: 2008-08-12
记得我有收藏这个的!等会弄上来
 用户自定义字符的应用:
我们从cgrom表上可以看到,在表的最左边是一列可以允许用户自定义的cgram,从上往下看着是16个,实际只有8个字节可用。它的字符码是00000000-00000111这8个地址,表的下面还有8个字节,但因为这个cgram的字符码规定0-2位为地址,3位无效,4-7全为零。因此cgram的字符码只有最后三位能用也就是8个字节了。等效为0000x111,x为无效位,最后三位为000-111共8个。
如果我们要想显示这8个用户自定义的字符,操作方法和显示cgrom的一样,先设置ddram位置,再向ddram写入字符码,例如“a”就是41h。现在我们要显示cgram的第一个自定义字符,就向ddram写入00000000b(00h),如果要显示第8个就写入00000111(08h),简单吧!
好!现在我们来看怎么向这八个自定义字符写入字模。有个设置cgram地址的指令大家还记得吗?赶快再找出来看看。


从这个指令可以看出指令数据的高2位已固定是01,只有后面的6位是地址数据,而这6位中的高3位就表示这八个自定义字符,最后的3位就是字模数据的八个地址了。例如第一个自定义字符的字模地址为01000000-01000111八个地址。我们向这8个字节写入字模数据,让它能显示出“℃”
地址:01000000  数据:00010000   图示:○○○■○○○○
   01000001     00000110       ○○○○○■■○
   01000010     00001001       ○○○○■○○■
   01000011     00001000       ○○○○■○○○
   01000100     00001000       ○○○○■○○○
   01000101     00001001       ○○○○■○○■
   01000110     00000110       ○○○○○■■○
   01000111     00000000       ○○○○○○○○
在线bg6qbv
发帖
5838
只看该作者 3楼 发表于: 2008-08-12
不错 1602正好学习了,

我现在弄的是128*64的屏,刚调试成字库显示和图形显示(开机logo)。

看来只能自定义字符试试了!!!!
离线小比尔/5
发帖
2582
只看该作者 4楼 发表于: 2008-08-13
黑块是255,或者 0xff
离线小比尔/5
发帖
2582
只看该作者 5楼 发表于: 2008-08-13
把要显示的字模写入cgram,大小是5x7(或8,但是8就不好看了)个bits,每一行5bits前填充三个空bit,共8x8 bits
下列程序需依赖lcd_wrtcmd() (写命令) 及 lcd_wrtdata() (写数据) 两个函数,请预先建立好。
wrtcmd的“,1“是等待命令执行完毕的意思,这是是我的库的一个参数,移植的时候可以删掉不管,前面是命令字。
uchar a是cgram字符号,它屏蔽了实现的细节,直接用0,1,2...就可以了。

例:
void lcd_wrtcgram(uchar a,uchar font[])
{
uchar i;
a=a<<3;
a=(a&0x3f)+0x40;
for(i=0;i<8;i++)
{
lcd_wrtcmd(a+i,1);
lcd_wrtdata(font);
}
}

a是写入的cgram地址,font[]是字模。
字模例:
uchar code volfont[8]={0x04,0x06,0x05,0x04,0x04,0x0c,0x1c,0x18};
在线bg6qbv
发帖
5838
只看该作者 6楼 发表于: 2008-08-13
刚自定义成功了,但是发现了个问题,就是难看了点!
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○  
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○  
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○
○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○○○■■■■○○


或者这样
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○○■■■■■■○
离线anybody-hf
发帖
1083
只看该作者 7楼 发表于: 2008-08-13
用像手机信号条一样的不就好看了, 重新定义吧
离线hackerboy
发帖
393
只看该作者 8楼 发表于: 2008-08-13
给你我的代码


unsigned char lcdcustomchar[] =
{
0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, // 0. 0/5 full progress block
0x00, 0x1f, 0x10, 0x10, 0x10, 0x10, 0x1f, 0x00, // 1. 1/5 full progress block
0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, // 2. 2/5 full progress block
0x00, 0x1f, 0x1c, 0x1c, 0x1c, 0x1c, 0x1f, 0x00, // 3. 3/5 full progress block
0x00, 0x1f, 0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0x00, // 4. 4/5 full progress block
0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00, // 5. 5/5 full progress block
}


void lcdloadcustomchar(u08* lcdcustomchararray, u08 romcharnum, u08 lcdcharnum)
{
  u08 i;
  u08 saveddramaddr;

  // backup the current cursor position
  saveddramaddr = lcdcontrolread() & 0x7f;

  // multiply the character index by 8
  lcdcharnum = (lcdcharnum<<3);   // each character occupies 8 bytes
  romcharnum = (romcharnum<<3);   // each character occupies 8 bytes

  // copy the 8 bytes into cg (character generator) ram
  for(i=0; i<8; i++)
  {
    // set cg ram address
    lcdcontrolwrite((1<<lcd_cgram) | (lcdcharnum+i));
    // write character data
    lcddatawrite( pgm_read_byte(lcdcustomchararray+romcharnum+i) );
  }

  // restore the previous cursor position
  lcdcontrolwrite(1<<lcd_ddram | saveddramaddr);

}


void lcdprogressbar(u16 progress, u16 maxprogress, u08 length)
{
  u08 i;
  u32 pixelprogress;
  u08 c;

  // draw a progress bar displaying (progress / maxprogress)
  // starting from the current cursor position
  // with a total length of "length" characters
  // ***note, lcd chars 0-5 must be programmed as the bar characters
  // char 0 = empty ... char 5 = full

  // total pixel length of bargraph equals length*progresspixels_per_char;
  // pixel length of bar itself is
  pixelprogress = ((progress*(length*progresspixels_per_char))/maxprogress);
 
  // print exactly "length" characters
  for(i=0; i<length; i++)
  {
    // check if this is a full block, or partial or empty
    // (u16) cast is needed to avoid sign comparison warning
    if( ((i*(u16)progresspixels_per_char)+5) > pixelprogress )
    {
        // this is a partial or empty block
        if( ((i*(u16)progresspixels_per_char)) > pixelprogress )
        {
          // this is an empty block
          // use space character?
          c = 0;
        }
        else
        {
          // this is a partial block
          c = pixelprogress % progresspixels_per_char;
        }
    }
    else
    {
        // this is a full block
        c = 5;
    }
   
    // write character to display
    lcddatawrite(c);
  }

}

int main(void)
{
  lcdloadcustomchar((u08*)lcdcustomchar,0,0);
  lcdloadcustomchar((u08*)lcdcustomchar,1,1);
  lcdloadcustomchar((u08*)lcdcustomchar,2,2);
  lcdloadcustomchar((u08*)lcdcustomchar,3,3);
  lcdloadcustomchar((u08*)lcdcustomchar,4,4);
  lcdloadcustomchar((u08*)lcdcustomchar,5,5);

  lcdprogressbar(56, 100, 16);

  return 1;
}