新手写的程序,实在不懂哪里错/* int.c test int0 */
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit trig = P3^7;
char DATA_7SEG[10]={0xC0, 0xF9, 0xA4, 0xB0, 0x99,
0x92, 0x82, 0xF8, 0x80, 0x90};
char act[4]={0xfe, 0xfd, 0xfb, 0xf7}; /* p2.0--p2.3 */
uint a,flag,x;
uchar hi,lo,Tm_count,f_count,Flash,ex0_count,b,count;
/*-----------------------------*/
void delay(int d)
{
int i, j;
for(i=0; i<d; i++)
for(j=0; j<100; j++) ;
}
/*-----------------------------------*/
void ex1_int(void) interrupt 2
{
TR0=0;
a=TH0*256+TL0;
count++;
}
void ex0_int(void) interrupt 0 using 1
{
ex0_count ++;
if(ex0_count==1)
{
TH1=hi;
TL1=lo;
EX1=1;
TR1=1;
}
else if(ex0_count==2)
{
EX1=0;
TR1=0;
b=0;
}
if(ex0_count==3)
{
TH1=hi;
TL1=lo;
EX1=1;
TR1=1;
count=0;
Tm_count=0;
}
else if(ex0_count==4)
{
EX1=0;
TR1=0;
ex0_count=0;
}
}
void de110(void)
{
char c;
c=1;c=1;c=1;
}
void tr_pu(void)
{
trig=1;
de110();
trig=0;
}
void t1isr(void) interrupt 3
{
TH1=hi;
TL1=lo;
TH0=0;
TL0=0;
tr_pu();
TR0=1;
Tm_count ++;
if(Flash==1)
{
f_count ++;
P1=~P1;
if(f_count==2)
Flash=0;
}
}
/*----------------------*/
main()
{
uint a1,a2,a3,a4,value;
uint y1,y2,b,avg;
uchar x1,x2,x3,x4;
value=65536-46082;
TH1=hi=value/256;
TL1=lo=value%256;
TCON=0x05;
TMOD=0x01;
IE=0x8D;
flag=0;
TR1=1;
x=0;
a=0;
a1=0;
a2=0;
a3=0;
a4=0;
b=0;
count=0;
Tm_count=0;
ex0_count=0;
while(1)
{
if(Tm_count==10)
{
avg=(a1+a2+a3+a4+a)/5;
b=(avg*0.18445-69.6);
x=count*2;
Tm_count=0;
count=0;
}
a4=a3;
a3=a2;
a2=a1;
a1=a;
if(ex0_count==0||ex0_count==1||ex0_count==2)
{
if(b>3500)
{
b=3500;
}
else if(b<100)
{
f_count=0;
Flash=1;
}
x1=b/1000;
y1=b%1000;
x2=y1/100;
y2=y1%100;
x3=y2/10;
x4=y2%10;
P0=DATA_7SEG[x1];
P2=act[0];
delay(1);
P0=DATA_7SEG[x2];
P2=act[1];
delay(1);
P0=DATA_7SEG[x3];
P2=act[2];
delay(1);
P0=DATA_7SEG[x4];
P2=act[3];
}
if(ex0_count==3||ex0_count==4)
{
x1=x/1000;
y1=x%1000;
P0=DATA_7SEG[x1];
P2=act[0];
x2=y1/100;
y2=y1%100;
P0=DATA_7SEG[x2];
P2=act[1];
x3=y2/10;
P0=DATA_7SEG[x3];
P2=act[2];
x4=y2%10;
P0=DATA_7SEG[x4];
P2=act[3];
}
}
}
|