#include "stc15.h" //定义51单片机特殊功能寄存器
#include "intrins.h"
#include <iic.h>
#include <ds1302.h>
bit s_flag;
bit k;
bit x;
bit s_flag;
unsigned char modes9=0;
unsigned char modee=0;
unsigned char tim;
unsigned char modes5=0;
unsigned char modes4=0;
unsigned char modes8=0;
unsigned char t=2;
unsigned int ds=20;
unsigned char SMG[10]={0xc0, 0xf9,0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90 };
unsigned char SMG_DOt[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
unsigned int distance;
unsigned char timer[3]={0x01,0x20,0x20};
unsigned char write_ds1302[3]={0x80,0x82,0x84};
unsigned char read_ds1302[3]={0x81,0x83,0x85};
int a[50];
int e=0;
sbit RX=P1^1;
sbit TX=P1^0;
sbit L1 = P0^0;
sbit L2 = P0^1;
sbit L3 = P0^2;
sbit L4 = P0^3;
sbit L5 = P0^4;
sbit L6 = P0^5;
unsigned char max;
unsigned char min;
unsigned char averge;
void show2();
unsigned char num;
unsigned int time_a[10]={0};
unsigned int rb2;
sbit C1=P3^0;
sbit C2=P3^1;
sbit C3=P3^2;
sbit C4=P3^3;
sbit R1=P3^4;
sbit R2=P3^5;
sbit R3=P4^2;
sbit R4=P4^4;
void display();
void find_min();
void find_max();
void find_avg();
void hc573(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;
case 0:P2=(P2&0x1f)|0x00;break;
}
}
void Delay13us() //@12.000MHz
{
unsigned char i;
_nop_();
_nop_();
i = 36;
while (--i);
}
void Save()
{unsigned char i;
for(i=0;i<8;i++)
{ TX=1;
Delay13us();
TX=0;
Delay13us();
}
}
void w_1302()
{ unsigned char i;
Write_Ds1302_Byte(0x8e,0x00);
for(i=0;i<3;i++)
{
Write_Ds1302_Byte(write_ds1302[i] ,timer[i] );
}
Write_Ds1302_Byte(0x8e,0x80);
}
void r_1302()
{ unsigned char i;
for(i=0;i<3;i++)
{
timer[i]= Read_Ds1302_Byte ( read_ds1302[i] );
}
}
void Write_PCF8591(unsigned char dat)
{
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x40);
IIC_WaitAck();
IIC_SendByte(dat);
IIC_WaitAck();
IIC_Stop();
}
void Read_rb2()
{
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x41);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
rb2 = IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
}
void wz(unsigned char pos,unsigned char value)
{
hc573(7);
P0=0xff;
hc573(6);
P0=0x01<<pos;
hc573(7);
P0=value;
hc573(0);
}
void delay(unsigned int t)
{
while(t--);
}
void close()
{hc573(7);
P0=0xff;
hc573(6);
P0=0xff;
}
void show1()
{
wz(0,SMG[ timer[2]/16]);
delay(500);
wz(1,SMG[ timer[2]%16]);
delay(500);
wz(2,0xbf);
delay(500);
wz(3,SMG[ timer[1]/16]);
delay(500);
wz(4,SMG[ timer[1]%16]);
delay(500);
wz(5,0xbf);
delay(500);
wz(6,SMG[ timer[0]/16]);
delay(500);
wz(7,SMG[ timer[0]%16]);
delay(500);
close();
}
void show2()
{
wz(0,0xc7);
delay(500);
wz(1,0xC6);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
wz(4,0xff);
delay(500);
if(distance>100)
{wz(5,SMG[distance/100]);
delay(500);}
if(distance>10)
{wz(6,SMG[(distance/10)%10]);
delay(500);}
wz(7,SMG[distance%10]);
delay(500);
close();
}
void isr_timer_0(void) interrupt 1 //默认中断优先级 1
{
static unsigned int intr = 0;
TH0 = (65536-2000)/256;
TL0 = (65536-2000)%256; //定时器重载
if(++intr == 200)
{
s_flag = 1;
intr = 0;
}
}
void show3()
{
wz(0,0xc7);
delay(500);
wz(1,0x8e);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
wz(4,0xff);
delay(500);
if(distance>100)
{wz(5,SMG[distance/10]);
delay(500);}
if(distance>10)
{wz(6,SMG[(distance/10)%10]);
delay(500);}
wz(7,SMG[distance%10]);
delay(500);
close();
}
void show4()
{find_max();
wz(0,0x89);
delay(500);
wz(1,0xfe);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
if(max>1000)
{
wz(4,SMG[max/1000]);
delay(500);
}
if(max>100)
{
wz(5,SMG[(max/100)%10]);
delay(500);
}
if(max>10)
{
wz(6,SMG[max/10]);
delay(500);
}
wz(7,SMG[max%10]);
delay(500);
close();
}
void show5()
{
find_avg();
wz(0,0x89);
delay(500);
wz(1,0xbf);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
if(averge>1000)
{
wz(4,SMG[averge/100]);
delay(500);
}
if(averge>100)
{
wz(5,SMG[(averge/100)%10]);
delay(500);
}
wz(6 ,SMG_DOt[(averge/10)%10]);
delay(500);
wz(7,SMG[averge%10]);
delay(500);
close();
}
void show6()
{find_min();
wz(0,0x89);
delay(500);
wz(1,0xf7);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
if(min>1000)
//{
wz(4,SMG[min/1000]);
delay(500);//}
//if(min>100)
//{
wz(5,SMG[(min/100)%10]);
delay(500);
//}
//if(min>10)
//{
wz(6,SMG[(min/10)]);
delay(500);//}
wz(7,SMG[min%10]);
delay(500);
close();
}
void show7()
{
wz(0,0x8c);
delay(500);
wz(1,0xf9);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
wz(4,0xff);
delay(500);
wz(5,0xff);
delay(500);
wz(6,SMG[ t/10]);
delay(500);
wz(7,SMG[ t%10]);
delay(500);
close();
}
void show8()
{
wz(0,0x8c);
delay(500);
wz(1,0xa4);
delay(500);
wz(2,0xff);
delay(500);
wz(3,0xff);
delay(500);
wz(4,0xff);
delay(500);
wz(5,0xff);
delay(500);
wz(6,SMG[ ds/10]);
delay(500);
wz(7,SMG[ ds%10]);
delay(500);
close();
}
void display()
{
if(modes4==0)
{if(modes5==0)
{
show1();
}
else if(modes5==1)
{ if(x==0)
{show2();modee=0;}
else if(x==1)
{show3();modee=1;}
}
else if(modes5==2)
{
if(modes8==0)
show4();
else if(modes8==1)
show6();
else if(modes8==2)
show5();
}
}
else if(modes4==1)
{
if(k==0)
show7();
else if(k==1)
show8();
}
}
void key()
{C4=0;
C1=C2=C3=1;
R1=R2=R3=R4=1;
if(R4==0)
{
delay(100);
if(R4==0)
{while(R4==0)
{display();}
if(modes4==0)
modes4=1;
else if(modes4==1)
{modes4=0;}
}
}
C3=0;
C1=C2=C4=1;
R1=R2=R3=R4=1;
if(R4==0)
{
delay(100);
if(R4==0)
{while(R4==0)
{display();}
if(modes5==0)
modes5=1;
else if(modes5==1)
{modes5=2;}
else if(modes5==2)
modes5=0;
k=~k;
}
}
C4=0;
C1=C2=C3=1;
R1=R2=R3=R4=1;
if(R3==0)
{
delay(100);
if(R3==0)
{while(R3==0)
{display();}
if(modes8==0)
modes8=1;
else if(modes8==1)
modes8=2;
else if(modes8==2)
modes8=0;
if(modes5==1)
x=~x;
}
}
C3=0;
C1=C2=C4=1;
R1=R2=R3=R4=1;
if(R3==0)
{
delay(100);
if(R3==0)
{while(R3==0)
{display();}
if(modes4==1)
{if(k==0)
{if(modes9==0)
{t=2,modes9=1;}
else if(modes9==1)
{t=3,modes9=2;}
else if(modes9==2)
{t=5,modes9=3;}
else if(modes9==3)
{t=7,modes9=4;}
else if(modes9==4)
{t=9,modes9=0;}
}
else if(k==1)
{if(modes9==0)
{ds=10,modes9=1;}
else if(modes9==1)
{ds=20,modes9=2;}
else if(modes9==2)
{ds=30,modes9=3;}
else if(modes9==3)
{ds=40,modes9=4;}
else if(modes9==4)
{ds=50,modes9=5;}
else if(modes9==5)
{ds=60,modes9=6;}
else if(modes9==6)
{ds=70,modes9=7;}
else if(modes9==7)
{ds=80,modes9=0;}
}
}
}
}
}
void da()
{
if(distance<=10)
Write_PCF8591(51);
else if(distance<=80)
Write_PCF8591((4/70.0*distance+3/7.0)/5.0*255);
else
Write_PCF8591(255);
}
void csb()
{unsigned int time = 0;
if(s_flag)
{
s_flag = 0;
Save();
TR1 = 1;
while((RX == 1) && (TF1 == 0));
TR1 = 0;
if(TF1 == 1)
{
TF1 = 0;
distance = 999;
}
else
{
time = TH1;
time <<= 8;
time |= TL1;
distance = (unsigned int)(time*0.017);
a[e]=distance;
e++;
}
TH1 = 0;
T
m0_68581441
- 粉丝: 7
- 资源: 5
最新资源
- 微信小程序源码-基于移动平台的远程在线诊疗系统-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-绘画学习平台-微信端-毕业设计源码-期末大作业.zip
- java实习心得体会ppt
- 微信小程序源码-计算机实验室排课与查询系统-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-计算机实验室排课与查询系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-基于移动平台的远程在线诊疗系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-家政服务管理系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-家政服务管理系统-服务端-毕业设计源码-期末大作业.zip
- 微信小程序源码-家政项目小程序-服务端-毕业设计源码-期末大作业.zip
- java试用期转正工作总结
- MinGW环境下编译CEF库基于102最后一个稳定版本编译,已经修改过camke文件和部分代码,可以直接编译(MinGW 6.4,cmake 3.31)
- 微信小程序源码-家政项目小程序-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-健身房私教预约系统-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-健身房私教预约系统-服务端-毕业设计源码-期末大作业.zip
- FPGA Verilog AD7606驱动代码,包含SPI模式读取和并行模式读取两种,代码注释详细
- 微信小程序源码-考研论坛设计-服务端-毕业设计源码-期末大作业.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