這個信號發生器可以產生多種波形,可以調頻、調幅,功能很強大.用按鍵切換波形.
0.png (30.25 KB, 下載次數: 130)
下載附件
2016-9-9 00:45 上傳
0.png (77.3 KB, 下載次數: 116)
下載附件
2016-9-9 00:45 上傳
仿真及源碼下載:
信號發生器.rar
(73.64 KB, 下載次數: 173)
2016-9-9 00:47 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
信號發生器源程序:
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit WR1 = P2^4;
- sbit CS = P2^5;
- #define DA0832 P1
- sbit VPP=P3^4;
- sbit RS = P2^0;
- sbit RW = P2^1;
- sbit E = P2^2;
- uchar c=0,tl,th,t;
- bit wave_change=0,is_stop=0;
- uint code T_WAVE_INIT_code[]={1,5,6,7,8,10,13,17,25,50,500,
- 526,556,588,625,667,714,769,833,909,1000,1111,1250,1429,1667,2000,2500,3333,5000};
- uint code f_code[]={1,100,80,70,60,50,40,30,20,10,1,
- 950,900,850,800,750,700,650,600,550,500,450,400,350,300,250,200,150,100};
- uchar code tosin[256]={0x80,0x83,0x86,0x89,0x8d,0x90,0x93,0x96,0x99,0x9c,0x9f,0xa2,0xa5,0xa8,0xab,0xae,0xb1,0xb4,0xb7,0xba,
- 0xbc,0xbf,0xc2,0xc5 ,0xc7,0xca,0xcc,0xcf,0xd1,0xd4,0xd6,0xd8,0xda,0xdd,0xdf,0xe1,0xe3,0xe5,0xe7,0xe9,0xea,0xec,0xee,0xef,
- 0xf1,0xf2,0xf4,0xf5 ,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
- 0xff,0xff,0xfe,0xfd ,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf2,0xf1,0xef,0xee,0xec,0xea,0xe9,0xe7,0xe5,0xe3,
- 0xe1,0xde,0xdd,0xda ,0xd8,0xd6,0xd4,0xd1,0xcf,0xcc,0xca,0xc7,0xc5,0xc2,0xbf,0xbc,0xba,0xb7,0xb4,0xb1,0xae,0xab,0xa8,0xa5,
- 0xa2,0x9f,0x9c,0x99 ,0x96,0x93,0x90,0x8d,0x89,0x86,0x83,0x80,0x80,0x7c,0x79,0x76,0x72,0x6f,0x6c,0x69,0x66,0x63,0x60,0x5d,
- 0x5a,0x57,0x55,0x51 ,0x4e,0x4c,0x48,0x45,0x43,0x40,0x3d,0x3a,0x38,0x35,0x33,0x30,0x2e,0x2b,0x29,0x27,0x25,0x22,0x20,0x1e,
- 0x1c,0x1a,0x18,0x16 ,0x15,0x13,0x11,0x10,0x0e,0x0d,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x02,0x01,0x00,0x00,
- 0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02 ,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0d,0x0e,
- 0x10,0x11,0x13,0x15 ,0x16,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x25,0x27,0x29,0x2b,0x2e,0x30,0x33,0x35,0x38,0x3a,0x3d,0x40,0x43,
- 0x45,0x48,0x4c,0x4e ,0x51,0x55,0x57,0x5a,0x5d,0x60,0x63,0x66 ,0x69,0x6c,0x6f,0x72,0x76,0x79,0x7c,0x80};
- char T_WAVE_INIT_code_num=28;
- uint temp;
- uint T_WAVE_INIT,H_count,T_count;
- bit is_L_H=0;
- uchar VPP_num=10,real_VPP_num=0xff;
- uchar Display_Buffer[2][16] ={
- {"square Vpp=5.0V"},
- {"010KHz step=50Hz"}
- };
- #include"1602.c"
- //函數聲明
- void Refesh_Disp_Buffer();// 刷新顯示緩沖
- //--------------------------------------------------------------
- // 主程序
- //-----------------------------------------------------------------
- void main()
- {
- uchar VPP_num_temp;
- CS=0;
- WR1=0;
- T_WAVE_INIT=T_WAVE_INIT_code[T_WAVE_INIT_code_num];
- th=(65536-T_WAVE_INIT)/256;
- tl=(65536-T_WAVE_INIT)%256;
- temp=f_code[T_WAVE_INIT_code_num];
- TMOD=0X11;
- TH0=th;
- TL0=tl;
- ET0=1;
- TR0=0;
- TH1=th;
- TL1=tl;
- ET1=1;
- TR1=0;
- EX0=1;
- IT0=1;
- EX1=1;
- IT1=1;
- PX1=1;
- EA=1;
- Initialize_LCD1602();//液晶初始化函數
- LCD_Write_Command(0x80);
- LCD_Display(Display_Buffer[0]);
- LCD_Write_Command(0xC0);
- LCD_Display(Display_Buffer[1]);
- TR0=1;
- while(1)
- {
-
- Refesh_Disp_Buffer();
- if(VPP==0)
- {
- DelayMS(5);
- if(VPP==0) //調節并顯示頻率的幅度
- {
-
- VPP_num--;
- if(VPP_num==0)VPP_num=10;
- VPP_num_temp=VPP_num*5;
- LCD_Write_Command(0x80+12);
- Write_LCD_Data(VPP_num_temp/10+'0');
- Write_LCD_Data('.');
- Write_LCD_Data(VPP_num_temp%10+'0');
- real_VPP_num=255.0/10*VPP_num;
- while(!VPP);
- }
- }
- }
- }
- //--------------------------------------------------------------------------
- // 刷新顯示緩沖
- //-------------------------------------------------------------------------
- void Refesh_Disp_Buffer()
- {
- //temp; //temp表示需顯示的頻率值
- Display_Buffer[1][0] = temp/100+'0'; //整數位 頻率
- Display_Buffer[1][1] = temp/10%10+'0'; //整數位
- Display_Buffer[1][2] = temp%10+'0'; //兩個小數位
- if(T_WAVE_INIT_code_num<11) //顯示頻率1K---100K T_WAVE_INIT:500-5
- {
- Display_Buffer[1][3] = 'K';
- LCD_Write_Command(0xC0+12); //顯示步進值 高頻
- Write_LCD_Data('1');
- Write_LCD_Data('0');
- Write_LCD_Data('K');
- Write_LCD_Data('H');
- }
- else
- {
- Display_Buffer[1][3] = ' ';
- LCD_Write_Command(0xC0+12); //顯示步進值 低頻
- Write_LCD_Data('5');
- Write_LCD_Data('0');
- Write_LCD_Data('H');
- Write_LCD_Data('z');
- }
- LCD_Write_Command(0xC0); //顯示當前頻率值
- Write_LCD_Data(Display_Buffer[1][0]);
- Write_LCD_Data(Display_Buffer[1][1]);
- Write_LCD_Data(Display_Buffer[1][2]);
- Write_LCD_Data(Display_Buffer[1][3]);
- if(wave_change==0)
- {
- LCD_Write_Command(0x80);
- Write_LCD_Data('s');
- Write_LCD_Data('q');
- Write_LCD_Data('u');
- Write_LCD_Data('a');
- Write_LCD_Data('r');
- Write_LCD_Data('e');
- Write_LCD_Data(' ');
- }
- else
- {
- LCD_Write_Command(0x80);
- Write_LCD_Data('s');
- Write_LCD_Data('i');
- Write_LCD_Data('n');
- Write_LCD_Data('w');
- Write_LCD_Data('a');
- Write_LCD_Data('v');
- Write_LCD_Data('e');
- }
- if(wave_change==1&&is_stop==1){TR1=1;is_stop=0;}
- if(wave_change==0&&is_stop==1){TR0=1;is_stop=0;}
- }
- //-------------------------------------------------
- void INT0_int(void) interrupt 0 //中斷服務程序 波形切換
- {
- wave_change=!wave_change;
- if(wave_change)
- {
- TR0=0;
- TR1=1;
- }
- else
- {
- TR1=0;
- TR0=1; //輸出方波形
- }
- }
- void INT1_int(void) interrupt 2 //按鍵中斷服務程序 調頻
- {
- if(wave_change) {TR1=0;is_stop=1;}
- else {TR0=0;is_stop=1;}
- T_WAVE_INIT_code_num=T_WAVE_INIT_code_num-1; //i增加,于是f減少
- if(T_WAVE_INIT_code_num==0)T_WAVE_INIT_code_num=28;
- T_WAVE_INIT=T_WAVE_INIT_code[T_WAVE_INIT_code_num];
- th=(65536-T_WAVE_INIT)/256;
- tl=(65536-T_WAVE_INIT)%256;
- temp=f_code[T_WAVE_INIT_code_num];
- }
- void time0_int(void) interrupt 1 //中斷服務程序 輸出方波形
- {
- static bit d;
-
- TH0=th;
- TL0=tl;
- d=~d;
- if(d)
- DA0832=0x00;
- else
- DA0832=real_VPP_num;
- }
- void time1_int(void) interrupt 3 //中斷服務程序 輸出正弦波形
- {
- static uchar b=0;
- TH0=th;
- TL0=tl;
- DA0832=tosin[b]/10*VPP_num; ; //正弦波
- b+=8;
- }
復制代碼
|