I am often away from home for several days, and have always wanted to make something that feeds fish automatically. I searched for it on the Internet for a long time, and I saw one that used a 15F104W microcontroller and only used the timer function to vibrate the fish food at a fixed time. I didn't like it very much. Today I would like to share with you a small work that I designed and made by myself, and I am quite satisfied with it.
The actual picture produced is as follows:
Pin Assignment lcd lcddata: P0
lcd_e: P2^7
lcd_rs: P2^6
lcd_rw: P2^5
Set the button limit_choise: P //Temperature upper and lower limit selection button
increase_temperature P //Increase temperature limit button
reduce_temperature P //Reduce temperature limit button
Buzzer alarm warning P
Temperature sensor temperature_sensor P
Heating
Refrigerating
LED display normal P //Normal temperature indicator
high_temperature P //High temperature indicator light
low_temperature P //Low temperature indicator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
The C language reference source code is as follows:
#include void DelayUs(unsigned char tu) { while(–tu); } void DelayMs(unsigned char tm) { while(tm–) { DelayUs(248); DelayUs(248); } } void dianji() //Feed the fish { unsigned int i; speed=10; i=3000; while(i–) { A_ON DelayMs(speed); AB_ON DelayMs(speed); B_ON DelayMs(speed); BC_ON DelayMs(speed); C_ON DelayMs(speed); CD_ON DelayMs(speed); D_ON DelayMs(speed); DA_ON DelayMs(speed); } ABCD_OFF } void dianji_shoudong() //Manually feed the fish { unsigned int i; speed=10; i=500; while(i–) { A_ON DelayMs(speed); AB_ON DelayMs(speed); B_ON DelayMs(speed); BC_ON DelayMs(speed); C_ON DelayMs(speed); CD_ON DelayMs(speed); D_ON DelayMs(speed); DA_ON DelayMs(speed); } ABCD_OFF } void Timer0Init() { TMOD|=0X01; TH0=0xB8; //11.0592M crystal oscillator timing 20ms TL0=0x00; ET0=1; EA=1; TR0=1; } void main()//main function { init(); //initialization function K1=1; XIAODU=1; YANGQI=1; BENG=1; Timer0Init(); while(1) { temp_control(); //Control button function unnormal_proccessing(get_temp(Ds18b20ReadTemp()),up_limit_temp,down_limit_temp);//Constant temperature control function if((h0)&(m0)&(s5))BENG=0; if((h3)&(m0)&(s0))BENG=1; if((h4)&(m0)&(s0))BENG=0; if((h7)&(m0)&(s0))BENG=1; if((h8)&(m0)&(s0))BENG=0; if((h11)&(m0)&(s0))BENG=1; if(BENG1) { YANGQI=0; XIAODU=1; } else { YANGQI=1; XIAODU=0; } if((h6)&(m0)&(s0)) { dianji(); } if(K10) { DelayMs(20); if(K10) { dianji_shoudong(); } } } } void init()//initialization function { uint i,j; // Function initialization LcdInit(); //LCD initialization function Ds18b20Init(); //I/O port initialization heating=1;//No heating refrigerating=1; // No refrigeration normal=1; //Normal temperature indicator light does not display unnormal=1; // Abnormal temperature indicator light does not display warning=1; //Buzzer does not alarm //LCD initialization display LcdWriteCom(0x80); //First line display j=strlen(num1); for(i=0; i LcdWriteData(num1[i]); delay_ms(1); } LcdWriteCom(0x80+0x40); //The second line is displayed j=strlen(num2); for(i=0; i LcdWriteData(num2[i]); delay_ms(1); } LcdWriteCom(0x04); //Close writing a pointer plus 1 } uint get_temp(uint temp) //Calculate temperature function { float tp; tp=temp; //Because the data processing has a decimal point, the temperature is assigned to a floating point variable //If the temperature is positive, then the original code of the positive number is the complement code itself temp=tp0.0625100+0.5; //Leave two decimal points and *100, +0.5 is rounded, because the decimal point is rounded when the C language floating point number is converted to an integer //The number behind is automatically removed, regardless of whether it is greater than 0.5, and after +0.5, the number greater than 0.5 is increased by 1, and the number less than 0.5 is increased by 1. //Calculate and add 0.5, or after the decimal point. return temp; } void display_real_tenp(uint temp) //Real-time temperature display function { uchar datas[] = {0, 0, 0, 0}; //define array datas[0] = temp % 10000 / 1000; datas[1] = temp % 1000 / 100; datas[2] = temp % 100 / 10; datas[3] = temp % 10; LcdWriteCom(0x80+0x0a); //Write address 80 indicates the initial address LcdWriteData('0'+datas[0]); //ten digits LcdWriteCom(0x80+0x0b); //Write address 80 indicates the initial address LcdWriteData('0'+datas[1]); //unit LcdWriteCom(0x80+0x0d); //Write address 80 indicates the initial address LcdWriteData('0'+datas[2]); //Display decimal point LcdWriteCom(0x80+0x0e); //Write address 80 indicates the initial address LcdWriteData('0'+datas[3]); //Display decimal point } void temp_control()//Control temperature upper and lower limit function { if(limit_choise0)//Select button { delay_ms(5); if(limit_choise0) { while(!limit_choise); limit_choise_num++; if(limit_choise_num>=3) { limit_choise_num=0; } } } if(limit_choise_num==0)//normal display { LcdWriteCom(0x0c); //Close the cursor display_real_tenp(get_temp(Ds18b20ReadTemp()));//display function } if(limit_choise_num1) //Adjust the upper limit temperature { LcdWriteCom(0x80+0X40+2); LcdWriteCom(0x0f); //Open the cursor if(increase_temperature0) //Increase temperature { delay_ms(5); if(increase_temperature0) { while(!increase_temperature); up_limit_temp++; if(up_limit_temp>=100) { up_limit_temp=0; } //Write new data LcdWriteCom(0x80+0X40+0x03); LcdWriteData('0'+up_limit_temp/10); LcdWriteCom(0x80+0X40+0x04); LcdWriteData('0'+up_limit_temp%10); LcdWriteCom(0x80+0X40+2); //Cursor write back } } if(reduce_temperature0) //Reduce temperature { delay_ms(5); if(reduce_temperature==0) { while(!reduce_temperature); up_limit_temp–; if(up_limit_temp<0) { up_limit_temp=99; } //Write new data LcdWriteCom(0x80+0X40+0x03); LcdWriteData('0'+up_limit_temp/10); LcdWriteCom(0x80+0X40+0x04); LcdWriteData('0'+up_limit_temp%10); LcdWriteCom(0x80+0X40+2); //Cursor write back } } } if(limit_choise_num2) //Adjust the lower limit temperature { LcdWriteCom(0x80+0X40+12); LcdWriteCom(0x0f); //Open the cursor if(increase_temperature0) //Increase temperature { delay_ms(5); if(increase_temperature0) { while(!increase_temperature); down_limit_temp++; if(down_limit_temp>=100) { down_limit_temp=0; } //Write new data LcdWriteCom(0x80+0X40+0x0d); LcdWriteData('0'+down_limit_temp/10); LcdWriteCom(0x80+0X40+0x0e); LcdWriteData('0'+down_limit_temp%10); LcdWriteCom(0x80+0X40+12); //Cursor write back } } if(reduce_temperature0) //Reduce temperature { delay_ms(5); if(reduce_temperature==0) { while(!reduce_temperature); down_limit_temp–; if(down_limit_temp<0) { down_limit_temp=99; } //Write new data LcdWriteCom(0x80+0X40+0x0d); LcdWriteData('0'+down_limit_temp/10); LcdWriteCom(0x80+0X40+0x0e); LcdWriteData('0'+down_limit_temp%10); LcdWriteCom(0x80+0X40+12); //Cursor write back } } } } void unnormal_proccessing(uint temp,uint up_temp,uint down_temp) //constant temperature control function { uchar datas[] = {0, 0, 0, 0}; //define array uint temp1=0; datas[0] = temp % 10000 / 1000; datas[1] = temp % 1000 / 100; datas[2] = temp % 100 / 10; datas[3] = temp % 10; temp1=datas[0]*1000+datas[1]*100+datas[2]*10+datas[3]; //The actual temperature multiplied by 100 if(temp1 < down_temp*100) // Heating function { heating=0; //Heating refrigerating=1; // No refrigeration unnormal=0; //Abnormal temperature indicator light display normal=1; //Normal temperature indicator light does not display //Buzzer alarm //warning=0; //delay_ms(10); //warning=1; } else if(temp1 > up_temp*100)//cooling function { heating=1;//No heating refrigerating=0; // refrigeration unnormal=0; //Abnormal temperature indicator light display normal=1; //Normal temperature indicator light does not display //Buzzer alarm // warning=0; //delay_ms(10); // warning=1; } else//normal { heating=1;//No heating refrigerating=1; // No refrigeration unnormal=1; // Abnormal temperature indicator light does not display normal=0; //Normal temperature indicator light display //Buzzer does not alarm // warning=1; } } void Time0() interrupt 1 { static u8 i; TH0=0xB8; //11.0592M crystal oscillator timing 20ms TL0=0x00; i++; if(i>=50) //1 second timeout { i=0; Due to limited space, only part of the code can be written
Previous article:Design and production of single chip microcomputer lithium battery capacity tester
Next article:Semiconductor refrigeration refrigerator made of single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- [GD32307E-START] Development practice->K2 button + USART to achieve user interaction control + USRT print output status
- Looking for TI training course handouts!
- BQ24172 abnormal charging discussion and solution
- EEWORLD University Hall ---- Xiaomeige 2019 FPGA training course full HD recording
- Introduction to Oscilloscope Probes
- Schottky diode voltage drop test
- Oscilloscope is fun, it’s more than just waveform display!
- Feiling FETT507-C core board 4-way AHD camera implementation solution
- DSP ccs2 C5000 compiles SUBC instruction to implement division
- Push-button start system power supply circuit