1/*---------------------------------------------------------------------*/ /* --- STC MCU Limited ------------------------------------------------*/ /* --- STC15F4K60S4 ϵ?? ??ʱ??2????????1?IJ????ʷ?????????------------*/ /* --- Mobile: (86)13922805190 ----------------------------------------*/ /* --- Fax: 86-755-82905966 -------------------------------------------*/ /* --- Tel: 86-755-82948412 -------------------------------------------*/ /* --- Web: www.STCMCU.com --------------------------------------------*/ /* ???Ҫ?ڳ?????ʹ?ô˴???,???ڳ?????ע??ʹ???˺꾧?Ƽ??????ϼ????? */ /* ???Ҫ????????Ӧ?ô˴???,??????????ע??ʹ???˺꾧?Ƽ??????ϼ????? */ /*---------------------------------------------------------------------*/ //??ʾ????Keil????????????ѡ??Intel??8058оƬ?ͺŽ??б??? //?ٶ?????оƬ?Ĺ???Ƶ??Ϊ18.432MHz //#include "reg51.h" #include "system.h" void uart_print() { ACC = P_SW1; ACC &= ~(S1_S0 | S1_S1); //S1_S0=0 S1_S1=0 P_SW1 = ACC; //(P3.0/RxD, P3.1/TxD) // ACC = P_SW1; // ACC &= ~(S1_S0 | S1_S1); //S1_S0=1 S1_S1=0 // ACC |= S1_S0; //(P3.6/RxD_2, P3.7/TxD_2) // P_SW1 = ACC; // // ACC = P_SW1; // ACC &= ~(S1_S0 | S1_S1); //S1_S0=0 S1_S1=1 // ACC |= S1_S1; //(P1.6/RxD_3, P1.7/TxD_3) // P_SW1 = ACC; #if (PARITYBIT == NONE_PARITY) SCON = 0x50; //8λ?ɱ䲨???? #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY) SCON = 0xda; //9λ?ɱ䲨????,У??λ??ʼΪ1 #elif (PARITYBIT == SPACE_PARITY) SCON = 0xd2; //9λ?ɱ䲨????,У??λ??ʼΪ0 #endif T2L = (65536 - (FOSC/4/BAUD)); //???ò???????װֵ T2H = (65536 - (FOSC/4/BAUD))>>8; AUXR = 0x14; //T2Ϊ1Tģʽ, ????????ʱ??2 AUXR |= 0x01; //ѡ??ʱ??2Ϊ????1?IJ????ʷ????? ES = 1; //ʹ?ܴ???1?ж? EA = 1; // SendString("STC15F2K60S2\r\nUart Test !\r\n"); // while(1) { SendString("STC15F2K60S2\r\nUart Test !\r\n"); } } /*---------------------------- UART ?жϷ?????? -----------------------------*/ void Uart() interrupt 4 using 1 { if (RI) { RI = 0; //???RIλ // P0 = SBUF; //P0??ʾ???????? // P22 = RB8; //P2.2??ʾУ??λ } if (TI) { TI = 0; //???TIλ busy = 0; //??æ??־ } } /*---------------------------- ???ʹ??????? ----------------------------*/ void SendData(BYTE dat) { while (busy); //?ȴ?ǰ??????ݷ?????? ACC = dat; //??ȡУ??λP (PSW.0) if (P) //????P??????У??λ { #if (PARITYBIT == ODD_PARITY) TB8 = 0; //????У??λΪ0 #elif (PARITYBIT == EVEN_PARITY) TB8 = 1; //????У??λΪ1 #endif } else { #if (PARITYBIT == ODD_PARITY) TB8 = 1; //????У??λΪ1 #elif (PARITYBIT == EVEN_PARITY) TB8 = 0; //????У??λΪ0 #endif } busy = 1; SBUF = ACC; //д???ݵ?UART???ݼĴ??? } /*---------------------------- ?????ַ??? ----------------------------*/ void SendString(char *s) { while (*s) //????ַ?????????־ { SendData(*s++); //???͵?ǰ?ַ? } }