原创 AD7715程序

2007-9-10 21:39 3425 3 3 分类: MCU/ 嵌入式

#include
#include
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define lcmcom XBYTE[0x3fff]     /*T6963C写命令口地址,读数据口地址*/
#define lcmdata XBYTE[0x3eff]    /*T6963C写数据口地址*/


#define   RD_SET_REG 0x18  //读设置寄存器
#define   WR_SET_REG 0x10  //写设置寄存器
#define   DAT_SET_REG 0x66    //设置寄存器数据
sbit CS="P1"^0;
sbit SCK="P1"^1;
sbit DIN="P1"^2;
sbit DOUT="P1"^3;
sbit DRDY="P1"^4;


uchar code ctable[];           /*汉字库必须先声明,以便字库可以安排在程序的任意位置*/


/***********************************************************
函数功能:判忙,空闲则返回
参数说明:flag为读取的状态位,flag中相应位为需要判断的位
/***********************************************************/


void busy_lcm(uchar flag)
{
 uchar i;
 i=flag;
 while(i==lcmcom&flag);
}


/*******************************************************************
函数功能:写数据、写指令
参数说明:数据(data1,data2)、指令(lcmcom)
          判别(count),count=1,只写指令(com);
                      count="2",写数据1和指令(data1,lcmcom);
                      count="3",写数据1数据2和指令(data1,data2,lcmcom);
/*******************************************************************/


void write_lcm(uchar count,uchar com,uchar data1,uchar data2)
{
 switch(count)
 {
  case 1:busy_lcm(0x3);lcmcom=com;break;
  case 2:busy_lcm(0x3);lcmdata=data1;busy_lcm(0x3);lcmcom=com;break;
  case 3:busy_lcm(0x3);lcmdata=data1;busy_lcm(0x3);lcmdata=data2;busy_lcm(0x3);lcmcom=com; break;
  default:break;
 }
}
/**************************************************************
函数功能:图形方式单个汉字显示
参数说明:x 为水平坐标,以汉字为单位(0-14)(240×128)
          y 为垂直坐标,以汉字为单位(0-7)(240×128)
       caddr 指针指向要显示的汉字在字符表中此字的绝对地址(32个字节)
*****************************************************************/
void display_1c(uchar caddr,uchar x,uchar y) 
{
 uchar i,j,*p;uint w;
 p=ctable+caddr*32;
    x="x"<<1;     
     for(i=0;i<=1;i++)
       {x=x+i; 
   for(j=0;j<16;j++)
    {w=y*16*30+x+32+j*30;    //x(以汉字为单位)+显示区首址(32)+y(以汉字为单位)
                            //×16字节/汉字×显示区宽度(30字节)+j×显示区宽度(30)
    write_lcm(0x3,0x24,w%256,w>>8);//w%256为低位字节,w>>8为高位字节
       write_lcm(0x2,0xc2,*p,NULL);
    p++;    
     }
       }
}



/**************************************************************
函数功能:图形方式单个半角西文或数字显示(8×16)
参数说明:x为水平坐标,以字为单位(0-29)(240×128)
          y为垂直坐标,以字为单位(0-15)(240×128)
          caddr为欲显示的半角西文或数字字符表中此字的绝对地址(偏移量)
          如显0,d=0;显A,d=11
*****************************************************************/
void display_1e(uchar caddr,uchar x,uchar y) 
{
     uchar j,*p;uint w;
     p="ctable"+caddr*32;
  for(j=0;j<16;j++)
   {w=y*16*30+x+32+j*30;    //x(以汉字为单位)+显示区首址(32)+y(以汉字为单位)
                            //×16行×显示区宽度(16)+j×显示区宽度(16)
    write_lcm(0x3,0x24,w%256,w>>8);
    write_lcm(0x2,0xc2,*p,NULL);
    p++;    
   }
}


/***************************************************************
函数功能:图形方式清屏
参数说明:自动写模式
/**************************************************************/
void clear_lcm()
{
    uint i;
    write_lcm(0x3,0x24,0x0,0x0);          /*设置显示RAM首地址*/
    write_lcm(0x1,0xb0,NULL,NULL);         /*设置自动写方式*/
    for (i=0;i<9600;i++)                   /*最大显示点阵为:320×240=9600*/
     {busy_lcm(0x0c);lcmdata=0x0;}         /*写00H清屏*/
      busy_lcm(0x0c);lcmcom=0xb2;          /*设置自动写结束*/
}


/***************************************************************
函数功能:图形方式初始化
参数说明:自动写模式
/**************************************************************/
void init_lcm()
{
  write_lcm(0x1,0xa1,NULL,NULL);    //设置光标形状为8(列)×1(行)
  write_lcm(0x3,0x21,0x0,0x0);      //设置光标指针
  write_lcm(0x3,0x40,0x0,0x0);      //设置文本显示区域首址
  write_lcm(0x3,0x41,0x1,0x0);      //设置文本显示区域宽度,即每一行显示所占字节数
  write_lcm(0x3,0x42,32,0x0);       //设置图形显示区域首址为32
  write_lcm(0x3,0x43,30,0x0);       //设置图形显示区域宽度为30字节
  write_lcm(0x1,0x80,NULL,NULL);    //设置显示为逻辑“或”方式
  write_lcm(0x1,0x9c,NULL,NULL);    //设置显示开关,图形/文本显示均开启
}


 



uint readAD() 
{
    uchar i;    uint readword;
 if(DRDY)
    {
  for(i=0;i<16;i++)
      {
          SCK=0;
          readword=readword<<1;
          if(DOUT)  readword+=0x01;
    SCK=1;
      }
   return(readword);
 }
    while(1);
}
void writeAD(uchar writebyte) 
{
    uchar i;
    for (i=0; i<8; i++)
    {
        SCK="0";
        writebyte="writebyte"<<1;
     DIN =(bit)(writebyte&0x80);
        SCK =1;
    }
    DIN="1";
}


void ADinit()
{
 CS=1;CS=0;
 writeAD(WR_SET_REG);   //写设置寄存器
    writeAD(DAT_SET_REG);   //设置寄存器数据
 CS=1;
}


void main()

 uint i;
 init_lcm();                //LCM初始化
 clear_lcm();               //LCM清屏 
 ADinit();
 i=readAD();
 display_1c(i/10000,4,5);
 display_1c(i/1000,5,5);
 display_1c((i%1000)/100,6,5);
 display_1c((i%100)/10,7,5);
 display_1c((i%10),8,5);
}


uchar code ctable[]=
{
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,//0=0 ,以字为单位的相对地址
0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,//1
0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,//2
0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,//3
0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,//4
0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,//5
0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,//6
0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,//7
0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,//8
0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,//9
0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//.
0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条