The registers associated with the serial 1 interrupt are IE, iph, and IP
Serial interrupt allow bit ES in interrupt allow register ie.
The total interrupt of the EA:CPU allows the control bit, EA=1,CPU open total interrupt, ea=0,cpu off total interrupt. Each interrupt source is controlled by the EA first, followed by the interrupt of each interrupt source to allow control bit control.
Registers IE2, IP2H, and IP2 associated with the serial Port 2 interrupt
The serial port 2 interrupt allows the ES2 to be located in the interrupt register IE2.
1 #ifndef _uart_h_2 #define_uart_h_3 4 #defineUchar unsigned char5 #defineUINT unsigned int6 7 //defines the serial port 1 switch, which cannot receive data when it is closed8 #defineOpenUART1 () Es=19 #defineCloseUART1 () es=0Ten #defineOpenUART2 () ie2|=0x01 One #defineCloseUART2 () Ie2&=0xfe A - //cache serial 1 and serial 2 received characters - externUchar Uart1_recv_val; the externUchar Uart2_recv_val; - - voidUart1_init (Uchar RELOAD, bit doublebaud, bit timemod); - voidUart2_init (Uchar RELOAD, bit doublebaud, bit timemod); + voidUart1_sendonechar (Uchar val); - voidUart2_sendonechar (Uchar val); + voidUART1_SENDSTR (UCHAR *str); A voidUART2_SENDSTR (UCHAR *str); at #endif
The UART.C code is as follows:
1#include <stc12c5a. H>//STC12C5A Series single chip microcomputer2#include <intrins.h>3#include"UART. H" 4 5 #defineUchar unsigned char6 #defineUINT unsigned int7 8 //cache serial 1 and serial 2 received characters9Uchar Uart1_recv_val =0; TenUchar Uart2_recv_val =0; One A - - voidUart1_init (Uchar RELOAD, bit doublebaud, bit timemod) the { -SCON |=0x50;//serial 1 Mode 1, receive the charge - -BRT = RELOAD;//baud rate 2400 + - if(Timemod = =1)//1T + { A //t0x12 t1x12 um0x6 brtr s2smod BRTx12 extram S1brs atAUXR |=0x15;//Serial 1 uses independent baud rate generator, independent baud rate generator 1T - } - Else //12T - { -AUXR |=0x11; - } in - if(Doublebaud = =1) to { +PCON |=0x80;//double the baud rate - } the Else * { $PCON &=0x7F;//baud rate not doubledPanax Notoginseng } - theEA =1; +ES =1;//Allow serial 1 interrupt A } the + - $ voidUart2_init (Uchar RELOAD, bit doublebaud, bit timemod) $ { - //s2sm0 s2sm1 s2sm2 s2ren s2tb8 s2rb8 s2ti s2ri -S2con |=0x50;//Serial 2, Mode 1, receive charge the -BRT =RELOAD; Wuyi the if(Timemod = =1)//1T - { Wu //t0x12 t1x12 um0x6 brtr s2smod BRTx12 extram S1brs -AUXR |=0x14;//Serial 1 uses independent baud rate generator, independent baud rate generator 1T About } $ Else //12T - { -AUXR = (AUXR |0x10) &0xFB; - } A + if(Doublebaud = =1) the { -AUXR |=0x08;//double the baud rate $ } the Else the { theAUXR &=0xf7;//baud rate not doubled the } - inEA =1; the //------ ESPI ES2 theIE2 |=0x01;//Allow Serial 2 interrupt About } the the the + voidUart1_sendonechar (Uchar val) - { the //ES = 0; //Turn off serial 1 interruptBayi theSbuf =Val; the while(TI = =0); -TI =0; - the //ES = 1; //Resume serial 1 interrupt the } the the - the voidUart2_sendonechar (Uchar val) the { the //IE2 = 0x00; //Turn off serial 2 interrupt94 theS2buf =Val; the while((S2con &0x02) ==0); theS2con &=0xFD; 98 About //IE2 = 0x01; //Resume Serial 2 interrupt - } 101 102 103 104 voidUART1_SENDSTR (UCHAR *str) the { 106 while((*STR)! ='/0' ) 107 { 108Uart1_sendonechar (*str); 109str++; the } 111 } the 113 the the voidUART2_SENDSTR (UCHAR *str) the { 117 while((*STR)! ='/0' ) 118 { 119Uart2_sendonechar (*str); -str++; 121 } 122 } 123 124 the 126 voidUart1_int (void) Interrupt4 127 { - if(RI = =1) 129 { theRI =0; 131Uart1_recv_val =Sbuf; the } 133 } 134 135 136 137 voidUart2_int (void) Interrupt8 138 { 139 if((S2con &0x01) ==1) $ { 141S2con &=0xFE; 142Uart2_recv_val =S2buf; 143 } 144}
STC12C5A60S2 single-Chip computer serial debugging