In addition to normal saving, after compiling correctly, choose to save as a .h file with the same name, and change the main function name in the h file to other names, such as xmain, or main1, etc., then the new project can call the function in the original project!
1. Project 1 first write LCD1602, and after compiling without error, save LCD1602.c as LCD1602.h, and change the main() function file in LCD1602.h to main0()
#include #include sbit rs=P2^0; sbit rw=P2^1; sbit e=P2^2; void delay(unsigned char us) { while(us--); } void w1602(bit r,unsigned char dat) { rs=r; rw=0; e=0; P1=dat; delay(3); e=1; delay(7); e=0; } void init1602() { w1602(0,0x38); w1602(0,0x06); w1602(0,0x0c); w1602(0,0x01); } void main() { char i; init1602(); w1602(0,0x80); for(i=0;i<10;i++) { w1602(1,0x30+i); } } 2. Create DS1302 perpetual calendar project DS1302 #include "reg52.h" #include "intrins.h" //Note that the above project is imported into this project as a header file #include "LCD1602.h" sbit rst=P2^3; sbit sclk=P2^4; sbit Dio=P2^5; sbit A7=ACC^7; sbit B0=B^0; void w1302(unsigned char addr,dat) { char i; rst=0; sclk=0; rst=1; for(i=0;i<8;i++) { B=addr>>i; sclk=0; Dio=B0; sclk=1; } for(i=0;i<8;i++) { B=dat>>i; sclk=0; Dio=B0; sclk=1; } rst=0; } unsigned char r1302 (unsigned char addr) { char i; rst=0; sclk=0; _nop_(); rst=1; for(i=0;i<8;i++) { B=addr>>i; sclk=0; Dio=B0; sclk=1; } for(i=0;i<8;i++) { A7=Dio; sclk=1; ACC=ACC>>1; sclk=0; } rst=0; return(ACC); } void main() { init1602(); //The functions in the above project can be called unconditionally w1302(0x80,0x33); while(1) { w1602(0,0x80); w1602(1,0x30+((r1302(0x81)>>4) & 0x0f));//Call w1602(1,0x30+(r1302(0x81) & 0x0f));//Call } } 3. Create a temperature DS18B20 program project #include "reg52.h" #include "intrins.h" #include "LCD1602.h" sbit ds18b20=P2^6; unsigned char dd[]="date:"; unsigned char dd1[]="temp:"; unsigned char temp1,temp2,TT,ttT; bit Reset(void) { bit k; ds18b20=0; delay(145); ds18b20=1; delay(10); k=ds18b20; delay(90); return k; } //--------------------------- unsigned char ReadByte(void) { unsigned char j,buf=0; for(j=0;j<8;j++) { buf=buf>>1; ds18b20=0; _nop_(); _nop_(); ds18b20=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); if(ds18b20==1) buf|=0x80; delay(8); } return buf; } //------------------------------- void WriteByte(unsigned char dat) { unsigned char j; for(j=0;j<8;j++) { if(dat&0x01) { ds18b20=0; _nop_(); _nop_(); ds18b20=1; delay(10); } else { ds18b20=0; delay(10); ds18b20=1; _nop_(); _nop_(); } dat=dat>>1; } } //------------------ bit Convert(void) { if(Reset()==0) { WriteByte(0xcc); WriteByte(0x44); return 1; } else { return 0; } } //--------------------------------------- void ReadFlash(void) { unsigned char Lsb,Msb; if(Reset()==0) { WriteByte(0xcc); WriteByte(0xbe); Lsb=ReadByte(); Msb=ReadByte(); temp1=Lsb; //L 8bit temp2=Msb; //H 8bit } else { temp1=0; temp2=0; } } void disp_temp(unsigned char addr) { char i,m; if(Convert()==1) { ReadFlash(); TT=(temp2<<4)|(temp1>>4)&0x7F; if((TT & 0x80)==0x80) ttT=(~TT & 0x3F)+1; else ttT=TT; } m=20; while(m--) { w1602(0,addr); for(i=0;i<5;i++) w1602(1,dd1[i]); if((TT & 0x80)==0x80) //- { if(TT==0x80) { ttT=128; w1602(1,0x20); w1602(1,0X30+(ttT/100)); w1602(1,0x30+(ttT%100)/10); w1602(1,0x30+ttT%10); } else { w1602(1,0x20); w1602(1,0x2d); if(ttT/10>0) w1602(1,0x30+ttT/10); else w1602(1,0x20); w1602(1,0x30+ttT%10); } } else //+ { w1602(1,0x20); if(ttT/100>0) { w1602(1,0X30+(ttT/100)); w1602(1,0x30+(ttT%100)/10); w1602(1,0x30+(ttT%10)); } else { if((ttT%100)/10>0) { w1602(1,0x30+(ttT%100)/10); w1602(1,0x30+ttT%10); } else w1602(1,0x30+ttT%10); } } w1602(1,0x22); w1602(1,0x43); w1602(1,0x20); w1602(1,0x20); } } void main() { init1602(); while(1) { disp_temp(0xc3); } } 4. Establish comprehensive project DS1302_18B20 #include "reg52.h" #include "intrins.h" #include "DS1302.h" sbit ds18b20=P2^6; unsigned char dd[]="date:"; unsigned char dd1[]="temp:"; unsigned char temp1,temp2,TT,ttT; bit Reset(void) { bit k; ds18b20=0; delay(145); ds18b20=1; delay(10); k=ds18b20; delay(90); return k; } //--------------------------- unsigned char ReadByte(void) { unsigned char j,buf=0; for(j=0;j<8;j++) { buf=buf>>1; ds18b20=0; _nop_(); _nop_(); ds18b20=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); if(ds18b20==1) buf|=0x80; delay(8); } return buf; } //------------------------------- void WriteByte(unsigned char dat) { unsigned char j; for(j=0;j<8;j++) { if(dat&0x01) { ds18b20=0; _nop_(); _nop_(); ds18b20=1; delay(10); } else { ds18b20=0; delay(10); ds18b20=1; _nop_(); _nop_(); } dat=dat>>1; } } //------------------ bit Convert(void) { if(Reset()==0) { WriteByte(0xcc); WriteByte(0x44); return 1; } else { return 0; } } //--------------------------------------- void ReadFlash(void) { unsigned char Lsb,Msb; if(Reset()==0) { WriteByte(0xcc); WriteByte(0xbe); Lsb=ReadByte(); Msb=ReadByte(); temp1=Lsb; //L 8bit temp2=Msb; //H 8bit } else { temp1=0; temp2=0; } } void main() { unsigned char i; init1602(); while(1) { if(Convert()==1) { ReadFlash(); TT=(temp2<<4)|(temp1>>4); ttT=(~TT & 0x3F)+1; } //week w1602(0,0x81); for(i=0;i<5;i++) w1602(1,dd[i]); w1602(1,0x30+((r1302(0x85)>>4) & 0x0f)); w1602(1,0x30+(r1302(0x85) & 0x0f)); w1602(1,0x2d); w1602(1,0x30+((r1302(0x83)>>4) & 0x0f)); w1602(1,0x30+(r1302(0x83) & 0x0f)); w1602(1,0x2d); w1602(1,0x30+((r1302(0x81)>>4) & 0x0f)); w1602(1,0x30+(r1302(0x81) & 0x0f)); w1602(0,0xc3); //temp for(i=0;i<5;i++) w1602(1,dd1[i]); if(temp2 & 0x80==0x80) //- { w1602(1,0x2d); w1602(1,0x30+ttT/10); w1602(1,0x30+ttT%10); } else //+ { w1602(1,0x20); w1602(1,0x30+TT/10); w1602(1,0x30+TT%10); } w1602(0x22,1); w1602(0x43,1); } }
Previous article:Linux Embedded ARM-Linux Basics
Next article:Let ADS and KEIL coexist Warning: L6373W: libattrs.map file not found
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- 【Showing goods】The third wave
- High-speed DAC
- Aperture Tuning: An Essential Technology in 5G Smartphones
- 【RT-Thread Reading Notes】5 Chapter Reading Notes
- FPGA_100 Days Journey_AD Design
- What are some reasons why low-power op amps use pulsed power?
- Pingtouge RVB2601 board-SPI test
- LCD refresh problem
- The principle of phase-locked loop frequency control
- [AutoChips AC7801x motor demo board evaluation] Development environment construction