đây là code của thằng bạn nó gửi cho em, nhưng không có hình
*********/
#include<reg52.h>
#include<stdio.h>
#include<math.h>
//khai bao cac bit
sbit adc_int=P2^5;
sbit adc_rd=P2^3;
sbit adc_rw=P2^4;
sbit led1=P2^0;
sbit led2=P2^1;
sbit led3=P2^2;
sbit thang1=P1^7;
sbit thang2=P1^6;
sbit thang3=P1^5;
float volt,ampe;
unsigned char chuc,donvi,phan1,phan2,nguyen,phan;
unsigned int x;
unsigned char M[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x02,0x82,0xF8,0x80,0x9 0}; //array use dp
unsigned char M1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0}; //arrray use dp
void delay(delay) //delay use timer 0 mode 2
{
TMOD=0x02;
TH0=TL0=-100;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
}
void dieukhien_adc(void)//control adc
{
adc_rw=0;
delay(2);
adc_rw=1;
while(adc_int);
adc_rd=0;
x=P3;
adc_rd=1;
}
void hienthi(void)//scan led
{
unsigned int i;
ampe=ampe*10;
ampe=(int)(ampe);
nguyen=ampe/10;
phan=(int)(ampe)%10;
phan1=phan/10;
phan2=phan%10;
if((nguyen==0)&&(phan1<=1))
{
donvi=nguyen;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;i++)
{
led3=1;
led1=0;
led2=0;
P0=0x40;
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
delay(100);
}
}
if((nguyen<1)&&(phan1>1))
{
donvi=nguyen;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;++i)
{
led3=1;
led1=0;
led2=0;
P0=M1[donvi];
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
delay(100);
}
}
if((nguyen<=10)&&(nguyen>=1))
{
donvi=nguyen/10;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;++i)
{
led3=1;
led2=0;
led1=0;
P0=M1[nguyen];
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
}
}
}
void tatled(void) //off led
{
led1=0;
led2=0;
led3=0;
P0=0xFF;
}
void main(void) //main funtion
{
while(1)
{
while(thang1==0)
{
dieukhien_adc();
volt=(float)(x*100)/255; //range from 0 to 10
}
while(thang2==0)
{
dieukhien_adc();
volt=(float)(x*10)/255; //range from 0 to 1
}
while(thang3==0)
{
dieukhien_adc();
volt=(float)(x*1)/255; //range from 0 to 0.1
}
ampe=volt/10;
hienthi();
}
}
hicc , đề bài của em là : đo dòng 1 chiều sử dụng 8051 hiển thị lên led 7 thanh. Ai giúp em với
*********/
#include<reg52.h>
#include<stdio.h>
#include<math.h>
//khai bao cac bit
sbit adc_int=P2^5;
sbit adc_rd=P2^3;
sbit adc_rw=P2^4;
sbit led1=P2^0;
sbit led2=P2^1;
sbit led3=P2^2;
sbit thang1=P1^7;
sbit thang2=P1^6;
sbit thang3=P1^5;
float volt,ampe;
unsigned char chuc,donvi,phan1,phan2,nguyen,phan;
unsigned int x;
unsigned char M[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x02,0x82,0xF8,0x80,0x9 0}; //array use dp
unsigned char M1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x1 0}; //arrray use dp
void delay(delay) //delay use timer 0 mode 2
{
TMOD=0x02;
TH0=TL0=-100;
TR0=1;
while(!TF0);
TF0=0;
TR0=0;
}
void dieukhien_adc(void)//control adc
{
adc_rw=0;
delay(2);
adc_rw=1;
while(adc_int);
adc_rd=0;
x=P3;
adc_rd=1;
}
void hienthi(void)//scan led
{
unsigned int i;
ampe=ampe*10;
ampe=(int)(ampe);
nguyen=ampe/10;
phan=(int)(ampe)%10;
phan1=phan/10;
phan2=phan%10;
if((nguyen==0)&&(phan1<=1))
{
donvi=nguyen;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;i++)
{
led3=1;
led1=0;
led2=0;
P0=0x40;
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
delay(100);
}
}
if((nguyen<1)&&(phan1>1))
{
donvi=nguyen;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;++i)
{
led3=1;
led1=0;
led2=0;
P0=M1[donvi];
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
delay(100);
}
}
if((nguyen<=10)&&(nguyen>=1))
{
donvi=nguyen/10;
phan1=phan/10;
phan2=phan%10;
for(i=0;i<100;++i)
{
led3=1;
led2=0;
led1=0;
P0=M1[nguyen];
delay(100);
led2=1;
led1=0;
led3=0;
P0=M[phan1];
delay(100);
led1=1;
led2=0;
led3=0;
P0=M[phan2];
}
}
}
void tatled(void) //off led
{
led1=0;
led2=0;
led3=0;
P0=0xFF;
}
void main(void) //main funtion
{
while(1)
{
while(thang1==0)
{
dieukhien_adc();
volt=(float)(x*100)/255; //range from 0 to 10
}
while(thang2==0)
{
dieukhien_adc();
volt=(float)(x*10)/255; //range from 0 to 1
}
while(thang3==0)
{
dieukhien_adc();
volt=(float)(x*1)/255; //range from 0 to 0.1
}
ampe=volt/10;
hienthi();
}
}
hicc , đề bài của em là : đo dòng 1 chiều sử dụng 8051 hiển thị lên led 7 thanh. Ai giúp em với
Comment