<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 基于51單片機+DAC0832的信號發(fā)生器

          基于51單片機+DAC0832的信號發(fā)生器

          作者: 時間:2017-01-12 來源:網(wǎng)絡 收藏

            最近幫別人設計一個畢業(yè)設計,做一個多種信號發(fā)生器(四種波形:方波、三角波、鋸齒波、梯形波),現(xiàn)在貼上來給大家參考,如果有錯誤的地方,望指出~

          本文引用地址:http://www.ex-cimer.com/article/201701/342829.htm

            下面先貼上仿真的電路圖(仿真的軟件是Protuse,上傳一個大點的圖,方便大家看的清楚點):

            原件清單:STC89C52單片機X1、轉換器X1、12M晶振X1、電容22pfX2、10uf的電容X1、1nf陶瓷電容X1、獨立按鍵X4、10千歐排阻X1、10KΩ電阻X5、LM358 單電源運放X1。仿真就需要這些原件,具體的硬件設計大家定好了在制作~

           

            下面上傳一下C程序吧~(使用的IDE環(huán)境是Keil 4,語言是C語言)

            Source文件(.c文件):

            1main.c文件:

            1 #include "reg52.h"

            2 #include "init.h"

            3 #include "single.h"

            4 #include "delay.h"

            5 #include "Key.h"

            6 int main(void)

            7 {

            8 unsigned char Model=0;//0-方波 1-三角波 2-鋸齒波 3-正弦波

            9 unsigned int Count=0;//計數(shù)器

            10 unsigned int Squ_Per=256;

            11 unsigned int Tri_Per=256;

            12 unsigned int Saw_Per=256;

            13 unsigned int Sin_Per=256;

            14 init();

            15 while(1)

            16 {

            17 while(Model==0)

            18 {

            19 Square_wave(Squ_Per,&Count);

            20 Count+=4;

            21 Squ_Per=Key_Plus(Squ_Per);

            22 Squ_Per=Key_Subc(Squ_Per);

            23 Model=Key_Model(Model,&Squ_Per,&Count);//每次退出當前while時記得復原Period和Count的數(shù)據(jù)

            24 }

            25 while(Model==1)

            26 {

            27 Triangle_wave(Tri_Per,&Count);

            28 Count+=4;

            29 Tri_Per=Key_Plus(Tri_Per);

            30 Tri_Per=Key_Subc(Tri_Per);

            31 Model=Key_Model(Model,&Tri_Per,&Count);

            32 }

            33 while(Model==2)

            34 {

            35 Sawtooth_wave(Saw_Per,&Count);

            36 Count+=4;

            37 Saw_Per=Key_Plus(Saw_Per);

            38 Saw_Per=Key_Subc(Saw_Per);

            39 Model=Key_Model(Model,&Saw_Per,&Count);

            40 }

            41 while(Model==3)

            42 {

            43 Sin_wave(Sin_Per,&Count);

            44 Count+=4;

            45 Sin_Per=Key_Plus(Sin_Per);

            46 Sin_Per=Key_Subc(Sin_Per);

            47 Model=Key_Model(Model,&Sin_Per,&Count);

            48 }

            49 }

            50 return 0;

             }

            2init.c文件:

            1 #include "reg52.h"

            2 sbit CS_DAC=P1^5;//的片選端口

            3 sbit WR_DAC=P1^6;//的數(shù)據(jù)寫入端口

            4 extern void init(void)

            5 {

            6 P0=0xff;

            7 P1=0xff;

            8 P2=0xff;

            9 P3=0xff;

            10 CS_DAC=0;//一直片選中DAC0832,低電平有效啊~

            11 WR_DAC=0;//一直寫入數(shù)據(jù)到DAC0832

            12 }

            3single.c文件

            1 #include "reg52.h"

            2 #include "single.h"

            3 #include "delay.h"

            4 #define DATA P0

            5 void Square_wave(unsigned int Per,unsigned int *Count)

            6 {

            7 if(*Count>=Per) *Count=0;

            8 if(*Count

            9 {

            10 DATA=0x00;

            11 }

            12 else

            13 {

            14 DATA=0xFF;

            15 }

            16 }

            17 void Triangle_wave(unsigned int Per,unsigned int *Count)

            18 {

            19 if(*Count>=Per) *Count=0;

            20 if(*Count

            21 {

            22 DATA=*Count;

            23 }

            24 else

            25 {

            26 DATA=Per-*Count;

            27 }

            28 }

            29 void Sawtooth_wave(unsigned int Per,unsigned int *Count)

            30 {

            31 if(*Count>=Per) *Count=0;

            32 if(*Count

            33 {

            34 DATA=*Count;

            35 }

            36 }

            37 void Sin_wave(unsigned int Per,unsigned int *Count)

            38 {

            39 if(*Count>Per) *Count=0;

            40 if(*Count

            41 {

            42 DATA=*Count;

            43 }

            44 else if(*Count==Per/2)

            45 {

            46 delay(100);

            47 }

            48 else if(*Count

            49 {

            50 DATA=Per-*Count;

             }

            52 else if(*Count==Per)

            53 {

            54 delay(100);

            55 }

            56 }

            4Key.c文件:

            1 #include "Key.h"

            2 #include "delay.h"

            3 sbit key2=P3^3; //wave Change

            4 sbit key3=P3^4; //Fre plus

            5 sbit key4=P3^5; //Fre subc

            6 unsigned char Key_Model(unsigned char Model,unsigned int *Pre,unsigned int *Count)

            7 {

            8 if(key2==0)

            9 {

            10 delay(10);

            11 if(key2==0)

            12 {

            13 Model=Model+1;

            14 *Pre=256;

            15 *Count=0;

            16 }

            17 }

            18 while(key2==0);

            19 if(Model>3)

            20 {

            21 Model=0;

            22 }

            23 return Model;

            24 }

            25 unsigned int Key_Plus(unsigned int Per)

            26 {

            27 if(key3==0)

            28 {

            29 delay(10);

            30 if(key3==0)

            31 {

            32 Per=Per+8;

            33 }

            34 }

            35 while(key3==0);

            36 if(Per>256)

            37 {

            38 Per=0;

            39 }

            40 return Per;

            41 }

            42 unsigned int Key_Subc(unsigned int Per)

            43 {

            44 if(key4==0)

            45 {

            46 delay(10);

            47 if(key4==0)

            48 {

            49 Per=Per-8;

            50 }

             }

            52 while(key4==0);

            53 if(Per<0)

            54 {

            55 Per=256;

            56 }

            57 return Per;

            58 }

            5delay.c文件:

            1 void delay(unsigned int r)

            2 {

            3 unsigned int i,j;

            4 for(i=r;i>0;i--)

            5 for(j=110;j>0;j--);

            6 }

            Header文件(.h文件):

            1init.h文件:

            1 extern void init(void);

            2single.h文件:

            1 void Square_wave(unsigned int Per,unsigned int *Count);

            2 void Triangle_wave(unsigned int Per,unsigned int *Count);

            3 void Sawtooth_wave(unsigned int Per,unsigned int *Count);

            4 void Sin_wave(unsigned int Per,unsigned int *Count);

            3Key.h文件:

            1 #include "reg52.h"

            2 unsigned char Key_Model(unsigned char Model,unsigned int *Pre,unsigned int *Count);

            3 unsigned int Key_Plus(unsigned int Per);

            4 unsigned int Key_Subc(unsigned int Per);

            4delay.h文件:

            1 #include

            2 void delay(unsigned int r);

            3 #define NOP() _nop_()

            所用的工程文件我都已經(jīng)上傳嘍~,下面來看看仿真的結果:(大家在電路設計的時候可以進行一下濾波處理,然后對信號進行放大處理,這樣的話效果可能會更好點哦~)

            方波: 三角波: 鋸齒波: 梯形波:

            在這里要感謝GISPALAB實驗室的各位老師和學長學姐的幫助!謝謝~

            大家注意下,電路有個小問題,由于本人的失誤,DAC0832的Iout1和Iout2的輸出接口的接法應該按如下的接入方式:

            需要修改的地方有:

            1、電源改成雙電源

            2、Iout接口需要接地

           
                 修改完畢之后的結果就會比較完美了,下面上傳一個三角波的波形  
           

            感謝GISPALAB實驗室的老師和同學們的幫助和支持~



          關鍵詞: DAC0832 51

          評論


          相關推薦

          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();