串口波特率9600
通过CC2530芯片通风温湿度模块获取温度,将温度值通过串口软件发送到PC机,通过对温度值的大小(阈值自行设置)来控制风扇的开关



串口波特率9600
通过CC2530芯片通风温湿度模块获取温度,将温度值通过串口软件发送到PC机,通过对温度值的大小(阈值自行设置)来控制风扇的开关



关注先参考下这个:
#include <REG51.H>
#include <stdio.h>
#define FAN_PIN P1_0
#define BAUDRATE 9600
#define TH_RS232_TXV2 P0_4
void UART_Init(void)
{
P0SEL &= ~0x40;
P2DIR &= ~0xC0;
PERCFG |= 0x01;
U1CSR = 0x00;
U1BAUD = BAUDRATE;
U1GCR = 8;
U1CSR |=0x40;
IEN0 |= 0x84;
TH_RS232_TXV2 = 1;
}
void UART_Int_Enable(void)
{
URX1IE=1;
EA=1;
}
void UART_Int_Disable(void)
{
URX1IE=0;
}
void uart_send(char data)
{
U1DBUF = data;
while(!(U1CSR & 0x02));
U1CSR &= ~0x02;
}
void control_fan(int temperature)
{
if(temperature >= 25)
{
FAN_PIN = 1;
}
else
{
FAN_PIN = 0;
}
}
void UART_RX_ISR(void) interrupt 6
{
if (URX1IF==1)
{
int temprature = U1DBUF; // Assuming Temperature data is sent over UART.
control_fan(temperature);
URX1IF=0;
}
}
void main()
{
UART_Init();
UART_Int_Enable();
while(1)
{
_nop_(); // Just do nothing.
}
}