msp430f169 bluetooth fan adjustable speed program
[Copy link]
The design is relatively simple. The mobile phone is connected to the microcontroller via UART. The PWM can adjust the speed arbitrarily. Pay attention to the driving voltage of the fan.
#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; //Save the received data
key = data;
Uart0Send_Byte(data); //Send the received data again
}
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
Clock_Init(1); // 0 is 1M, 1 is 8M
PWM_init(); // Init the PWM
Port_init(); // Init the LCD1602
LCD_init();
UART0_Init();
LCD_Desk();
ADC_Init();
_BIS_SR(GIE); //Enable system interrupt
while(1){
LCD_Desk();
ADC();
LCD_DisplayTemp((uchar)TemperC);
delay_ms(500);
_NOP();
switch(key){
case 49:start(); LCD_write_str(4,2,"1"); 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, downloads: 4)
|