功能要求:
1.本設(shè)計(jì)基于STC89C51/52(與AT89S51/52、AT89C51/52通用,可任選)單片機(jī)。
2.LCD1602液晶顯示波形種類和頻率值(10-100HZ)。
3.按鍵設(shè)置波形種類和設(shè)定頻率步進(jìn)值。
4.電位器器改變振幅(0V-3.5V穩(wěn)定)。
5.本設(shè)計(jì)可產(chǎn)生正弦波、鋸齒波、三角波、矩形波。
6.有四個(gè)指示燈分別指示發(fā)出的是哪種波形,方便明了。
uchar code juchi[64]={
0,4,8,12,16,20,24,28,32,36,40,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,130,134,138,142,
146,150,154,158,162,166,170,174,178,182,186,190,194,198,202,206,210,215,219,223,227,231,235,239,243,247,251,255
}; //鋸齒波取碼
void delay(uint xms) //延時(shí)函數(shù)
{
int a,b;
for(a=xms;a>0;a--)
for(b=110;b>0;b--);
}
void write_com(uchar com) //寫命令函數(shù)
{
lcdrs=0;
P0=com;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
void write_date(uchar date) //寫數(shù)據(jù)函數(shù)
{
lcdrs=1;
P0=date;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
//自定義字符集
void Lcd_ram()
{
uint i,j,k=0,temp=0x40;
for(i=0;i<7;i++)
{
for(j=0;j<8;j++)
{
write_com(temp+j);
write_date(zifu[k]);
k++;
}
temp=temp+8;
}
}
void init_lcd() //初始化函數(shù)
{
uchar i;
lcden=0; //默認(rèn)開(kāi)始狀態(tài)為關(guān)使能端,見(jiàn)時(shí)序圖
Lcd_ram();
write_com(0x0f);
write_com(0x38); //顯示模式設(shè)置,默認(rèn)為0x38,不用變。
write_com(0x01); //顯示清屏,將上次的內(nèi)容清除,默認(rèn)為0x01.
write_com(0x0c); //顯示功能設(shè)置0x0f為開(kāi)顯示,顯示光標(biāo),光標(biāo)閃爍;0x0c為開(kāi)顯示,不顯光標(biāo),光標(biāo)不閃
write_com(0x06); //設(shè)置光標(biāo)狀態(tài)默認(rèn)0x06,為讀一個(gè)字符光標(biāo)加1.
write_com(0x80); //設(shè)置初始化數(shù)據(jù)指針,是在讀指令的操作里進(jìn)行的
for(i=10;i<20;i++) //顯示初始化
{
write_date(table1[i]);
}
write_com(0x80+0x40);
for(i=0;i<9;i++)
{
write_date(table1[i]);
}
write_com(0x80+10);
write_date(0);
write_date(1);
write_date(0);
write_date(1);
write_date(0);
write_date(1);
write_com(0x80+0x40+0x09);
write_date(' ');
write_date('1');
write_date('0');
write_date('.');
write_date('0');
write_date('H');
write_date('z');
}
void initclock() //時(shí)鐘初始化
{
TMOD=0x01;
TH0=a;
TL0=b;
EA=1;
ET0=1;
TR0=1;
}
void display() //顯示函數(shù)
{
uchar qian,bai,shi,ge;
qian=pinlv/1000;
bai=pinlv%1000/100;
shi=pinlv%1000%100/10;
ge=pinlv%1000%100%10;
write_com(0x80+0x40+0x09);
if(qian==0)
write_date(' ');
else
write_date(table[qian]);
if(qian==0&&bai==0)
write_date(' ');
else
write_date(table[bai]);
write_date(table[shi]);
write_date('.');
write_date(table[ge]);
write_date('H');
write_date('z');
if(boxing==0)
{
write_com(0x80+10);
write_date(0);
write_date(1);
write_date(0);
write_date(1);
write_date(0);
write_date(1);
led3=1;
led0=0;
}
if(boxing==1)
{
write_com(0x80+10);
write_date(2);
write_date(3);
write_date(2);
write_date(3);
write_date(2);
write_date(3);
led0=1;
led1=0;
}
if(boxing==2)
{
write_com(0x80+10);
write_date(4);
write_date(5);
write_date(4);
write_date(5);
write_date(4);
write_date(5);
led1=1;
led2=0;
}
if(boxing==3)
{
write_com(0x80+10);
write_date(6);
write_date(6);
write_date(6);
write_date(6);
write_date(6);