课程设计报告摩尔斯电码发声器.docx

上传人:b****7 文档编号:9021055 上传时间:2023-02-02 格式:DOCX 页数:30 大小:276.34KB
下载 相关 举报
课程设计报告摩尔斯电码发声器.docx_第1页
第1页 / 共30页
课程设计报告摩尔斯电码发声器.docx_第2页
第2页 / 共30页
课程设计报告摩尔斯电码发声器.docx_第3页
第3页 / 共30页
课程设计报告摩尔斯电码发声器.docx_第4页
第4页 / 共30页
课程设计报告摩尔斯电码发声器.docx_第5页
第5页 / 共30页
点击查看更多>>
下载资源
资源描述

课程设计报告摩尔斯电码发声器.docx

《课程设计报告摩尔斯电码发声器.docx》由会员分享,可在线阅读,更多相关《课程设计报告摩尔斯电码发声器.docx(30页珍藏版)》请在冰豆网上搜索。

课程设计报告摩尔斯电码发声器.docx

课程设计报告摩尔斯电码发声器

课程设计报告

——Morse电码发声器

 

程序方案:

0-9和A-Z的摩尔斯电码表如下图所示:

将0-9和A-Z的摩尔斯电码制作为一个36行6列的二维数组,如下图所示

当输入0-9或A-Z之间的字符时,程序会根绝具体的字符,从摩尔斯电码表的二维数组中选出对应该字符的一行数组输出,作为该字符的摩尔斯电码。

用一个字节的二进制数代表一个字符的摩尔斯电码,左起第一个1为起始标志(起始标志及之前的0无效)。

起始标志后的0表示点。

起始标志后的1表示划。

如:

A的报文信息00000101

B的报文信息00011000

C的报文信息00011010

按此规律建立一个报文信息表,报文信息表要按0—9、A—Z的顺序排列,发送时先查表找字符对应的报文信息,左移报文信息找起始标志,(起始标志及之前的0不发声),然后调用点划子程序发点划声响,发送一个字符循环8次则自动结束。

报文信息表同样为一个36行6列的二维数组,如下图所示:

系统细节方案:

点划间隔子程序是通过调用window.h库中的Beep函数是系统发出声音。

程序收到字符后,根据字符对应的摩尔斯电码表中的数组,输出该字符的摩尔斯电码,并且查找到该字符的01报文信息表,通过两个循环,调用点划子程序,完成电码的发音功能。

子程序及其流程图:

点声音程序代码:

点声音程序流程图

intdot()//点声音

{

Beep(7000,200);

return0;

}

 

划声音程序代码:

划声音程序流程图

intdash()//划声音

{

Beep(7000,600);

return0;

}

点划之间间隔程序代码:

intspace()//电码间隔声音

{

Beep(0,400);

return0;

}

 

主程序详解:

程序设计初期,用C++编写了一个控制台应用,先编写了一个电码编译的子程序:

inttra(charc)//电码编译

{

if(c>=48&&c<=57)

{

cout<

"<

for(i=0;i<8;i++)

{

if(n[c-48][i]==1)

{

j=i+1;

break;

}

}

for(i=j;i<8;i++)

{

if(n[c-48][i]==0)

dot();//调用响铃点函数

if(n[c-48][i]==1)

dash();//调用响铃划函数

space();

}

}

elseif(c>=65&&c<=90)

{

cout<

"<

for(i=0;i<8;i++)

{

if(n[c-65+10][i]==1)

{

j=i+1;

break;

}

}

for(i=j;i<8;i++)

{

if(n[c-65+10][i]==0)

dot();

if(n[c-65+10][i]==1)

dash();

space();

}

}

elseif(c<48||(c>57&&c<65)||c>90)

{

cout<

}

return0;

}

电码编译子程序流程图:

在主程序中利用fstream库中的ifstream文件流又编写了一段可以打开文件的语句,主程序代码如下:

intmain()//主程序

{

while

(1)

{

cout<<"请选择输入字符或者文件路径"<

cin>>ch;

if(ch=='c')//输入字符进行编括译

{

cout<<"请输入0-9或A-Z之间的字符"<

while

(1)

{

cin>>c;

tra(c);//调用编码函

Sleep(500);//设置读取字符延迟

}

}

elseif(ch=='f')//输入文件路径进行编译

{

cout<<"请输入文件路径"<

stringfilename;

cin>>filename;

ifstreaminfile(filename,ios:

:

in);

if(!

infile)

{

cerr<<"打开文件错误"<

}

while(infile.get(c))

{

tra(c);

Sleep(500);//设置读取字符延迟

}

}

else

cout<<"输入格式错误"<

}

}

主程序流程图

编译运行的结果:

