PIC Single-Chip Microcomputer (PIC16F877A) serial transceiver

Source: Internet
Author: User
# Include <PIC. h> # define uchar unsigned char uchar rtemp, sflag; void serialinit (void) {txsta = 0x24; // enable the transmitting enable and high baud rate, the initial value of trmt can be 0 to 1 rcsta = 0x90; // enable serial port, continuous receiving, spbrg = 0x19; // 4 m crystal oscillator, baud rate 9600, then, the initial value of spbrg is 25 rcie = 1; // enable the serial port reception to complete the interruption. The gie = 1; // enable the global interruption peie = 1; // enable the first peripheral interrupt} void interrupt serialservice (void) // receives the interrupt {If (rcie & rcif) {rcif = 0; // indicates the number of rtemp = rcreg after receiving is cleared. // read and Receive Buffer sflag = 1 ;}} void main (void) {serialinit (); While (1) {If (sflag = 1) {rcie = 0; // disable receiving before sending Disallow bit sflag = 0; txreg = rtemp; // data sending buffer while (! Txif); // wait until the sending is completed. trmt is queried in the tutorial, and trmttxif = 0 is not cleared after sending. // The rcie = 1 flag is cleared; // enable allowed receiving interrupt when sending is complete }}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.