Home > Back-end >  Detailed translation o C program
Detailed translation o C program

Time:09-25

# include
# define uint unsigned int
# define uchar unsigned char

Uchar code shu []={x5b x3f 0, 0 x06, 0, 0 x4f,
X6d 0 x66, 0, 0 x7d, 0 x07,
0 x7f, 0 x6f};//0 ~ 9
XBF uchar code shu2 []={0, 0 x86, 0 XDB, 0 XCF,
XFD xe6 0, 0 xed, 0, 0 x87,
0 XFF. Zero xef};//with decimal point 0 ~ 9
Uchar code wei []={XBF xef 0, 0 XDF, 0, 0 x7f, 0 xf7, 0 XFB};//digital tube a selected code
Uchar [x]=,0,0,0 {0};
Uchar y []=,0,0,0,0,0 {0};
Uint hour=12, min, SEC, h=22, m=0;
Uint a, s1=1, s2=1, s3=0, I=0, status=0, num=0, class=0;
Bit flag=0;
Sbit P3_7=P3 ^ 7;
Void delay (uint t);
Void keyprint (unsigned char key);
Void the display ();
Void timer0 ();
Void sint () interrupt 4//serial port interrupt, realizes the PC quickly set time and alarm clock
{
S3 + +;
S3=s3%4;
If (RI& & S3==1)
{
RI=0;
Hour=SBUF;
}
If (RI& & S3==2)
{
RI=0;
Min=SBUF;
}
If (RI& & S3==3)
{
RI=0;
H=SBUF;
}
If (RI& & S3==0)
{
RI=0;
M=SBUF;
}

if(! TI)
TI=0;
}
Void delay (uint t)
{
Uint I;
While (t -)
for(i=0; i<125; I++);
}

The main ()
{
Uchar n;
Uchar input;
N=0 x0f;
TMOD=0 x21;
TH0=(65536-5000)/256;
TL0=(65536-5000) % 256;
TH1=0 XFD;
TL1=0 XFD;
SCON=0 x50;
PCON=0 x00;
TR1=1;

IP=0 x10;
TR0=1;
IE=0 x92;//timer 0, a serial port interrupt
While (1)//key scanner
{
Input=P2 & amp; 0 x0f;
If (input!=0 x0f & amp; & S1==1)
{
Delay (10);
S1=0;
If (input!=0 x0f & amp; & S2==1)
{
S2=0;//hold on
N=input;//n used to temporarily store keys
}
}
If (input==0 x0f & amp; & S1==0)
{
S1=1;
S2=1;
Keyprint (n);
N=0 x0f;
}
If ((hour==h& & Min==m) | | (h!=0 & amp; & Min==0))
{
If (SEC==0)
P3_7=0;
If (SEC==1)
P3_7=1;
If (SEC==2)
P3_7=0;
If (SEC==3)
P3_7=1;
If (SEC==4)
P3_7=0;
If (SEC==5)
P3_7=1;
}
The else
P3_7=1;
If (h>=24)
H=0;
The display ();

}
}

Void keyprint (unsigned char key)//each button function
{
If (key==0 x0e)
{
num++;
If (num==1) {class=1; }
If (num==2) {class=2; Num=0; }

}
If (key==0 x0d)
{
Status++;
If (status>
=5)Status=0;
}
If (key==0 x0b)
{
If (status==1)
{
If (min<59) min++;
The else {min=0; Hour++; }
}
If (status==2)
{
If (hour<23) hour++;
The else hour=0;
}
If (status==3)
{
If (m<59) m++;
The else {m=0; H++; }
}
If (status==4)
{
If (h<23) h++;
The else h=0;
}
}
}

Void the display ()//digital tube display function,
{
Uchar d=0;
If (class==1 | | class==0)
{
X [0]=hour/10;//show the ten
X [1]=10 hour %;//show the bits of
X [2]=min/10;//show points 10
[3]=min x % 10;//show points bits
While (d<4)
{
The P2=wei [d];
P0=shu [d] [x];
delay(1);
D++;
}
}
Else if (class==2)
{
Y [0]=h/10;//show the ten
[1]=y h % 10;//show the bits of
Y [2]=m/10;//show points 10
Y [3]=10 m %;//show points bits
D=0;
If (flag==0)//every 0.5 s decimal flashing a
{
While (d<4)
{
The P2=wei [d];
P0=shu2 [[d]] y;
delay(1);
D++;
}
}
Else if (flag==1)
{
While (d<4)
{
The P2=wei [d];
P0=shu [[d]] y;
delay(1);
D++;
}
}
}
}
Void timer0 ()//timer interrupt 1 0 way 1 interrupt function
{
Uint count;
TH0=(65536-5000)/256;//timer 0 set initial value 1 ms interrupt the initial value
TL0=(65536-5000) % 256;
TR0=1;
count++;//normal timing
If (count>
=100){
Flag=1;
If (count>=200)//time 1 s to, the following is a normal clock go clock logic
{
Flag=0;
Count=0;
Sec++;
If (sec>=60)
{
The SEC=0;
Min++;//second to 60 points plus one, second reset
}
If (min>=60)
{
min=0;
Hour++;//to sixty plus one, zero
}
If (hour>=24)
{
Hour=0;//to 24 immediately to 0
}
}
}
}

CodePudding user response:

Urgent need! The great god

CodePudding user response:

Too long. Didn 't read

CodePudding user response:

Is not very simple, is the control of digital tube display, no advanced grammar, just for some condition judgment with assignment, understand you patience to read it again
  • Related