程序设计后期在windows窗体应用中创建项目,建立一个窗体,在窗体中完成字符、文件的打开、编译功能,在窗体中添加控件,将之前的程序写入各个控件的动作中,完成程序的功能,程序运行结果如下图:

在textBox1中输入字符,程序将textBox1中的字符存入指向字符数组的指针中,再根绝数组中字符,找到相对应的报文信息进行编译发声。

利用openFileDialog打开文件,利用richTextBox中的LoadFile方法加载文件,再将richTextBox中的字符存入数组指针中,利用指针循环自加对数组指针中的字符进行编译发声。

Morse电码主程序自动生成的cpp:

//morse.cpp:

主项目文件

#include"stdafx.h"

#include"Form1.h"

usingnamespacemorse;

[STAThreadAttribute]

intmain(array

:

String^>^args)

{

//在创建任何控件之前启用WindowsXP可视化效果

Application:

:

EnableVisualStyles();

Application:

:

SetCompatibleTextRenderingDefault(false);

//创建主窗口并运行它

Application:

:

Run(gcnewForm1());

return0;

}

Form1.h库中的源代码:

#pragmaonce

#include

namespacemorse{

usingnamespaceSystem;

usingnamespaceSystem:

:

ComponentModel;

usingnamespaceSystem:

:

Collections;

usingnamespaceSystem:

:

Windows:

:

Forms;

usingnamespaceSystem:

:

Data;

usingnamespaceSystem:

:

Drawing;

usingnamespaceSystem:

:

Runtime:

:

InteropServices;

///

///Form1摘要

///

publicrefclassForm1:

publicSystem:

:

Windows:

:

Forms:

:

Form

{

public:

Form1(void)

{

InitializeComponent();

//

//TODO:

在此处添加构造函数代码

//

}

protected:

///

///清理所有正在使用的资源

///

~Form1()

{

if(components)

{

deletecomponents;

}

}

private:

System:

:

Windows:

:

Forms:

:

Label^label1;

protected:

private:

System:

:

Windows:

:

Forms:

:

TextBox^textBox1;

private:

System:

:

Windows:

:

Forms:

:

ListBox^listBox1;

private:

System:

:

Windows:

:

Forms:

:

Button^button1;

private:

System:

:

Windows:

:

Forms:

:

Label^label3;

private:

System:

:

Windows:

:

Forms:

:

Label^label4;

private:

System:

:

Windows:

:

Forms:

:

OpenFileDialog^openFileDialog1;

private:

System:

:

Windows:

:

Forms:

:

RichTextBox^richTextBox1;

private:

System:

:

Windows:

:

Forms:

:

Button^button3;

private:

System:

:

Windows:

:

Forms:

:

Label^label2;

private:

System:

:

Windows:

:

Forms:

:

Label^label5;

private:

System:

:

Windows:

:

Forms:

:

Button^button4;

private:

System:

:

Windows:

:

Forms:

:

Button^button6;

private:

System:

:

Windows:

:

Forms:

:

Button^button2;

 

private:

///

///必需的设计器变量

///

System:

:

ComponentModel:

:

Container^components;

#pragmaregionWindowsFormDesignergeneratedcode

///

///设计器支持所需的方法不要

///使用代码编辑器修改此方法的内容

///

voidInitializeComponent(void)

{

this->label1=(gcnewSystem:

:

Windows:

:

Forms:

:

Label());

this->textBox1=(gcnewSystem:

:

Windows:

:

Forms:

:

TextBox());

this->listBox1=(gcnewSystem:

:

Windows:

:

Forms:

:

ListBox());

this->button1=(gcnewSystem:

:

Windows:

:

Forms:

:

Button());

this->label3=(gcnewSystem:

:

Windows:

:

Forms:

:

Label());

this->label4=(gcnewSystem:

:

Windows:

:

Forms:

:

Label());

this->openFileDialog1=(gcnewSystem:

:

Windows:

:

Forms:

:

OpenFileDialog());

this->richTextBox1=(gcnewSystem:

:

Windows:

:

Forms:

:

RichTextBox());

this->button3=(gcnewSystem:

:

Windows:

:

Forms:

:

Button());

this->label2=(gcnewSystem:

:

Windows:

:

Forms:

:

Label());

this->label5=(gcnewSystem:

:

Windows:

:

Forms:

:

Label());

this->button4=(gcnewSystem:

:

Windows:

:

Forms:

:

Button());

this->button6=(gcnewSystem:

:

Windows:

:

Forms:

:

Button());

this->button2=(gcnewSystem:

:

Windows:

:

Forms:

:

Button());

this->SuspendLayout();

//

//label1

//

this->label1->AutoSize=true;

this->label1->Location=System:

:

Drawing:

:

Point(51,32);

this->label1->Name=L"label1";

this->label1->Size=System:

:

Drawing:

:

Size(65,12);

this->label1->TabIndex=0;

this->label1->Text=L"请输入字符";

//

//textBox1

//

this->textBox1->Location=System:

:

Drawing:

:

Point(53,49);

this->textBox1->Name=L"textBox1";

this->textBox1->Size=System:

:

Drawing:

:

Size(100,21);

this->textBox1->TabIndex=1;

this->textBox1->KeyDown+=gcnewSystem:

:

Windows:

:

Forms:

:

KeyEventHandler(this,&Form1:

:

textBox1_KeyDown);

//

//listBox1

//

this->listBox1->FormattingEnabled=true;

this->listBox1->ItemHeight=12;

this->listBox1->Location=System:

:

Drawing:

:

Point(315,55);

this->listBox1->Name=L"listBox1";

this->listBox1->Size=System:

:

Drawing:

:

Size(120,184);

this->listBox1->TabIndex=2;

//

//button1

//

this->button1->Location=System:

:

Drawing:

:

Point(67,132);

this->button1->Name=L"button1";

this->button1->Size=System:

:

Drawing:

:

Size(75,23);

this->button1->TabIndex=4;

this->button1->Text=L"发声";

this->button1->UseVisualStyleBackColor=true;

this->button1->MouseClick+=gcnewSystem:

:

Windows:

:

Forms:

:

MouseEventHandler(this,&Form1:

:

button1_MouseClick);

//

//label3

//

this->label3->AutoSize=true;

this->label3->Location=System:

:

Drawing:

:

Point(53,95);

this->label3->Name=L"label3";

this->label3->Size=System:

:

Drawing:

:

Size(89,12);

this->label3->TabIndex=6;

this->label3->Text=L"输入的字符是:

";

//

//label4

//

this->label4->AutoSize=true;

this->label4->Location=System:

:

Drawing:

:

Point(138,95);

this->label4->Name=L"label4";

this->label4->Size=System:

:

Drawing:

:

Size(0,12);

this->label4->TabIndex=7;

//

//openFileDialog1

//

this->openFileDialog1->FileName=L"openFileDialog1";

//

//richTextBox1

//

this->richTextBox1->Location=System:

:

Drawing:

:

Point(12,256);

this->richTextBox1->Name=L"richTextBox1";

this->richTextBox1->Size=System:

:

Drawing:

:

Size(213,132);

this->richTextBox1->TabIndex=8;

this->richTextBox1->Text=L"";

//

//button3

//

this->button3->Location=System:

:

Drawing:

:

Point(315,256);

this->button3->Name=L"button3";

this->button3->Size=System:

:

Drawing:

:

Size(74,25);

this->button3->TabIndex=9;

this->button3->Text=L"打开文件";

this->button3->UseVisualStyleBackColor=true;

this->button3->Click+=gcnewSystem:

:

EventHandler(this,&Form1:

:

button3_Click);

//

//label2

//

this->label2->AutoSize=true;

this->label2->Location=System:

:

Drawing:

:

Point(313,32);

this->label2->Name=L"label2";

this->label2->Size=System:

:

Drawing:

:

Size(29,12);

this->label2->TabIndex=11;

this->label2->Text=L"编码";

//

//label5

//

this->label5->AutoSize=true;

this->label5->Location=System:

:

Drawing:

:

Point(55,238);

this->label5->Name=L"label5";

this->label5->Size=System:

:

Drawing:

:

Size(0,12);

this->label5->TabIndex=12;

//

//button4

//

this->button4->Location=System:

:

Drawing:

:

Point(315,312);

this->button4->Name=L"button4";

this->button4->Size=System:

:

Drawing:

:

Size(75,23);

this->button4->TabIndex=13;

this->button4->Text=L"编码";

this->button4->UseVisualStyleBackColor=true;

this->button4->Click+=gcnewSystem:

:

EventHandler(this,&Form1:

:

button4_Click);

//

//button6

//

this->button6->Location=System:

:

Drawing:

:

Point(315,364);

this->button6->Name=L"button6";

this->button6->Size=System:

:

Drawing:

:

Size(75,23);

this->button6->TabIndex=15;

this->button6->Text=L"发声";

this->button6->UseVisualStyleBackColor=true;

this->button6->Click+=gcnewSystem:

:

EventHandler(this,&Form1:

:

button6_Click);

//

//button2

//

this->button2->Location=System:

:

Drawing:

:

Point(453,55);

this->button2->Name=L"button2";

this->button2->Size=System:

:

Drawing:

:

Size(75,23);

this->button2->TabIndex=16;

this->button2->Text=L"清空";

this->button2->UseVisualStyleBackColor=true;

this->button2->Click+=gcnewSystem:

:

EventHandler(this,&Form1:

:

button2_Click);

//

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1