《波形发生器代码有显示.doc》由会员分享,可在线阅读,更多相关《波形发生器代码有显示.doc(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include #define uchar unsigned char#define uint unsigned int/*/ / 12864显示定义/*/ #include /定义绝对地址访问#include #include #include sbit RS=P23;sbit WRD=P21;sbit E=P22;sbit PSB=P24;sbit RES=P25;void TransferData(char data1,bit DI);void delayms(unsigned int n);void delay(unsigned int m);void lcd_mesg003(uns
2、igned char code *addr1);unsigned char code IC_DAT1=输出波形:方波;unsigned char code IC_DAT=输出波形:正弦波 频率;unsigned char code IC_DAT2=输出波形:三角波 频率;unsigned char code IC_DAT3=输出波形:锯齿波 频率;void initinal(void)delay(40);PSB=1; /并口工作模式delay(1);RES=0; /复位delay(1);RES=1; /复位置高delay(10);TransferData(0x30,0);delay(100);
3、TransferData(0x30,0);delay(37);TransferData(0x08,0);delay(100);TransferData(0x10,0);delay(100);TransferData(0x0C,0);delay(100);TransferData(0x01,0);delay(10);TransferData(0x06,0);delay(100);/*lcd显示部分*/void lcd_mesg003(unsigned char code *addr1)unsigned char i;/第一行TransferData(0x80,0); delay(100); fo
4、r(i=0;i16;i+) TransferData(*addr1,1); addr1+; /delayms(50); void TransferData(char data1,bit DI) /传送数据或是命令,当DI=0时,传送命令,当DI=1时,传送数据WRD=0;RS=DI;delay(1);P0=data1;E=1;delay(1);E=0;void delayms(unsigned int n)unsigned int i,j;for(i=0;in;i+) for(j=0;j2000;j+);void delay(unsigned int m)unsigned int i,j;fo
5、r(i=0;im;i+)for(j=0;j=5)flag=1; else if(flag_sub = 0) flag -= 1;lcd_mesg003(IC_DAT1); if(flag=20)time_control=20; else if(fm_sub = 0) time_control -= 1; if(time_control =256) num =0; break; case 2: /方波 switch(time_control) case 1:fbt=300;break; /5mscase 2:fbt=280;break; /2.5mcase 3:fbt=260;break; /1
6、.3mcase 4:fbt=240;break; /0.12 case 5:fbt=220;break; /5mscase 6:fbt=200;break; /2.5mcase 7:fbt=180;break; /1.3mcase 8:fbt=160;break; /0.12 case 9:fbt=140;break; /5mscase 10:fbt=120;break; /2.5mcase 11:fbt=100;break; /1.3mcase 12:fbt=80;break; /0.12 case 13:fbt=60;break; /5mscase 14:fbt=40;break; /2.
7、5mcase 15:fbt=30;break; /1.3mcase 16:fbt=20;break; /0.12 case 17:fbt=15;break; /5mscase 18:fbt=12;break; /2.5mcase 19:fbt=8;break; /1.3mcase 20:fbt=6;break; /0.12if(f = 0)f = 1;P1 = 0x01;pdelay(fbt);elsef = 0;P1 = 0xff;pdelay(fbt);break; case 3: /锯齿 if( jct =sjt) f=1; sanjiao+=time_control; P1 = sanjiao; else sanjiao-=time_control; P1 = sanjiao; if(sanjiao=6) sanjiao=0x06; f=0; break; /END/LCD测试函数/*void main(void) initinal();/调用LCD字库初始化程序 IT0 = 1; IE = 0x83; while(1)lcd_mesg003(IC_DAT); /initinal();/调用LCD字库初始化程序 / delay(100); /lcd_mesg003(IC_DAT); */