全部文件:提取码:azxy
#include "STC15F2K60S2.h"
#include "intrins.h"
#include "iic.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
u8 code duan[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
u8 model=1;
u8 stat=1;
u8 led_flag=0;
u8 smg_flag=0;
u16 Hz=0;
u16 Rb2_V=0;
u16 pl=0;
u8 count=0;
void delay(u16 i)
{
while(i--);
}
void Timer0Init(void)
{
TMOD = 0x16;
TL0 = 0xff;
TH0 = 0xff;
TL1 = (65535-5000+1)/256;
TH1 = (65535-5000+1)%256;
TR0 = 1;
TR1 = 1;
ET0 = 1;
ET1 = 1;
EA = 1;
}
void Service_T0() interrupt 1
{
pl++;
}
void Service_T1() interrupt 3
{
TL1=(65535-5000+1)/256;
TH1=(65535-5000+1)%256;
count++;
if(count==200)
{
Hz=pl;
pl=0;
count=0;
}
}
void Chan_hc573(chose)
{
switch(chose)
{
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 Init_system()
{
Chan_hc573(5);
P0=0x00;
Chan_hc573(4);
P0=0xff;
}
void Smg_display(u8 com,u8 dat)
{
Chan_hc573(7);
P0=0xff;
Chan_hc573(6);
P0=0x01<<com;
Chan_hc573(7);
P0=dat;
}
void Close_smg()
{
Chan_hc573(6);
P0=0x00;
Chan_hc573(7);
P0=0xff;
}
void Display_F_U()
{
if(model==2)
{
Smg_display(0,0x8e); delay(1000);
Smg_display(1,duan[10]); delay(1000);
if(Hz>99999)
{
Smg_display(2,duan[Hz/10000]); delay(1000);
}
if(Hz>9999)
{
Smg_display(3,duan[(Hz/10000)%10]); delay(1000);
}
if(Hz>999)
{
Smg_display(4,duan[(Hz/1000)%10]); delay(1000);
}
if(Hz>99)
{
Smg_display(5,duan[(Hz/100)%10]); delay(1000);
}
if(Hz>9)
{
Smg_display(6,duan[(Hz/10)%10]); delay(1000);
}
Smg_display(7,duan[Hz%10]); delay(1000);
Close_smg();
}
else if(model==1)
{
Smg_display(0,0xc1); delay(1000);
Smg_display(1,duan[10]); delay(1000);
Smg_display(2,duan[10]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(5,duan[(Rb2_V/100)%10]+0x80); delay(1000);
Smg_display(6,duan[(Rb2_V/10)%10]); delay(1000);
Smg_display(7,duan[Rb2_V%10]); delay(1000);
Close_smg();
}
}
void Key_Down()
{
if(S4==0)
{
delay(100);
if(S4==0)
{
while(S4==0);
model++;
if(model==3) {model=1;}
}
}
if(S5==0)
{
delay(100);
if(S5==0)
{
while(S5==0);
stat++;
if(stat==3) {stat=1;}
}
}
if(S6==0)
{
delay(100);
if(S6==0)
{
while(S6==0);
led_flag=~led_flag;
}
}
if(S7==0)
{
delay(100);
if(S7==0)
{
while(S7==0);
smg_flag=~smg_flag;
}
}
}
void LED()
{
Chan_hc573(4);
if(model==1)
{
P00=0;
}
else if(model==2)
{
P01=0;
}
if(stat==2)
{
if(Rb2_V<150)
{
P02=1;
}
else if(Rb2_V>=150&&Rb2_V<250)
{
P02=0;
}
else if(Rb2_V>=250&&Rb2_V<350)
{
P02=1;
}
else if(Rb2_V>=350)
{
P02=0;
}
}
if(Hz<1000)
{
P03=1;
}
else if(Hz>=1000&&Hz<5000)
{
P03=0;
}
else if(Hz>=5000&&Hz<10000)
{
P03=1;
}
else if(Hz>=10000)
{
P03=0;
}
}
void Key_set_up()
{
if(stat==1)
{
Rb2_V=200;
}
else
{
Rb2_V=read_pcf8591(3)/0.51;
}
if(smg_flag==0)
{
Display_F_U();
}
else
{
Close_smg();
}
if(led_flag==0)
{
LED();
}
else
{
Chan_hc573(4);
P0=0xff;
}
}
void main()
{
Init_system();
Timer0Init();
while(1)
{
Key_Down();
Key_set_up();
}
}
|