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
Recommended ReadingLatest update time:2024-11-23 07:33
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Can a smart socket really be used as an electricity meter?
- ESP32 BLE Motor Control
- Hunan University launches new diagnostic theory and method for analog circuits and switched capacitor networks
- Can the simulation be successful when using UC3842 as a non-isolated buck without a floating ground driver?
- What versions of Java are there?
- GD32E231 DIY Part 1: Unboxing
- Belide Electronic Technology (Shenzhen) Co., Ltd. Recruitment (SMT Supervisor)
- Analysis and Suppression of Electromagnetic Interference of Switching Power Supply
- Analysis of I2C communication protocol and GPIO simulation in C2000
- Should I choose DSP or ARM?