1602+18b20+ds1302的程序

时间:2025-07-09

1602+18b20+ds1302的C程序

一个1602+18b20+ds1302的程序(转)

2009-10-04 18:23

CEPARK-51 电子时钟程序设计大赛

功能:时间+日期+星期+温度+按键调整

作者:qchpanna

时间:2009年7月28日星期三

版本:v1.0

#include <stc89c52.h>

#include <intrins.h>

#include <string.h>

unsigned char readdata[2]; //读取温度值缓冲

bit sflag=0; //温度测试负号位

int result;

int tem=0;//用于显示的温度

bit enable;//无传感器标志

unsigned char tem1=0;//字节低8位

unsigned char tem2=0;//字节高8位

1602+18b20+ds1302的C程序

int tem3=0;//合成数据

int tem4; //进行正负转换的临时值

unsigned char tem6;//比较使用低8位

unsigned char tem7;//比较使用高8位

int tem8;//用于比较的当前温度值,解决调整规定值时误动作现象(tem的)

sbit DQ=P1^6;

unsigned char count;//设置状态下 延时

unsigned char timecount=0; //温度转换过程计时(800ms)

sbit DS_CLK=P3^3; /*实时时钟时钟线引脚 */

sbit DS_IO=P3^4; /*实时时钟数据线引脚 */

sbit DS_RST=P3^5; /*实时时钟复位线引脚 */

unsigned char bite[5];

/***********************************************************************

//引脚定义

************************************************************************/

sbit LCD1602_RS=P1^0;

sbit LCD1602_RW=P1^1;

1602+18b20+ds1302的C程序

sbit LCD1602_E=P1^2;

sbit LCD1602_Busy=P0^7;

/***********************************************************************

//定义LCD1602指令集

************************************************************************/

#define CMD_clear 0x01 //清除屏幕

#define CMD_back 0x02 //DDRAM回零位

#define CMD_dec1 0x04 //读入后AC指针减一,向左写 #define CMD_add1 0x06 //读入后AC指针加一,向右写 #define CMD_dis_gb1 0x0f //开显示,开光标,开光标闪烁 #define CMD_dis_gb2 0x0e //开显示,开光标,关光标闪烁 #define CMD_dis_gb3 0x0c //开显示,关光标,关光标闪烁 #define CMD_OFF_dis 0x08 //关显示,关光标,关光标闪烁 #define CMD_set82 0x38 //8位总线_2行显示

#define CMD_set81 0x30 //8位总线_1行显示 (上边行) #define CMD_set42 0x28 //4位总线_2行显示

#define CMD_set41 0x20 //4位总线,1行显示(上边行) #define lin_1 0x80 //4位总线,1行显示(上边行) #define lin_2 0xc0 //4位总线,1行显示(上边行)

/***********************************************************

1602+18b20+ds1302的C程序

**************

读LCM忙程序

//LCM1602测忙,若LCD1602处于忙状态,本函数将等待至非忙状态 /*************************************************************************/

void LCD1602_TestBusy()

{

P0=0xff;//设备读状态

LCD1602_RS=0;

LCD1602_RW=1;

LCD1602_E=1;

while(LCD1602_Busy);

LCD1602_E=0;

}

/******************************************************************************

//写指令程序

//想LCD1602写命令,本函数需要一个指令集的入口参数

*******************************************************************************/

void LCD1602_WriteCMD(unsigned char LCD1602_command) {

1602+18b20+ds1302的C程序

LCD1602_TestBusy();

P0=LCD1602_command;

LCD1602_RS=0;

LCD1602_RW=0;

LCD1602_E=1;

LCD1602_E=0;

}

/********************************************************************************

//写数据程序

//向LCD1602写数据//

/********************************************************************************/

void LCD1602_WriteData(unsigned char LCD1602_data)

{

LCD1602_TestBusy();

P0=LCD1602_data;

LCD1602_RS=1;

LCD1602_RW=0;

LCD1602_E=1;

LCD1602_E=0;

}

1602+18b20+ds1302的C程序

*********************************

// 打印字符串程序 // (本函数调用指针函数)

// 向LCM发送一个字符串,长度48字符之内

// 第一行位置 0x00~0x17 第二行位置 0x40~0x57

// 应用举例:print(0x80,"http://www.77cn.com.cn"); //在第一行第一位处从左向右打印 http://www.77cn.com.cn字符串

/********************************************************************************************/

void print(unsigned char a,unsigned char *str){

LCD1602_WriteCMD(a | 0x80);

while(*str != '\0'){

LCD1602_WriteData(*str++);

}

*str = 0;

}

/********************************************************************************************

// 打印单字符程序 //

// 第一行位置 0x00~0x17 第二行位置 0x40~0x57

// 向LCM发送一个字符,以十六进制(0x00)表示

// 应用举例:print(0xc0,0x30); //在第二行第一位处打印字符“0”

1602+18b20+ds1302的C程序

*********************************/

void print2(unsigned char a,unsigned char t){

LCD1602_WriteCMD(a | 0x80);

LCD1602_WriteData(t);

}

/********************************************************************************************

// 定义小汉字 //

// 可写入8个自字义字符,写入后可用其CGRAM 代码直接提取显示。

// 字符定义方法请参考技术手册

/********************************************************************************************/

unsigned char code Xword[]={

0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, //℃,代码 0x00

0x00,0x00,0x00,0x00,0 …… 此处隐藏:5941字,全部文档内容请下载后查看。喜欢就下载吧 ……

1602+18b20+ds1302的程序.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219