How to Design a Bluetooth Control Fan System with 51 Single-chip Microcomputer

This is a project I did when I was a sophomore to learn 51 SCM. In fact, this project is relatively simple, but it is too difficult for us to think of it myself. Let me summarize the specific design process.

First buy a Bluetooth module, I bought the HC-06, download a Bluetooth serial debugging assistant on the phone, equivalent to the UART serial port communication microcontroller, use BUFF to obtain the received data, here only need to pay attention to a problem, that is, testing Coding, if the APP sends 0xFF, (APP Bluetooth Serial Debugging Assistant already supports manual setting of button names and sent characters) But the Bluetooth module is likely to receive 0xF8, 0xF2, 0xFE. So here we should first test the coding. HC-06 generally has 5 ports, RX, TX, VCC, GND, AT, AT here we do not use, refers to change the password, the default password is generally 1234 or 0000, connect VCC and GND, then RX and TX Respectively and the one-chip computer's TX and RX are connected (is P3^0 and P3^1, must remember to connect to the contrary), then we according to the general UART serial communication is OK, the inspection receives the BUFF data, then the switch can realize the corresponding Features.

#include

#define uchar unsigned char

#define uint unsigned int

Sbit PWM=P1^0;

Sbit DSPORT=P3^7;

Void Ds18b20ReadTemp();

Void UsartConfiguration();

Unsigned int temp=0;

Unsigned char zhuanshu=20;

Unsigned int cnt=0;

Unsigned char receiveData;

Unsigned int dingshi=0;

Unsigned char min=1;

Void main(void)

{

Unsigned int i=3000;

UsartConfiguration();

While(1)

{

If(cnt>=3000)

{

Cnt=0;

Ds18b20ReadTemp(); //3s detects temperature once

}

Switch(receiveData)

{

Case 177:ET0=1;zhuanshu=20;receiveData=0;break; // Number 1 fan start

Case 178: zhuanshu=0;while(i--);ET0=0;receiveData=0;break; //The number 2 fan stops because the IO port is high by default so let zhuanshu=0

Case 179: zhuanshu=30;break;//number 3 low

Case 180: zhuanshu=50;break;//number 4 middle block

Case 181:zhuanshu=70;break;// digital 5 high gear

Case 182: // Digital 6 automatically adjusts the speed according to the temperature

{

If(temp<3200)

{

Zhuanshu=25;

}

If((temp>3200)&&(temp<3300))

{

Zhuanshu=30;

}

If((temp>3400)&&(temp<3600))

{

Zhuanshu=50;

}

If((temp>3200)&&(temp<3300))

{

Zhuanshu=60;

}

} break;

Case 183: //Timed number digit 7

{

Static dingshi=0;

If(dingshi>=60000) //A benchmark for 1 minute

{

Min--;

Dingshi=0;

If(min==0)

{

ET0=0;

Zhuanshu=0;

}

}

Break;

Case 184: receiveData=0;min++;break; // increase time number 8

Case 185: receiveData=0;min--;break; //decrease time number 9

}

}

}

}

Void UsartConfiguration()

{

SCON=0X50; //Set to work mode 1

TMOD=0X21; //Set counter work mode 2

PCON=0X80; // Double the baud rate

TH0 = 0xFC;

TL0 = 0x66;

TH1 = 0XF9; / / counter initial value settings, pay attention to the baud rate is 9600

TL1=0XF9;

ET0=1;

ES=1; //Open receive interrupt

EA=1; //Open total interrupt

TR1=1;

TR0=1; //Open the counter

}

Void Usart() interrupt 4

{

receiveData=SBUF; //Outgoing received data

RI = 0; // Clear Receive Interrupt Flag

}

Void Time1(void) interrupt 1 //3 is the interrupt number 1 of timer 1 Interrupt number 0 of timer 0 External interrupt 1 2 External interrupt 2 4 Serial port interrupt

