c语言编程输出一个正弦波,C语言查表法实现DA正弦波输出.doc

C语言查表法实现DA正弦波输出

毕设又开始..

终于把三角波程序换成正弦波了!

正弦表!网上太难找..

//------分隔线-----------

//三角波

?????int s;

?????for(s=1;s<250;s+=step){

???????delay();

??????SPISend1(0x17) ;

??????SPISend1(s) ;

??????SPISend1(0xf0) ;?

???????delay();

//正弦波

extern int sin[720]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xdd,0xde,0xdf,0xdf,0xe0,0xe1,0xe2,0xe2,0xe3,0xe4,0xe4,0xe5,0xe6,0xe6,0xe7,0xe8,0xe8,0xe9,0xea,0xea,0xeb,0xeb,0xec,0xed,0xed,0xee,0xee,0xef,0xef,0xf0,0xf1,0xf1,0xf2,0xf2,0xf3,0xf3,0xf4,0xf4,0xf4,0xf5,0xf5,0xf6,0xf6,0xf7,0xf7,0xf7,0xf8,0xf8,0xf9,0xf9,0xf9,0xfa,0xfa,0xfa,0xfb,0xfb,0xfb,0xfb,0xfc,0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfd,0xfd,0xfd,0xfd,0xfc,0xfc,0xfc,0xfc,0xfb,0xfb,0xfb,0xfb,0xfa,0xfa,0xfa,0xf9,0xf9,0xf9,0xf8,0xf8,0xf7,0xf7,0xf7,0xf6,0xf6,0xf5,0xf5,0xf4,0xf4,0xf4,0xf3,0xf3,0xf2,0xf2,0xf1,0xf1,0xf0,0xef,0xef,0xee,0xee,0xed,0xed,0xec,0xeb,0xeb,0xea,0xea,0xe9,0xe8,0xe8,0xe7,0xe6,0xe6,0xe5,0xe4,0xe4,0xe3,0xe2,0xe2,0xe1,0xe0,0xdf,0xdf,0xde,0xdd,0xdc,0xdc,0xdb,0xda,0xd9,0xd8,0xd8,0xd7,0xd6,0xd5,0xd4,0xd3,0xd3,0xd2,0xd1,0xd0,0xcf,0xce,0xcd,0xcd,0xcc,0xcb,0xca,0xc9,0xc8,0xc7,0xc6,0xc5,0xc4,0xc3,0xc2,0xc1,0xc0,0xc0,0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb0,0xaf,0xae,0xad,0xac,0xab,0xaa,0xa9,0xa8,0xa7,0xa6,0xa5,0xa4,0xa3,0xa2,0xa1,0xa0,0x9e,0x9d,0x9c,0x9b,0x9a,0x99,0x98,0x97,0x96,0x95,0x94,0x92,0x91,0x90,0x8f,0x8e,0x8d,0x8c,

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用定时器来测量正弦波的频率。具体实现是:首先设置定时器的计数器,然后将正弦波的周期作为定时器的计数器上限,当定时器计数器达到上限时,触发定时器中断,记录下当前时间戳,然后重置定时器计数器,继续等待下一次定时器中断。通过记录两次定时器中断的时间戳,可以计算出正弦波的周期,从而得到正弦波的频率。 以下是一个简单的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <sys/time.h> #include <math.h> #define PI 3.14159265358979323846 volatile int count = 0; volatile int flag = 0; struct timeval start, end; void timer_handler(int signum) { count++; if (count == 2) { gettimeofday(&end, NULL); flag = 1; } } int main() { double freq; int period; struct sigaction sa; struct itimerval timer; sa.sa_handler = &timer_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGALRM, &sa, NULL) == -1) { perror("sigaction"); exit(1); } timer.it_value.tv_sec = 0; timer.it_value.tv_usec = 10000; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = 10000; if (setitimer(ITIMER_REAL, &timer, NULL) == -1) { perror("setitimer"); exit(1); } while (1) { if (flag) { period = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); freq = 1000000.0 / period; printf("Frequency: %f Hz\n", freq); flag = 0; count = 0; } } return 0; } ``` 这个程序使用了定时器来测量正弦波的频率,每隔10毫秒触发一次定时器中断,记录下两次中断的时间戳,计算出正弦波的周期,从而得到正弦波的频率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值