#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[6]="00.00V";
uchar num, temp;
uint voltage;
sbit ad_clk=P3^3;
sbit ad_out=P3^4;
sbit ad_cs=P3^5;
sbit lcden=P2^4;
sbit lcdrs=P2^5;
void delayms(uint xms);
void write_com(uchar com);
void write_data(uchar date);
void led_init();
void tlc549_ad();
void main ()
{
led_init ();
tlc549_ad ();
}
void led_init ()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void tlc549_ad ()
{
ad_cs=1;
ad_clk=0;
ad_cs=0;
_nop_ ();
_nop_();
for(num=0;num<8;num++)
{
temp<<=1;
temp|=ad_out;
ad_clk=1;
_nop_ ();
ad_clk=0;
}
ad_cs=1;
for(num=17;num>0;num--)
_nop_ ();
voltage=(uint)(5.0/256*temp*400);
temp=0;
table[0]=voltage/1000+48;
table [1] =voltage%1000/100+48;
table[3]=voltage%1000%100/10+48;
table [4] =voltage%1000%100%10+48;
write_com(0x80);
for(num=0;num<6;num++)
{
write_data (table [num]);
delayms (5);
}
delayms(2000);
}
void delayms (uint xms)
{
uint i, j;
for (i=xms; i>0; i--)
for (j=110; j>0; j--);
}
void write_com (uchar com)
{
lcdrs=0;
P0=com;
delayms (5);
lcden=1;
delayms (5);
lcden=0;
}
void write_data (uchar date)
{
lcdrs=1;
P0=date;
delayms (5);
lcden=1;
delayms (5);
lcden=0;
}
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
#define PI 3.1415926
uchar code table1 [8] ="Welcome!";
uchar table2 [16] ="f (Hz) =";
uchar table3 [16] ="R (Ohm) =";
uchar table4 [16] ="C (pF) =";
uchar table5 [16] ="L (uH) =";
uchar num, a=0, th0, tl0;
uint C, L;
ulong f, R;
sbit Lcden=P2^4;
sbit Lcdrs=P2^5;
sbit key_R=P1^5;
sbit key_C=P1^6;
sbit key_L=P1^7;
sbit R_out=P1^2;
sbit C_out=P1^3;
sbit L_out=P1^4;
void delayms1(uint xms);
void write_com1(uchar com);
void write_data1(uchar date);
void led_init1();
void t_init1();
void keyscan1();
void display_f1(ulong f);
void display_R1(ulong R);
void display_C1(uint C);
void display_L1(uint L);
void main ()
{
led_init1 ();
t_init1 ();
keyscan1 ();
write_com (0x01);
while (1)
{
display_f1 (f);
switch (a)
{
case 1: R= (ulong) (5000000.0/0.6931472/f-150+0.5); display_R1(R); break;
case 2: C= (int) (100000000.0/153/0.6931472/f+0.5); display_C1(C); break;
case 3: L= (int) (1000000000000.0/0.1/PI/PI/f/f+0.5); display_L1 (L); break;
}
}
}
void T0_count () interrupt 1
{
switch (a)
{
case 1: while (R_out);
while (! R_out);
TH0=0;
TL0=0;
while (R_out);
while (! R_out);
th0=TH0;
tl0=TL0;
TR0=0;
break;
case 2: while (C_out);
while (! C_out);
TH0=0;
TL0=0;
while (C_out);
while (! C_out);
th0=TH0;
tl0=TL0;
TR0=0;
break;
case 3: while (L_out);
while (! L_out);
TH0=0;
TL0=0;
while (L_out);
while (! L_out);
th0=TH0;
tl0=TL0;
TR0=0;
break;
}
f=1000000.0/1.085069/(th0*256+tl0)+0.5;
}
void delayms1 (uint xms)
{
uint i, j;
for (i=xms;i>0;i--)
for (j=110;j>0;j--);
}
void write_com1(uchar com)
{
Lcdrs=0;
P0=com;
delayms (5);
Lcden=1;
delayms (5);
Lcden=0;
}
void write_data1(uchar date)
{
Lcdrs=1;
P0=date;
delayms (5);
Lcden=1;
delayms (5);
Lcden=0;
}
void led_init1 ()
{
Lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for (num=0; num<8; num++)
{
write_data (table1 [num]);
delayms (5);
}
}
void t_init1 ()
{
TMOD=0x01;
TH0=0;
TL0=0;
EA=1;
ET0=1;
TR0=1;
}
void keyscan1 ()
{
if (key_R==0)
{
delayms (10);
if (key_R==0)
a=1;
}
else
if (key_C==0)
{
delayms (10);
if (key_C==0)
a=2;
}
else
if (key_L==0)
{
delayms (10);
if (key_L==0)
a=3;
}
else
while(key_R&&key_C&&key_L);
}
void display_f1 (ulong f)
{
uchar count=0;
ulong f0;
f0=f;
while (f)
{
f=f/10;
count++;
}
for (num=5+count; num>5; num--)
{
table2 [num] =f0%10+48;
f0=f0/10;
}
write_com (0x80);
for (num=0; num<6+count; num++)
{
write_data (table2 [num]);
delayms (5);
}
}
void display_R1 (ulong R)
{
uchar count=0;
ulong R0;
R0=R;
while(R)
{
R=R/10;
count++;
}
for (num=6+count; num>6; num--)
{
table3 [num] =R0%10+48;
R0=R0/10;
}
write_com (0x80+0x40);
for (num=0; num<7+count; num++)
{
write_data (table3 [num]);
delayms (5);
}
}
void display_C1 (uint C)
{
uchar count=0;
uint C0;
C0=C;
while(C)
{
C=C/10;
count++;
}
for (num=5+count; num>5; num--)
{
table4 [num] =C0%10+48;
C0=C0/10;
}
write_com (0x80+0x40);
for (num=0; num<6+count; num++)
{
write_data (table4 [num]);
delayms (5);
}
}
void display_L2 (uint L)
{
uchar count=0;
uint L0;
L0=L;
while (L)
{
L=L/10;
count++;
}
for (num=5+count; num>5; num--)
{
table5 [num] =L0%10+48;
L0=L0/10;
}
write_com (0x80+0x40);
for (num=0; num<6+count; num++)
{
write_data (table5 [num]);
delayms (5);
}
}
*** FATAL ERROR L256: MODULE CONTAINS DUPLICATE SEGMENT NAMES
SEGMENT: ?PR?MAIN?TEXT1
MODULE: Text1.obj (TEXT1)
Target not created
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>