可以做到在自动车床停止工作一段时间后,把电动机关闭,用以节省电能,延时关闭时间可控,数码管显示控制时间,单片机工作状态有数码管显示
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- unsigned char yanshishu,xianshishu,yanshishu2,xianshishu2,qqq;
- sbit kaiqi=P1^0;// 自动关闭启动开关
- sbit stop=P1^1;// 连动停止检测
- sbit ka=P1^2; // 继电器输出
- sbit on=P1^3; // 电源状态指示
- sbit off=P1^4; // 工作状态指示
- code unsigned char dis1[]={0xc0,0xf9,0xa4,
- 0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};//数码管显示码
- void csh(void)
- {
- IT0=1;
- IT1=1;
- EX0=1;
- EX1=1;
- EA=1;
- }
- void delay(unsigned int amt) //@12.000MHz
- { unsigned int w;
- unsigned char i, j, k;
- for(w=amt;w>0;w--)
-
- {
- _nop_();
- i = 8;
- j = 154;
- k = 122;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- if(kaiqi==0)
- {
- on=0;
- off=1;
- }
- if(kaiqi==1)
- {
- on=1;
- off=0;
- }
- }
- }
-
- void main()
- { csh();
- yanshishu=1;
- xianshishu=1;
- yanshishu2=0;
- xianshishu2=0;
- P2=dis1[xianshishu2];
- P0=dis1[xianshishu];
- while(1)
- { kaiqi=1;
- stop=1;
- ka=1;
- if(kaiqi==0)
- {
- on=0;
- off=1;
- }
- if(kaiqi==1)
- {
- on=1;
- off=0;
- }
- if(kaiqi==0)
- { if(kaiqi==0)
- {
- on=0;
- off=1;
- }
- if(kaiqi==1)
- {
- on=1;
- off=0;
- }
- delay(3);
- if(stop==0)
- {
- qqq=yanshishu2*60+yanshishu*10;
- delay(qqq);
- if(stop==0)
- {
- ka=0;
-
- delay(3);
- ka=1;
- }
- }
- }
- }
- }
- void wzd0(void) interrupt 0
- {
- yanshishu++;
- xianshishu++;
- P0=dis1[xianshishu];
- if(xianshishu==7)
- {
- xianshishu=1;
- yanshishu=1;
- }
- }
- void wzd1(void) interrupt 2
- {
- yanshishu2++;xianshishu2++;
- P2=dis1[xianshishu2];
- if(xianshishu2==10)
- {
- xianshishu2=0;
- yanshishu2=0;
- }
- }
复制代码
所有资料51hei提供下载:
关冲床.zip
(755.97 KB, 下载次数: 15)
|