PIC microcontroller RS232 serial communication program (USART)

Publisher:YudieLatest update time:2016-11-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//★★★★★★★★★★Application of PIC microcontroller USART (serial communication)★★★★★★★★★★★\\

//Single-signal machine model: PIC16F877A
//Function description: Application of PIC microcontroller USART, serial port debugging assistant sends data to 877, and 877 forwards it back to the serial port assistant after receiving it
//Assist work through "serial port debugging assistant"

#include //Includes the predefined
 __CONFIG(0xf73a) of the internal resources of the MCU;        
//Chip configuration word, watchdog off, power-on delay on, power-off detection off, low voltage programming off, encryption, 4M crystal HS oscillation

//=======================================================================
//Function description: main program  
//Function name: void main()
 
void main()
 {
  TRISC=0XFF; //Set the direction of port C to all output
  SPBRG=0XC; //Set the baud rate to 19200BPS
  TXSTA=0X24; //Enable serial port sending, select high-speed baud rate
  RCSTA=0X90; //Enable serial port work, continuous reception
  RCIE=0X1; //Enable receive interrupt
  GIE=0X1; //Open global interrupt
  PEIE=0X1; //Enable external interrupt
  while(1) //Wait for interrupt
   {;}
  }

//========================================================================
//Function description: interrupt function
//Function name: void interrupt usart(void)
void interrupt usart(void)
  {
   if(RCIE&&RCIF) //Judge whether it is a serial port receive interrupt
     {
      TXREG=RCREG; //Send the received data back
     }
   }

Reference address:PIC microcontroller RS232 serial communication program (USART)

Previous article:MCC18 platform code for frequency measurement based on PIC18F45K20
Next article:Use of LCD1602A

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号