函數(shù)信號(hào)發(fā)生器源程序.doc_第1頁(yè)
函數(shù)信號(hào)發(fā)生器源程序.doc_第2頁(yè)
函數(shù)信號(hào)發(fā)生器源程序.doc_第3頁(yè)
函數(shù)信號(hào)發(fā)生器源程序.doc_第4頁(yè)
函數(shù)信號(hào)發(fā)生器源程序.doc_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include#include#define dac0832 xbyte0x0fffint pinlv=256; /改變頻率的時(shí)延自變量sbit p20=p20;sbit p21=p21;sbit p22=p22;sbit p23=p23;sbit rs=p30;sbit rw=p31; /液晶顯示的端口sbit e=p34;int j=0;unsigned char code tab=0123456789mstime:;unsigned char code tab1=zhengxianbofangbo sanjiaobo jvchibo ;unsigned char table4;floa

2、t code table2= /正弦波信號(hào)采點(diǎn)值 0x80,0x83,0x85,0x88,0x8a,0x8d,0x8f,0x92,0x94,0x97,0x99,0x9b,0x9e,0xa0,0xa3,0xa5, 0xa7,0xaa,0xac,0xae,0xb1,0xb3,0xb5,0xb7,0xb9,0xbb,0xbd,0xbf,0xc1,0xc3,0xc5,0xc7, 0xc9,0xcb,0xcc,0xce,0xd0,0xd1,0xd3,0xd4,0xd6,0xd7,0xd8,0xda,0xdb,0xdc,0xdd,0xde, 0xdf,0xe0,0xe1,0xe2,0xe3,0xe3,0x

3、e4,0xe4,0xe5,0xe5,0xe6,0xe6,0xe7,0xe7,0xe7,0xe7, 0xe7,0xe7,0xe7,0xe7,0xe6,0xe6,0xe5,0xe5,0xe4,0xe4,0xe3,0xe3,0xe2,0xe1,0xe0,0xdf, 0xde,0xdd,0xdc,0xdb,0xda,0xd8,0xd7,0xd6,0xd4,0xd3,0xd1,0xd0,0xce,0xcc,0xcb,0xc9, 0xc7,0xc5,0xc3,0xc1,0xbf,0xbd,0xbb,0xb9,0xb7,0xb5,0xb3,0xb1,0xae,0xac,0xaa,0xa7, 0xa5,0xa

4、3,0xa0,0x9e,0x9b,0x99,0x97,0x94,0x92,0x8f,0x8d,0x8a,0x88,0x85,0x83,0x80, 0x7d,0x7b,0x78,0x76,0x73,0x71,0x6e,0x6c,0x69,0x67,0x65,0x62,0x60,0x5d,0x5b,0x59, 0x56,0x54,0x52,0x4f,0x4d,0x4b,0x48,0x47,0x45,0x43,0x41,0x3f,0x3d,0x3b,0x39,0x37, 0x35,0x34,0x32,0x30,0x2f,0x2d,0x2c,0x2a,0x29,0x28,0x26,0x25,0x24,

5、0x23,0x22,0x21, 0x20,0x1f,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b,0x1b,0x1a,0x1a,0x1a,0x19,0x19,0x19,0x19, 0x19,0x19,0x19,0x19,0x1a,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1e,0x1f,0x20, 0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2a,0x2c,0x2d,0x2f,0x30,0x32,0x34,0x35, 0x37,0x39,0x3b,0x3d,0x3f,0x41,0x43,0x45,0

6、x47,0x49,0x4b,0x4d,0x4f,0x52,0x54,0x56, 0x59,0x5b,0x5d,0x60,0x62,0x65,0x67,0x69,0x6c,0x6e,0x71,0x73,0x76,0x78,0x7b,0x7d;void delay(unsigned char ms); /延時(shí)函數(shù)void write_com(unsigned char com); /液晶寫指令void write_data(unsigned char dat); /液晶寫數(shù)據(jù)void lcd1602_init(void) /液晶初始化 delay(15); write_com(0x38); del

7、ay(5); write_com(0x38); delay(5); write_com(0x38); write_com(0x38); write_com(0x08); write_com(0x01); write_com(0x06); write_com(0x0c);void write_com(unsigned char com) e=0; /復(fù)位初始為高電平 rs=0; rw=0; p1=com; delay(1); e=1; delay(1); e=0;void write_data(unsigned char dat) e=0; /復(fù)位初始為高電平 rs=1; rw=0; p1=da

8、t; delay(1); e=1; delay(1); e=0;void delay(unsigned char ms) /晶振12khz unsigned char i; while(ms-) for(i=0;i=120;i+); void fang() /方波 dac0832=0; delay(pinlv/2); dac0832=0xff; delay(pinlv/2);void jvchi() /鋸齒波 unsigned char i; for(i=0;i255;i+) dac0832=i; delay(pinlv/256); void tran() /三角波 unsigned char

9、 i; for(i=0;i0;i-) dac0832=i; delay(pinlv/256); void sin() /正弦波 unsigned int i; for(i=0;i255;i+) dac0832=table2i; delay(pinlv/256); void main(void) /主函數(shù) ie=0x85; /外部中斷設(shè)定 改變頻率 tcon=0x05; lcd1602_init(); table0=pinlv/1000; /計(jì)算周期作為輸出 table1=pinlv%1000/100; table2=pinlv%100/10; table3=pinlv%10; write_co

10、m(0x80+0x40); /設(shè)置待寫入數(shù)據(jù)的地址,寫lcd1602的第2行 寫出產(chǎn)生波形的周期 for(j=12;j17;j+) write_data(tabj); delay(1); for(j=0;j4;j+) write_data(tabtablej); delay(1); write_data(tab10); /在周期后面加上“ms” write_data(tab11); while(1) if(p20=0) /方波 write_com(0x80); /寫lcd1602的第1行,寫明產(chǎn)生的波形 for(j=11;j22;j+) write_data(tab1j); while(p20

11、=0) fang(); if(p21=0) /鋸齒波 write_com(0x80); /寫lcd1602的第2行 for(j=33;j44;j+) write_data(tab1j); while(p21=0) jvchi(); if(p22=0) /三角波 write_com(0x80); /寫lcd1602的第2行 for(j=22;j33;j+) write_data(tab1j); while(p22=0) tran(); if(p23=0) /正弦波 write_com(0x80); /寫lcd1602的第2行 for(j=0;j11;j+) write_data(tab1j);

12、while(p23=0) sin(); void int0(void) interrupt 0 /中斷0 降頻 pinlv=pinlv*2; /頻率減半 table0=pinlv/1000; table1=pinlv%1000/100; table2=pinlv%100/10; table3=pinlv%10; write_com(0x80+0x40); /設(shè)置代寫入數(shù)據(jù)的地址,寫lcd1602的第2行 for(j=12;j17;j+) write_data(tabj); delay(1); for(j=0;j4;j+) write_data(tabtablej); delay(1); write_data(tab10); write_data(tab11);void int1(void) interrupt 2 /中斷2 升頻 pinlv=pinlv/2; table0=pinlv/1000; table1=pinlv%1000/100; table2=pinlv%100/1

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論