亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
1602 18b20 1302單片機驅動程序
[打印本頁]
作者:
Qaz461
時間:
2017-10-17 20:06
標題:
1602 18b20 1302單片機驅動程序
分享一個1602 18b20 1302驅動
單片機源程序如下:
#include<reg52.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit TSCIK=P1^0;
sbit TI0=P1^1;
sbit TRST=P1^2;
sbit RS=P3^5;
sbit RW=P3^6;
sbit EN=P3^4;
sbit DS=P2^2;
void delay_us(uchar us)
{
while(us--);
}
void read_1602busy()//判斷液晶忙不忙
{
uchar busy;
P0=0xff;
RS=0;
RW=1;
do
{
EN=1;
busy=P0;
EN=0;
}while(busy&0x80);
}
void write_1602cmd(uchar cmd)//對1602寫命令
{
read_1602busy();
RS=0;
RW=0;
P0=cmd;
EN=1;
EN=0;
}
void write_1602dat(uchar dat)//對1602寫數據
{
read_1602busy();
RS=1;
RW=0;
P0=dat;
EN=1;
EN=0;
}
/********************************************/
/*函數名稱:顯示字符串*/
/*函數功能:在指定位置顯示一個字符串*/
/*輸入:x要顯示的橫坐標取值0-40,y要顯示的縱坐標取值0-1
,*str:需要顯示的字符串*/
void dis_1602str(uchar x,uchar y,uchar *str)
{
if(y) x|=0x40;
x|=0x80;
while(*str!='\0')
{
write_1602dat(*str++);
}
}
/*******************************************/
/*函數名稱:顯示字符*/
/*函數功能:在指定位置顯示一個字符*/
/*輸入:x要顯示的橫坐標取值0-40,y要顯示的縱坐標取值0-1
,dat:需要顯示的數據已ASCLL形式*/
void dis_1602onechar(uchar x,uchar y,uchar dat)
{
if(y) x|=0x40;
x|=0x80;
write_1602cmd(x);
write_1602dat(dat);
}
void init_1602()//1602初始化
{
write_1602cmd(0x38);//16*2顯示
write_1602cmd(0x0c);//開顯示
write_1602cmd(0x06);//讀一個字節后指針加一
write_1602cmd(0x01);//清除顯示/
}
void write_ds1302_dat(uchar cmd,uchar dat)//寫ds1302數據
{
uchar i;
TRST=0; //拉低使能端
TSCIK=0; //拉低數據總線
TRST=1; //拉高使能端,產生上升沿
for(i=0;i<8;i++) //每次寫一位,寫八次
{
TSCIK=0;
TI0=cmd&0x01;
TSCIK=1;
cmd>>=1;
}
for(i=0;i<8;i++)
{
TSCIK=0;
TI0=dat&0x01;
TSCIK=1;
dat>>=1;
}
}
uchar read_ds1302_dat(uchar cmd)//讀ds1302數據
{
uchar i,dat;
TRST=0;
TSCIK=0;
TRST=1;
for(i=0;i<8;i++)
{
TSCIK=0;
TI0=cmd&0x01;
TSCIK=1;
cmd>>=1;
}
for(i=0;i<8;i++)
{
TSCIK=0;
dat>>=1;
if(TI0) dat|=0x80;
TSCIK=1;
}
return dat;
}
uchar dat_to_bcd(uchar dat)//數據轉bcd碼
{
uchar dat1,dat2;
dat1=dat/10;
dat2=dat%10;
dat2=dat2+dat1*16;
return dat2;
}
uchar bcd_to_dat(uchar dat)//bcd碼轉數據
{
uchar dat1,dat2;
dat1=dat/16;
dat2=dat%16;
dat2=dat2+dat1*10;
return dat2;
}
bit ds18b20_init()//da18b20初始化
{
bit i;
DS=1;
_nop_();
DS=0;
delay_us(75);
DS=1;
delay_us(4);
i=DS;
delay_us(20);
DS=1;
_nop_();
return(i);
}
void write_byte18b20(uchar dat)//ds18b20寫數據
{
uchar i;
for(i=0;i<8;i++)
{
DS=0;
_nop_();
DS=dat&0x01;
delay_us(10);
DS=1;
_nop_();
dat>>=1;
}
}
uchar read_byte18b20()//ds188b20讀數據
{
uchar i,j,dat;
for(i=0;i<8;i++)
{
DS=0;
_nop_();
DS=1;
_nop_();
j=DS;
delay_us(10);
DS=1;
_nop_();
dat=(j<<7|(dat>>1));
}
return(dat);
}
/**************************/
/***函數功能:獲得溫度(三位數無小數點)***/
uint get_tmp()
{
uchar L,M;
uint i;
ds18b20_init();
write_byte18b20(0xcc);//發送跳躍ROM指令
write_byte18b20(0x44);//發送溫度轉換指令
ds18b20_init();
write_byte18b20(0xcc);
write_byte18b20(0xbe);
L=read_byte18b20();
M=read_byte18b20();
i=M;
i<<=8;
i|=L;
i=i*0.0625*10+0.5;//讀取正溫度值
return(i);
}
void main()
{
uchar sec,min,hour,secshi,secge,minshi,minge,hourshi,hourge,ge,shi,bai,k;
uint i;
write_ds1302_dat(0x8e,0);
write_ds1302_dat(0x80,dat_to_bcd(00));//對秒寫數據
write_ds1302_dat(0x82,dat_to_bcd(02));//對分寫數據
write_ds1302_dat(0x84,dat_to_bcd(17));//對時寫數據
write_ds1302_dat(0x8e,0x80);
init_1602();
while(1)
{
write_ds1302_dat(0x8e,0);
sec= bcd_to_dat(read_ds1302_dat(0x81));//秒
min= bcd_to_dat(read_ds1302_dat(0x83));//分
hour=bcd_to_dat(read_ds1302_dat(0x85));//時
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
lcd1602,ds18b20,ds1302驅動.doc
(4.41 KB, 下載次數: 5)
2017-10-17 20:05 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1