#蓝桥杯第十届省赛个人参考代码
#include"stc15.h"
#include “key_read.h”
#include “iic.h”
#include “Ne555.h”
#define u8 unsigned char
#define u16 unsigned int
u8 Display[8];
code u8 Duan[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
code u8 Wei[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
bit key_read_flag=0;
bit Smg_read_flag=0;
bit AD_read_flag;
bit Fre_read_stop_flag=0;
bit Ne555_Capture_flag=0;
bit AD_output_flag=0;
u8 key_data= 0;
u8 Trg= 0;
u8 AD_Output_count=0;
u8 menu=1; //菜单一:电压测量 菜单二:频率测量
u8 vol_val=0;
u16 Cont= 0;
u16 AD_val=0;
u16 Fre_Low_level_count=0;
u16 Fre_val=0;
void Timer0Init(void) //1毫秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xCD; //设置定时初值
TH0 = 0xD4; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void Time0() interrupt 1
{
static u8 key_read_count= 0;
static u8 Smg_display_count=0;
static u8 i=0;
static u8 Ne555_Capture_count=0;
static u8 AD_Output_count =0;
static u16 Smg_read_count=0;
static u16 AD_read_count =0;
static u16 Fre_count=0;
key_read_count ++;
if(key_read_count >= 10)
{
key_read_count =0;
key_read_flag =1;
}
Smg_display_count ++;
if(Smg_display_count >= 2)
{
Smg_display_count=0;
P2 =0xe0; P0=0xff; P2=0;
P2 =0xe0; P0=Display[i]; P2=0;
P2 =0xc0; P0=Wei[i]; P2=0;
i++;
if(i >= 8) i=0;
}
Smg_read_count ++;
if(Smg_read_count >= 500)
{
Smg_read_count=0;
Smg_read_flag =1;
}
AD_read_count ++;
if(AD_read_count >= 400)
{
AD_read_count =0;
AD_read_flag =1;
}
if(Fre_read_stop_flag ==0)
{
Fre_count ++;
if(Fre_count >= 1000) //1s
{
Fre_count =0;
Fre_read_stop_flag =1;
}
}
Ne555_Capture_count ++;
if(Ne555_Capture_count >= 5)
{
Ne555_Capture_count =0;
Ne555_Capture_flag =1;
}
AD_Output_count ++;
if(AD_Output_count >= 2)
{
AD_Output_count =0;
AD_output_flag =1;
}
}
void main()
{
P2 =0xa0; P0=0xbf; P2=0;
Timer0Init();
ET0 =1;
EA =1;
P0 =0xff;
while(1)
{
// Ne555_read();
// if(Ne555_Capture_flag ==1)
// {
// Ne555_Capture_flag=0;
// Ne555_Capture();
// }
//
// if(AD_output_flag ==1)
// {
// AD_output_flag=0;
// DA_Output(vol_val);
// }
//
// if(AD_read_flag ==1)
// {
// AD_read_flag=0;
// AD_val = AD_read(0x03);
// AD_val = (float)AD_val/2555100;
// }
if(Smg_read_flag ==1)
{
Smg_read_flag=0;
if(menu ==1)
{
Display[0] = 0xC1;
Display[1] = 0xff;
Display[2] = 0xff;
Display[3] = 0xff;
Display[4] = 0xff;
Display[5] = (~Duan[AD_val/100]) &0x7f;
Display[6] = ~Duan[AD_val%100/10];
Display[7] = ~Duan[AD_val%10];
}
else if(menu ==2)
{
Display[0] = 0x8E;
Display[1] = 0xff;
Display[2] = ~Duan[Fre_val/100000] ;
Display[3] = ~Duan[Fre_val%100000/10000];
Display[4] = ~Duan[Fre_val%10000/1000];
Display[5] = ~Duan[Fre_val%1000/100];
Display[6] = ~Duan[Fre_val%100/10];
Display[7] = ~Duan[Fre_val%10];
}
}
if(key_read_flag ==1)
{
key_read_flag=0;
key_read();
if(Trg & 0x08) //S4
{
menu++;
if(menu >=3) menu =1;
}
if(Trg & 0x04) //S5
{
P2 =0x80; P0=~P0; P2=0;
}
if(Trg & 0x02) //S6
{
P2 =0x80; P0=~P0; P2=0;
}
if(Trg & 0x01) //S7
{
P2 =0x80; P0=~P0; P2=0;
}
}
}
}