程序:
sin
Summary #include <math.h>
float sin (float x) /* value to calculate sine for */
Description The sin function calculates the sine of the floating-point value x. The value of x must be in the -65535 to +65535 range or an NaN error value is generated.
Return Value The sin function returns the sine of x.
See Also cos, cos517, sin517, tan, tan517
Example
#include <math.h>
#include <stdio.h>/* for printf */
void tst_sin (void) {
float x
float y
for (x = 0x <(2 * 3.1415)x += 0.1) {
y = sin (x)
printf ("SIN(%f) = %f\n", x, y)
}
}
注:角度不是用度算的,以弧度为单位
500HZ方波周期是2ms,只需定时器1ms,将管脚状态取反一次就其可,若按下按键,改为定时500us即可,程序如下:#include <reg51.h>
sbit key=P1^0
void main()
{
unsigned int n=1000
TMOD=0X01//定时器0工作方式1
TH0=(65536-N)/256//定时器初值,先是定时1000US
TL0=(65536-N)%256
ET0=1//开定时器0中断
EA=1//开总中断
TR0=1//启动定时器0
while(1)
{
if(key==0)//判断按键是否按下
{
delay_ms(20)//延时消抖动
if(key==0)n=500
}
}
}
中断程序如下:
void timer0() interrupt 1
{
TH0=(65536-N)/256
TL0=(65536-N)%256
P2^0=~P2^0//P2.0输出方波
}
延时子程序略
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)