⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digital-v-lcd-ok-11-17.lst

📁 基于AT89C51的数字电压表
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   DIGITAL_V_LCD_OK_11_17                                                11/17/2008 19:57:19 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE DIGITAL_V_LCD_OK_11_17
OBJECT MODULE PLACED IN digital-V-LCD-OK-11-17.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE digital-V-LCD-OK-11-17.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          
   2          //Editor: zhangmin
   3          //Version: V1.0
   4          //Description: LCD1602显示数字电压表,精度:0.01V 
   5          //Date:2008.11.11 
   6          //CPU:35%
   7          /**********************************************************
   8                             头文件定义 
   9          **********************************************************/
  10          
  11          #include<at89x51.h>
  12          
  13          #include<intrins.h>
  14          
  15          /**********************************************************
  16                             自变量定义 
  17          **********************************************************/
  18          #define uchar unsigned char
  19          #define uint unsigned int
  20          //#define INTERVAL 20  //定义采样周期 
  21          sbit RS=P3^4;  //LCD数据/指令选择端 
  22          sbit RW=P3^3;  //LCD读写选择端 
  23          sbit E=P3^2;  //LCD使能信号,从低到高有效 
  24          sbit busyFlag=P2^7;  //LCD读忙标志位 
  25          sbit dataIn=P1^1;   //TLC2543控制字输入端 
  26          sbit dataOut=P1^0;  //TLC2543数据输出 
  27          sbit CS=P1^2;       //TLC2543片选端 
  28          sbit CLK=P1^3;      //TLC2543时钟信号输入端 
  29          //bit ADFlag; //是否进行采样标志 
  30          /**********************************************************
  31          函数名称: delay
  32          函数描述: 延时ms (11.0592MHz) 
  33          入口参数: uint i 
  34          **********************************************************/
  35          
  36          void delay(uint i) 
  37          { 
  38   1       uchar a;
  39   1       while(i--)
  40   1       {
  41   2         for(a=0;a<250;a++)
  42   2           {
  43   3            _nop_();_nop_();_nop_();_nop_();
  44   3                }
  45   2       }    
  46   1      }
  47          /**********************************************************
  48          函数名称: delayAD
  49          函数描述: AD转换时间延时us (11.0592MHz) 
  50          入口参数: uint i 
  51          **********************************************************/
  52          void delayAD(uint i)
  53          {
  54   1        while(--i);   
  55   1        } 
C51 COMPILER V8.08   DIGITAL_V_LCD_OK_11_17                                                11/17/2008 19:57:19 PAGE 2   

  56          
  57          /**********************************************************
  58          函数名称: adConvert 
  59          函数描述: TLC2543驱动程序 
  60          入口参数: 转换地址 
  61          返回值:   转换结果 uint ad
  62          **********************************************************/
  63          uint adConvert(uchar port) 
  64          {
  65   1        uint ad=0;
  66   1        uchar i;
  67   1        CS=0;
  68   1        CLK=0;
  69   1        port<<=4;
  70   1        for(i=0;i<12;i++)
  71   1         {
  72   2          if(dataOut)
  73   2            ad|=0x01;
  74   2          dataIn=(bit)(port&0x80);
  75   2          CLK=1;    //时钟上升沿,读入一个字符 
  76   2          delayAD(3);  //采样时间 
  77   2          CLK=0;    //下降沿,输出一个字符 
  78   2          delayAD(3);  //转换时间 
  79   2          port<<=1;  //移出下一个字符 
  80   2          ad<<=1;    //移出下一位空间 
  81   2            }
  82   1         CS=1;
  83   1         ad>>=1;
  84   1         return (ad);   
  85   1      }
  86          
  87          
  88          /**********************************************************
  89          函数名称: dataConvert 
  90          函数描述: AD转换数据处理,精度0.01 
  91          入口参数: uint adRusult 
  92          **********************************************************/
  93          /*uint dataConvert(uint adResult)
  94          {
  95            uint data;
  96            uchar hundredBit,tenBit,oneBit;
  97            data=adResult*1.0/4096*500; //设置精度为0.01,AD参考电压为5V 
  98            oneBit=data%10;            //个位数 
  99            tenBit=(data/10)%10;       //十位数 
 100            hundredBit=(data/100)%10;  // 百位数 
 101               }
 102               
 103               
 104          //以下是LCD1602驱动程序 
 105            
 106          /**********************************************************
 107          函数名称: testBusy 
 108          函数描述: LCD检测是否忙碌函数
 109          入口参数: 无
 110          **********************************************************/
 111          
 112          
 113          uchar testBusy(void)
 114          {  
 115   1        bit flag;
 116   1        P2=0xff;
 117   1        RS=0;         //选择指令端 
C51 COMPILER V8.08   DIGITAL_V_LCD_OK_11_17                                                11/17/2008 19:57:19 PAGE 3   

 118   1        RW=1;         //选择读取 
 119   1        E=1;          //使能端由低到高有效  
 120   1        if (busyFlag==1) flag=1;
 121   1          else flag=0;
 122   1         E=0;
 123   1        return flag; 
 124   1           }          
 125             
 126          
 127          /**********************************************************
 128          函数名称: writeCommand 
 129          函数描述: LCD写入指令函数
 130          入口参数: 指令参数command 
 131          **********************************************************/
 132               
 133          void writeCommand(uchar command)
 134          {  while(testBusy());
 135   1        
 136   1         RS=0;   //选择指令端 
 137   1         RW=0;   //选择写入 
 138   1         E=1;    //下降沿读入 
 139   1         P2=command;
 140   1         E=0;
 141   1       }
 142            
 143          /**********************************************************
 144          函数名称: writeData
 145          函数描述: LCD写入数据函数
 146          入口参数: 指令参数writedata 
 147          **********************************************************/
 148               
 149          void writeData(uchar writedata)
 150          {  
 151   1         while(testBusy());
 152   1         RS=1;    //选择数据端 
 153   1         RW=0;    //选择写入
 154   1         E=1;
 155   1         P2=writedata;
 156   1         E=0;
 157   1       }   
 158           
 159          /**********************************************************
 160          函数名称: initialLcd1602() 
 161          函数描述: LCD写入指令函数
 162          入口参数: 无
 163          **********************************************************/
 164               
 165          
 166          void initialLcd1602(void)
 167          { 
 168   1           
 169   1        /*delay(100);
 170   1        writeCommand(0x38);
 171   1        delay(10);
 172   1        writeCommand(0x38); 
 173   1        delay(10);
 174   1        writeCommand(0x38); 
 175   1        delay(10);    */     //初次使用 
 176   1        
 177   1        writeCommand(0x38); //设置显示格式为:8位,双行显示,5X7点阵 
 178   1        writeCommand(0x80);
 179   1        writeCommand(0x01);                  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -