Implement monitoring (using PROTEUS serial port example) V1.0
M8 MCU simulation schematic diagram is as follows
The microcontroller source program is as follows:
////////////////////////////////////////////////////////////////////////////////
// ICC-AVR application builder : 6-25 06:02:39 PM
// Target : M8
// Crystal: 3.6864Mhz
// Author: Anwarye
// Title: Detcetaphone
////////////////////////////////////////////////////////////////////////////////
#include #include #include "var.h" #define XTAL == 3.6864M //////////////////////////////////////////////////////////////////////////////// #pragma interrupt_handler uart0_rx_isr:12 void uart0_rx_isr(void) { unsigned char i,j; if(UDR == 0x0A) { return; // Receive 0x0A and discard it directly } i = RxIndex; j = RxIndex-1; if((RxBuf[0] == 0x30) && (RxBuf[1] == 0x0D)) { RxIndexTail = RxIndex; // Save the receive buffer pointer tail RxIndex = 0; // Receive buffer pointer reset to zero RxStatus = 1; // Set the reception completion flag OkFlag = 1; error = 0; return; } if((RxBuf[0] == 0x32) && (RxBuf[1] == 0x0D)) // Received incoming call signal, set the incoming call flag { CallInFlag = 1; // Set incoming call flag RxIndex = 0; RxStatus = 1; OkFlag = 1; return; } else if((RxBuf[0] == 0x33) && (RxBuf[1] == 0x0D)) // The called number is busy or the caller is on hang-up { BusyFlag = 1; //Set incoming call flag RxIndex = 0; RxStatus = 1; OkFlag = 1; return; } else if((RxBuf[0] == 0x37) && (RxBuf[1] == 0x0D)) // Received incoming call signal, set the incoming call flag { NoCarrierFlag = 1; // Set the incoming call flag NO CARRIER RxIndex = 0; RxStatus = 1; OkFlag = 1; return; } else if((RxBuf[0] == 0x34) && (RxBuf[1] == 0x0D)) // Received incoming call signal, set the incoming call flag { RxIndex = 0; RxStatus = 1; OkFlag = 1; error = 1; return; } else { RxBuf[RxIndex++] = UDR; // Continue receiving data and put it into the receive buffer RxStatus = 0; // Serial port receiving // return; // End receiving and exit directly } } //////////////////////////////////////////////////////////////////////////////// #pragma interrupt_handler uart0_tx_isr:14 void uart0_tx_isr(void) { if(!TxStatus) // This frame of data has not been sent out, so continue to send { //while ( !(UCSRA & (1< } if((TxBuf[TxIndex] == 0x0D) || (TxBuf[TxIndex] == 0x1A)) // End of sending this frame of data { TxStatus = 1; // Set the sending completion status flag TxIndex = 0; // Send buffer pointer reset to zero UCSRB &= ~((1< } TxIndex++; } unsigned char CheckRx(void) { unsigned char i,j; i = RxIndex; j = RxIndex - 1; if(( RxBuf[j] == 0x30) && (RxBuf[i] == 0x0D)) { RxIndex = 0; return (1); } else { return (0); } } /*-----------------------------------------------------------------------*/ ///////////////////////////// Clear receive buffer ////////////////////////////////// /*-----------------------------------------------------------------------*/ void ClearRxBuf(void) { unsigned char i; for(i=0;i<128;i++) { RxBuf[i] = 0; } } /*-----------------------------------------------------------------------*/ ///////////////////////////// Enable serial port sending ///////////////////////////////// /*-----------------------------------------------------------------------*/ void TxEnable(void) { //RxIndex = 0; UDR = TxBuf[0]; // Send the buffer header to the serial port send register, activate and start sending UCSRB |= ((1< /*-----------------------------------------------------------------------*/ ////////////////////////////// Send AT command//////////////////////////////// /*-----------------------------------------------------------------------*/ void Put_AT_command(const unsigned char *atc, unsigned char atlen) { unsigned char count; for(count = 0;count < atlen;count++) // AT command is moved into the send buffer { TxBuf[count] = atc[count]; } TxBuf[atlen] = 0x0D; // Add "Enter" to the end of the send buffer TxBuf[atlen + 1] = 0x00; // Send buffer end symbol OkFlag = 0; TxStatus = 0; TxIndex = 1; // Send pointer offset 1 TxEnable(); // Activate sending while(!TxStatus); // Wait for the transmission to end, and then send after the transmission buffer pointer is zero DelayMs(20); while(!OkFlag); // Receive the module return OK, the command ends OkFlag = 0; } /*-----------------------------------------------------------------------*/ /////////////////////////// Send AT command string from memory ////////////////////////////// /*-----------------------------------------------------------------------*/ void Put_AT_String(unsigned char *atc, unsigned char atlen) { unsigned char count; for(count = 0;count < atlen;count++) { TxBuf[count] = *(atc+count); } TxBuf[atlen] = 0x0D; // Add "Enter" to the end of the send buffer TxBuf[atlen + 1] = 0x00; // Send buffer end symbol OkFlag = 0; TxStatus = 0; TxIndex = 1; // Send pointer offset 1 TxEnable(); // Activate sending while(!TxStatus); // Wait for the transmission to end, and then send after the transmission buffer pointer is zero DelayMs(20); while(!OkFlag); // Receive the module return OK, the command ends OkFlag = 0; } /*-----------------------------------------------------------------------*/ ////////////////////////// Send a string of data to the serial port ///////////////////////////// /*-----------------------------------------------------------------------*/ void PutString(unsigned char *str, unsigned char length,unsigned char retflag) { unsigned char count; for(count = 0;count < length;count++) { TxBuf[count] = *(str+count); } TxBuf[length] = 0x0D; // Add "Enter" to the end of the send buffer TxBuf[length+ 1] = 0x00; // Send buffer end symbol TxStatus = 0; TxIndex = 1; // Send pointer offset 1 OkFlag = 0; TxEnable(); // Activate sending while(!TxStatus); // Wait for the transmission to end, and then send after the transmission buffer pointer is zero DelayMs(20); if(retflag) { while(!OkFlag); // Receive the module return OK, the command ends OkFlag = 0; } else { DelayMs(200); OkFlag = 0; } } //////////////////////////////////////////////////////////////////////////////// /*-----------------------------------------------------------------------*/ //////////////////////////// Dial //////////////////////////// /*-----------------------------------------------------------------------*/ void DialNum(void) { unsigned char i,count=0,length=0; while ((PhoneNum[count++] != 0)) // Calculate the length of the phone number { length++; } TxBuf[0] = 'A'; TxBuf[1] = 'T'; TxBuf[2] = 'D'; i = 3; for(count=0;count TxBuf[i++] = PhoneNum[count]; } TxBuf[length+3] = ';'; TxBuf[length+4] = 0x0D; OkFlag = 0; TxStatus = 0; TxIndex = 1; // Send pointer offset 1 TxEnable(); // Activate sending while(!TxStatus); // Wait for the transmission to end, and then send after the transmission buffer pointer is zero DelayMs(20); //while(!OkFlag); // Receive the module return OK, the command ends OkFlag = 0; } /*-----------------------------------------------------------------------*/ ////////////////////////////// Compare two strings///////////////////////////////// /*-----------------------------------------------------------------------*/ unsigned char StringCompare(volatile unsigned char *str1,const unsigned char *str2,unsigned char strlen) { while(strlen--) { if(*str1++ != *str2++) return(FALSE); // If the two strings are not equal, return false } return(TRUE); } /*-----------------------------------------------------------------------*/ //////////////////////////////// Delete text message //////////////////////////////// /*-----------------------------------------------------------------------*/ void Delete_SMS(unsigned char num) // Delete SMS, =0 deletes all SMS { unsigned char count; for(count = 0;count < AtcmgdLen;count++) // AT command is transferred into the send buffer { TmpBuf[count] = Atcmgd[count]; } if(num == ALL) { for(count = 1; count < 10; count++) { TmpBuf[AtcmgdLen] = count + 0x30; Put_AT_String((unsigned char*)TmpBuf,(AtcmgdLen+1)); } TmpBuf[AtcmgdLen] = 0x31; for(count = 0; count < 10; count++) { TmpBuf[AtcmgdLen+1] = count + 0x30; Put_AT_String((unsigned char*)TmpBuf,(AtcmgdLen+2)); } } else {
Previous article:Dynamixel digital servo driver
Next article:M16 MCU l infrared decoding program + led digital tube display
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Basic knowledge of Zigbee
- CTRL+ALT+DEL: Restart 2020
- Knowledge about electromagnetic radiation
- A33 development board has a strange problem, I hope experts can give me some advice! Thank you!
- AD20 is significantly faster than AD19
- Design of Ethernet physical layer chip clock synchronization PLL
- si514 programmable oscillator debugging, with engineering source code
- Two new TI boards
- GD32 loopback mode CAN_TX pin cannot detect data
- [Chuanglong TL570x-EVM] Use the new version of Prossessor SDK and create a working environment