anh nào giúp em đoạn code này với.
#include <REGX52.H>
#include<stdio.h>
#include<math.h>
#include<string.h>
sbit t1 = P2^0;
sbit t2 = P2^1;
sbit t3 = P2^2;
sbit INTR_ADC = P3^3;
sbit WR_ADC = P3^4;
sbit RD_ADC = P3^5;
float volt,a;
unsigned long x,s;
unsigned char dem;
//tao tre ngan
void tre(unsigned char t)
{
unsigned char i;
for(i=0;i<t;i++);
}
void main(void)
{
SCON=0X52; // PORT NOI TIEP CHE DO 1; REN = TI = 1
T2CON=0X30; //RCLK=TCLK=1
RCAP2H=255;
RCAP2L=-36; //Toc do baud la 9600
TR2=1;
printf("\n DO AN DO DONG DIEN HIEN THI MAY TINH! ");
printf("\n Thang do 0-0.1A | Thang do 0-1A | Thang do 1-10A ");
while(1)
{
for (dem=0;dem<40;dem++)
{
WR_ADC = 0;
RD_ADC = 0;
tre(10);
WR_ADC = 1;
while (!INTR_ADC);
tre(3);
x=P1;
s=s+x;
}
x=s/40;
dem=s=0;
volt = ((float)(x*500)/(255*100));
if(t1 == 0)
{
a float)(volt/3));
if(a>0.1)
a=0.1;
printf("\nThang do 0-0.1A gia tri do duoc la: %1.3f A ",a);
}
if(t2 == 0)
{
a float)(volt/5));
if(a>1)
a=1;
printf("\nThang do 0-1A gia tri do duoc la: %1.3f A ",a);
}
if(t3 == 0)
{
a float)(volt/10));
if(a>10)
a=10;
printf("\nThang do 0-10A gia tri do duoc la: %2.3f A ",a);
}
}
}
còn đây là mạch mô phỏng..
#include <REGX52.H>
#include<stdio.h>
#include<math.h>
#include<string.h>
sbit t1 = P2^0;
sbit t2 = P2^1;
sbit t3 = P2^2;
sbit INTR_ADC = P3^3;
sbit WR_ADC = P3^4;
sbit RD_ADC = P3^5;
float volt,a;
unsigned long x,s;
unsigned char dem;
//tao tre ngan
void tre(unsigned char t)
{
unsigned char i;
for(i=0;i<t;i++);
}
void main(void)
{
SCON=0X52; // PORT NOI TIEP CHE DO 1; REN = TI = 1
T2CON=0X30; //RCLK=TCLK=1
RCAP2H=255;
RCAP2L=-36; //Toc do baud la 9600
TR2=1;
printf("\n DO AN DO DONG DIEN HIEN THI MAY TINH! ");
printf("\n Thang do 0-0.1A | Thang do 0-1A | Thang do 1-10A ");
while(1)
{
for (dem=0;dem<40;dem++)
{
WR_ADC = 0;
RD_ADC = 0;
tre(10);
WR_ADC = 1;
while (!INTR_ADC);
tre(3);
x=P1;
s=s+x;
}
x=s/40;
dem=s=0;
volt = ((float)(x*500)/(255*100));
if(t1 == 0)
{
a float)(volt/3));
if(a>0.1)
a=0.1;
printf("\nThang do 0-0.1A gia tri do duoc la: %1.3f A ",a);
}
if(t2 == 0)
{
a float)(volt/5));
if(a>1)
a=1;
printf("\nThang do 0-1A gia tri do duoc la: %1.3f A ",a);
}
if(t3 == 0)
{
a float)(volt/10));
if(a>10)
a=10;
printf("\nThang do 0-10A gia tri do duoc la: %2.3f A ",a);
}
}
}
còn đây là mạch mô phỏng..