#include <system.h> #include <LCD1602.h> #include <INTRINS.H> #include <stdio.h> sbit T2Pin=P3^5; unsigned char a[16]="H: T: "; unsigned char b[10]; unsigned char p; unsigned char n,k=0; //k 计数器1的中断次数 unsigned long count; //555 输出频率 unsigned char i=0; #define th0 (15536>>8) #define tl0 ((unsigned char)(15536)) unsigned int th,tl; void counter1(void) interrupt 3 { k++; } main() { //delay(5000); TMOD=0x51; ET0=0; ET1=1;EA=1; LCDInit(); while(1) { //delay(20000); TH0=th0;TL0=tl0; TH1=TL1=0;k=0; TR0=TR1=1; for(n=0;n<20;n++) //定时1S { while(!TF0); TF0=0; TH0=th0;TL0=tl0; } TR0=TR1=0; count=TH1; count<<=8; count+=TL1; count+=(((unsigned long)k)<<16); sprintf(&a[0],"%ldHz",count); SetCurPos(1,1); LCDPrint(&a[0]); TH0=TL0=0; while(T2Pin); while(!T2Pin);TR0=1; while(T2Pin);TR0=0;//高电平时间 th=(TH0<<8)+TL0; TH0=TL0=0; while(!T2Pin); while(T2Pin);TR0=1; while(!T2Pin);TR0=0;//高电平时间 tl=(TH0<<8)+TL0; sprintf(&a[0],"%4.1f",th100.0/(th+tl)); SetCurPos(2,1); LCDPrint(&a[0]); } }此代码是用外部中断来测量占空比
时间: 2023-10-14 10:06:05 浏览: 29
这个代码是通过外部中断来测量占空比的方式进行测量的。具体来说,它使用了定时器0和定时器1来测量出周期时间,然后通过外部中断计数器1的中断次数来测量出高电平时间,从而计算出占空比。在代码中,T2Pin表示用于测量的引脚,当引脚为高电平时,计时器1开始计数,直到引脚变为低电平时停止计数,并通过计算得出高电平时间。同样地,通过测量周期时间来计算出周期长度,从而计算出占空比。
相关问题
#include<intrins.h>
`#include<intrins.h>` 是C/C++编程中引入头文件的一行,它通常用于访问处理器特定的指令集或扩展功能,这些功能可能不在标准库的其他头文件中。`intrins.h` 文件通常包含了处理器特定的优化内联汇编代码(intrinsic functions),比如SIMD(Single Instruction Multiple Data)操作,可以帮助提高程序性能。
以下是一个简单的示例,展示了如何使用`intrins.h`中的`__builtin_clz`函数来获取一个整数的最低有效位(Least Significant Bit)的索引:
```c
#include <intrins.h>
int main() {
int num = 0x12345678;
int bit_count = __builtin_clz(num); // 获取num二进制表示中第一个0的位数
printf("Bit count of %d is %d\n", num, bit_count); // 输出:Bit count of 12345678 is 28
return 0;
}
```
#include <intrins.h>
#include <intrins.h>是C语言中的一个头文件,它提供了一些内置函数和内联汇编指令,用于访问特定的硬件功能或执行底层操作。该头文件通常用于嵌入式系统开发或需要直接操作底层硬件的场景。
该头文件中包含了一些与特定硬件平台相关的函数和指令,例如位操作、字节交换、循环延时等。这些函数和指令可以直接在代码中使用,以实现对底层硬件的控制和操作。
需要注意的是,<intrins.h>是一个非标准的头文件,它的具体内容和功能可能因编译器和硬件平台而异。在使用时,建议查阅相关编译器和硬件平台的文档,以了解具体支持的函数和指令。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)