函数信号发生器源程序_第1页
函数信号发生器源程序_第2页
函数信号发生器源程序_第3页
函数信号发生器源程序_第4页
函数信号发生器源程序_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include#include#define dac0832 xbyte0x0fffint pinlv=256; /改变频率的时延自变量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= /正弦波信号采点值 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); /延时函数void write_com(unsigned char com); /液晶写指令void write_data(unsigned char dat); /液晶写数据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; /复位初始为高电平 rs=0; rw=0; p1=com; delay(1); e=1; delay(1); e=0;void write_data(unsigned char dat) e=0; /复位初始为高电平 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) /主函数 ie=0x85; /外部中断设定 改变频率 tcon=0x05; lcd1602_init(); table0=pinlv/1000; /计算周期作为输出 table1=pinlv%1000/100; table2=pinlv%100/10; table3=pinlv%10; write_co

10、m(0x80+0x40); /设置待写入数据的地址,写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); /在周期后面加上“ms” write_data(tab11); while(1) if(p20=0) /方波 write_com(0x80); /写lcd1602的第1行,写明产生的波形 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); /设置代写入数据的地址,写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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论