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