1、课程设计报告课程设计报告 MorseMorse 电码发声器电码发声器 程序方案: 0-9 和 A-Z 的摩尔斯电码表如下图所示: 将 0-9 和 A-Z 的摩尔斯电码制作为一个 36 行 6 列的二维数组,如下图所示 当输入 0-9 或 A-Z 之间的字符时,程序会根绝具体的字符,从摩尔斯电码表 的二维数组中选出对应该字符的一行数组输出,作为该字符的摩尔斯电码。 用一个字节的二进制数代表一个字符的摩尔斯电码, 左起第一个 1 为起始标 志(起始标志及之前的 0 无效) 。 起始标志后的 0 表示点。 起始标志后的 1 表示划。 如: A 的报文信息 0000 0101 B 的报文信息 0001
2、 1000 C 的报文信息 0001 1010 按此规律建立一个报文信息表,报文信息表要按 09 、AZ 的顺序排列, 发送时先查表找字符对应的报文信息,左移报文信息找起始标志, (起始标志及 之前的 0 不发声) ,然后调用点划子程序发点划声响,发送一个字符循环 8 次则 自动结束。报文信息表同样为一个 36 行 6 列的二维数组,如下图所示: 系统细节方案: 点划间隔子程序是通过调用 window.h库中的 Beep 函数是系统发出声音。 程 序收到字符后,根据字符对应的摩尔斯电码表中的数组,输出该字符的摩尔斯电 码,并且查找到该字符的 01 报文信息表,通过两个循环,调用点划子程序,完
3、成电码的发音功能。 子程序及其流程图: 点声音程序代码: 点声音程序流程图 int dot()/点声音 Beep(7000,200); return 0; 划声音程序代码: 划声音程序流程图 int dash()/划声音 Beep(7000,600); return 0; Beep(7000,200) 点声音 返回 0 值 结束 开始 开始 Beep(7000,600) 划声音 返回 0 值 结束 点划之间间隔程序代码: int space()/电码间隔声音 Beep(0,400); return 0; 主程序详解: 程序设计初期,用C+编写了一个控制台应用,先编写了一个电码编译的子程序: i
4、nt tra(char c)/电码编译 if(c=48 for(i=0;ich; if(ch=c)/输入字符进行编括译 coutc; tra(c);/调用编码函 Sleep(500);/设置读取字符延迟 else if(ch=f)/输入文件路径进行编译 coutfilename; ifstream infile(filename,ios:in); if(!infile) cerrlabel1 = (gcnew System:Windows:Forms:Label(); this-textBox1 = (gcnew System:Windows:Forms:TextBox(); this-lis
5、tBox1 = (gcnew System:Windows:Forms:ListBox(); this-button1 = (gcnew System:Windows:Forms:Button(); this-label3 = (gcnew System:Windows:Forms:Label(); this-label4 = (gcnew System:Windows:Forms:Label(); this-openFileDialog1 = (gcnew System:Windows:Forms:OpenFileDialog(); this-richTextBox1 = (gcnew Sy
6、stem:Windows:Forms:RichTextBox(); this-button3 = (gcnew System:Windows:Forms:Button(); this-label2 = (gcnew System:Windows:Forms:Label(); this-label5 = (gcnew System:Windows:Forms:Label(); this-button4 = (gcnew System:Windows:Forms:Button(); this-button6 = (gcnew System:Windows:Forms:Button(); this-button2 = (gcnew System:Windows:Forms:Button(); this-SuspendLayout(); / / label1 / this