protues单片机各子程序模块Word文件下载.docx

上传人:b****5 文档编号:17376765 上传时间:2022-12-01 格式:DOCX 页数:20 大小:18.31KB
下载 相关 举报
protues单片机各子程序模块Word文件下载.docx_第1页
第1页 / 共20页
protues单片机各子程序模块Word文件下载.docx_第2页
第2页 / 共20页
protues单片机各子程序模块Word文件下载.docx_第3页
第3页 / 共20页
protues单片机各子程序模块Word文件下载.docx_第4页
第4页 / 共20页
protues单片机各子程序模块Word文件下载.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

protues单片机各子程序模块Word文件下载.docx

《protues单片机各子程序模块Word文件下载.docx》由会员分享,可在线阅读,更多相关《protues单片机各子程序模块Word文件下载.docx(20页珍藏版)》请在冰豆网上搜索。

protues单片机各子程序模块Word文件下载.docx

#defineuintunsignedint

sbitDQ=P2^7;

//定义

uchartemp0,temp1,i;

//温度转换的低位和高位

voiddelay1(ucharn)//n为1时大概6.9us

while(n--);

ucharInit_DS18B20()//初始化

ucharm;

DQ=0;

delay1(100);

DQ=1;

delay1(4);

m=DQ;

delay1(40);

returnm;

ucharread_byte()//读字节

uchari,n;

for(i=0;

i<

8;

i++)

{

DQ=0;

n>

>

=1;

DQ=1;

if(DQ)n|=0x80;

delay1(10);

}

returnn;

voidwrite_byte(uchark)//写字节

uchari;

DQ=k&

0x01;

k>

voidread_temp()//读取温度

Init_DS18B20();

write_byte(0xcc);

write_byte(0xbe);

temp0=read_byte();

temp1=read_byte();

write_byte(0x44);

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

温度显示

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

voiddisplay()

ucharaa,cc,k,i=0;

k=temp_value[1]&

0xf8;

//与以后是否为负数

if(k==0xf8)//假如为负数

{

temp_value[1]=~temp_value[1];

//高位取反

temp_value[0]=~temp_value[0]+1;

//低位取反加1

DSY_CODE2[7]='

-'

;

//显示负号

if(temp_value[0]==0){temp_value[1]=~temp_value[1]+1;

}//低位为0时高位取反加1

}

else

'

cc=(temp_value[0]>

4)|((temp_value[1])<

<

4);

//cc为整数

aa=(temp_value[0]&

0x0f)*10/16;

//aa为小数*10

disbuffer[0]=cc/10;

disbuffer[1]=cc%10;

disbuffer[2]=aa;

DSY_CODE2[8]=disbuffer[0]+'

0'

DSY_CODE2[9]=disbuffer[1]+'

DSY_CODE2[10]='

.'

DSY_CODE2[11]=disbuffer[2]+'

DSY_CODE2[13]='

C'

write_com(0x80);

for(i=0;

16;

write_data(DSY_CODE1[i]);

write_com(0x80+0x40);

write_data(DSY_CODE2[i]);

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

多点测温程序

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

#include<

reg52.h>

#include<

intrins.h>

lcd1602.h>

ucharSN[8][8]={

{0x28,0x30,0xc5,0xb8,0x00,0x00,0x00,0x8e},

{0x28,0x31,0xc5,0xb8,0x00,0x00,0x00,0xb9},

{0x28,0x32,0xc5,0xb8,0x00,0x00,0x00,0xe0},

{0x28,0x33,0xc5,0xb8,0x00,0x00,0x00,0xd7},

{0x28,0x34,0xc5,0xb8,0x00,0x00,0x00,0x52},

{0x28,0x35,0xc5,0xb8,0x00,0x00,0x00,0x65},

{0x28,0x36,0xc5,0xb8,0x00,0x00,0x00,0x3c},

{0x28,0x37,0xc5,0xb8,0x00,0x00,0x00,0x0b}

};

ucharcodeDSY_CODE1[]={"

CurrentTemp:

"

};

ucharDSY_CODE2[]={"

TEMP:

sbitDQ=P1^0;

uchartemp_value[]={0x00,0x00};

uchardisbuffer[]={0,0,0};

ucharnum;

voiddelay1(ucharn)//n=1时大概延时6.9us

ucharow_DS18B20()//DS18B20复位

ucharm;

delay1(100);

delay1(4);

m=DQ;

delay1(40);

returnm;

ucharread_byte()//读取字节

ucharn=0;

n>

if(DQ)

n|=0x80;

delay1(10);

return(n);

k>

voidread_temp()//读温度

uchari,j;

ucharaa,cc,k;

for(j=0;

j<

j++)

ow_DS18B20();

delay

(1);

write_byte(0x55);

write_byte(SN[j][i]);

write_byte(0xbe);

temp_value[0]=read_byte();

temp_value[1]=read_byte();

voidmain()

init();

ow_DS18B20();

read_temp();

delay(40);

while

(1)

ADC0832获取AD转换结果(模数转换电压)

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

//ADC0832端口定义

sbitCS=P1^0;

sbitCLK=P1^1;

sbitDIO=P1^2;

ucharget_adc()//获得的结果就是k=get_adc();

unsignedchari,dat;

CS=1;

CLK=0;

CS=0;

DIO=1;

CLK=1;

CLK=0;

DIO=0;

i++)

CLK=1;

dat<

dat|=(unsignedchar)DIO;

}

