|
任務(wù)名稱:基于單片機(jī)的固定頻率、占空比的方波發(fā)生器。
功能要求:產(chǎn)生固定頻率和占空比的方波電壓。
硬件要求:單片機(jī)芯片采用AT89C51,D/A轉(zhuǎn)換器采用DAC0832,顯示器使用LCD1602,運(yùn)放使用LM324。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
固定頻率占空比的信號(hào)發(fā)生器.png (235.57 KB, 下載次數(shù): 32)
下載附件
信號(hào)發(fā)生器
2023-1-28 19:28 上傳
單片機(jī)源程序如下:
- #include "reg52.h"
- #include "intrins.h"
- #include "absacc.h"
- #define DAC0832 XBYTE[0x7fff]
- #define LCD_DATA P1
- unsigned char LcdBuf[2][16]={{"Square F: 100Hz"},{"Duty Cycle:50%"}};
- unsigned int Fr=100,D=50;
- unsigned int low,high;
- sbit LCD_RS = P2^0;
- sbit LCD_RW = P2^1;
- sbit LCD_E = P2^2;
- void dellay(unsigned int h)
- {
- while(h--); //0.01MS
- }
- void WriteDataLcd(unsigned char wdata)
- {
- LCD_DATA=wdata;
- LCD_RS=1;
- LCD_RW=0;
- LCD_E=0;
- dellay(1000);
- LCD_E=1;
- }
- void WriteCommandLcd(unsigned char wdata)
- {
- LCD_DATA=wdata;
- LCD_RS=0;
- LCD_RW=0;
- LCD_E=0;
- dellay(1000);
- LCD_E=1;
- }
- void lcd_init(void)
- {
- LCD_DATA=0;
- WriteCommandLcd(0x38);
- dellay(1000);
- WriteCommandLcd(0x38);
- dellay(1000);
- WriteCommandLcd(0x01);
- WriteCommandLcd(0x0c);
- }
- void display_xy(unsigned char x,unsigned char y)
- {
- if(y==1)
- x+=0x40;
- x+=0x80;
- WriteCommandLcd(x);
- }
- void display_string(unsigned char x,unsigned char y,unsigned char *s)
- {
- display_xy(x,y);
- while(*s)
- {
- WriteDataLcd(*s);
- s++;
- }
- }
- void delayhus(unsigned int hus)
- {
- unsigned int i,j;
- for(i=hus;i>0;i--)
- for(j=11;j>0;j--);
- }
復(fù)制代碼
51hei.png (12.06 KB, 下載次數(shù): 34)
下載附件
2023-1-29 00:29 上傳
Keil代碼與Proteus8.13 Proteus7.5版本的仿真下載:(按鍵調(diào)節(jié)功能暫未加入,大家可以在此基礎(chǔ)上改進(jìn))
固定頻率、占空比方波發(fā)生器.rar
(100.27 KB, 下載次數(shù): 32)
2023-1-28 19:31 上傳
點(diǎn)擊文件名下載附件
仿真代碼 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|