功能说明:1.该程序可产生三种不同的波形分别是(方波,锯齿波,三角波)
2.分别可以通过三个按键选择对应的波形。
#include #include #include #define uchar unsigned char #define uint unsigned int #define out P0 sbit fbo=P2^0;//选择方波按钮 sbit jcbo=P2^1;//选择锯齿波按钮 sbit sjbo=P2^2;//选择三角波按钮 void anjsm(); void delay(uchar date) { uchar i,k; for (i=date;i>0;i--) for(k=50;k>0;k--); } void fbodate()//方波子程序 { while(1) { out=0x00; delay(5); out=0xff; delay(5); anjsm(); } } void jcbodate()//锯齿波子程序 { uchar h; while(1) { for(h=0;h<255;h++) { out=h; anjsm(); } } } void sjbodate()//三角波子程序 { uchar h; while(1) { for(h=0;h<255;h++) { out=h; anjsm(); } for(h=255;h>0;h--) { out=h; anjsm(); } } } void txbodate()//梯形波子程序 { uchar h; while(1) { for(h=0;h<255;h++) { out=h; anjsm(); } delay(1); for(h=255;h>0;h--) { out=h; anjsm(); delay(1); } } } void anjsm()//键盘扫描子程序 { if(fbo==0)fbodate(); if(jcbo==0)jcbodate(); if(sjbo==0)sjbodate(); if(txbo==0)txbodate(); } void main() {while(1) {anjsm();} }