找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9480|回复: 4
打印 上一主题 下一主题
收起左侧

Si7021废弃的LCD19264液晶制作温湿度显示,实物&单片机代码开源

  [复制链接]
跳转到指定楼层
楼主
准备整采用19264液晶显示的甲醛、万年历、温湿度桌面时钟,发现家里有闲置的建行19264可用。
参考网络上的程序,自己做一定调整,先放出温湿度显示的源码,供大家欣赏,已做分享和记录。

实物图:


传感器真身



温湿度显示



背部接线


下雨后的车内数据

假想主界面1:


液晶驱动UC1604c
lcd引脚线序
1 升压输出
2 电容1
3 电容2
4 电容2
5 电容1
6 vcc
7 gnd
8 cs片选
9 cd(rs)寄存器选择
10 rst复位
11 sck
12 sda
不同批次的液晶屏,引脚排列可能不同。前五个引脚就不说了,看电路板很容易看出来,vcc和gnd用万用表量一下就行了,与那个8引脚芯片的5、6脚相连的肯定是sck和sda,剩下3个引脚的就算顺序全部打乱,排列组合只用6种,全都试一遍,绝对能得出结论。

单片机源程序如下:
  1. #include "si7021.h"
  2. #include <intrins.h>
  3. #include <stc15.h>

  4. void delay_x_us ( void )//(1+2)*60=180指令周期 180us
  5. {
  6.         char x=60;
  7.         for ( ; x>0; x-- )
  8.                 _nop_();
  9. }      
  10.                                                          
  11. //函数名称: start_i2c
  12. void start_i2c ( void )
  13. {
  14.          SI7021_SDA_HIGH();  
  15.         delay_x_us();
  16.         SI7021_SCLK_HIGH();   
  17.         delay_x_us();     
  18.         SI7021_SDA_LOW();   
  19.         delay_x_us();                 
  20.         SI7021_SCLK_LOW();
  21.         delay_x_us();
  22. }
  23. //函数名称: stop_i2c
  24. void stop_i2c ( void )
  25. {
  26.         SI7021_SDA_LOW();
  27.         delay_x_us();  
  28.         SI7021_SCLK_HIGH();
  29.         delay_x_us();
  30.         SI7021_SDA_HIGH();
  31.         delay_x_us();
  32. }
  33. //函数名称: send_1byte
  34. //函数功能: 写一个字节到si7021芯片
  35. bit send_1byte ( unsigned char send_data )
  36. {
  37.         unsigned char bit_cnt;
  38.         bit        b_ack=0;
  39.         unsigned char i=200;
  40.         
  41.         for( bit_cnt=0; bit_cnt<8; bit_cnt++ )
  42.         {
  43.              SI7021_SCLK_LOW();
  44.              if ( (send_data<<bit_cnt)&0x80 )
  45.                          SI7021_SDA_HIGH();  
  46.              else SI7021_SDA_LOW();  
  47.                  delay_x_us();              
  48.              SI7021_SCLK_HIGH();      
  49.              delay_x_us();           
  50.         }

  51.         delay_x_us();
  52.         SI7021_SCLK_LOW();
  53.         SI7021_SDA_HIGH();      
  54.         delay_x_us();
  55.         delay_x_us();
  56.         SI7021_SCLK_HIGH();
  57.         delay_x_us();
  58.          
  59.         i = 200;
  60.         while ( i-- )
  61.         {
  62.                 delay_x_us();
  63.                 if(SI7021_SDA==0)
  64.                 {
  65.                         b_ack = 1;
  66.                         break;
  67.                 }  
  68.         }

  69.         if ( i == 0 ) b_ack = 0;
  70.                
  71.         SI7021_SCLK_LOW();
  72.         delay_x_us ();

  73.         return b_ack;
  74. }

  75. //函数名称: read_1byte
  76. //函数功能: 从si7021读取一个字节
  77. unsigned char read_1byte ( void )
  78. {
  79.         unsigned char read_value=0;
  80.         unsigned char bit_cnt;

  81.         for ( bit_cnt=0; bit_cnt<8; bit_cnt++ )
  82.         {         
  83.            SI7021_SCLK_HIGH();      
  84.            delay_x_us();
  85.                  read_value <<= 1;

  86.            if ( SI7021_SDA==1 )
  87.                          read_value +=1;

  88.            SI7021_SCLK_LOW();
  89.         }
  90.         return (read_value);
  91. }
  92. //函数名称:master_i2c_ack
  93. //函数功能:MCU应答从器件
  94. void master_i2c_ack ( void )
  95. {
  96.         SI7021_SDA_LOW();   
  97.         delay_x_us();
  98.         SI7021_SCLK_LOW();
  99.         delay_x_us();      
  100.         SI7021_SCLK_HIGH();
  101.         delay_x_us();
  102.         SI7021_SCLK_LOW();   
  103.         delay_x_us();
  104.         SI7021_SDA_HIGH();
  105.         delay_x_us();
  106. }
  107. //函数名称:master_i2c_noack
  108. //函数功能:MCU不发送应答信号到从器件
  109. void master_i2c_noack ( void )
  110. {
  111.         SI7021_SDA_HIGH();
  112.         delay_x_us();      
  113.         SI7021_SCLK_HIGH();
  114.         delay_x_us();
  115.         SI7021_SCLK_LOW();
  116. }
  117. //函数名称:measure_si7021
  118. //函数功能:HOLD MASTER模式下读取温湿度
  119. int measure_si7021 ( unsigned char model)
  120. {
  121.         int i,reda;
  122.         //发起始信号
  123.         start_i2c();               
  124.         if ( 0== send_1byte ( SALVE_ADDR ) )//写slave addr
  125.         {
  126.                 return 0;
  127.         }

  128.         if ( 0 == send_1byte( model ) )//measure cmd
  129.         {
  130.                 return 0;
  131.         }
  132.         //默认湿度转换时间为10~12ms 温度 6~10ms  
  133.         i = 600;        //600*180=108ms        非准确延时
  134.         while ( i-- )
  135.                 delay_x_us ();        //温湿度数据转换延时等待(延时参照手册,此处仅为测试)

  136.         start_i2c ();                                 //重新发起始信号
  137.         if ( 0==send_1byte(SALVE_ADDR+1) ) //读命令
  138.         {

  139.                 return 0;
  140.         }

  141.         reda= read_1byte ();//读取温湿度的高位字节
  142.         //mcu应答
  143.         master_i2c_ack ();
  144.         reda=reda*256+read_1byte ();//读取温湿度的低位字节数据,与高位进行加和;
  145.         //mcu无应答
  146.         master_i2c_noack ();
  147.         
  148.         //mcu应答->read_1byte()读取校验值->mcu无应答

  149.         //发送停止位
  150. //        value->uint = 0x7890;
  151.         stop_i2c ();
  152.         if(model==TEMP_HOLD_MASTER)
  153.         {
  154.                 //return reda;
  155.                 reda=10*((float)(175.72*(float)reda)/65536-46.85);
  156.                
  157.         }else if(model==HUMI_HOLD_MASTER)
  158.                 reda=10*((float)(125*(float)reda)/65536-6);
  159.         return reda;
  160. }
