打印

st7290续

[复制链接]
1495|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chuandaoxy|  楼主 | 2007-9-11 09:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我在网上找到如下代码

可调通,我有几个地方不明白,请大家帮助

问题1:函数 void Gra(uchar x,uchar y)里
最后一句Sendint(0x8000>>(x%16));是啥意思

问题2:函数void Sendint(uint dd)也不明白

问题3:程序执行结果液晶屏的分为上下两部分两个IBM
       是由哪个函数引起的我觉得是由函数
       void put(uchar *p)引起,原来我用过12232用字模程序倒入图像是全屏的,而这个程序分为上下两部分,


请大家帮助分析一下

 #include <reg51.h>
#include <intrins.h>

sbit E_CLK =P0^1;//clock input                    同步时钟输入端
sbit RW_SID=P1^3;//data input/output                串行数据输入、输出端




#define uchar unsigned char
#define uint  unsigned int

 #define ROW1 0x80
 #define ROW2 0x90
 #define ROW3 0x88
 #define ROW4 0x98





//////////////////////
//内部函数原型
//////////////////////

void SendData(unsigned char dat);


  unsigned char code AC_TABLE[]={
  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,      
                              //第一行汉字位置
  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,      
                              //第二行汉字位置
  0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,      
                              //第三行汉字位置
  0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,      
                              //第四行汉字位置
                              };

void delay(unsigned int n)
{
  unsigned int i;
  for(i=0; i<n; i++) {;}
}



 //串行发送一字节数据
void SendByte(unsigned char dat)
{
     unsigned char i;
     for(i=0;i<8;i++)
           {
                 E_CLK=0;
                 if(dat&0x80)RW_SID=1;else RW_SID=0;
                 E_CLK=1;
                 dat=dat<<1;
            }
}
//串行接收一字节数据
unsigned char ReceieveByte(void)
{
     unsigned char i,d1,d2;
     for(i=0;i<8;i++)
           {
                 E_CLK=0;delay(100);
                 E_CLK=1;
                 if(RW_SID)d1++;
                 d1=d1<<1;
            }
     for(i=0;i<8;i++)
           {
                 E_CLK=0;delay(100);
                 E_CLK=1;
                 if(RW_SID)d2++;
                 d2=d2<<1;
            }
     return (d1&0xF0+d2&0x0F);
}


//读取标志位BF
bit ReadBF(void)
{
     unsigned char dat;
     bit bf;
     SendByte(0xFA);//11111,01,0 RW=1,RS=0
     dat=ReceieveByte();
     if(dat>0x7F)bf=1;else bf=0;
     return bf;
     }
//写控制命令
void SendCMD(unsigned char dat)
{

     SendByte(0xF8);//11111,00,0 RW=0,RS=0 同步标志
     SendByte(dat&0xF0);//高四位
     SendByte((dat&0x0F)<<4);//低四位

}




//写显示数据或单字节字符
void SendData(unsigned char dat)
{

     SendByte(0xFA);//11111,01,0 RW=0,RS=1
     SendByte(dat&0xF0);//高四位
     SendByte((dat&0x0F)<<4);//低四位

}





