设计做的,比较简单,手机通过UART连接单片机,PWM可任意调速,注意风扇的驱动电压。
#include <msp430f169.h>
#include "lcd12864.h"
#include "PWM.h"
#include "UART.h"
#include "adc.h"
unsigned char key = 0;
unsigned char Statu = 0;
unsigned int a = 0;
#pragma vector=USART0RX_VECTOR
__interrupt void USART0_RX_ISR(void)
{
unsigned char data=0;
data=U0RXBUF; //接收到的数据存起来
key = data;
Uart0Send_Byte(data); //将接收到的数据再发送出去
}
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
Clock_Init(1); // 0 就是 1M, 1 就是 8M
PWM_init(); // Init the PWM
Port_init(); // Init the LCD1602
LCD_init();
UART0_Init();
LCD_Desk();
ADC_Init();
_BIS_SR(GIE); //开启系统中断
while(1){
LCD_Desk();
ADC();
LCD_DisplayTemp((uchar)TemperC);
delay_ms(500);
_NOP();
switch(key){
case 49:start(); LCD_write_str(4,2,"1"); LCD_write_str(4,1,"ON ");break;
case 50:speed(1);LCD_Display_num(4,2,2);LCD_write_str(4,1,"ON ");break;
case 51:speed(2);LCD_Display_num(4,2,3);LCD_write_str(4,1,"ON ");break;
case 52:speed(3);LCD_Display_num(4,2,4);LCD_write_str(4,1,"ON ");break;
case 48:stop(); LCD_write_str(4,2,"0");LCD_write_str(4,1,"OFF");break;
default:break;
}
key=0;
}
}
lan_ya_fan.7z
(43.55 KB, 下载次数: 4)
|