教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 说明书 >

配料槽最终程序

来源:网络收集 时间:2026-01-20
导读: #includereg51.h //头文件 #define uchar unsigned char //宏定义,为方便编程 #define uint unsigned int #define LED P0 //宏定义,将P1口定义为0804输出数据位 #define LED P2 //宏定义,将P0口定义为LED uchar num,num1,num2,num3; uchar cyc; sbit P2_0

#include<reg51.h> //头文件
#define uchar unsigned char //宏定义,为方便编程
#define uint unsigned int

#define LED P0 //宏定义,将P1口定义为0804输出数据位
#define LED P2 //宏定义,将P0口定义为LED

uchar num,num1,num2,num3;
uchar cyc;

sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit K1_A=P2^4; // A槽传感器
sbit K2_B=P2^5; // B槽传感器
sbit K3_C=P2^6; // C槽传感器
sbit st_open=P2^7;
sbit P1_0=P1^0; // A槽料空指示灯
sbit P1_1=P1^1; // B槽料空指示灯
sbit P1_2=P1^2; // C槽料空指示灯
sbit P1_3=P1^3; //主槽料满指示灯
uchar a,b,c,sum;

uchar digivalue[]={0x28,0x7e,0x0a2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60};
uchar LedOut[4];



void delay0(unsigned char i) //动态显示延时
{
char j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}



void display (unsigned char m ) //动态显示子程序
{ uchar i;
LedOut[1]=digivalue[m%10];
LedOut[2]=digivalue[m%100/10];
LedOut[3]=digivalue[m/100];

for( i=1; i<4; i++)
{
switch(i) //使用switch 语句控制位选
{
case 1: P2_0=1; P2_1=1; P2_2=0;LED = LedOut[i];delay0(180); break; //continue;
case 2: P2_0=1; P2_1=0; P2_2=1; LED = LedOut[i];delay0(180); break;
case 3: P2_0=0; P2_1=1; P2_2=1; LED = LedOut[i];delay0(180); break;
}
}
}

void main() //主函数
{ num=0;
TMOD=0x10;
TH1 = 0xd8;
TL1 = 0xf0;
ET1 = 1;
TR1 = 1;
EA=1;
cyc=1; //
while(1)
{
display(sum);

}

}


void time1(void) interrupt 3//10ms中断
{
TH1=0xd8;
TL1=0xf0;
num++;
num1++;
num2++;
num3++;
if(st_open==0&&cyc==1)
{
if(num==20&&K1_A==1)
{
a++;
num=0;
P1_0=1;
}

if(num1==10&&K2_B==1)
{ b++;
num1=0;
P1_1=1; //
}
if(num2==200&&K3_C==1)
{ c++;
num2=0;
P1_2=1;

}
if(K1_A==0) P1_0=0; //
if(K2_B==0) P1_1=0; //
if(K3_C==0) P1_2=0; //

if(K1_A==0&&K2_B==0&&K3_C==0)
{ num3=0;
P1_3=0;
cyc=0;
}

}


else num3++;

P1_3=1;

if(num3==200)
{
P1_0=1;P1_1=1;P1_2=1;P1_3=1; //
num3=0;
//cyc=1;
}


sum=a+b+c; //
}

配料槽最终程序.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/1484394.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)