?? 89c52.c
字號(hào):
#include <AT89X52.H>
#define LED_0 0xc0
#define LED_1 0xf9
#define LED_2 0xa4
#define LED_3 0xb0
#define LED_4 0x99
#define LED_5 0x92
#define LED_6 0x82
#define LED_7 0xf8
#define LED_8 0x80
#define LED_9 0x90
#define LED_d 0x7f
#define LED_f0 0x02
#define LED_f1 0x04
#define LED_f2 0x08
#define LED_f3 0x10
#define LED_f4 0x20
#define LED_f5 0x40
#define t2_2 2
#define t2_20 20
float fx = 0;
int flag;
int t2;
int f[6] = {0, 0, 0, 0, 0, 0};
void fx_init(void)
{
long temp_fx;
if(fx >= 1000000)
{
temp_fx = (long)(fx);
flag = 0;
}
else if(fx >= 100000)
{
temp_fx = (long)(fx * 10);
flag = 1;
}
else if(fx >= 10000)
{
temp_fx = (long)(fx * 100);
flag = 2;
}
else if(fx >= 1000)
{
temp_fx = (long)(fx * 1000);
flag = 3;
}
else if(fx >= 100)
{
temp_fx = (long)(fx * 10000);
flag = 4;
}
f[0] = temp_fx / 1000000;
temp_fx %= 1000000;
f[1] = temp_fx / 100000;
temp_fx %= 100000;
f[2] = temp_fx / 10000;
temp_fx %= 10000;
f[3] = temp_fx / 1000;
temp_fx %= 1000;
f[4] = temp_fx / 100;
temp_fx %= 100;
f[5] = temp_fx / 10;
}
void show(int t)
{
if(t == 0)
P0 = LED_0;
else if(t == 1)
P0 = LED_1;
else if(t == 2)
P0 = LED_2;
else if(t == 3)
P0 = LED_3;
else if(t == 4)
P0 = LED_4;
else if(t == 5)
P0 = LED_5;
else if(t == 6)
P0 = LED_6;
else if(t == 7)
P0 = LED_7;
else if(t == 8)
P0 = LED_8;
else if(t == 9)
P0 = LED_9;
else if(t == 10)
P0 = LED_d;
P0 = 0xff;
}
void Led_show(void)
{
P2 = LED_f0;
show(f[0]);
P2 = LED_f1;
show(f[1]);
P2 = LED_f2;
show(f[2]);
P2 = LED_f3;
show(f[3]);
P2 = LED_f4;
show(f[4]);
P2 = LED_f5;
show(f[5]);
if(flag == 0)
{
P2 = LED_f5;
show(10);
}
else if(flag == 1)
{
P2 = LED_f4;
show(10);
}
else if(flag == 2)
{
P2 = LED_f3;
show(10);
}
else if(flag == 3)
{
P2 = LED_f2;
show(10);
}
else if(flag == 4)
{
P2 = LED_f1;
show(10);
}
}
void time_2() interrupt 5
{
static int i = 0;
TF2 = 0;
if(i >= t2)
{
i = 0;
P1_0 = ~P1_0;
}
else
i++;
}
void device_init(void)
{
T2MOD = 0x02;
T2CON = 0x04;
TH2 = 0x3C;
TL2 = 0xB0;
RCAP2H = 0x3C;
RCAP2L = 0xB0;
TMOD = 0xDD;
TH0 = 0x00;
TL0 = 0x00;
TH1 = 0x00;
TL1 = 0x00;
TCON = 0x50;
IE = 0xA0;
}
void main(void)
{
float nx, ns;
int a, b;
t2 = t2_2;
/*fx = 100;
fx_init();
while(1)
{
Led_show();
}*/
device_init();
while(1)
{
while (P1_0 == 0)
{
TCON = 0x00;
a = TL0;
b = TH0;
nx = (b<<8)+a;
/*if(nx == 0)
{
t2 = t2_20;
device_init();
}*/
a = TL1;
b = TH1;
ns = (b<<8)+a;
fx = nx/ns*10000000;
TH0 = 0x00;
TL0 = 0x00;
TH1 = 0x00;
TL1 = 0x00;
fx_init();
Led_show();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -