• 简单的12864显示程序


    • 2864是128*64点阵液晶模块的点阵数简称。我使用的内部自带汉字库的一款液晶作为风速显示
    • 好了废话不多说,接下来就贴上我的程序
    • #//头信息
      #include <reg51.h>
      #include <math.h>
      #include <INTRINS.H>
      
      //定义数据类型
      #define  uchar unsigned char
      #define  uint unsigned int
      #define  xchar unsigned char code  
      
      #define      DataPort P1
      #define     DELAYMS 80
      
      //端口定义
      sbit RS_Port    =    P2^7;
      sbit RW_Port    =    P2^6;
      sbit E_Port      = P2^5;
      sbit PSB_Port    =    P2^4;
      
      
      //输入显示的内容   # 每行显示七个字 要改内内容直接在下边该就行了 
      // 但是需要留意的是,每行必须七个字 否则乱码  后期我会修改
      xchar CorpInf[]=
      {
           "风速风速风速风"
          "风速风速风速风"
          "风速风速风速风"
          "风速风速风速风"
      };
      
      //短延时函数
      #pragma disable         
      void delay(uchar uc_dly)
      {
          while (uc_dly--);
      }
      
      //长延时函数,以秒每单位
      #pragma disable      
      void delays() 
      {
          uchar uc_dly,uc_dly1,uc_dly2;
      
          uc_dly =DELAYMS;
          
          while (uc_dly --)
          {
              for (uc_dly1=0;uc_dly1<50;uc_dly1++)
                  for (uc_dly2=0;uc_dly2<50;uc_dly2++);
          };
      }
      
      
      //写命令
      #pragma disable  
      void wr_cmd(uchar cmd)  
      {
          E_Port = 0;
          _nop_();
          _nop_();
      
          RS_Port=0;
          _nop_();
          _nop_();
      
          RW_Port=0;
          _nop_();
          _nop_();
      
          E_Port=1;
          _nop_();
          _nop_();
      
          DataPort=cmd;
          _nop_();
          _nop_();
      
          E_Port=0;
          _nop_();
          _nop_();
      
          delay(5);
      }
      
      //写数据
      #pragma disable
      void wr_dat(uchar dat) 
      {    
          E_Port = 0;
          _nop_();
          _nop_();
       RS_Port=1;
          _nop_();
          _nop_();
          
          RW_Port=0;
          _nop_();
          _nop_();
      
          E_Port=1;
          _nop_();
          _nop_();
              
          DataPort=dat;
          _nop_();
          _nop_();
      
          E_Port=0;
          _nop_();
          _nop_();
      
          delay(5);
      }
      
      //显示初始化
      #pragma disable
      void Init(void)   
      {
          wr_cmd(0x30);     //DL=1:8-BIT interface
          wr_cmd(0x30);     //RE=0:basic instruction
          wr_cmd(0x06);     //Entire display shift right by 1
          wr_cmd(0x08);     //Display OFF,Cursor OFF,Cursor position blink OFF
      
          wr_cmd(0x34);     //DL=1:8-BIT interface
          wr_cmd(0x34);     //RE=0:Extend instruction
          wr_cmd(0x03);
      }
      
      
      //写入数据的行数以及数据的分布
      #pragma disable
      void DisGBStr(xchar *CorpInf)
      {
          uchar uc_GBCnt;
      
          wr_cmd(0x30);     //DL=1:8-BIT interface
          wr_cmd(0x30);     //RE=0:basic instruction
          wr_cmd(0x0C);     //Display OFF,Cursor OFF,Cursor position blink OFF
      
          wr_cmd(0x80);
          for (uc_GBCnt=0;uc_GBCnt<16;uc_GBCnt++)
          {
              wr_dat(CorpInf[2 * uc_GBCnt]);
              wr_dat(CorpInf[2 * uc_GBCnt + 1]);
          };
      
          wr_cmd(0x90);
          for (uc_GBCnt=0;uc_GBCnt<16;uc_GBCnt++)
          {
              wr_dat(CorpInf[2 * uc_GBCnt + 32]);
              wr_dat(CorpInf[2 * uc_GBCnt + 33]);
          };
      
          delays();
      }
      
      #pragma disable
      void CRAM_OFF()
      {
          wr_cmd(0x30);     //DL=1:8-BIT interface
          wr_cmd(0x30);     //RE=0:basic instruction
          wr_cmd(0x08);    //Display ON,Cursor OFF,Cursor position blink OFF
          wr_cmd(0x01);     //CLEAR
          delay(250);
      }
      
      void main()
      {
          EA=1; //Interurupt Enabled
      
          IT0 = 1;//INT0 Low Level Trigger
      
          EX0 = 1;//INT0 Enabled
      
          PSB_Port =1;
          _nop_();
          delay(250);
      
          //ST7920 Init
          Init();
      
          while (1)
          {
              CRAM_OFF();
              DisGBStr(CorpInf);
          }
      }

    • 其中需要注意的是在数组中显示的是可以变化的 如果不想写这么多字的化 也可以修改后边的for循环来是显示的字变少,但是如果不这样操作的话,就会使显示乱码
      xchar CorpInf[]=
      {
           "风速风速风速风"
          "风速风速风速风"
          "风速风速风速风"
          "风速风速风速风"
      };
  • 相关阅读:
    Linux之流程判断
    Linux之Shell变量
    Linux之RAID
    Y-Sport
    [ST2017] Lab1: Triangle type and Junit test
    [ST2017] Hw3: Prime Path
    [ST2017] Hw2: Fault, Error, Failure and test case for projects
    [SPM2017] Hw1: The outcome of my project [Deadline: 23:59:59, Mar.1, 2017]
    [ST2017] Hw1: An error from my past projects [Deadline: 23:59:59, Feb.27, 2017]
    一个使用Jmeter做接口性能测试的实战案例
  • 原文地址:https://www.cnblogs.com/hourglass-/p/9202412.html
Copyright © 2020-2023  润新知