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

📄 lcd1.lst

📁 这是一个非常不错的12864液晶串口程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   LCD1                                                                  03/13/2008 15:50:32 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE LCD1
OBJECT MODULE PLACED IN lcd1.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE lcd1.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //***************************************************************************
   2          //连线表: CPU=89C52  SystemClock=12Mhz                                      *
   3          //CS=P3.0           SCLK=P3.1        SID=P3.2       Reset=RC in Board       *
   4          //***************************************************************************
   5          #include<AT89X52.H> 
   6          #include <intrins.h>
   7           
   8          sbit CS =P2^5;
   9          sbit SCK=P2^7;
  10          sbit SID=P2^6;
  11          sbit Key=P2^4;
  12          unsigned char code AC_TABLE[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,      //第一行汉字位置
  13                                         0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,      //第二行汉字位置
  14                                                                     0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,      //第三行汉字位置
  15                                                                     0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,      //第四行汉字位置
  16                                                                     };
  17          unsigned char code str2[]="欢迎光临sonsan!!";
  18          unsigned char code str1[]="黄河远上白云间,一片孤城万仞山。羌笛何须怨杨柳,春风不度玉门关。";
  19          unsigned char code bmp1[];
  20          //串口发送一个字节
  21          void SendByte(unsigned char Dbyte)
  22          {     unsigned char i;   
  23   1          for(i=0;i<8;i++)    
  24   1               {         
  25   2                 SCK = 0;         
  26   2                 Dbyte=Dbyte<<1;      //左移一位         
  27   2                 SID = CY;            //移出的位给SID      
  28   2             SCK = 1;          
  29   2                 SCK = 0;    
  30   2               }
  31   1      }
  32          //串口接收一个字节
  33          //仅在读取数据的时候用到
  34          //而读出的数据是一次只能读出4bit的
  35          unsigned char ReceiveByte(void)
  36          {    
  37   1        unsigned char i,temp1,temp2;   
  38   1        temp1=temp2=0;   
  39   1        for(i=0;i<8;i++)   
  40   1        {          
  41   2          temp1=temp1<<1;        
  42   2          SCK = 0;          
  43   2          SCK = 1;                       
  44   2              SCK = 0;           
  45   2              if(SID) temp1++;    
  46   2        }    
  47   1        for(i=0;i<8;i++)    
  48   1        {          
  49   2          temp2=temp2<<1;           
  50   2              SCK = 0;           
  51   2              SCK = 1;           
  52   2              SCK = 0;           
  53   2              if(SID) temp2++;    
  54   2        }     
  55   1        return ((0xf0&temp1)+(0x0f&temp2));
C51 COMPILER V8.02   LCD1                                                                  03/13/2008 15:50:32 PAGE 2   

  56   1      }
  57          void CheckBusy( void )
  58          {     do  SendByte(0xfc);  
  59   1          //11111,RW(1),RS(0),0     
  60   1              while(0x80&ReceiveByte());     //BF(.7)=1 Busy
  61   1      }
  62          void WriteCommand( unsigned char Cbyte )
  63          {     
  64   1        CS = 1;     
  65   1        CheckBusy();     
  66   1        SendByte(0xf8);            //11111,RW(0),RS(0),0     
  67   1        SendByte(0xf0&Cbyte);      //高四位     
  68   1        SendByte(0xf0&Cbyte<<4);//低四位(先执行<<)    
  69   1         CS = 0;
  70   1      }
  71          void WriteData( unsigned char Dbyte )
  72          {    
  73   1        CS = 1;     
  74   1        CheckBusy();    
  75   1        SendByte(0xfa);             //11111,RW(0),RS(1),0    
  76   1        SendByte(0xf0&Dbyte);      //高四位     
  77   1        SendByte(0xf0&Dbyte<<4);//低四位(先执行<<)     
  78   1        CS = 0;
  79   1      }
  80          unsigned char ReadData( void )
  81          {     
  82   1        CheckBusy();     
  83   1        SendByte(0xfe);            //11111,RW(1),RS(1),0     
  84   1        return ReceiveByte();
  85   1      }
  86          void Delay(unsigned int MS)
  87          {    
  88   1       unsigned char us,usn;    
  89   1       while(MS!=0)            //for 12M          
  90   1       { 
  91   2         usn = 2;                
  92   2         while(usn!=0)                      
  93   2         {                             
  94   3          us=0xf5;                             
  95   3              while (us!=0){us--;};                             
  96   3              usn--;                       
  97   3              }                
  98   2         MS--;           
  99   2        }
 100   1      }
 101          //维捷登测试架专用延时函数
 102          /*void Delay(unsigned int Second )
 103          {                              
 104            //输入精确到0.1S,是用","     
 105            unsigned int i,j;     
 106            for(i=0;i<Second;i++)
 107             for(j=180;j>0;j--);
 108          } */
 109          void LcmInit( void )
 110          {     
 111   1      WriteCommand(0x30);      //8BitMCU,基本指令集合     
 112   1      WriteCommand(0x03);      //AC归0,不改变DDRAM内容     
 113   1      WriteCommand(0x0C);      //显示ON,游标OFF,游标位反白OFF     
 114   1      WriteCommand(0x01);      //清屏,AC归0     
 115   1      WriteCommand(0x06);      //写入时,游标右移动
 116   1      }
 117          //文本区清RAM函数
C51 COMPILER V8.02   LCD1                                                                  03/13/2008 15:50:32 PAGE 3   

 118          void LcmClearTXT( void )
 119          {     
 120   1      unsigned char i;     
 121   1      WriteCommand(0x30);      //8BitMCU,基本指令集合     
 122   1      WriteCommand(0x80);      //AC归起始位     
 123   1      for(i=0;i<64;i++)        
 124   1      WriteData(0x20);
 125   1      }
 126          //图形区和文本区显示在两个不同的RAM区
 127          //图形区清RAM函数
 128          void LcmClearBMP( void )
 129          {     
 130   1      unsigned char i,j;     
 131   1      WriteCommand(0x34);      //8Bit扩充指令集,即使是36H也要写两次     
 132   1      WriteCommand(0x36);      //绘图ON,基本指令集里面36H不能开绘图     
 133   1      for(i=0;i<32;i++)            //12864实际为256x32    
 134   1       {           
 135   2        WriteCommand(0x80|i);      //行位置          
 136   2        WriteCommand(0x80);      //列位置           
 137   2        for(j=0;j<32;j++)            //256/8=32 byte               
 138   2        WriteData(0);     
 139   2        }
 140   1      }
 141          void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
 142          {    
 143   1        WriteCommand(0x30);      //8BitMCU,基本指令集合     
 144   1        WriteCommand(AC_TABLE[8*row+col]);      //起始位置     
 145   1      while(*puts != '\0')      //判断字符串是否显示完毕     
 146   1      {           
 147   2        if(col==8)            //判断换行           
 148   2        {            //若不判断,则自动从第一行到第三行                 
 149   3        col=0;                 
 150   3        row++;           

⌨️ 快捷键说明

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