#include <STC12C5A60S2.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define ADC_POWER 0x80
#define ADC_START 0x08
#define ADC_FLAG 0x10
#define ADC_SPEEDLL 0x00
unsigned char count,jd1,jd2,m1,m2;
uint code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint disp[4];
uint temp1,temp2,result;
sbit pwm=P1^6;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
char jd;
void delay(unsigned int i)
{
unsigned int j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void Time0_init()
{
TMOD=0x01;
IE=0x82;
TH0=0xff;
TL0=0x19;
TR0=1;
}
void Time0_int() interrupt 1
{
TH0=0xff;
TL0=0x19;
if(count<jd)
pwm=1;
else
pwm=0;
count++;
count=count%40;
}
void keyscan()
{
if(1015<temp1<1023)
{
delay(50);
if(1015<temp1<1023)
{
jd++;
count=0;
if(jd==50)
jd=6;
while(1015<temp1<1023);
}
}
if(1009<temp1<1015)
{
delay(10);
if(1009<temp1<1015);
{
jd--;
count=0;
if(jd==0)
jd=1;
while(1009<temp1<1015);
}
}
}
void InitADC1()
{
P1ASF=0x01;
ADC_RES=0;
ADC_RESL=0;
ADC_CONTR=ADC_POWER|ADC_SPEEDLL;
delay(1);
}
uint Read(uchar CHA)
{
ADC_CONTR=ADC_POWER|ADC_SPEEDLL|CHA|ADC_START;
_nop_();
_nop_();
_nop_();
_nop_();
while(!(ADC_CONTR & ADC_FLAG));
ADC_CONTR &=~ADC_FLAG;
return(ADC_RES*4+ADC_RESL);
}
void datapros()
{
static uint i=0;
if(++i>=1000)
{
i=0;
temp1=Read(0);
disp[3]=smgduan[temp1/1000%10];
disp[2]=smgduan[temp1/100%10];
disp[1]=smgduan[temp1/10%10];
disp[0]=smgduan[temp1%10];
}
}
void main()
{
P1M0 = 0x00;
P1M1 = 0x01;
jd=1;
count=0;
InitADC1();
while(1)
{
datapros();
Time0_init();
keyscan();
delay(1);
}
}
|