会员申请ID:lichangle
申请ID:lichangle个人邮箱:191738162@qq.com
供水系统 proteus c51仿真源码
#include<reg52.h>
#include<intrins.h>
//#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit motor1=P2^0;//电机
sbit motor2=P2^1;
sbit motor3=P2^2;
sbit shwe1=P1^0; //水位
sbit shwe2=P1^1;
sbit shwe3=P1^2;
void initTimer(void);
void delayms(uint xms);//声明延时子程序
/************
主函数
************/
void main(void)
{
initTimer();
}
//timer init
void initTimer(void)
{
IT0=1; //INT0下降沿中断
EX0=1; //允许INT1中断
IT1=1; //INT1下降沿中断
EX1=1; //允许INT1中断
TMOD=0x11;
TH0=0xdc;
TL0=0x32;
TH1=0xdc;
TL1=0x32;
TR0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
}
//timer0/counter0 interrupt
uint time1=0,time2=0,time3=0,time4=0;
void timer0(void) interrupt 1
{
TH0=0xdc;
TL0=0x32;
//add your code here.
time1++;
if (time1>100) //1秒
{
time2 ++;
time1 =0;
}
if (time2>60) //一分钟
{
time2 =0;
time3 ++;
}
if (time3>30) //30分钟
{
time3 =0;
}
}
//timer1/counter1 interrupt
void timer1(void) interrupt 3
{
TH1=0xdc;
TL1=0x32;
//add your code here.
}
//int0 interrupt
void int0(void) interrupt 0
{
//add your code here
}
//int1 interrupt
void int1(void) interrupt 2
{
//add your code here
}
void delayms(uint xms) //延时子程序
{ uint i, j;
for (i=xms; i>0; i--)
for (j-110; j>0; j--);
}
你这是用哪的程序,看不懂啊,原创吗? Hmily 发表于 2014-11-23 20:51
你这是用哪的程序,看不懂啊,原创吗?
原创,c51程序 游客 114.235.173.x 发表于 2014-11-24 15:10
原创,c51程序
来给解说下,没有看懂。 Hmily 发表于 2014-11-24 15:14
来给解说下,没有看懂。
图里的三个拨动开关,模拟水位的高低,同时通过单片机控制三个电机的启动和停止,每30分钟检测一次水位
最低水位的时候三个电机同时开启,中水位的时候开启2个,最高水位的时候开启一个
抱歉我给的那个源码我没仔细看,那个不完全,
中断程序替换成这个:
uint time1=0,time2=0,time3=0,time4=0;
void timer0(void) interrupt 1
{
TH0=0xdc;
TL0=0x32;
//add your code here.
time1++;
if (time1>100) //1秒
{
time2 ++;
time1 =0;
}
if (time2>60) //一分钟
{
time2 =0;
time3 ++;
}
if (time3>30) //30分钟
{
time3 =0;
if(shwe1==0)
{
motor1=0;
motor2=1;
motor3=1;
goto tab1;
}
if(shwe2==0)
{
motor1=0;
motor2=0;
motor3=1;
goto tab1;
}
if(shwe3==0)
{
motor1=0;
motor2=0;
motor3=0;
}
tab1:
}
} 游客 114.235.173.x 发表于 2014-11-24 19:13
图里的三个拨动开关,模拟水位的高低,同时通过单片机控制三个电机的启动和停止,每30分钟检测一次水位
最 ...
感觉内容有些简单。 Hmily 发表于 2014-11-24 19:14
感觉内容有些简单。
那我在给个电机速度检测的源码
#include<reg52.h>
#include <intrins.h>
//#include <stdio.h>
#define uint unsigned int
#define ulong unsigned long
#define uchar unsigned char
sbit led4=P2^0;
sbit led3=P2^1;
sbit led2=P2^2;
sbit led1=P2^3;
sbit wula=P3^1;
sbit dula=P3^0;
code uchar LED_CODE[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; //显示码
uint time1=0,time2=0,time3=0;
uint boxing=0;
sbit IN1=P1^5;
sbit IN2=P1^6;
sbit ENA=P1^7;
void initTimer(void);
void Display(uint Play);
void delay(uint s);
void delayms(uint ms);
void delayus(uint us);
/*******************主函数**************************/
void main()
{
initTimer();
while(1)
{
uint i,cycle=0,T=2048;
IN1=1; //正转
IN2=0;
for(i=0;i<100;i++)
{
delayms(10);//PWM占空比为50%,修改延时调整PWM脉冲
ENA=~ENA;
}
// Display (time3);
}
}
//timer init
void initTimer(void)
{
IT0=1; //INT0下降沿中断
EX0=1; //允许INT1中断
IT1=1; //INT1下降沿中断
EX1=1; //允许INT1中断
TMOD=0x11;
TH0=0xdc;
TL0=0x32;
TH1=0xdc;
TL1=0x32;
TR0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
}
//timer0/counter0 interrupt
void timer0(void) interrupt 1
{
TH0=0xdc;
TL0=0x32;
//add your code here.
time1++;
if (time1>10) //100毫秒
{
time2 ++;
time1 =0;
}
if (time2>10) //一秒
{
time3 =boxing * 60;
time2 =0;
boxing =0; //复位输入脉冲
}
}
//timer1/counter1 interrupt
void timer1(void) interrupt 3
{
TH1=0xdc;
TL1=0x32;
//add your code here.
Display (time3);
}
//int0 interrupt
void int0(void) interrupt 0
{
//add your code here
}
//int1 interrupt
void int1(void) interrupt 2
{
//add your code here
boxing ++;
}
void Display(uint i) {
uint qian,bai,shi,ge; //以下分离出数位并显示
ge = i%10;
shi = (i%100)/10;
bai = (i%1000)/100;
qian = i/1000;
wula =1;
led1=1;
wula =0;
led1 =0;
//P3 = 0x01 << 3;
dula =1;
P0 = LED_CODE;
dula =0;
P0 = 0xff;
delayms(1);
wula =1;
led2=1;
wula =0;
led2 =0;
// P3 = 0x01 << 2;
dula =1;
P0 = LED_CODE;
dula =0;
P0 = 0xff;
delayms(1);
wula =1;
led3=1;
wula =0;
led3 =0;
// P3 = 0x01 << 1;
dula =1;
P0 = LED_CODE;
dula =0;
P0 = 0xff;
delayms(1);
wula =1;
led4=1;
wula =0;
led4 =0;
// P3 = 0x01 << 0;
dula =1;
P0 = LED_CODE;
dula =0;
P0 = 0xff;
delayms(1);
}
/******************z秒延时函数*************************/
void delay(uint s)
{
uint x;
for(x=s;x>0;x--)
delayms(1000);
}
void delayms(uint ms)//延时毫秒
{
uint x,y;
for(x=ms;x>0;x--)
for(y=110;y>0;y--);
}
/****************微秒延时******************************/
void delayus(uint us)
{
_nop_();
}
Hmily 发表于 2014-11-24 19:14
感觉内容有些简单。
我还有几十个普通设计没发,太复杂的那些都是我的商业程序,不能发出来
单片机程序也能申请吗,吾爱可是计算机技术交流的论坛诶
页:
[1]