信号发生器程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
while(!s2);
pinlv-=bujin;
if(pinlv<10)
{
pinlv=10;
}
display();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
EA=1;
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
EA=0;
while(!s3);
boxing++;
sbitlcdrs=P2^3;//液晶控制位
sbitlcdrw=P2^4;
sbitlcden=P2^5;
charnum,boxing,u;//定义全局变量
intpinlv=100,bujin=1,bujin1=1;
ucharcode table[]="0123456789";//定义显示的数组
ucharcode table1[]="frequence:boxing:";
delay(1);
write_date(table[shi]);
delay(1);
write_date('.');
delay(1);
write_date(table[ge]);
delay(1);
}
voidbujinjiance()
{
if(s4==0)
{
delay(5);
if(s4==0)
{
while(!s4);
write_date('');
write_date('');
write_com(0x80+0x40+0xa);
//write_date('');
write_date('1');
write_date('0');
write_date('H');
delay(5);
write_date('Z');
deபைடு நூலகம்ay(5);
write_com(0x01);//显示清屏,将上次的内容清除,默认为0x01.
write_com(0x0c);//显示功能设置0x0f为开显示,显示光标,光标闪烁;0x0c为开显示,不显光标,光标不闪
write_com(0x06);//设置光标状态默认0x06,为读一个字符光标加1.
write_com(0x80);//设置初始化数据指针,是在读指令的操作里进行的
248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0
};//三角波取码
ucharcodejuchi[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,
write_date('');
}
if(boxing==1)
{
write_com(0x80+7);
write_date('j');
write_date('u');
write_date('x');
write_date('i');
write_date('n');
write_date('g');
}
if(boxing==2)
}
voidinitclock()//时钟初始化
{
uinti;
TMOD=0x01;
TH0=a;
TL0=b;
EA=1;
ET0=1;
TR0=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
{
write_date(table1[i]);
delay(5);
}
write_com(0x80);
h++;
if(h==1)
{
write_com(0x01);
write_com(0x80);
write_date('b');delay(1);
write_date('u');delay(1);
write_date('j');delay(1);
write_date('i');delay(1);
write_date('n');delay(1);
for(a=xms;a>0;a--)
for(b=110;b>0;b--);
}
voidwrite_com(ucharcom)//写命令函数
{
lcdrs=0;
lcdrw=0;
lcden=0;
P0=com;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
voidwrite_date(uchardate)//写数据函数
write_date('Z');
delay(5);
if(boxing==0)
{
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date('');
write_date('');
write_date('');
for(i=10;i<17;i++)//显示初始化
{
write_date(table1[i]);
delay(5);
}
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date('');
write_date('');
{
lcdrs=1;
lcdrw=0;
lcden=0;
P0=date;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
voidinit_lcd()//初始化函数
{
//lcden=0;//默认开始状态为关使能端,见时序图
write_com(0x0f);
write_com(0x38);//显示模式设置,默认为0x38,不用变。
write_date('j');
write_date('u');
write_date('c');
write_date('h');
write_date('i');
write_date('');
write_date('');
}
}
voidkeyscan()//键盘检测函数
{
if(s1==0)
{
EA=0;
delay(2);
{
write_com(0x80+7);
write_date('s');
write_date('a');
write_date('n');
write_date('j');
write_date('i');
write_date('a');
write_date('o');
}
if(boxing==3)
{
write_com(0x80+7);
if(s1==0)
{
while(!s1);
pinlv+=bujin;
if(pinlv>1000)
{
pinlv=1000;
}
display();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
EA=1;
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
EA=0;
if(boxing==4)
{
boxing=0;
}
display();
EA=1;
}
}
}
voidbujindisplay()
{
uintbai,shi,ge;
bai=bujin1/100;
shi=bujin1%100/10;
ge=bujin1%100%10;
write_com(0x80+6);
write_date(table[bai]);
delay(5);
write_date(table[bai]);
delay(5);
write_date(table[shi]);
delay(5);
write_date('.');
delay(5);
write_date(table[ge]);
delay(5);
write_date('H');
delay(5);
255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};//矩形波取码
ucharcodesanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,
unsigned longintm;
inta,b,h,num1;
ucharcode sin[64]={
135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,
#include<reg52.h>//包含头文件
#include<intrins.h>
#defineucharunsigned char//宏定义
#defineuintunsignedint
sbits1=P3^4;//定义按键的接口
sbits2=P3^5;
sbits3=P3^6;
sbits4=P3^7;
}
}
}
}
void main()//主函数
{
init_lcd();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
initclock();
while(1)
{
if(h==0)
{
keyscan();
display();
}
bujinjiance();
}
}
void T0_time()interrupt 1//定时器
146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128
};//正弦波取码
ucharcodejuxing[64]={
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
{
while(!s1);
bujin1++;
if(bujin1==101)
{
bujin1=100;
}
bujindisplay();
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
bujin1--;
if(bujin1==0)
{
bujin1=1;
}
bujindisplay();
}
void display()//显示函数
{
ucharqian,bai,shi,ge;
qian=pinlv/1000;
bai=pinlv%1000/100;
shi=pinlv%1000%100/10;
ge=pinlv%1000%100%10;
write_com(0x80+0x40+0x08);
write_date(table[qian]);
write_date(':');delay(1);
bujin1=bujin;
bujindisplay();
}
if(h==2)
{
h=0;
bujin=bujin1;
init_lcd();
initclock();
display();
}
}
}
if(h==1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
TH0=a;
TL0=b;
if(boxing==0)
{
P1=sin[u];
}
if(boxing==1)
{
P1=juxing[u];
}
if(boxing==2)
{
P1=sanjiao[u];
}
if(boxing==3)
{
P1=juchi[u];
}
u++;
if(u==64)
{
u=0;
}
}
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(uintxms)//延时函数
{
inta,b;
pinlv-=bujin;
if(pinlv<10)
{
pinlv=10;
}
display();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
EA=1;
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
EA=0;
while(!s3);
boxing++;
sbitlcdrs=P2^3;//液晶控制位
sbitlcdrw=P2^4;
sbitlcden=P2^5;
charnum,boxing,u;//定义全局变量
intpinlv=100,bujin=1,bujin1=1;
ucharcode table[]="0123456789";//定义显示的数组
ucharcode table1[]="frequence:boxing:";
delay(1);
write_date(table[shi]);
delay(1);
write_date('.');
delay(1);
write_date(table[ge]);
delay(1);
}
voidbujinjiance()
{
if(s4==0)
{
delay(5);
if(s4==0)
{
while(!s4);
write_date('');
write_date('');
write_com(0x80+0x40+0xa);
//write_date('');
write_date('1');
write_date('0');
write_date('H');
delay(5);
write_date('Z');
deபைடு நூலகம்ay(5);
write_com(0x01);//显示清屏,将上次的内容清除,默认为0x01.
write_com(0x0c);//显示功能设置0x0f为开显示,显示光标,光标闪烁;0x0c为开显示,不显光标,光标不闪
write_com(0x06);//设置光标状态默认0x06,为读一个字符光标加1.
write_com(0x80);//设置初始化数据指针,是在读指令的操作里进行的
248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0
};//三角波取码
ucharcodejuchi[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,
write_date('');
}
if(boxing==1)
{
write_com(0x80+7);
write_date('j');
write_date('u');
write_date('x');
write_date('i');
write_date('n');
write_date('g');
}
if(boxing==2)
}
voidinitclock()//时钟初始化
{
uinti;
TMOD=0x01;
TH0=a;
TL0=b;
EA=1;
ET0=1;
TR0=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
{
write_date(table1[i]);
delay(5);
}
write_com(0x80);
h++;
if(h==1)
{
write_com(0x01);
write_com(0x80);
write_date('b');delay(1);
write_date('u');delay(1);
write_date('j');delay(1);
write_date('i');delay(1);
write_date('n');delay(1);
for(a=xms;a>0;a--)
for(b=110;b>0;b--);
}
voidwrite_com(ucharcom)//写命令函数
{
lcdrs=0;
lcdrw=0;
lcden=0;
P0=com;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
voidwrite_date(uchardate)//写数据函数
write_date('Z');
delay(5);
if(boxing==0)
{
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date('');
write_date('');
write_date('');
for(i=10;i<17;i++)//显示初始化
{
write_date(table1[i]);
delay(5);
}
write_com(0x80+7);
write_date('s');
write_date('i');
write_date('n');
write_date('');
write_date('');
{
lcdrs=1;
lcdrw=0;
lcden=0;
P0=date;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
voidinit_lcd()//初始化函数
{
//lcden=0;//默认开始状态为关使能端,见时序图
write_com(0x0f);
write_com(0x38);//显示模式设置,默认为0x38,不用变。
write_date('j');
write_date('u');
write_date('c');
write_date('h');
write_date('i');
write_date('');
write_date('');
}
}
voidkeyscan()//键盘检测函数
{
if(s1==0)
{
EA=0;
delay(2);
{
write_com(0x80+7);
write_date('s');
write_date('a');
write_date('n');
write_date('j');
write_date('i');
write_date('a');
write_date('o');
}
if(boxing==3)
{
write_com(0x80+7);
if(s1==0)
{
while(!s1);
pinlv+=bujin;
if(pinlv>1000)
{
pinlv=1000;
}
display();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
EA=1;
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
EA=0;
if(boxing==4)
{
boxing=0;
}
display();
EA=1;
}
}
}
voidbujindisplay()
{
uintbai,shi,ge;
bai=bujin1/100;
shi=bujin1%100/10;
ge=bujin1%100%10;
write_com(0x80+6);
write_date(table[bai]);
delay(5);
write_date(table[bai]);
delay(5);
write_date(table[shi]);
delay(5);
write_date('.');
delay(5);
write_date(table[ge]);
delay(5);
write_date('H');
delay(5);
255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};//矩形波取码
ucharcodesanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,
unsigned longintm;
inta,b,h,num1;
ucharcode sin[64]={
135,145,158,167,176,188,199,209,218,226,234,240,245,249,252,254,254,253,251,247,243,237,230,222,213,204,193,182,170,158,
#include<reg52.h>//包含头文件
#include<intrins.h>
#defineucharunsigned char//宏定义
#defineuintunsignedint
sbits1=P3^4;//定义按键的接口
sbits2=P3^5;
sbits3=P3^6;
sbits4=P3^7;
}
}
}
}
void main()//主函数
{
init_lcd();
m=65534-(156250/pinlv);
a=m/256;
b=m%256;
initclock();
while(1)
{
if(h==0)
{
keyscan();
display();
}
bujinjiance();
}
}
void T0_time()interrupt 1//定时器
146,133,121,108,96,84,72,61,50,41,32,24,17,11,7,3,1,0,0,2,5,9,14,20,28,36,45,55,66,78,90,102,114,128
};//正弦波取码
ucharcodejuxing[64]={
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
{
while(!s1);
bujin1++;
if(bujin1==101)
{
bujin1=100;
}
bujindisplay();
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
bujin1--;
if(bujin1==0)
{
bujin1=1;
}
bujindisplay();
}
void display()//显示函数
{
ucharqian,bai,shi,ge;
qian=pinlv/1000;
bai=pinlv%1000/100;
shi=pinlv%1000%100/10;
ge=pinlv%1000%100%10;
write_com(0x80+0x40+0x08);
write_date(table[qian]);
write_date(':');delay(1);
bujin1=bujin;
bujindisplay();
}
if(h==2)
{
h=0;
bujin=bujin1;
init_lcd();
initclock();
display();
}
}
}
if(h==1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
TH0=a;
TL0=b;
if(boxing==0)
{
P1=sin[u];
}
if(boxing==1)
{
P1=juxing[u];
}
if(boxing==2)
{
P1=sanjiao[u];
}
if(boxing==3)
{
P1=juchi[u];
}
u++;
if(u==64)
{
u=0;
}
}
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(uintxms)//延时函数
{
inta,b;