C51 COMPILER V9.59.0.0 APP_PCA_CAPTURE 06/10/2021 18:07:14 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_PCA_CAPTURE OBJECT MODULE PLACED IN .\list\APP_PCA_Capture.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_PCA_Capture.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR( -..\Driver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_PCA_Capture.lst) TABS(2) OBJECT(.\list\APP_PCA_Capture.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.h" 14 #include "STC8A_PCA.h" 15 #include "STC8A_GPIO.h" 16 #include "STC8A_UART.h" 17 #include "STC8A_NVIC.h" 18 19 /************* ¹¦ÄÜ˵Ã÷ *************** 20 21 PCA0 ÉèÖÃΪ8λPWM, P1.7Êä³ö±ä»¯µÄPWMÐźÅ, ÀàËÆ"ºôÎüµÆ"µÄÇý¶¯. 22 PCA1 ÉèÖÃΪ²¶»ñ. ¿ÉÒÔÁ¬½Óµ½P1.7»òÕßP1.5ÓÃÀ´²âÊÔ²¶»ñ, ²¶»ñµÄʱÖÓÊý´Ó´®¿Ú1Êä³ö. Ò²¿ÉÒÔ´ÓÍⲿÊäÈëÒ»¸öÐźÅÀ´² -¶»ñ. 23 PCA2 ÉèÖÃΪ16λÈí¼þ¶¨Ê±, ¶¨Ê±Ê±¼äΪ15000¸öPCAʱÖÓ, ²¢ÇÒ´ÓP1.5Êä³öÕâ¸öÐźÅ,Êä³öÖÜÆÚΪ30000¸öPCAʱÖÓ. 24 PCA3 ÉèÖÃΪ10λPWM, P1.4Êä³ö¹Ì¶¨µÄPWMÐźÅ. 25 26 ²¶»ñÂö¿íʱ¼ä=²¶»ñµÄʱÖÓÊý/PCAʱÖÓÔ´, ±ÈÈç ²¶»ñµÄʱÖÓÊý = 256, PCAʱÖÓÔ´ = 22.1184MHz(1T), Âö¿í = 256/22.11 -84MHz = 11.57us. 27 28 ÏÂÔØʱ, Ñ¡ÔñʱÖÓ 22.1184MHz (Óû§¿ÉÔÚ"config.h"ÐÞ¸ÄƵÂÊ). 29 30 ******************************************/ 31 32 33 //======================================================================== 34 // ±¾µØ³£Á¿ÉùÃ÷ 35 //======================================================================== 36 37 38 //======================================================================== 39 // ±¾µØ±äÁ¿ÉùÃ÷ 40 //======================================================================== 41 42 static u8 cnt0; 43 static u8 pwm0; //pwm 44 static bit B_PWM0_Dir; //·½Ïò, 0Ϊ+, 1Ϊ-. 45 46 //======================================================================== 47 // ±¾µØº¯ÊýÉùÃ÷ 48 //======================================================================== 49 50 51 //======================================================================== 52 // Íⲿº¯ÊýºÍ±äÁ¿ÉùÃ÷ C51 COMPILER V9.59.0.0 APP_PCA_CAPTURE 06/10/2021 18:07:14 PAGE 2 53 //======================================================================== 54 55 56 //======================================================================== 57 // º¯Êý: PCA_Capture_init 58 // ÃèÊö: Óû§³õʼ»¯³ÌÐò. 59 // ²ÎÊý: None. 60 // ·µ»Ø: None. 61 // °æ±¾: V1.0, 2020-09-28 62 //======================================================================== 63 void PCA_Capture_init(void) 64 { 65 1 COMx_InitDefine COMx_InitStructure; //½á¹¹¶¨Òå 66 1 PCA_InitTypeDef PCA_InitStructure; 67 1 68 1 P1_MODE_IN_HIZ(GPIO_Pin_6); //P1.6 ÉèÖÃΪ¸ß×èÊäÈë 69 1 P1_MODE_IO_PU(GPIO_Pin_7 | GPIO_Pin_5 | GPIO_Pin_4); //P1.7,P1.5,P1.4 ÉèÖÃΪ׼˫Ïò¿Ú 70 1 //-------------------------------------------- 71 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART -_9bit_BRTx 72 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //ʹÓò¨ÌØÂÊ, BRT_Timer1, BRT_Timer2 (×¢Òâ: ´®¿Ú2¹Ì¶¨Ê¹ -ÓÃBRT_Timer2) 73 1 COMx_InitStructure.UART_BaudRate = 115200ul; //²¨ÌØÂÊ, Ò»°ã 110 ~ 115200 74 1 COMx_InitStructure.UART_RxEnable = ENABLE; //½ÓÊÕÔÊÐí, ENABLE»òDISABLE 75 1 COMx_InitStructure.BaudRateDouble = DISABLE; //²¨ÌØÂʼӱ¶, ENABLE»òDISABLE 76 1 UART_Configuration(UART1, &COMx_InitStructure); //³õʼ»¯´®¿Ú1 UART1,UART2,UART3,UART4 77 1 NVIC_UART1_Init(ENABLE,Priority_1); //ÖжÏʹÄÜ, ENABLE/DISABLE; ÓÅÏȼ¶(µÍµ½¸ß) Priority_0,Priority_1,Pri -ority_2,Priority_3 78 1 79 1 printf("STC8A8K64D4 PCA Test Programme!\r\n"); //UART1·¢ËÍÒ»¸ö×Ö·û´® 80 1 //-------------------------------------------- 81 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_8bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 82 1 PCA_InitStructure.PCA_Value = 128 << 8; //¶ÔÓÚPWM,¸ß8λΪPWMÕ¼¿Õ±È 83 1 PCA_Init(PCA0,&PCA_InitStructure); 84 1 85 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 86 1 PCA_InitStructure.PCA_Value = 0; //¶ÔÓÚ²¶»ñ, Õâ¸öֵûÒâÒå 87 1 PCA_Init(PCA1,&PCA_InitStructure); 88 1 89 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 90 1 PCA_InitStructure.PCA_Value = 15000; //¶ÔÓÚÈí¼þ¶¨Ê±, ΪƥÅä±È½ÏÖµ 91 1 PCA_Init(PCA2,&PCA_InitStructure); 92 1 93 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_10bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bi -t 94 1 PCA_InitStructure.PCA_Value = 256 << 8; //¶ÔÓÚPWM,¸ß8λΪPWMÕ¼¿Õ±È 95 1 PCA_Init(PCA3,&PCA_InitStructure); 96 1 97 1 PCA_InitStructure.PCA_Clock = PCA_Clock_1T; //PCA_Clock_1T, PCA_Clock_2T, PCA_Clock_4T, PCA_Clock_6T, - PCA_Clock_8T, PCA_Clock_12T, PCA_Clock_Timer0_OF, PCA_Clock_ECI 98 1 PCA_InitStructure.PCA_RUN = ENABLE; //ENABLE, DISABLE 99 1 PCA_Init(PCA_Counter,&PCA_InitStructure); //ÉèÖù«ÓÃCounter 100 1 101 1 NVIC_PCA_Init(PCA_Counter,DISABLE,Priority_0); 102 1 NVIC_PCA_Init(PCA0,PCA_Mode_PWM,Priority_0); //PWM 103 1 NVIC_PCA_Init(PCA1,PCA_Mode_Capture,Priority_0); //Capture 104 1 NVIC_PCA_Init(PCA2,PCA_Mode_HighPulseOutput,Priority_0); //HighPulseOutput 105 1 NVIC_PCA_Init(PCA3,PCA_Mode_PWM,Priority_0); //PWM 106 1 //-------------------------------------------- 107 1 pwm0 = 128; 108 1 B_PWM0_Dir = 0; 109 1 UpdatePcaPwm(PCA3,500); C51 COMPILER V9.59.0.0 APP_PCA_CAPTURE 06/10/2021 18:07:14 PAGE 3 110 1 } 111 112 113 //======================================================================== 114 // º¯Êý: Sample_PCA_Capture 115 // ÃèÊö: Óû§Ó¦ÓóÌÐò. 116 // ²ÎÊý: None. 117 // ·µ»Ø: None. 118 // °æ±¾: V1.0, 2020-09-28 119 //======================================================================== 120 void Sample_PCA_Capture(void) 121 { 122 1 if(B_Capture1) 123 1 { 124 2 B_Capture1 = 0; 125 2 //²¶»ñÂö¿íʱ¼ä=CCAP1_tmp/PCA_Clock, ±ÈÈç CCAP1_tmp = 256, PCA_Clock = 22.1184MHz(1T), Âö¿í = 256/22.1184 -MHz = 11.57us 126 2 printf("Capture=%d\r\n",CCAP1_tmp); 127 2 } 128 1 129 1 cnt0++; 130 1 if((cnt0 & 15) == 15) //16ms 131 1 { 132 2 if(B_PWM0_Dir) 133 2 { 134 3 if(--pwm0 <= 8) B_PWM0_Dir = 0; 135 3 } 136 2 else if(++pwm0 >= 248) B_PWM0_Dir = 1; 137 2 UpdatePcaPwm(PCA0,pwm0); 138 2 } 139 1 } 140 141 142 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 330 ---- CONSTANT SIZE = 47 ---- XDATA SIZE = 2 14 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = 1 ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)