51单片机控制DAC0832产生正弦波,如何用定时器改变频率,求代码!
#include<reg51.h>unsignedinti;codeunsignedcharSin[128]={64,67,70,73,76,79,82,85,88,91...
#include <reg51.h>
unsigned int i;
code unsigned char Sin[128]={
64,67,70,73,76,79,82,85,88,91,94,96,99,102,104,106,
109,111,113,115,117,118,120,121,123,124,125,126,126,
127,127,127,127,127,127,127,126,126,125,124,123,121,
120,118,117,115,113,111,109,106,104,102,99,96,94,91,
88,85,82,79,76,73,70,67,64,60,57,54,51,48,45,42,39,
36,33,31,28,25,23,21,18,16,14,12,10,9,7,6,4,3,2,1,
1,0,0,0,0,0,0,0,1,1,2,3,4,6,7,9,10,12,14,16,18,21,23,
25,28,31,33,36,39,42,45,48,51,54,57,60};
main()
{
while(1)
{
i++;
if(i==128)i=0;
P1=Sin[i];
}
} 展开
unsigned int i;
code unsigned char Sin[128]={
64,67,70,73,76,79,82,85,88,91,94,96,99,102,104,106,
109,111,113,115,117,118,120,121,123,124,125,126,126,
127,127,127,127,127,127,127,126,126,125,124,123,121,
120,118,117,115,113,111,109,106,104,102,99,96,94,91,
88,85,82,79,76,73,70,67,64,60,57,54,51,48,45,42,39,
36,33,31,28,25,23,21,18,16,14,12,10,9,7,6,4,3,2,1,
1,0,0,0,0,0,0,0,1,1,2,3,4,6,7,9,10,12,14,16,18,21,23,
25,28,31,33,36,39,42,45,48,51,54,57,60};
main()
{
while(1)
{
i++;
if(i==128)i=0;
P1=Sin[i];
}
} 展开
3个回答
展开全部
你确定是使用定时器改变频率??
下面的程序是使用定时器改变幅值的,你要是确定是定时器改变频率的话,把具体的要求贴出来
#include <reg51.h>
unsigned int i;
code unsigned char Sin[128]={
64,67,70,73,76,79,82,85,88,91,94,96,99,102,104,106,
109,111,113,115,117,118,120,121,123,124,125,126,126,
127,127,127,127,127,127,127,126,126,125,124,123,121,
120,118,117,115,113,111,109,106,104,102,99,96,94,91,
88,85,82,79,76,73,70,67,64,60,57,54,51,48,45,42,39,
36,33,31,28,25,23,21,18,16,14,12,10,9,7,6,4,3,2,1,
1,0,0,0,0,0,0,0,1,1,2,3,4,6,7,9,10,12,14,16,18,21,23,
25,28,31,33,36,39,42,45,48,51,54,57,60};
main()
{
TMOD=0X01;
EA=1;
ET0=1;
TR0=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
while(1)
{
P1=Sin[i];
}
}
void timer0(void) interrupt 1
{
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
i=i+1;
if(i==128)i=0;
}
下面的程序是使用定时器改变幅值的,你要是确定是定时器改变频率的话,把具体的要求贴出来
#include <reg51.h>
unsigned int i;
code unsigned char Sin[128]={
64,67,70,73,76,79,82,85,88,91,94,96,99,102,104,106,
109,111,113,115,117,118,120,121,123,124,125,126,126,
127,127,127,127,127,127,127,126,126,125,124,123,121,
120,118,117,115,113,111,109,106,104,102,99,96,94,91,
88,85,82,79,76,73,70,67,64,60,57,54,51,48,45,42,39,
36,33,31,28,25,23,21,18,16,14,12,10,9,7,6,4,3,2,1,
1,0,0,0,0,0,0,0,1,1,2,3,4,6,7,9,10,12,14,16,18,21,23,
25,28,31,33,36,39,42,45,48,51,54,57,60};
main()
{
TMOD=0X01;
EA=1;
ET0=1;
TR0=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
while(1)
{
P1=Sin[i];
}
}
void timer0(void) interrupt 1
{
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
i=i+1;
if(i==128)i=0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询