//初始化 LCM
void initlcm(void)
{

     delay(100);

     SendCMD(0x30);//功能设置,一次送8位数据,基本指令集
     SendCMD(0x0c);//0000,1100  整体显示,游标off,游标位置off
     SendCMD(0x01);//0000,0001 清DDRAM
     SendCMD(0x02);//0000,0010 DDRAM地址归位
     SendCMD(0x80);//1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC
     
}




   void PutStr(unsigned char row,unsigned char 
               col,unsigned char *puts)
 {
  SendCMD(0x30);      //8BitMCU,基本指令集合
  SendCMD(AC_TABLE[8*row+col]);      //起始位置
 while(*puts != '\0')      //判断字符串是否显示完毕
 {
 if(col==8)            //判断换行
 {            //若不判断,则自动从第一行到第三行
 col=0;
 row++;
 }
  if(row==4) row=0;      //一屏显示完,回到屏左上角
 SendCMD(AC_TABLE[8*row+col]);
 SendData(*puts);      //一个汉字要写两次
puts++;
SendData(*puts);
puts++;
col++;
}



 void Sendint(uint dd)
  {
  SendData(dd>>8);
  SendData(dd);
              }


 void Gra(uchar x,uchar y)
  {
    uchar xx,yy;
    SendCMD(0x34);
    SendCMD(0x36);
    xx=x/16;
    yy=63-y;
    if(yy>=32){xx=xx+8;yy-=32;}
    SendCMD(0x80+yy);
    SendCMD(0x80+xx);
    Sendint(0x8000>>(x%16));
                              
          }
                              
                              
                              
                              
                              

 void put(uchar *p)

{
  uchar xx,yy ;

for(yy=0;yy<32;yy++)
for(xx=0;xx<8;xx++)
{
 SendCMD(0x80+yy);   //y 按位
 SendCMD(0x80+xx);   //x 按16位
 SendData(*p);
p++;
 SendData(*p);
 p++;
}

for(yy=0;yy<32;yy++)
 for(xx=8;xx<16;xx++)
 {
 SendCMD(0x80+yy);   //y 按位
 SendCMD(0x80+xx);   //x 按16位
 SendData(*p);
 p++;
 SendData(*p);
  p++;
   }
  }
  
  

  void PutBMP(unsigned char *puts)
{
  unsigned int x=0;
  unsigned char i,j;
  SendCMD(0x34);      //8Bit扩充指令集,即使是36H也要写两次
  SendCMD(0x36);      //绘图ON,基本指令集里面36H不能开绘图
  for(i=0;i<32;i++)            //12864实际为256x32
 {
  SendCMD(0x80|i);      //行位置
  SendCMD(0x80);      //列位置
  for(j=0;j<32;j++)      //256/8=32 byte
 {            //列位置每行自动增加
  SendData(puts[x]);
  x++;
         }
       }
   }
   
   
    void  Clear()
  {    uchar  i,j;
    //LCDInittest();
     SendCMD(0x34);
     SendCMD(0x3e);// RE=1  扩展指令选择  G=1  开图形显示 
                                    
     for(j=0;j<16;j++)
     for(i=0;i<32;i++)
                               
    {
     SendCMD(0x80+i);
     SendCMD(0x80+j);
     SendData(0x00);
     SendData(0x00);
       }
                                   
     } 



            uchar code IBM[]=
                              {
                               
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xF0,0x00,0x1F,0xFF,0xFE,
                              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,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xF8,0x00,0x3F,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,
                              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,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,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFE,0x01,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x01,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x03,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0x80,0x03,0xFF,0xFF,0x83,0xFF,0xFF,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,0x00,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFF,0x00,0x03,0xFF,0xFF,0xCF,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0xBF,0xFF,0xFB,0xFF,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,0x00,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0x8F,0xFF,0xF3,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0x87,0xFF,0xE3,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0x87,0xFF,0xE3,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFF,0x00,0x03,0xFF,0x87,0xFF,0xC3,0xFF,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,0x00,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0x80,0x01,0xFF,0x83,0xFF,0x83,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x81,0xFF,0x03,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x81,0xFF,0x03,0xFF,0x00,
                              0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x80,0xFF,0x03,0xFF,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,0x00,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x7E,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x7C,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x3C,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xC0,0x3C,0x03,0xFF,0xFE,
                              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,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xC0,0x18,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xC0,0x18,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xC0,0x08,0x03,0xFF,0xFE,
                              0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xC0,0x00,0x03,0xFF,0xFE,
                              0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


                              };





void main(void)
{
   initlcm();
  
      Clear();

     PutBMP(IBM);
     
    while(1);

}





相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

854

主题

1043

帖子

4

粉丝