returndat;

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

DS1302数字时钟

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

uchardisbuffer[7];

sbitIO=P1^0;

sbitSCLK=P1^1;

sbitRST=P1^2;

voidwrite_byte(ucharx)//写入一字节

IO=x&

SCLK=1;

SCLK=0;

x>

ucharread_byte()//读取一字节

uchari,b=0x00;

b|=_crol_((uchar)IO,i);

return(b/16*10+b%16);

ucharread_data(ucharaddr)//在指定地址读数据

uchardat;

RST=0;

SCLK=0;

RST=1;

write_byte(addr);

dat=read_byte();

SCLK=1;

voidget_time()//读取时间

uchari,addr=0x81;

7;

disbuffer[i]=read_data(addr);

//声明:

disbuffer[0]是秒的值

addr+=2;

//disbuffer[1]是分

}//disbuffer[0~6]秒,分,时,日,星期,月,年

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

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

时钟显示部分

ucharLCD_DSY1[]={"

DATE00-00-00"

//日期

ucharLCD_DSY2[]={"

TIME00:

00:

00"

//时间

get_time();

LCD_DSY2[12]=disbuffer[0]%10+'

LCD_DSY2[11]=disbuffer[0]/10+'

//秒低位,秒高位

LCD_DSY2[9]=disbuffer[1]%10+'

LCD_DSY2[8]=disbuffer[1]/10+'

//分

LCD_DSY2[6]=disbuffer[2]%10+'

LCD_DSY2[5]=disbuffer[2]/10+'

//时

LCD_DSY1[12]=disbuffer[3]%10+'

LCD_DSY1[11]=disbuffer[3]/10+'

//日

//disbuffer[5]是星期

LCD_DSY1[9]=disbuffer[4]%10+'

LCD_DSY1[8]=disbuffer[4]/10+'

//月

LCD_DSY1[6]=disbuffer[6]%10+'

LCD_DSY1[5]=disbuffer[6]/10+'

//年

LCD_write_com(0x80);

LCD_write_data(LCD_DSY1[i]);

LCD_write_com(0x80+0x40);

LCD_write_data(LCD_DSY2[i]);

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

4*4矩阵键盘Keyboard

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

voidkeyboard()//键盘扫描

{

uchara,b;

P1=0x0f;

delay

(2);

a=P0;

if(a!

=0xf0)

delay(10);

b=P1^0x0f;

//屏蔽高四位

switch(b)//先去确定行

case1:

c=0;

break;

//第一列

case2:

c=1;

case4:

c=2;

case8:

c=3;

default:

c=16;

P1=0xf0;

b=P1>

4^0x0f;

switch(b)//先去确定列

c=c+0;

//第一行

c=c+4;

c=c+8;

c=c+12;

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

LCD12864相关程序

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

#definedisp_Off0x3e//关显示

#definedisp_On0x3f//开显示

#definePage_Add0xb8//页地址

#defineCol_Add0x40//列地址

#defineStart_Line0xc0//行地址

sbitRS=P2^0;

sbitRW=P2^1;

sbitE=P2^2;

sbitCS1=P2^3;

sbitCS2=P2^4;

sbitRST=P2^5;

ucharcodewenzi[][32];

//文字字模的定义

ucharcodeshuzi[][16];

//数字字摸的定义

bitLCD_busy()//检查忙位

P0=0xff;

RW=1;

return(bit)(P0&

0x80);

voidLCD_write_com(ucharcom)//写命令到LCD

LCD_busy();

voidLCD_write_data(uchardate)//写数据到LCD

voidLCD_Reset()//初始化LCD屏

CS1=1;

CS2=1;

LCD_write_com(0x0f);

LCD_write_com(Start_Line);

voidCLR_12864()//清屏

ucharj,k;

CS1=0;

CS2=0;

LCD_write_com(Page_Add+0);

LCD_write_com(Col_Add+0);

for(k=0;

k<

k++)

LCD_write_com(Page_Add+k);

for(j=0;

64;

LCD_write_com(Col_Add+j);

LCD_write_data(0x00);

voiddisplay_a_char(ucharp,ucharl,ucharn)//显示数字8*16的数字//第P行第L位显示M

2;

LCD_write_com(Page_Add+p+j);

LCD_write_com(Col_Add+l);

LCD_write_data(shuzi[n][8*j+i]);

//shuzi为需要的数字

voiddisplay_a_word(ucharp,ucharl,ucharn)//显示数字16*16的汉字

LCD_write_data(wenzi[n][16*j+i]);

//wenzi为需要的数字

voiddisp_img(ucharcode*img)//显示12864图片不需图片时可以不要

CS2=1;

CS1=0;

LCD_write_com(Col_Add+0);

j++)

LCD_write_data(img[k*128+j]);

CS2=0;

CS1=1;

for(j=64;

128;

LCD_write_data(img[k*128+j

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1