专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
51单片机函数信号发生器
2020-02-05 09:06
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
3933
13
13
小弟刚入门,刚做到51函数信号发生器那里,
我现在已经能仿真出几种波形了,但是我想用按键控制信号的频率,
而且要以精确的1或0.1HZ步进,我不能弄到这么精确,延时不知道怎么弄,高手指点一下啊。多谢了!!!!!
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
12条回答
qqq511153186
1楼-- · 2020-02-05 09:42
回复【楼主位】qqq511153186
-----------------------------------------------------------------------
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit E =P1^2;
sbit cs=P1^3;
sbit wr=P1^4;
sbit keyu=P1^5;
sbit keyd=P1^6;
uchar code table[]="Kind: val: 5VFreq: HZ";
uchar code table1[]="Fan JuSanSin";
uchar code sin[]={
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,0xDF,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 };
void write_com(uchar com);
uchar key=0;
uchar qian,bai,ge,shi,rate=1;
uint Y;
void delayms(uint j)
{
uchar i;
for(;j>0;j--)
for(i=110;i>0;i--);
}
void init()
{
TMOD=0x01;
TH0=(65536-3922/rate)/256;
TL0=(65536-3922/rate)%256;
EA=1;
ET0=1;
TR0=1;
IT0=1;
EX0=1;
cs=0;
wr=0;
write_com(0x0c);
write_com(0x01);
write_com(0x38);
write_com(0x06);
}
void write_com(uchar com)
{
RS=0;
RW=0;
E=0;
P2=com;
delayms(1);
E=1;
delayms(1);
E=0;
}
void write_date(uchar date)
{
RS=1;
RW=0;
E=0;
P2=date;
delayms(1);
E=1;
delayms(1);
E=0;
}
void display()
{ uchar i;
write_com(0x80);
for(i=0;i<16;i++)
write_date(table
);
// write_com(0x80+0x40);
// for(i=16;i<26;i++)
// write_date(table
);
}
void write_f()//显示频率
{
qian=rate/1000;
bai=rate%1000/100;
shi=rate%1000%100/10;
ge=rate%1000%100%10;
write_com(0x80+0x40);//第4格开始显示
write_date(0x30+qian);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void scan()
{
if(keyu==0)
{
delayms(5);
if(keyu==0)
{
while(!keyu);
rate++;
}
}
}
void main(void)
{
uchar j;
init();
display();
while(1)
{ scan();
switch(key)
{
case 3:
{
write_com(0x80+5);
for(j=0;j<3;j++)
write_date(table1[j]);
write_f();
}
break;
case 1:
{
write_com(0x80+5);
for(j=3;j<6;j++)
write_date(table1[j]);
}
break;
case 2:
{
write_com(0x80+5);
for(j=6;j<9;j++)
write_date(table1[j]);
}
break;
case 0:
{
write_com(0x80+5);
for(j=9;j<12;j++)
write_date(table1[j]);
write_f();
}
break;
}
/***************SWITCH结束**************/
}
}
/***************外中断0扫描按键**************/
void key_press()interrupt 0
{
key++;
if(key==4)key=0;
}
void timer() interrupt 1
{
uchar i,dir;
TR0=0;
TH0=(65536-3922/rate)/256;
TL0=(65536-3922/rate)%256;
switch(key)
{
/***************矩形波*******************/
case 3:
{
P0=0XFF;
delayms(2300-Y);
P0=0;
delayms(2300-Y);
}
break;
/***************锯齿波*******************/
case 1:
{
P0=i;
i++;
}
break;
/***************三角波*******************/
case 2:
{
P0=i;
delayms(3000);
if(!dir)i++;else i--;
if(i==255||i==0)dir=!dir;
}
break;
/***************正弦波*******************/
case 0:
{
P0=sin
;
i++;
}
break;
}
TR0=1;
}
加载中...
ourgalaxy
2楼-- · 2020-02-05 13:54
虽然你的工作值得肯定。但你这里面什么都没描述清楚,实在是笔糊涂帐!
加载中...
caoxiang2020
3楼-- · 2020-02-05 18:45
看不懂!!!
加载中...
qqq511153186
4楼-- · 2020-02-05 21:49
精彩回答 2 元偷偷看……
加载中...
qqq511153186
5楼-- · 2020-02-06 02:11
回复【2楼】ourgalaxy
-----------------------------------------------------------------------
是因为没有标注吗?
加载中...
fangshanlong
6楼-- · 2020-02-06 05:09
程序没错 缺电路图 呵呵
加载中...
1
2
下一页
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
东软载波ESF0654 PDS开发板串口USART0代码分享
1 个回答
普通32位单片机使用linux的应用代码
5 个回答
东软载波ESF0654 PDS开发板AT24C04的调试
9 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
-----------------------------------------------------------------------
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^0;
sbit RW=P1^1;
sbit E =P1^2;
sbit cs=P1^3;
sbit wr=P1^4;
sbit keyu=P1^5;
sbit keyd=P1^6;
uchar code table[]="Kind: val: 5VFreq: HZ";
uchar code table1[]="Fan JuSanSin";
uchar code sin[]={
0x80,0x83,0x86,0x89,0x8D,0x90,0x93,0x96,0x99,0x9C,0x9F,
0xA2,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35,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 };
void write_com(uchar com);
uchar key=0;
uchar qian,bai,ge,shi,rate=1;
uint Y;
void delayms(uint j)
{
uchar i;
for(;j>0;j--)
for(i=110;i>0;i--);
}
void init()
{
TMOD=0x01;
TH0=(65536-3922/rate)/256;
TL0=(65536-3922/rate)%256;
EA=1;
ET0=1;
TR0=1;
IT0=1;
EX0=1;
cs=0;
wr=0;
write_com(0x0c);
write_com(0x01);
write_com(0x38);
write_com(0x06);
}
void write_com(uchar com)
{
RS=0;
RW=0;
E=0;
P2=com;
delayms(1);
E=1;
delayms(1);
E=0;
}
void write_date(uchar date)
{
RS=1;
RW=0;
E=0;
P2=date;
delayms(1);
E=1;
delayms(1);
E=0;
}
void display()
{ uchar i;
write_com(0x80);
for(i=0;i<16;i++)
write_date(table);
// write_com(0x80+0x40);
// for(i=16;i<26;i++)
// write_date(table);
}
void write_f()//显示频率
{
qian=rate/1000;
bai=rate%1000/100;
shi=rate%1000%100/10;
ge=rate%1000%100%10;
write_com(0x80+0x40);//第4格开始显示
write_date(0x30+qian);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void scan()
{
if(keyu==0)
{
delayms(5);
if(keyu==0)
{
while(!keyu);
rate++;
}
}
}
void main(void)
{
uchar j;
init();
display();
while(1)
{ scan();
switch(key)
{
case 3:
{
write_com(0x80+5);
for(j=0;j<3;j++)
write_date(table1[j]);
write_f();
}
break;
case 1:
{
write_com(0x80+5);
for(j=3;j<6;j++)
write_date(table1[j]);
}
break;
case 2:
{
write_com(0x80+5);
for(j=6;j<9;j++)
write_date(table1[j]);
}
break;
case 0:
{
write_com(0x80+5);
for(j=9;j<12;j++)
write_date(table1[j]);
write_f();
}
break;
}
/***************SWITCH结束**************/
}
}
/***************外中断0扫描按键**************/
void key_press()interrupt 0
{
key++;
if(key==4)key=0;
}
void timer() interrupt 1
{
uchar i,dir;
TR0=0;
TH0=(65536-3922/rate)/256;
TL0=(65536-3922/rate)%256;
switch(key)
{
/***************矩形波*******************/
case 3:
{
P0=0XFF;
delayms(2300-Y);
P0=0;
delayms(2300-Y);
}
break;
/***************锯齿波*******************/
case 1:
{
P0=i;
i++;
}
break;
/***************三角波*******************/
case 2:
{
P0=i;
delayms(3000);
if(!dir)i++;else i--;
if(i==255||i==0)dir=!dir;
}
break;
/***************正弦波*******************/
case 0:
{
P0=sin;
i++;
}
break;
}
TR0=1;
}
-----------------------------------------------------------------------
是因为没有标注吗?
一周热门 更多>