称重没问题了,就是控制有问题。当xh为低电平时Liao1为高电平,可当显示值为13是Liao2不为高电平,Liao1不置低电平,控制不了Liao2,Liao3,Liao4,Liao5
我的程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
uchar flag=0;
uint liao1,liao2,liao3,liao4,liao5;
uint aa,temp,COM1_DATA,COM2_DATA,COM3_DATA,COM4_DATA,COM5_DATA;
sbit ADSK = P1^2;
sbit ADDO = P1^1;
sbit COM5=P1^3;
sbit COM4=P1^4;
sbit COM3=P1^5;
sbit COM2=P1^6;
sbit COM1=P1^7;
sbit speak=P3^3;
sbit kz1=P2^0;
sbit kz2=P2^1;
sbit kz3=P2^2;
sbit xh=P1^0;
sbit Liao1=P2^7;
sbit Liao2=P2^6;
sbit Liao3=P2^5;
sbit Liao4=P2^4;
sbit Liao5=P2^3;
uchar code table[]={0x7f,0x4c,0xdb,0xde,0xec,0xf6,0xf7,0x5c,0xff,0xfe};
void Delay_ms(uint x)//延时程序
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<125;j++);
}
void delay(uchar t)
{
uchar i,j;
for(i=0;i<t;i++)
for(j=0;j<100;j++);
}
unsigned long HX711Read(void)
{
ulong Count;
uchar z;
ADSK=0;
Count=0;
while(ADDO);
for(z=0;z<24;z++)
{
ADSK=1;
Count=Count<<1;
ADSK=0;
if(ADDO)
Count++;
}
ADSK=1;
Count=Count^0x800000;
ADSK=0;
return(Count);
}
void pizhong()
{
ulong hx711_dat;
Delay_ms(10);
hx711_dat=HX711Read();
temp=(uint)((hx711_dat/10000)-1);
}
void weight()
{
ulong hx711_data;
uint get,aa;
hx711_data=HX711Read();
get=(uint)((hx711_data/10000)-1);
aa=get-temp;
COM5_DATA=aa/10000;
COM4_DATA=aa%10000/1000;
COM3_DATA=aa%10000%1000/100;
COM2_DATA=aa%10000%1000%100/10;
COM1_DATA=aa%10000%1000%100%10;
}
void kongzhi()
{
liao1=13;
liao2=23;
liao3=86;
liao4=386;
liao5=1190;
if(xh==0)
{
Liao1=0;
}
if(aa==liao1)
{
Liao1=1;
Liao2=0;
}
if(aa==liao2)
{
Liao2=1;
Liao3=0;
}
if(aa==liao3)
{
Liao3=1;
Liao4=0;
}
if(aa==liao4)
{
Liao4=1;
Liao5=0;
}
if(aa==liao5)
{
P2=0xff;}
}
/*
void Init_
timer0()
{
TMOD=0x01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
ET0=1;
EA=1;
} */
void display()
{
COM1=1;
COM2=0;
COM3=0;
COM4=0;
COM5=0;
P0=table[COM1_DATA];
delay(15);
P0=0x00;
COM1=0;
COM2=1;
COM3=0;
COM4=0;
COM5=0;
P0=table[COM2_DATA];
delay(15);
P0=0x00;
COM1=0;
COM2=0;
COM3=1;
COM4=0;
COM5=0;
P0=table[COM3_DATA];
delay(15);
P0=0x00;
COM1=0;
COM2=0;
COM3=0;
COM4=1;
COM5=0;
P0=table[COM4_DATA];
delay(15);
P0=0x00;
COM1=0;
COM2=0;
COM3=0;
COM4=0;
COM5=1;
P0=table[COM5_DATA];
delay(15);
P0=0x00;
}
void main()
{
uchar i;
pizhong();
Delay_ms(500);
while(1)
{
weight();
kongzhi();
for(i=0;i<7;i++) //必须加for 如果不加显示有闪烁 等于调用7次显示程序
{
display();
}
}
}/*
void Timer0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TF0=0;
yc++;
if(yc==500)
{
yc=0;
}
} */
一周热门 更多>