{

Static unsigned char timer1=0;

TH0 = 0xF6; //Reassign initial value

TL0 = 0x66;

Timer1++;

Cnt++;

Dingshi++;

If(dingshi>=60050)

{

Dingshi=0;

}

If(timer1>100) //The PWM period is 100*0.5ms

{

Timer1=0;

}

If(timer1

{

PWM=1;

}

Else

{

PWM=0;

}

}

Void Delay1ms(uint y) //Delay program

{

Uint x;

For( ; y>0; y--)

{

For(x=110; x>0; x--);

}

}

Uchar Ds18b20Init() // temperature subfunction

{

Uchar i;

DSPORT = 0; //Pull the bus low 480us~960us

i = 70;

While(i--);//delay 642us

DSPORT = 1; //then pull up the bus, if the DS18B20 reacts it will pull the bus low after 15us~60us

i = 0;

While(DSPORT) //wait for the DS18B20 to pull down the bus

{

i++;

If(i>5)//wait >5MS

{

Return 0;//initialization failed

}

Delay1ms(1);

}

Return 1;// initialization was successful

}

Void Ds18b20WriteByte(uchar dat)

{

Uint i, j;

For(j=0; j<8; j++)

{

DSPORT = 0; // Pull the bus low 1us before writing one bit of data

i++;

DSPORT = dat & 0x01; // Then write a data starting from the lowest bit

i=6;

While(i--); // delay 68us, duration 60us minimum

DSPORT = 1; // Then release the bus, at least 1us to the bus recovery time to write the second value

Dat >>= 1;

}

}

Uchar Ds18b20ReadByte()

{

Uchar byte, bi;

Uint i, j;

For(j=8; j>0; j--)

{

DSPORT = 0;//first pull the bus low 1us

i++;

DSPORT = 1;// Then release the bus

i++;

i++;//delay 6us waiting for data stabilization

Bi = DSPORT; //Read data, read from lowest bit

/* Moves byte one bit to the left, and then shifts the first 7 bits from the right to the right bit. Note that the zero is removed after the move. */

Byte = (byte >> 1) | (bi << 7);

i = 4; // After reading, wait 48us and then read the next number

While(i--);

}

Return byte;

}

Void Ds18b20ChangTemp()

{

Ds18b20Init();

Delay1ms(1);

Ds18b20WriteByte(0xcc) ;// Skip ROM operation command

Ds18b20WriteByte(0x44); //temperature conversion command

// Delay1ms(100) ;// Wait for the conversion to succeed, and if you are always brushing, then do not use this delay

}

Void Ds18b20ReadTempCom()

{

Ds18b20Init();

Delay1ms(1);

Ds18b20WriteByte(0xcc) ;// Skip ROM operation command

Ds18b20WriteByte(0xbe);//Send read temperature command

}

Void Ds18b20ReadTemp()

{

Float tp;

Int temp1 = 0;

Uchar tmh, tml;

Ds18b20ChangTemp();//write conversion command first

Ds18b20ReadTempCom () ;/ / Then wait for the conversion to send the read temperature command

Tml = Ds18b20ReadByte();//Read temperature value total 16 bits, read low byte first

Tmh = Ds18b20ReadByte(); //Reread high byte

Temp1 = tmh;

Temp1 <<= 8;

Temp1 |= tml;

If(temp1< 0)

{

Temp1=temp1-1;

Temp1=~temp1;

Tp=temp1;

Temp1=tp*0.0625*100+0.5;

}

Else

{

Tp=temp1;

Temp1=tp*0.0625*100+0.5;

}

Temp=temp1%10000;

}


LCD TFT

LCD (short for Liquid Crystal Display) liquid crystal display. The LCD structure is to place a liquid crystal cell between two parallel glass substrates. The lower substrate glass is equipped with TFT (Thin Film Transistor), and the upper substrate glass is equipped with a color filter. The liquid crystal molecules are controlled by the signal and voltage changes on the TFT. Rotate the direction, so as to control whether the polarized light of each pixel point is emitted or not to achieve the purpose of display. LCD has replaced CRT as the mainstream, and the price has dropped a lot, and it has become fully popular.


According to data from CINNO Research, 2020 is expected to be the first year for mass production of mobile phones with fingerprint recognition under LCD screens.

LCD features:

(1) Low-voltage micro power consumption
(2) The appearance is small and exquisite, the thickness is only 6.5~8mm
(3) Passive display type (no glare, no irritation to human eyes, and no eye fatigue)
(4) The amount of display information is large (because the pixels can be made small)
(5) Easy to colorize (reproduce very accurately on the chromatogram)
(6) No electromagnetic radiation (safe for the human body, conducive to information confidentiality)
(7) Long life (this kind of device has almost no deterioration problem, so the life is extremely long, but the life of the LCD backlight is limited, but the backlight part can be replaced)

Lcd Tft,Tft Lcd Led Projector,Tft Lcd Library,LCD panels

ESEN Optoelectronics Technology Co., Ltd, , https://www.esenlcd.com