基于89C51单片机太阳能水温水位控制系统(6)

2019-03-28 11:13

2002

[4] 杨帮文 新型继电器实用手册[M].北京:北京人民邮电出版社.2004

附 录

单片机与显示器件连接图

系统软件源代码

#include

#include

#define uchar unsigned char

uchar hostmark; uchar idata

sec,min,hr,date,mon,day,year;

uchar idata

uplq,downlq,numm,prelq,xdat,key;

uchar xdata * idata numtab; uchar xdata * idata xmark; uchar idata num1,num2; int tab;

uchar bdata iodat; uchar bdata ddat; sbit iodat7=iodat^7; sbit ddat0=ddat^0;

sbit SCLK=P1^0; sbit IO_DATA=P1^1; sbit RST=P1^2; sbit adRD=P1^3; sbit adWR=P1^4; sbit E=P1^5; sbit DIS=P1^6; sbit RELAY=P1^7;

//****延迟子程序********** yanshi() { int i,j;

for(i=0;i<120;i++) for(j=0;j<120;j++) { ; } }

//显示转换

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

uchar dis_transform(uchar num) {

uchar ac,quotient,play,mid; ac=num%5;

quotient=(num-ac)/5; if(ac>2) quotient++; ac=quotient;

mid=(quotient-ac)/10; play=ac+mid*16; return play; }

//液位显示

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

display() {

DIS=0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_();

P0=dis_transform(prelq); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); DIS=1; }

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

//DS1302读写*******************

ds_read() {

uchar j; iodat=0x00; for(j=8;j>0;j--) { iodat=iodat>>1; iodat7=IO_DATA; _nop_(); SCLK=1; _nop_(); SCLK=0; } }

ds_write(uchar ad) {

uchar i;

ddat=ad;

for(i=8;i>0;i--) { IO_DATA=ddat0; _nop_(); SCLK=1; _nop_(); ddat=ddat>>1; SCLK=0; } }

//读取时间*****

uchar ds_gettime(uchar gadd) {

RST=0; _nop_(); SCLK=0; _nop_(); RST=1;

ds_write(gadd); IO_DATA=1; ds_read(); RST=0;

return iodat; }

//设置时间****

ds_settime(uchar sadd,uchar sdat) {

RST=0; _nop_(); SCLK=0; _nop_(); RST=1;

ds_write(sadd); ds_write(sdat); RST=0; }

//**************************** //********ad转换模块****** ad_start() //启动 {

adWR=0; _nop_(); _nop_();

_nop_(); _nop_(); _nop_(); _nop_(); adWR=1; _nop_(); _nop_(); _nop_(); }

ad_read() //读取 {

P0=0xff; // adWR=0; _nop_(); _nop_(); adRD=0; _nop_(); _nop_(); prelq=P0; _nop_(); _nop_(); adRD=1; adWR=1; }

getalltime() //读所有时间 {

sec=ds_gettime(0x81 ); min=ds_gettime(0x83 ); hr=ds_gettime(0x85 ); date=ds_gettime(0x87 ); mon=ds_gettime(0x89 ); day=ds_gettime(0x8b ); year=ds_gettime(0x8d ); }

//************************ //**************初始化sp_init() {

TMOD=0x22; SCON=0x40; TH1=0xf4; TL1=0xf4; PCON=0x80;

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

IE=0; TR1=1; REN=1; }

port_init() {

adRD=1; adWR=0; E=0; DIS=0; RELAY=1; }

data_init() {

xmark=0x7531; if(*xmark!=0xf0) { xmark=0x0000; *xmark=0; numtab=0x0001; xmark=0x7531; *xmark=0xf0; num1=0; num2=0; }

ad_start(); _nop_(); _nop_(); _nop_(); ad_read(); key=0;

uplq=0x0af; downlq=0x96; getalltime(); }

ds_init() {

if(ds_gettime(0xc1)!=0xaa) {

sec=0x00; min=0x00;

hr=0x00;

date=0x01; mon=0x01; day=0x04; year=0x09; ds_settime(0x90,0xab); ds_settime(0x80,sec); ds_settime(0x82,min); ds_settime(0x84,hr); ds_settime(0x86,date); ds_settime(0x88,mon); ds_settime(0x8a,day); ds_settime(0x8c,year); ds_settime(0xc0,0xaa); } }

main_init() {

port_init(); sp_init(); ds_init(); data_init(); display(); }

//****************************//串口通信******************** uchar receive() //接收 {

int tmp; E=0;

while(!RI); tmp=SBUF; RI=0; E=0;

return tmp; }

send(uchar dd) //发送 {

E=1; _nop_(); _nop_(); _nop_(); _nop_();

*


基于89C51单片机太阳能水温水位控制系统(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:论文5

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

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