微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > 硬件电路设计讨论 > 想产生正弦波通过单片机和max5312,可是调不出来,是da芯片的关系还是程序的关系

想产生正弦波通过单片机和max5312,可是调不出来,是da芯片的关系还是程序的关系

时间:10-02 整理:3721RD 点击:
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit DIN=P1^1;
sbit SCLK=P1^0;
sbit CS=P1^2;
uint k,i,Dignum;
uchar code sin[201]={0x0800,0x0840,0x0881,0x08c1,0x0901,0x0940,0x0980,0x09bf,0x09fd,0x0a3b,
        0x0a79,0x0ab5,0x0af2,0x0b2d,0x0b68,0x0ba1,0x0bda,0x0c12,0x0c49,0x0c7f,0x0cb3,0x0ce7,0x0d19,
        0x0d4a,0x0d79,0x0da7,0x0dd4,0x0dff,0x0e29,0x0e51,0x0e78,0x0e9d,0x0ec0,0x0ee2,0x0f02,0x0f20,
        0x0f3c,0x0f57,0x0f6f,0x0f86,0x0f9b,0x0fae,0x0fbf,0x0fce,0x0fdb,0x0fe6,0x0fef,0x0ff6,0x0ffb,
        0x0ffe,0x0fff,0x0ffe,0x0ffb,0x0ff6,0x0fef,0x0fe6,0x0fdb,0x0fce,0x0fbf,0x0fae,0x0f9b,0x0f86,
        0x0f6f,0x0f57,0x0f3c,0x0f20,0x0f02,0x0ee2,0x0ec0,0x0e9d,0x0e78,0x0e51,0x0e29,0x0dff,0x0dd4,
        0x0da7,0x0d79,0x0d4a,0x0d19,0x0ce7,0x0cb3,0x0c7f,0x0c49,0x0c12,0x0bda,0x0ba1,0x0b68,0x0b2d,
        0x0af2,0x0ab5,0x0a79,0x0a3b,0x09fd,0x09bf,0x0980,0x0940,0x0901,0x08c1,0x0881,0x0840,0x0800,
        0x07c0,0x077f,0x073f,0x06ff,0x06c0,0x0680,0x0641,0x0603,0x05c5,0x0587,0x054b,0x050e,0x04d3,
        0x0498,0x045f,0x0426,0x03ee,0x03b7,0x0381,0x034d,0x0319,0x02e7,0x02b6,0x0287,0x0259,0x022c,
        0x0201,0x01d7,0x01af,0x0188,0x0163,0x0140,0x011e,0x00fe,0x00e0,0x00c4,0x00a9,0x0091,0x007a,
        0x0065,0x0052,0x0041,0x0032,0x0025,0x001a,0x0011,0x000a,0x0005,0x0002,0x0001,0x0002,0x0005,
        0x000a,0x0011,0x001a,0x0025,0x0032,0x0041,0x0052,0x0065,0x007a,0x0091,0x00a9,0x00c4,0x00e0,
        0x00fe,0x011e,0x0140,0x0163,0x0188,0x01af,0x01d7,0x0201,0x022c,0x0259,0x0287,0x02b6,0x02e7,
        0x0319,0x034d,0x0381,0x03b7,0x03ee,0x0426,0x045f,0x0498,0x04d3,0x050e,0x054b,0x0587,0x05c5,
  0x0603,0x0641,0x0680,0x06c0,0x06ff,0x073f,0x077f,0x07c0,0x0800,};
void DA_conver(uint Dignum)
{
        uint Dig=0;
        uchar i=0;
        SCLK=1;
        CS=0;           
        for(i=0;i<16;i++)   
        {
           Dig=Dignum&0x8000;
           if(Dig)
           {
            DIN=1;
           }
           else
           {
            DIN=0;
           }
           SCLK=0;
           _nop_();
           Dignum<<=1;//×óò?
           SCLK=1;
           _nop_();//1us
        }
        SCLK=1;
        CS=1;      
}

void delay40ms()                //40ms?óê±@20.000MHz
{
        unsigned char i, j;
  i = 130;
        j = 176;
        do
        {
                while (--j);
        }
        while (--i);
}
void main()
{
while(1)
        {  
  for(i=0;i<201;i++)
    {
                        Dignum=sin[i];
     DA_conver(Dignum);       
                        delay40ms();
      if(i==200)
      {i=0;}                               
    }               
  }
}


你的DA输出频率是多少啊,会不会被你干掉了

应该不是,我想输出模拟信号频率才25Hz,应该足够的啊

正弦表有问题,,,,,,,,,,,,,,

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top