Using Cygnal\'s C8051F020DK-U microcontroller development tool, you can achieve serial communication with the computer. This book starts from the simple and goes on to the complex, and elaborates on three serial communication modes. According to their respective serial data transmission capabilities, they can be applied to different practical projects. The microcontroller measures six voltages, the temperature inside the chip, records two time values, and sends them serially to the computer; the computer stores the calculated physical voltage values, etc., in an Excel file named after the current moment using ODBC and automation. This book has the characteristics of clear ideas and detailed explanations. Starting from practical applications, the program code has been repeatedly debugged and can be directly used by microcontroller programmers using Keil C and serial programmers using VC++6.0. Part 1 Basic Knowledge Chapter 1 C8051F020 MCU 2 1.1 Development Tools 2 1.1.1 Hardware Connection Diagram 2 1.1.2 Introduction to Main Components 3 1.1.3 Jumper Connections of Target Board 4 1.1.4 Homemade Parts 5 1.2 Integrated Development Environment 7 1.2.1 Introduction to Integrated Development Environment 7 1.2.2 Configuration of Integrated Development Environment 8 1.2.3 Introduction to Keil 9 1.3 C8051F020 MCU 10 1.3.1 System Clock SYSCLK 10 1.3.2 Expansion of External Data Memory 10 1.3.3 Low Ports P0~P3 11 1.3.4 Introduction to T0, T1, T2, T3, T4 13 1.3.5 Analog-to-Digital Converter ADC0 17 1.3.6 Serial Communication Bus UART0 20 1.4 Header File C8051F020.h 22 1.4.1 Abbreviations 22 1.4.2 File Code 23 Chapter 2 Basics of Computer Serial Port Communication 30 2.1 Windows API Serial Port Communication Functions 30 2.1.1 Opening and Closing the Serial Port 30 2.1.2 Serial Port Configuration 31 2.1.3 Serial Port Buffer Control 33 2.1.4 Timeout Control for Read and Write Operations 33 2.1.5 Operation of Serial Communication Events 35 2.1.6 Serial Port Read and Write Operations 37 2.1.7 Asynchronous Operation 39 2.2 Multithreading 41 2.2.1 Introduction to Threads 41 2.2.2 Related Functions of Worker Threads 42 2.2.3 Communication between Threads 43 2.2.4 Synchronization between Threads 45 2.3 Introduction to Visual C++ 6.0 46 2.3.1 A Brief Introduction to the Work Interface 46 2.3.2 Common operations in programming 54 2.3.3 The origin of the constants used in this article 58 Part 2 Serial communication mode A-1 Chapter 3 Microcontroller programming A-1 66 3.1 Communication protocol 66 3.1.1 Example of start-stop asynchronous protocol 66 3.1.2 Character frame format 67 3.1.3 The meaning of each byte in data packet I 67 3.1.4 The meaning of each byte in data packet II 68 3.1.5 Specific serial communication protocol 69 3.2 Flowchart of two interrupt functions 72 3.3 Microcontroller program A-1 76 Chapter 4 Computer programming A-1 100 4.1 Project creation, window initialization 100 4.1.1 Project creation 100 4.1.2 Resource.h file list 1 103 4.1.3 Window initialization 103 4.2 Custom Comm menu 104 4.2.1 4.2.2 Adding menu resources 104 4.2.3 Code added by ClassWizard 1 106 4.3 Customizing the Comm Setting dialog box 110 4.3.1 Adding dialog box resources 110 4.3.2 Adjusting controls in the dialog box 114 4.3.3 Resource.h file listing 2 115 4.3.4 Associated variables 116 4.3.5 Message mapping 2 118 4.3.6 Code added by ClassWizard 2 119 4.4 Data members in the document class 122 4.4.1 Description of document class data members 122 4.4.2 Adding document class data members 127 4.4.3 Code added by ClassWizard 3 129 4.4.4 Initialization of document class data members 131 4.5 Serial buffer read/write functions 133 4.5.1 4.5.2 Serial receive buffer write function 135 4.6 Worker thread control function 137 4.6.1 Flowchart of global function ThreadFunction1 () 137 4.6.2 Serial receive buffer read method 138 4.6.3 Code list of global function ThreadFunction1 () 138 4.6.4 Worker thread termination 141 4.6.5 Use of continue statement 142 4.7 UPDATE_COMMAND_UI message response function of menu item 143 4.8 WM_TIMER message response function 145 4.8.1 The significance of timer use 145 4.8.2 WM_TIMER message mapping 146 4.8.3 Code list of function CTianView :: OnTimer () 146 4.9 COMMAND message response function of Connect menu item 147 4.9.1 Flowchart of the CTianDoc :: OnCommConnect ( ) function 147 4.9.2 Viewing the Microsoft Excel driver 148 4.9.3 Constant definition 1 149 4.9.4 Code listing of the CTianDoc :: OnCommConnect ( ) function 150 4.9.5 Custom function CTianDoc :: Function_SetCommState ( ) 154 4.10 COMMAND message response function of the Start menu item 157 4.10.1 Flowchart of the CTianDoc :: OnCommStart ( ) function 157 4.10.2 Code listing of the CTianDoc :: OnCommStart ( ) function 158 4.11 COMMAND message response function of the Setting menu item 161 4.11.1 Flowchart of the CTianDoc :: OnCommSetting ( ) function 161 4.11.2 Adding pre-included files 162 4.11.3 4.12 Response function of custom message WM_USER_1 165 4.12.1 Flowchart of function CTianView :: OnMessageUser1 ( ) 165 4.12.2 Brief description 166 4.12.3 Constant definition in TianView.cpp file 167 4.12.4 Code listing of function CTianView :: OnMessageUser1 ( ) 167 4.13 COMMAND message response function of Stop menu item 174 4.14 COMMAND message response function of Disconnect menu item 175 4.15 Document class destructor 176 4.16 Running result 1 176 4.16.1 Display effect of Comm Setting dialog box 176 4.16.2 Execution result of Connect menu item 1 177 4.16.3 Execution result of Start menu item 1 177 4.17 Execution results of EV_RXCHAR event 178 4.18 Experiment of using for loop to continuously send characters in single-chip microcomputer 180 Part 3 Automatic access to Excel Chapter 5 Single-chip microcomputer programming A-2 184 5.1 Analysis of single-chip microcomputer receiving two consecutive characters 184 5.2 Flowchart of interrupt function UART0_ISR () 1 185 5.3 Single-chip microcomputer program A-2 187 Chapter 6 Computer programming A-2 200 6.1 Importing the Excel class library 200 6.1.1 Automation programming steps 200 6.1.2 Initializing COM components 200 6.1.3 Importing the Excel class library 201 6.2 Adding data members to the document class 203 6.2.1 In the document class, add a class object for operating Excel 203 6.2.2 Initializing the newly added class object 205 6.3 Code Listing 1 of the function CTianDoc :: OnCommConnect ( ) 205 6.4 Code Listing 1 of the function CTianDoc :: OnCommStart ( ) 208 6.4.1 In the document class, add the variable m_nFillingRow 208 6.4.2 Initializing the variable m_nFillingRow 209 6.4.3 Code Listing 1 of the function OnCommStart ( ) 209 6.5 Code Listing 1 of the function CTianView :: OnMessageUser1 ( ) 217 6.6 Code Listing of Function CTianDoc::OnCommStop() 1 230 6.7 Code Listing of Function CTianDoc::OnCommDisconnect() 1 231 6.8 Code Listing of Function CTianView::OnTimer() 1 232 6.9 Operation Results 2 233 6.9.1 Example of Operation Results 233 6.9.2 Abnormal Termination 234 6.9.3 Instructions on VC Using Automation to Access Excel 2007 235 Part 4 Serial Port Communication Mode B Chapter 7 Microcontroller Programming B 238 Chapter 8 Computer Programming B 242 8.1 Simple Modification of Computer Program 1 242 8.2 Modification of Function CTianView::OnMessageUser1() 1 243 8.2.1 Modification of Flowchart 1 243 8.2.2 Modification of Code 1 243 8.2.3 Extract the three characters on the left in the string 252 8.2.4 Operation results 3 253 Part 5 Serial communication mode C-1 Chapter 9 Microcontroller programming C-1 256 9.1 Communication protocol 1 256 9.1.1 Description of the communication protocol 256 9.1.2 The meaning of each byte in data packet I 1 257 9.1.3 The meaning of each byte in data packet II 1 257 9.2 Flowcharts of two interrupt functions 1 259 9.2.1 Flowchart of interrupt function ADC0_ISR () 1 259 9.2.2 Flowchart of interrupt function UART0_ISR () 1 260 9.3 Microcontroller program C-1 261 9.4 Use Excel to generate multiple lines of similar code 284 Chapter 10 Computer programming C-1 287 10.1 Simple modification of computer program 2 287 10.1.1 Modify according to Section 8.1 287 10.1.2 Add the variable m_nGroupRightNo in the document class 287 10.1.3 Initialize the variable m_nGroupRightNo 288 10.1.4 Code modification of function OnCommStart ( ) 288 10.2 Modification of function CTianView :: OnMessageUser1 ( ) 2 289 10.2.1 Modification of flowchart 2 289 10.2.2 Code modification 2 290 10.3 Running results 4 299 10.3.1 Serial communication termination 299 10.3.2 Reduce transmission traffic 299 Part 6 Serial communication mode C-2 Chapter 11 Microcontroller Programming C-2 302 Chapter 12 Computer Programming C-2 310 Appendix A Part 2 \"Comm | Appendix B: Results of Running the “Comm | Start” Menu Item in Part 3 317 Appendix C: Results of Running the “Comm | Start” Menu Item in Part 4 318 Appendix D: Results of Running the “Comm | Start” Menu Item in Part 5 319 Appendix E: Results of Running the “Comm | Start” Menu Item in Part 6 320 References 3212 Reduce the transmission flow 299 Part 6 Serial communication mode C-2 Chapter 11 Microcontroller programming C-2 302 Chapter 12 Computer programming C-2 310 Appendix A The operating results of the \"Comm | Start\" menu item in Part 2 316 Appendix B The operating results of the \"Comm | Start\" menu item in Part 3 317 Appendix C The operating results of the \"Comm | Start\" menu item in Part 4 318 Appendix D The operating results of the \"Comm | Start\" menu item in Part 5 319 Appendix E The operating results of the \"Comm | Start\" menu item in Part 6 320 References 3212 Reduce the transmission flow 299 Part 6 Serial communication mode C-2 Chapter 11 Microcontroller programming C-2 302 Chapter 12 Computer programming C-2 310 Appendix A The operating results of the \"Comm | Start\" menu item in Part 2 316 Appendix B The operating results of the \"Comm | Start\" menu item in Part 3 317 Appendix C The operating results of the \"Comm | Start\" menu item in Part 4 318 Appendix D The operating results of the \"Comm | Start\" menu item in Part 5 319 Appendix E The operating results of the \"Comm | Start\" menu item in Part 6 320 References 321
You Might Like
Recommended ContentMore
Open source project More
Popular Components
Searched by Users
Just Take a LookMore
Trending Downloads
Trending ArticlesMore