资源描述:
《时钟温度程序和原理图.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*:功能1602时钟和18B20温度/*作者:斌彬/*时间:2012年9月22日20:22:37*/#include//包含52单片机头文件#include"18b20.h"#include#defineucharunsignedchar#defineuintunsignedint#defineN64#definePortP0sbitRS=P2^4;//定义液晶RS端sbitRW=P2^5;sbitLCDEN=P2^6;//定义液晶LCDEN端sbits1=P1^1;//定义功能键sbits2=P1^2;//定义增加键sbits3=P1^3;//定义减小键
2、sbitBE=P1^4;ucharidataCGCODE[]={0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02,//"年"代码0x000x0F,0x09,0x0F,0x09,0x0F,0x09,0x13,0x00,//"月"代码0x010x0F,0x09,0x09,0x0F,0x09,0x09,0x0F,0x00,//"日"代码0x020x01,0x06,0x1C,0x04,0x1F,0x0E,0x15,0x04,//“秒“的右部”禾“0x030x04,0x06,0x07,0x0D,0x14,0x06,0x0C,0x18,//”秒“的左部"少"0x040x10,
3、0x06,0x09,0x08,0x08,0x09,0x06,0x00,//“℃”0x050x07,0x14,0x07,0x14,0x07,0x10,0x07,0x05,//温度0x060x1E,0x02,0x1E,0x02,0x1E,0x00,0x1C,0x14//0x07};//写字符//uchartab1[3]={0};//显示温度//uchartab2[7]={2,2,':',4,4,0,0};//当前时间ucharidatacount,count1,s1_num;//时间计数器和合功能键的位移charsecond,shi,minute,year,month,day;ucharcodet
4、able[7]="TEMP12";//两千年的前缀ucharidatatemp1[]="TEMP";charidatadisplaytemp[5];//定义显示区域临时存储数组/*----------------------/延时函数/----------------------*/voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}/*----------------------/写命令/----------------------*/voidLCD_Write_Com(ucharcom){RS=0;LCDEN=0;Por
5、t=com;delay(5);LCDEN=1;delay(5);LCDEN=0;}/*----------------------/写数据/----------------------*/voidLCD_Write_Data(uchardate){RS=1;LCDEN=0;Port=date;delay(5);LCDEN=1;delay(5);LCDEN=0;}/*----------------------/写自定义字符/----------------------*/voidDDRAM(){inti,j;LCD_Write_Com(0x40);for(i=0;i6、ite_Data(CGCODE[i]);}}/*----------------------/函数功能:写字符串说明:line为选择的行position为选择的位置*s为字符串的首地址/----------------------*/voidLCD_Write_String(ucharline,ucharposition,uchar*s){if(line==1){LCD_Write_Com(0x80+position);//表示第一行}if(line==2){LCD_Write_Com(0xC0+position);//表示第二行}while(*s){LCD_Write_Data(*s);//
7、传递首地址s++;}}/*----------------------/向第二行某地址写数据把时间分解成两位/----------------------*/voidwrite_sfm(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date%10;LCD_Write_Com(0xc0+add);LCD_Write_Data(0x30+shi);//0