数字温度计
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit DS=P2^4;
- uint temp;
- int tempnew;
- uchar a,b,test;
- char num,temphigh=35,templow=1;
- uchar code s7_table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x39,0x40};
- uchar code s7_table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
- uchar weishidisplay[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- uchar wendu[7];
- uchar wendu0[3];
- void shuzu();
- void display();
- void displaynew();
- void dsreset(void);
- void tmpchange(void);
- void tmpwritebyte(uchar dat);
- void delay(uint count)
- {
- uint i;
- while(count)
- {
- i=200;
- while(i>0)
- i--;
- count--;
- }
- }
- void dsreset(void)
- {
- uint i;
- DS=0;
- i=103;
- while(i>0)i--;
- DS=1;
- i=4;
- while(i>0)i--;
- }
- bit tmpreadbit(void)
- {
- uint i;
- bit dat;
- DS=0;i++;
- DS=1;i++;i++;
- dat=DS;
- i=8;
- while(i>0) i--;
- return(dat);
- }
- uchar tmpread(void)
- {
- uchar i,j,dat;
- dat=0;
- for(i=1;i<=8;i++)
- {
- j=tmpreadbit();
- dat=(j<<7)|(dat>>1);
- }
- return(dat);
- }
- void tmpwritebyte(uchar dat)
- {
- uint i;
- uchar j;
- bit testb;
- for(j=1;j<=8;j++)
- {
- testb=dat&0x01;
- dat=dat>>1;
- if(testb)
- {
- DS=0;
- i++;i++;
- DS=1;
- i=8;
- while(i>0) i--;
- }
- else
- {
- DS=0;
- i=8;
- while(i>0) i--;
- DS=1;
- i++;i++;
- }
- }
- }
- void tmpchange(void)
- {
- dsreset();
- delay(1);
- tmpwritebyte(0xcc);
- tmpwritebyte(0x44);
- }
- void tmp()
- {
- float tt;
- uchar a,b;
- dsreset();
- delay(1);
- tmpwritebyte(0xcc);
- tmpwritebyte(0xbe);
- a=tmpread();
- b=tmpread();
- temp=b;
- temp<<=8;
- temp=temp|a;
- if(temp<= 0x0fff)
- {
- test=0;
- tt=temp*0.0625;
- tempnew=tt*100;
- }
- else
- {
- temp=~temp+1;
- tt=temp*0.0625;
- tempnew=tt*100;
- test=1;
- }
- }
- void shuzu()
- {
- uchar i,j;
- wendu0[0]=tempnew/100/100;
- wendu0[1]=tempnew/100%100;
- wendu0[2]=tempnew%100;
- for(i=0,j=0;j<3;j++,i+=2)
- {
- wendu[i]=wendu0[j]/10;
- wendu[i+1]=wendu0[j]%10;
- }wendu[6]=10;
- }
- void display(uchar n)
- {
- uchar i,j;
- shuzu();
- for(j=0;j<=10;j++)
- {
- for(i=n;i<=6;i++)
- {if(i==3||i==3)
- {
- P0=0x00;
- P3=0xff;
- P3=weishidisplay[i-1];
- P0=P0=s7_table1[wendu[i]];
- delay(1);
- }
- else if(i==5) {
- P0=0x00;
- P3=0xff;
- P3=weishidisplay[i-1];
- P0=P0=0x63;
- delay(1);
- }
- else
- {
- P0=0x00;
- P3=0xff;
- P3=weishidisplay[i-1];
- P0=P0=s7_table[wendu[i]];
- delay(1);
- if(test==1)
- {
- P0=0x00;
- P3=0xff;
- P3=weishidisplay[0];
- P0=P0=s7_table[11];
- delay(1);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
数字温度计.rar
(64.12 KB, 下载次数: 27)
|