我学的是强电专业,这个是我毕业设计做的一个很简单而且被我做的很粗糙的的东西,用了DHT11,DS1302,HMI的显示屏,还有一个5v直流电动机,两个按键,一个按键是单片机根据温度自动控制电机转速,一个是手动按,按一下就加快转速,当然,时间,温度,湿度,电机转速,是否是自动控制,风速多少,都在HMI显示屏显示出来了,我的电机是和单片机I/O口直接连接,因为能动能显示出不同风速的差别,毕业设计嘛,没想的太多,程序和编写HMI的界面软件都在在附件里面,本来是不想写这个帖子的,因为自己做的非常粗糙,但是想到自己这两个月又是实物又是论文,大家找资料并不容易,希望我的东西能给大家一些参考的东西,因为已经出来工作了,所以关于实物的图片并没有了,只能给大家看一下,HMI显示的仿真界面,为什么不用TFT的呢。其实我有一块TFT的,但是焊接的时候弄坏了,之后淘宝一看人机界面多高端啊,就买了个HMI的,对了HMI的软件是
usart hmi
这个就是界面,真的和仿真的是一样的
STC90C516RD+单片机源程序如下:
- #include <reg52.h>
- #include <hmi.h>
- #include <intrins.h>
- #include <stdio.h>
- #include <THT11.h>
- #include <delay.h>
- #include <i2c.h>
- #include <ds1302.h>
- #define KeyPort P0
- sbit DCOUT = P1^7;
- unsigned char PWM_ON=0,PWM; //定义速度等级
- #define CYCLE 10 //周期
- unsigned char KeyScan(void);//键盘扫描
- void Init_Timer0(void);
- unsigned char code digit[10]={"0123456789"};
- int TMEPX[6]={40,50,60,70,80,90};
- unsigned char second,minute,Value,hour,day,month,year;
- unsigned char m,n,j,k,h,g;
- unsigned char ReadValue;
- char str[1];
- main()
- {
- unsigned char num;
- PWM_ON=0;
- Init_Timer0();
- Init_DS1302();
- system_Ini();
- DHT11_ReadTempAndHumi();
- m=temp_value/10/10;
- n=temp_value/10%10;
- j=humi_value/10/10;
- k=humi_value/10%10;
- while(1)
- {
- Delay_1ms(10);
- Delay_1ms(10);
- ReadValue = ReadSet1302(0x81);
- second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- h=second/10;
- g=second%10;
- UART_Send_Str("t10.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t11.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- ReadValue = ReadSet1302(0x83);
- minute=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- h=minute/10;
- g=minute%10;
- UART_Send_Str("t8.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t9.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- ReadValue = ReadSet1302(0x85);
- hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- h=hour/10;
- g=hour%10;
- UART_Send_Str("t6.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t7.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- ReadValue = ReadSet1302(0x87);
- day=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- h=day/10;
- g=day%10;
- UART_Send_Str("t4.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t5.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- ReadValue = ReadSet1302(0x89);
- month=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- h=month/10;
- g=month%10;
- UART_Send_Str("t2.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t3.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- ReadValue = ReadSet1302(0x8d);
- year=((ReadValue&0xf0)>>4)*10 + (ReadValue&0x0F);
- h=year/10;
- g=year%10;
- UART_Send_Str("t0.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(h+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t1.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(g+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t12.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(j+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t13.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(k+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t14.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(m+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t15.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(n+48);
- UART_Send_Byte(34);
- UART_Send_END();
- num=KeyScan();
- if(num==1)
- {
- UART_Send_Str("t16.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(1+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t18.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(0+48);
- UART_Send_Byte(34);
- UART_Send_END();
- if(PWM_ON<CYCLE)
- PWM_ON++;
- }
- else if(num==2)
- {
- UART_Send_Str("t16.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(0+48);
- UART_Send_Byte(34);
- UART_Send_END();
- UART_Send_Str("t18.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(1+48);
- UART_Send_Byte(34);
- UART_Send_END();
- if(m==0)
- PWM_ON=1;
- if(m==1)
- PWM_ON=3;
- if(m==2)
- PWM_ON=5;
- if(m==3)
- PWM_ON=9;
- }
- PWM=PWM_ON%10;
- UART_Send_Str("t20.txt=");
- UART_Send_Byte(34);
- UART_Send_Byte(PWM+48);
- UART_Send_Byte(34);
- UART_Send_END();
-
- DelayMs(100);
- }
- }
- void Init_Timer0(void)
- {
- TMOD |= 0x01;
- EA=1;
- ET0=1;
- TR0=1;
- }
- void Timer0_isr(void) interrupt 1
- {
- static unsigned char count;
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- if (count==PWM_ON)
- {
- DCOUT = 0;
- }
- count++;
- if(count == CYCLE)
- {
- count=0;
- if(PWM_ON!=0)
- DCOUT = 1;
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
20170405 - 副本 (2).zip
(93.78 KB, 下载次数: 24)
|