|
利用STC15的PCA進(jìn)行脈沖計(jì)數(shù),計(jì)算頻率
單片機(jī)源程序如下:
- /********************************************************
- *
- * 平臺(tái):keil5 + STC154K58S4
- *
- * 頻率:24MHz
- *
- * 功能:使用PCA模塊的捕獲功能,判斷脈沖個(gè)數(shù),計(jì)算頻率,使用串口輸出
- *
- * 作者: 李鐵
- *
- * 時(shí)間:2022年7月3日
- *
- ***********************************************************/
- #include "config.h"
- #include <stdio.h>
- #include "bsp_pca.h"
- #include "bsp_uart.h"
- #include "delay.h"
- #define uchar unsigned char
- #define uint unsigned int
- void Delay10ms(); //@24.000MHz
- sbit LED = P0^0; //輸出脈沖端口
- bit flag;
- uint count;//脈沖數(shù)
- uchar count_L,count_H;
- uint over_count; //PCA計(jì)數(shù)器溢出次數(shù)
- float Fre;
- uint count1;
- void main()
- {
- UART_InitConfig();
- TI = 1; //使用printf()函數(shù)時(shí),TI必須為1
- PCA_InitConfig();
- EA = 1;
- while(1)
- {
- LED = ~LED;
- // printf("hello,world!\n\r");
- printf("脈沖數(shù):%d\n\r",count);
- printf("溢出數(shù):%d\n\r",over_count);
- printf("頻率:%fHz\n\r",Fre);
- delay_ms(100);
- }
- }
- void PCA(void) interrupt 7
- {
- if(CCF0 == 1)
- {
- CCF0 = 0;
- CCAP0H = 0;
- CCAP0L = 0;
- flag = 1;
- count++;
- if(flag)
- {
- flag = 0;
- count_H = CCAP0H;
- count_L = CCAP0L;
- count1 = count_H;
- count1 = (count1<<8)|count_L;
- Fre = 1/((65535*over_count+count1)*0.0000000416);
- over_count = 0;
- }
-
- }
- if(CF == 1)
- {
- CF = 0;
- over_count++;
- }
- }
復(fù)制代碼 |
-
邏輯分析儀頻率
-
串口輸出頻率
-
-
PCA脈沖計(jì)數(shù).zip
2022-7-3 17:20 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
68.66 KB, 下載次數(shù): 90, 下載積分: 黑幣 -5
Keil代碼
評(píng)分
-
查看全部評(píng)分
|