PIC serial communication program (2) interrupt 1602 echo

Publisher:huanliLatest update time:2016-11-02 Source: eefocusKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/***************************************************************************************************
*** Function: The serial port debugging assistant sends data to 877, and 877 forwards it back to the serial port assistant after receiving it
*** Experimental content: Send data to 877 through the PC software "Serial Port Debug Assistant" c,
877 sends the received data to the computer
*** Development board connection method: Use a serial cable to connect to the serial port on the microcontroller development board.
The other end is connected to the 9-pin serial port of the computer. If there is no serial port, please purchase a USB to serial cable.
****************************************************************************************************/
#include //Includes the predefined internal resources of the MCU
 __CONFIG(0xFF32); //Chip configuration word, watchdog off, power-on delay on, power-off detection off, low voltage programming off, encryption, 4M crystal HS oscillation
 
#define rs RA5
#define rw RA4
#define and RA3
 
 
unsigned char recdata;
 
void init(); //Declare I/O port initialization function
void lcd_init(); //Declare LCD initialization function
void write(char x); //Declare the function to display 1 byte data
void lcd_enable(); //Declare LCD display setting function
void delay(); //Declare the delay function
void writelcd(char *pt); //Declare LCD write string function
/****************************************************************************
* Name: main() 
* Function: Main function
* Entry parameters: None
* Export parameters: None
* Description: None
****************************************************************************/
void main()
 {
  TRISC=0XFF; //Set the direction of port C to output
  SPBRG=0XC; //Set the baud rate to 19200BPS
  TXSTA=0X24; //Enable serial port transmission and select high-speed baud rate
  RCSTA=0X90; //Enable serial port, continuous reception
  RCIE=0X1; //Enable receive interrupt
  GIE=0X1; //Open global interrupt
  PEIE=0X1; //Enable external interrupt
  init(); //Call I/O port initialization function
  lcd_init(); //Call LCD initialization function
  while(1) //wait for interrupt
   {    
    ;
   }
  }
/****************************************************************************
* Name: usart()
* Function: interrupt function
* Entry parameters:
* Export parameters:
* Note: Note that the keyword interrupt is required. If there are multiple interrupts, in the interrupt service function,
To determine the interrupt source flag
****************************************************************************/
void interrupt usart(void)
  {
   int i;
   if(RCIE&&RCIF) //Judge whether it is a serial port receiving interrupt
     {             
  TXREG=RCREG;
  write(TXREG); //Only 3 characters can be displayed, is there a problem? ???
     }
   }
 
/****************************************************************************
* Name: init() 
* Function: I/O port initialization
****************************************************************************/
void init()
{
ADCON1 = 0X07; //Set port A to a normal I/O port
    RA1=1;
TRISA = 0X00; //Set port A to output
TRISD = 0X00; //Set port D to output
}
 
/****************************************************************************
* Name: lcd_init() 
* Function: LCD initialization
****************************************************************************/
void lcd_init()
{
PORTD = 0X1; // Clear display
lcd_enable();
PORTD = 0X38; //8-bit 2-row 5*7 dot matrix
lcd_enable();
PORTD = 0X0e; //Display on, cursor on, blinking
lcd_enable();
PORTD = 0X06; //The text does not move, the cursor moves right
lcd_enable();
PORTD = 0X80; //Company web display address
lcd_enable();
}
 
/****************************************************************************
* Name: write() 
* Function: Write one byte of data to LCD
* Input parameter: char x character
****************************************************************************/
void write(char x)
{
PORTD = x; //Send the data to be displayed to PORTD
rs = 1; //This byte is data, not a command
rw = 0; //This operation is a write, not a read
e = 0; // Pull the enable signal low
delay(); //Keep the enable signal low for a while
e = 1; //Pull up the enable signal to establish the rising edge required for LCD operation
}
 
/****************************************************************************
* Name: lcd_enable() 
* Function: LCD display settings
****************************************************************************/
void lcd_enable()
{
rs = 0; //This byte data is a command, not data
rw = 0; //This operation is a write, not a read
e = 0; // Pull the enable signal low
delay(); //Keep the enable signal low for a while
e = 1; //Pull up the enable signal to establish the rising edge required for LCD operation
}
 