复制代码

所有资料51hei提供下载,Keil工程源码:
温湿度19264显示.zip (66.84 KB, 下载次数: 107)
类似主题:
http://www.51hei.com/bbs/dpj-27356-1.html
http://www.51hei.com/bbs/dpj-190973-1.html
http://www.51hei.com/bbs/dpj-35520-1.html
http://www.51hei.com/bbs/dpj-213269-1.html
http://www.51hei.com/bbs/dpj-186003-1.html
http://www.51hei.com/bbs/dpj-59981-1.html
http://www.51hei.com/bbs/dpj-129947-1.html
http://www.51hei.com/bbs/dpj-202400-1.html
http://www.51hei.com/bbs/dpj-88462-1.html
http://www.51hei.com/bbs/dpj-36379-1.html
http://www.51hei.com/bbs/dpj-80238-1.html
http://www.51hei.com/bbs/dpj-178374-1.html
http://www.51hei.com/bbs/dpj-151707-1.html
http://www.51hei.com/bbs/dpj-155801-1.html

评分

参与人数 1黑币 +100 收起 理由
admin + 100 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏12 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:447180 发表于 2020-5-12 12:39 | 只看该作者
LCD屏,还是OLED屏?
回复

使用道具 举报

板凳
ID:205015 发表于 2020-8-12 07:45 | 只看该作者
lcd的。
回复

使用道具 举报

地板
ID:392485 发表于 2023-11-24 09:20 | 只看该作者
手上正好有一个,下载看看学习学习。
回复

使用道具 举报

5#
ID:1030595 发表于 2023-12-22 12:03 | 只看该作者
如何移植到stm32上,就可以了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表