C51 COMPILER V9.59.0.0 APP_INT_UART1 06/10/2021 10:21:36 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_INT_UART1 OBJECT MODULE PLACED IN .\list\APP_INT_UART1.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_INT_UART1.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(.. -\Driver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_INT_UART1.lst) TABS(2) OBJECT(.\list\APP_INT_UART1.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */ 11 /*---------------------------------------------------------------------*/ 12 13 #include "APP_INT_UART1.h" 14 #include "STC8A_GPIO.h" 15 #include "STC8A_Exti.h" 16 #include "STC8A_UART.h" 17 #include "STC8A_Delay.h" 18 #include "STC8A_NVIC.h" 19 20 /************* 功能说明 ************** 21 22 演示INT0~INT4 5个唤醒源将MCU从休眠唤醒. 23 24 从串口输出唤醒源跟唤醒次数,115200,N,8,1. 25 26 用定时器做波特率发生器,建议使用1T模式(除非低波特率用12T),并选择可被波特率整除的时钟频率,以提高精度。 27 28 下载时, 选择时钟 22.1184MHz (用户可在"config.h"修改频率). 29 30 ******************************************/ 31 32 33 //======================================================================== 34 // 本地常量声明 35 //======================================================================== 36 37 38 //======================================================================== 39 // 本地变量声明 40 //======================================================================== 41 42 u8 WakeUpCnt; 43 44 //======================================================================== 45 // 本地函数声明 46 //======================================================================== 47 48 49 //======================================================================== 50 // 外部函数和变量声明 51 //======================================================================== 52 53 54 //======================================================================== C51 COMPILER V9.59.0.0 APP_INT_UART1 06/10/2021 10:21:36 PAGE 2 55 // 函数: INTtoUART_init 56 // 描述: 用户初始化程序. 57 // 参数: None. 58 // 返回: None. 59 // 版本: V1.0, 2020-09-28 60 //======================================================================== 61 void INTtoUART_init(void) 62 { 63 1 EXTI_InitTypeDef Exti_InitStructure; //结构定义 64 1 COMx_InitDefine COMx_InitStructure; //结构定义 65 1 66 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART -_9bit_BRTx 67 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //使用波特率, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使 -用BRT_Timer2) 68 1 COMx_InitStructure.UART_BaudRate = 115200ul; //波特率, 一般 110 ~ 115200 69 1 COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE 70 1 COMx_InitStructure.BaudRateDouble = DISABLE; //波特率加倍, ENABLE或DISABLE 71 1 UART_Configuration(UART1, &COMx_InitStructure); //初始化串口1 UART1,UART2,UART3,UART4 72 1 NVIC_UART1_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Pri -ority_2,Priority_3 73 1 //------------------------------------------------ 74 1 Exti_InitStructure.EXTI_Mode = EXT_MODE_Fall;//中断模式, EXT_MODE_RiseFall,EXT_MODE_Fall 75 1 Ext_Inilize(EXT_INT0,&Exti_InitStructure); //初始化 76 1 NVIC_INT0_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Prio -rity_2,Priority_3 77 1 78 1 Exti_InitStructure.EXTI_Mode = EXT_MODE_Fall;//中断模式, EXT_MODE_RiseFall,EXT_MODE_Fall 79 1 Ext_Inilize(EXT_INT1,&Exti_InitStructure); //初始化 80 1 NVIC_INT1_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Prio -rity_2,Priority_3 81 1 82 1 NVIC_INT2_Init(ENABLE,NULL); //中断使能, ENABLE/DISABLE; 无优先级 83 1 NVIC_INT3_Init(ENABLE,NULL); //中断使能, ENABLE/DISABLE; 无优先级 84 1 NVIC_INT4_Init(ENABLE,NULL); //中断使能, ENABLE/DISABLE; 无优先级 85 1 86 1 P3_MODE_IO_PU(GPIO_Pin_HIGH); //P3.4~P3.7 设置为准双向口 87 1 } 88 89 //======================================================================== 90 // 函数: Sample_INTtoUART 91 // 描述: 用户应用程序. 92 // 参数: None. 93 // 返回: None. 94 // 版本: V1.0, 2020-09-24 95 //======================================================================== 96 void Sample_INTtoUART(void) 97 { 98 1 if(!INT0) return; //等待外中断为高电平 99 1 if(!INT1) return; //等待外中断为高电平 100 1 if(!INT2) return; //等待外中断为高电平 101 1 if(!INT3) return; //等待外中断为高电平 102 1 if(!INT4) return; //等待外中断为高电平 103 1 delay_ms(10); //delay 10ms 104 1 105 1 if(!INT0) return; //等待外中断为高电平 106 1 if(!INT1) return; //等待外中断为高电平 107 1 if(!INT2) return; //等待外中断为高电平 108 1 if(!INT3) return; //等待外中断为高电平 109 1 if(!INT4) return; //等待外中断为高电平 110 1 111 1 WakeUpSource = 0; C51 COMPILER V9.59.0.0 APP_INT_UART1 06/10/2021 10:21:36 PAGE 3 112 1 113 1 PCON |= 2; //Sleep 114 1 _nop_(); 115 1 _nop_(); 116 1 _nop_(); 117 1 delay_ms(1); //delay 1ms 118 1 119 1 if(WakeUpSource == 1) PrintString1("外中断INT0唤醒 "); 120 1 if(WakeUpSource == 2) PrintString1("外中断INT1唤醒 "); 121 1 if(WakeUpSource == 3) PrintString1("外中断INT2唤醒 "); 122 1 if(WakeUpSource == 4) PrintString1("外中断INT3唤醒 "); 123 1 if(WakeUpSource == 5) PrintString1("外中断INT4唤醒 "); 124 1 125 1 WakeUpCnt++; 126 1 TX1_write2buff(WakeUpCnt/100+'0'); 127 1 TX1_write2buff(WakeUpCnt%100/10+'0'); 128 1 TX1_write2buff(WakeUpCnt%10+'0'); 129 1 PrintString1("次唤醒\r\n"); 130 1 } 131 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 350 ---- CONSTANT SIZE = 94 ---- XDATA SIZE = 1 10 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)