/****************************************************************************
* Name: delay() 
* Function: Delay
****************************************************************************/
void delay()
{
int i;
for (i = 0;i < 5000;i++);
}
Keywords:PIC Reference address:PIC serial communication program (2) interrupt 1602 echo

Previous article:PIC IIC read and write
Next article:PIC serial communication program (1)

Recommended ReadingLatest update time:2024-11-22 13:03

PIC16-bit microcontroller CAN (8) watchdog
The framework of the program has been completed. After turning on the watchdog, all that remains is to improve the program structure. According to the documentation, the watchdog is mainly about the configuration bits. Here is my configuration: _FWDT(WDTPOST_PS4096&WDTPRE_PR32&PLLKEN_OFF&WINDIS_OFF&FWDTEN_ON); /
[Microcontroller]
Research on Adaptive Control Technology of Stepping Motor Based on PIC Microcontroller
1 Introduction The stepper motor is a discrete motion device, which has a close essential connection with modern digital control technology. The stepper motor is also an actuator that converts electrical pulses into angular displacement or linear displacement. When the stepper motor driver receives a pulse signal, it
[Microcontroller]
Research on Adaptive Control Technology of Stepping Motor Based on PIC Microcontroller
Introduction to 16-bit MCU technology designed with PIC24FJ256DA210
PIC24FJ256DA210 is a 16-bit MCU with a graphics controller (GFX) module that can interface with LCD displays and up to 96KB of data RAM. The PIC24FJ256DA210 high-performance CPU uses a modified Harvard architecture, with performance up to 16MIPS at 32MHz, an internal oscillator of 8MHz, a 17-bit x 17-bit sin
[Microcontroller]
Introduction to 16-bit MCU technology designed with PIC24FJ256DA210
Intelligent humidity measuring instrument circuit based on PIC microcontroller
The circuit of the intelligent humidity meter composed of HM1500/1520 humidity sensor and single chip is shown in the figure below. The meter adopts +5V power supply and is equipped with 4 common cathode LED digital tubes. There are 3 ICs in total in the circuit: IC1 is HM1500/1520 humidity sensor, IC2 is PIC16F874, a
[Microcontroller]
Intelligent humidity measuring instrument circuit based on PIC microcontroller
Programming of PIC microcontroller port RB interrupt
    In this example, a modular programming method is used, and the program planning, writing, assembling, debugging, modifying,   The program flow is shown in Figures 1 to 7.   Figure 1 Main program flow   Figure 2 Interrupt service subroutine flow   Figure 3 Low-pronunciation subroutine flow   Fi
[Microcontroller]
Programming of PIC microcontroller port RB interrupt
Design of External Oscillator Circuit for PIC Microcontroller
Crystal oscillator design is one of the important links in microcontroller application design, so it is necessary to understand the characteristics and composition of the crystal oscillator circuit and how to select related electronic components. The PIC microcontroller has four oscillation modes to choose from. The
[Microcontroller]
Design of External Oscillator Circuit for PIC Microcontroller
PIC internal EEPROM read and write
Steps to read data from EEPROM: 1. Write the address to the address register EEADR. Note that the address cannot exceed the actual capacity of the internal EEPROM of the PIC1687X microcontroller. 2. Clear the control bit EEPGD to select the EEPROM data memory as the read object. 3. Set the control bit RD to 1 to sta
[Microcontroller]
LCD driver HT1621 PIC microcontroller source code
STATUS  EQU     3H FSR     EQU     4H RB      EQU     6H RC      EQU     7H OPTIONA EQU     81H TRISB   EQU     86H TRISC   EQU     87H GENR0 EQU 053H GENR1 EQU 054H WD_RG EQU 055H DA_AG0 EQU 056H ;SEG0 SEG1 DA_AG8 EQU 05EH ;SEG16 SEG17 ;............................. C
[Microcontroller]
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号