《课程设计(论文)基于单片机的波形发生器设计及实现.doc》由会员分享,可在线阅读,更多相关《课程设计(论文)基于单片机的波形发生器设计及实现.doc(14页珍藏版)》请在三一办公上搜索。
1、北京联合大学信息学院电子系统设计与实习实验报告题目:基于单片机的波形发生器设计及实现专 业: 电子信息工程 班 级: 电子1201B 姓 名: 学号: 目录1.系统简介12.系统组成框图13.软件流程图14.功能及使用说明15.结果截图16.原理图及源代码程序11. 系统简介这个系统是基于AT89S52单片机的波形信号发生器。使用AT89S52单片机作为控制核心,该系统由数字/模拟转换电路(DAC0832)、按键电路和放大电路等组成。通过按键可控制方波、三角波、正弦波的产生,并可以通过按键来观测占空比。这个设计方法简单、性能良好。2.系统组成框图3.软件流程图64.功能及使用说明本系统的功能有
2、:通过按键控制,产生方波、正旋波、三角波,观测占空比。5.结果截图1、 实物图2、 正旋波3、 三角波5、方波6.原理图及源代码程序#include #include #define uint unsigned int#define uchar unsigned charuchar KEY;ucharfrekeycount;ucharfzkeycount;ucharzkbkeycount;uchar F;uchar FSIGN=1;uchar ASIGN=1;uchar ZSIGN=1;uchar A;uchar Z;uchar sign;sbitfb=P10;sbitsjb=P11;sbit
3、zxb=P12;sbitpl=P13;sbitfz=P14;sbitzkb=P37;sbit led=P36;/*uchar code sin100=128 ,136 ,143 ,151 ,159 ,167 ,174 ,182 ,189 ,196 ,202,209,215 ,220,226 ,231 ,235 ,239 ,243 ,246 ,249 ,251 ,253 ,254 ,255 ,255 ,255 ,254 ,253 ,251 ,249 ,246 ,243 ,239 ,235 ,231 ,226 ,220 ,215 ,209 ,202 ,196 ,189 ,182 ,174 ,167
4、 ,159 ,151 ,143 ,136 ,128 ,119 ,112 ,104 ,96 ,88 ,81 ,73 ,66 ,59 ,53 ,46 ,40 ,35 ,29 ,24 ,20 ,16 ,12 ,9 ,6 ,4 ,2 ,1 ,0 ,0 ,0 ,1 ,2 ,4 ,6 ,9 ,12 ,16 ,20 ,24 ,29 ,35 ,40 ,46 ,53 ,59 ,66 ,73 ,81 ,88 ,96 ,104 ,112 ,119 ; */*uchar code sin50=128 ,143 ,159 ,174 ,189 ,202 ,215 ,226 ,235 ,243 ,249 ,253 ,255
5、 ,255 ,253 ,249 ,243 ,235 ,226 ,215 ,202 ,189 ,174 ,159 ,143 ,128 ,112 ,96 ,81 ,66 ,53 ,40 ,29 ,20 ,12 ,6 ,2 ,0 ,0 ,2 ,6 ,12 ,20 ,29 ,40 ,53 ,66 ,81 ,96 ,112 ;*/*uchar code sin25=128,159,189,215,235,249,255,253,243,226,202,174,143,112,81,53,29,12,2,0,6,20,40,66,96; */uchar code sin250=0x7F,0x82,0x85
6、,0x89,0x8C,0x8F,0x92,0x95,0x98,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,0xB1,0xB4,0xB7,0xBA,0xBC,0xBF,0xC2,0xC5,0xC7,0xCA,0xCD,0xCF,0xD1,0xD4,0xD6,0xD9,0xDB,0xDD,0xDF,0xE1,0xE3,0xE5,0xE7,0xE9,0xEB,0xEC,0xEE,0xEF,0xF1,0xF2,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFC,0xFD,0xFD,0xFE,0xFE,0xFE,0xFE,0xFE
7、,0xFE,0xFE,0xFE,0xFE,0xFE,0xFD,0xFD,0xFC,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEB,0xE9,0xE7,0xE5,0xE3,0xE1,0xDF,0xDD,0xDB,0xD9,0xD6,0xD4,0xD1,0xCF,0xCD,0xCA,0xC7,0xC5,0xC2,0xBF,0xBC,0xBA,0xB7,0xB4,0xB1,0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,0x98,0x95,0x92,0x8F,0x8C,0x89
8、,0x85,0x82,0x7F,0x7C,0x79,0x75,0x72,0x6F,0x6C,0x69,0x66,0x62,0x5F,0x5C,0x59,0x56,0x53,0x50,0x4D,0x4A,0x47,0x44,0x42,0x3F,0x3C,0x39,0x37,0x34,0x31,0x2F,0x2D,0x2A,0x28,0x25,0x23,0x21,0x1F,0x1D,0x1B,0x19,0x17,0x15,0x13,0x12,0x10,0x0F,0x0D,0x0C,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x02,0x01,0x01
9、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0C,0x0D,0x0F,0x10,0x12,0x13,0x15,0x17,0x19,0x1B,0x1D,0x1F,0x21,0x23,0x25,0x28,0x2A,0x2C,0x2F,0x31,0x34,0x37,0x39,0x3C,0x3F,0x42,0x44,0x47,0x4A,0x4D,0x50,0x53,0x56,0x59,0x5C,0x5F,0x62,0x66
10、,0x69,0x6C,0x6F,0x72,0x75,0x79,0x7C;/uchar code tri256=1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,
11、151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,253,251,249,247,245,243,241,239,237,235,233,231,229,227,225,223,221,219,217,215,213,211,
12、209,207,205,203,201,199,197,195,193,191,189,187,185,183,181,179,177,175,173,171,169,167,165,163,161,159,157,155,153,151,149,147,145,143,141,139,137,135,133,131,129,127,125,123,121,119,117,115,113,111,109,107,105,103,101,99,97,95,93,91,89,87,85,83,81,79,77,75,73,71,69,67,65,63,61,59,57,55,53,51,49,47
13、,45,43,41,39,37,35,33,31,29,27,25,23,21,19,17,15,13,11,9,7,5,3,1;void delay() /?计数器值为理论值的4倍(即40us 机械周期等同)TH0=0xff; /40usTL0=0xf6;TR0=1;while(!TF0);TF0=0;void mydelay(uchar n) /200us延时uchari,j;for(i=0;in;i+)for(j=0;j6;j+)delay();voiddisplay_zhengxian(uchar x, uchar y) /x zhouqi y fuduuchar n;for(n=0;
14、n250/x;n+)P2=sinn*x/y;void display_fangbo(uchar x, uchary,uchar z)/x 占空比,y,周期,z幅度y=y*5;P2=0xff/z;mydelay(x);P2=0x00/z;mydelay(y-x);voiddisplay_sanjiaobo(uchar x, uchar y)uchar n;x=x*4;for(n=0;ntemp|ZSIGN=temp) ZSIGN=1; else ZSIGN=ZSIGN+1; Z=ZSIGN; else Z=ZSIGN;else Z=ZSIGN;void main() TMOD=0x01;EA=1;ET0=1;while(1)led=0;KEY=key_scan();if(KEY=0)adjust();adjust_zkb();display_fangbo(Z,F,A);if(KEY=1)adjust();display_sanjiaobo(F,A);if(KEY=2)adjust();display_zhengxian(F,A);void timer0() interrupt 1/TF0=0; /TH0=0xff;/TL0=0xf6;/P2=sini+/A;/if(i=100)/i=0;