zoukankan      html  css  js  c++  java
  • 1602液晶显示

     1602LCD分两行显示文字(不能显示中文)

     1 /*
     2 RS =数据/命令选择端(H/L)
     3 R/W=读/写选择端(H/L)因TX-1X开发板此脚接地所以只能写不能读取,故本程序不读只写
     4 此试验板1602液晶接P0口故此数据通过P0传送
     5 lilongjiang@live.com 8/16/2010
     6  */
     7 
     8 #include<reg52.h>
     9 #define uchar unsigned char
    10 #define uint unsigned int
    11 sbit EN=P3^4;        
    12 sbit RS=P3^5;
    13 sbit dula=P2^6;        //断选
    14 sbit wela=P2^7;        //位选 因这两个芯片也接在P0口故使用液晶避免造成电压低故关闭这两个芯片
    15 uchar code tab1[]="0123456789ABCDEF";    //第一样显示的数据
    16 uchar code tab2[]="GHIJKLMNOPQRSTUV";    //第二行显示的数据
    17 void delay(uint);
    18 uchar i;
    19 void write_com(uchar com)    //写命令
    20 {
    21     RS=0;
    22     P0=com;
    23     delay(1);
    24     EN=1;
    25     EN=0;
    26 }
    27 void write_data(uchar date)    //写数据
    28 {
    29     RS=1;
    30     P0=date;
    31     delay(1);
    32     EN=1;
    33     EN=0;
    34 }
    35 void init()
    36 {
    37     EN=0;
    38     dula=0;                //关闭断选
    39     wela=0;                //关闭位选
    40     write_com(0x38);    //开显示
    41     write_com(0x0F);    //光标
    42     write_com(0x06);    //指针
    43     write_com(0x01);    //清屏
    44 }
    45 void main()
    46 {
    47     init();
    48     write_com(0x80);        //第一行显示地址设为80H
    49     for(i=0;i<16;i++)
    50     {
    51         write_data(tab1[i]);
    52     }
    53     write_com(0xC0);        //第二行显示地址设为80H+40H
    54     for(i=0;i<16;i++)
    55     {
    56         write_data(tab2[i]);
    57     }    
    58     while(1);
    59 }
    60 void delay(uint x)
    61 {
    62     uint i;
    63     while(x--)
    64         for(i=0;i<110;i++);
    65 }
  • 相关阅读:
    ESP8266 RTOS SDK烧写环境构建
    杂记:解决Android扫描BLE设备名称不刷新问题
    deviceMotion.userAcceleration加速度方向
    二、多功能提示框——MBProgressHUD
    一、初识CocoaPods——XCode的依赖库管理工具
    摄像机的控制
    DOTween 使用方法
    Unity依赖注入使用详解
    Unity中对SQL数据库的操作
    unity导弹算法 预计目标点
  • 原文地址:https://www.cnblogs.com/lilongjiang/p/1800674.html
Copyright © 2011-2022 走看看