Fan control system-initial version

Source: Internet
Author: User
Tags 0xc0
Fan control system-initial versionUse 51 Single-Chip Microcomputer to implement the fan control system, including hardware to software. (Functions are not complete and need to be improved)



The hardware code is as follows: /*************************************** * ***************************** File Name: fan control intelligent system * description: 1. the infrared remote control board controls the switch speed of the fan. 2. The liquid crystal display displays the fan's working condition. 3. The client displays the fan's working condition. 4. The client controls the fan. 5. The timed switch fan is led down to 6, when the fan is turned on, record the last speed stop * created: wu_zhuojun, February 16, 2014 Beijing * version: 2.0 *************************************** * ******************************/# include <reg51.h> # include <intrins. h> # define uchar unsigned char # define uint unsigned in T uchar LCD _id_1 [16] = {"I Have a Dream! "}; Uchar LCD _id_2 [16] = {" Speed: 0 "}; void delay (uchar X); // x * 0.14 msvoid delay1 (INT MS ); void BEEP (); sbit IRIN = P3 ^ 3; // infrared receiver data line sbit beep = p1 ^ 5; // buzzer driver line sbit relay = p1 ^ 4; // relay driving line uchar ircom [7]; sbit E = P2 ^ 7; // 1602 enable pin sbit RW = P2 ^ 6; // 1602 read/write pin sbit rs = P2 ^ 5; // 1602 data/command selection pin /******************************* * *********************************** Name: delay () * function: delay. The delay time is about 140us. * Input: none * output: no *************************************** * ******************************/void delay2 () {int I, j; for (I = 0; I <= 10; I ++) for (j = 0; j <= 2; j ++ );} /*************************************** * ***************************** Name: enable (uchar del) * function: 1602 command function * input: input command value * output: no *************************************** * ******************************/void enable (uchar del) {p0 = del; RS = 0; RW = 0; E = 0; delay2 (); E = 1; delay2 ();} /*************************************** * ***************************** Name: write (uchar del) * function: 1602 write data function * input: 1602 of the data to be written * output: no *************************************** * ******************************/void write (uchar del) {p0 = del; RS = 1; RW = 0; E = 0; delay2 (); E = 1; delay2 ();} /*************************************** * ***************************** Name: l1602_in It () * function: 1602 initialization. Please refer to the information in section * input: none * output: no *************************************** * ******************************/void l1602_init (void) {enable (0x01); Enable (0x38); Enable (0x0c); Enable (0x06); Enable (0xd0 );} /*************************************** * ***************************** Name: l1602_char (uchar hang, uchar lie, char sign) * function: change a value in the liquid crystal. If you want to display the first line with the fifth character "B ", call this function as follows l1602_char (, 'B') * input: Row, column, required Input 1602 of Data * output: no *************************************** * *****************************/void l1602_char (uchar hang, uchar lie, char sign) {uchar A; If (Hang = 1) A = 0x80; If (Hang = 2) A = 0xc0; A = a + lie-1; Enable (a); write (sign );} /*************************************** * ***************************** Name: l1602_string (uchar hang, uchar lie, uchar * P) * function: change a value in the liquid crystal. If you want to display the first line with the fifth character "AB CD EF ", call this letter The numbers are as follows: l1602_string (1602, "AB CD EF;") * input: Row, column, of data is required * output: no *************************************** ******************************/void l1602_string (uchar hang, uchar lie, uchar * P) {uchar A; If (Hang = 1) A = 0x80; If (Hang = 2) A = 0xc0; A = a + lie-1; Enable (a); While (1) {If (* P = '\ 0') break; write (* P ); P ++ ;}} /*************************************** * ***************************** Name: com_init () * Function: Initialize the serial program, crystal oscillator 11.0592, baud rate 9600 * input: none * output: no *************************************** * *******************************/void com_init (void) {tmod = 0x20; pcon = 0x00; scon = 0x50; Th1 = 0xfd; TL1 = 0xfd; tr1 = 1 ;} /*************************************** * ***************************** Name: main () * function: * input: none * output: no *************************************** * *******************************/main () {// required The serial port used to send the data is the serial port of the program, not the 9-pin serial port // uchar code buffer [] = "wo Shi wuzhuojun"; // uchar * P = buffer; // P2 = 0x00; // P = buffer; /// ============ initialize the infrared control begin ==========// Ie = 0x84; // allow the total interruption, enable int1 External Interrupt tcon = 0x10; // trigger mode: pulse negative edge trigger IRIN = 1; // I/O port initialization beep = 1; relay = 1; // =========== initialize the infrared control end ==========/delay1 (10); // latency l1602_init (); // initialize the LCD l1602_string (1, 1, LCD _id_1); // set the LCD display content l1602_string (2, 1, LCD _ I D_2); // set the content of LCD _id_2 displayed on the LCD screen // ======== initialize the serial port begin ========/com_init (); # If 0 while (1) {sbuf = * P; while (! Ti) // if the sending is complete, the hardware will set Ti {_ NOP _ ();} p ++; If (* P = '\ 0') break; // at the end of each string, A '\ 0' Ti = 0; // Ti erasing} # endif // ======= initialize the serial port begin ========// while (1 );} // end main /*********************************** * ********************************* Name: ir_in interrupt 2 using 0 * function: receives infrared data and interrupts processing. The LCD screen displays * input: none * output: no *************************************** * ******************************/void ir_in () interrupt 2 using 0 {// = ===== Initialize the data variable begin =/uchar code strspeed [] [4] = {"0", "1 ", "2", "3"}; uchar * P = strspeed [0]; // The Initialization is 0. // ======== initialize the data transmission variable end ========/// unsigned char j, k, n = 0; ex1 = 0; delay (15); If (IRIN = 1) {ex1 = 1; return;} // confirm that the while (! IRIN) // wait for the IR to become high, skipping the 9 ms leading low level signal. {Delay (1) ;}for (j = 0; j <4; j ++) // collect four groups of data {for (k = 0; k <8; k ++) // each group of data records has eight characters {While (IRIN) // The other IR changes to a low level, skipping the leading high level signal of Ms. {Delay (1) ;}while (! IRIN) // wait for the IR to become high {delay (1);} while (IRIN) // calculate the height of the IR at ordinary times {delay (1); N ++; if (n> = 30) {ex1 = 1; return;} // If (n> = 30) // 0.14ms the count is too long and automatically leaves.} // While (IRIN) // ircom [J] = ircom [J]> 1 after the High-Level count is completed; // The maximum bit of data is "0" if (n> = 8) {ircom [J] = ircom [J] | 0x80; // fill in "1"} // If (n> = 8) n = 0 ;} // For (k = 0; k <8; k ++)} // For (j = 0; j <4; j ++) if (ircom [2]! = ~ Ircom [3]) {ex1 = 1; return;} ircom [5] = ircom [2] & 0x0f; // The minimum four-digit ircom [6] = ircom [2]> 4; // shifts the value four times to the right, the four-digit increase is changed to the four-digit lower if (ircom [5]> 9) {ircom [5] = ircom [5] + 0x37 ;} else ircom [5] = ircom [5] + 0x30; If (ircom [6]> 9) {ircom [6] = ircom [6] + 0x37 ;} else ircom [6] = ircom [6] + 0x30; // ======== begin control of LCD display data ============/// l1602_char (, ircom [5]); // l1602_char (2, 9, ircom [6]); If ('4' = ircom [6]) & ('5' = ircom [5]) // trigger key {P = Strspeed [0]; // speed l1602_char (2, 8, '0');} else if ('0' = ircom [6]) & ('c' = ircom [5]) // trigger key 1 {P = strspeed [1]; // speed l1602_char, '1');} else if ('1' = ircom [6]) & ('8' = ircom [5]) // trigger key 2 {P = strspeed [2]; // speed l1602_char (2, 8, '2 ');} else if ('5' = ircom [6]) & ('E' = ircom [5]) // trigger key 3 {P = strspeed [3]; // speed l1602_char (2, 8, '3 ');} // ========= control the end of the LCD display data ============//// ====== = Send serial data begin ==========/// while (1) {sbuf = * P; while (! Ti) // if the sending is complete, the hardware will set Ti {_ NOP _ ();} p ++; If (* P = '\ 0') break; // at the end of each string, A '\ 0' Ti = 0; // Ti erasing} // ========== send serial port data end ============/// BEEP (); ex1 = 1 ;} /*************************************** * ******************/void BEEP () {unsigned char I; for (I = 0; I <100; I ++) {delay (4); beep =! Beep; // obtain the inverse of beep} beep = 1; // close the BUZZER }/********************************** * **********************/void delay (unsigned char X) // x * 0.14 Ms {unsigned char I; while (X --) {for (I = 0; I <13; I ++) {}}}/*********************************** */void delay1 (int ms) {unsigned char y; while (MS --) {for (y = 0; y <250; y ++) {_ NOP _(); _ NOP _ (); _ NOP _ () ;}} the serial port receives data from a single-chip microcomputer: the software implementation code is as follows: (to be continued)

Fan control system-initial version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.