DS18B20的读取,可以直接写在总线的c程序中。读取小数该如何处理,单总线底层文件延时的改写 *4 ,最后一个延时 为70-100
矩阵键盘的使用:按键按下进行变量的赋值处理,也要进行消抖处理(独立按键也一样)矩阵键盘赋值 从高到低赋值
iic总线:dac的采集(0x43),光敏电阻(0X01),电位器(0x03),24c02的 (0xa0,0xa1)书写 都可以直接放在iic中
dac采集 直接放入数据进去 ,0-255 对应的是0-5;自己给电压显示 dac输出的电压为自己给的*51
数码管显示小数,另外创建一个显示函数,P0的断码&0x7f
界面显示函数:利用switch语句来实现,创建变量来实现,利用变量的加减来实现,
#include <STC15F2K60S2.H>
#include "onewire.h"
#include "iic.h"
#define uint unsigned int
#define uchar unsigned char
sbit L1=P3^0;
sbit L2=P3^1;
sbit L3=P3^2;
sbit L4=P3^3;
sbit C1=P3^4;
sbit C2=P3^5;
sbit C3=P4^2;
sbit C4=P4^4;
unsigned char code SMG_NoDot[18] ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e
,0xb6,0x86};
uint date1; //温度
uint dat2;
uchar state,num1;
uchar a=25;
bit mode=0;
void xz(unsigned char n)
{
switch(n)
{
case 4: P2=(P2&0x1f)|0x80;
break;
case 5: P2=(P2&0x1f)|0xa0;
break;
case 6: P2=(P2&0x1f)|0xc0;
break;
case 7: P2=(P2&0x1f)|0xe0;
break;
}
}
void smg_bite(unsigned char pos,date)
{
xz(6);
P0=0x01<<pos;
xz(7);
P0= SMG_NoDot[date];
}
void smg_all()
{
xz(6);
P0=0x00;
xz(7);
P0=0xff;
}
void smgfloat(unsigned char pos,date)
{
xz(6);
P0=0x01<<pos;
xz(7);
P0= SMG_NoDot[date]&0x7f;
}
void delay(uint i)
{
while(i--);
}
void key()
{
L4=0;
L2=L3=L1=1;
C1=C2=C3=C4=1;
if(C4==0)
{
num1=4;
}while(C4==0);
if(C3==0)
{
num1=8;
}while(C3==0);
if(C2==0)
{
num1=12;
}while(C2==0);
if(C1==0)
{
num1=16;
}while(C1==0);
L3=0;
L2=L4=L1=1;
C1=C2=C3=C4=1;
if(C4==0)
{
num1=5;
}while(C4==0);
if(C3==0)
{
num1=9;
}while(C3==0);
if(C2==0)
{
num1=13;
}while(C2==0);
if(C1==0)
{
num1=17;
}while(C1==0);
L2=0;
L3=L4=L1=1;
C1=C2=C3=C4=1;
if(C4==0)
{
num1=6;
}while(C4==0);
if(C3==0)
{
num1=10;
}while(C3==0);
if(C2==0)
{
num1=14;
}while(C2==0);
if(C1==0)
{
num1=18;
}while(C1==0);
L1=0;
L2=L4=L3=1;
C1=C2=C3=C4=1;
if(C4==0)
{
num1=7;
}while(C4==0);
if(C3==0)
{
num1=11;
}while(C3==0);
if(C2==0)
{
num1=15;
}while(C2==0);
if(C1==0)
{
num1=19;
}while(C1==0);
}
void xswd()
{
date1= wendu();
smg_bite(0,19);
delay(500);
smg_bite(4,date1/1000);
delay(500);
smgfloat(5,date1%1000/100);
delay(500);
smg_bite(6,(date1%100)/10);
delay(500);
smg_bite(7, date1%10);
delay(500);
smg_all();
}
void xsdac()
{
uchar t;
date1=wendu();
if(mode==1)
{
if(date1<a*100)
{
DAC(0);
smgfloat(5,0);
delay(500);
smg_bite(6,0);
delay(500);
smg_bite(7,0);
delay(500);
smg_all();
}
else if(date1>a*100)
{
DAC(255);
smgfloat(5,5);
delay(500);
smg_bite(6,0);
delay(500);
smg_bite(7,0);
delay(500);
smg_all();
}
}
else if(mode==0)
{
if(date1<=2000)
{
DAC(51);
smgfloat(5,1);
delay(500);
smg_bite(6,0);
delay(500);
smg_bite(7,0);
delay(500);
smg_all();
}
else if(date1>=4000)
{
DAC(204);
smgfloat(5,4);
delay(500);
smg_bite(6,0);
delay(500);
smg_bite(7,0);
delay(500);
smg_all();
}
else if(date1>2000 && date1<4000)
{
t=0.0015*date1-2;
DAC(t*51);
smgfloat(5,t/100);
delay(500);
smg_bite(6,(t%100)/10);
delay(500);
smg_bite(7,t%10);
delay(500);
smg_all();
}
}
}
void cssz()
{
smg_bite(0,18);
delay(500);
smg_bite(6,a/10);
delay(500);
smg_bite(7,a%10);
delay(500);
smg_all();
}
void keypro()
{
if(num1==4)
{
state++;
if(state==3)
{
state=0;
}
}
if(num1==8&& state==1)
{
a--;
}
if(num1==9&& state==1)
{
a++;
}
if(num1==5)
{
mode=~mode;
}
num1=0;
}
void xsgn()
{
switch(state)
{
case 0:xswd();break;
case 1:cssz();break;
case 2:xsdac();break;
}
}
void led()
{
xz(4);
if(state==0&&mode==1)
{
P0=0xfe;
}
if(state==0)
{
P0=0xfd;
}
if(state==1)
{
P0=0xfb;
}
if(state==2)
{
P0=0xf7;
}
}
void main()
{
while(1)
{
key();
keypro();
xsgn();
led();
}
}