

免费预览已结束,剩余29页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机科学与工程学院课程设计报告题目全称: 用高级语言vc+仿真键盘工作过程(软件扫描键盘) 课程名称: 计算机组成原理 ;任课教师: 指导老师: 职称: 副教授 序号学生姓名学号班号成绩12345678910(注:学生姓名填写按学生对该课程设计的贡献及工作量由高到底排列,分数按排名依次递减。序号排位为“1”的学生成绩最高,排位为“10”的学生成绩最低。)指导老师评语: 签字: 一、课程设计的目的与要求本课程设计是在完成了计算机组成原理的教学后进行的,目的在于让学生在掌握了计算机组成原理的基本理论之后,在实验室里老师指导下,自己动手,做出一个简单模拟键盘输入仿真其响应的软件,并运行此段程序,且显示该段程序运行后其结果的正、误,分析其原因。通过该实习,让学生在实际操作中加深对计算机的组成原理和指令在计算机中运行过程的理解。二、课程设计的内容及其要求设计内容:使用vc开发出软件扫描键盘工作过程的仿真程序。设计要求:用仿真程序以图形/图像的方式呈现ibm-pc键盘及其接口的组成粗框图,并将8048单片机执行扫描程序时,各个部件之间的数据流向动态演示出来。三、课程设计的时间安排 序号教 学 顺 序教学内容学时(天)性质1准备阶段实习动员、了解实习目的要求、查阅资料半天理解2设计阶段硬件和软件设计,设计流程2设计3上机调试阶段编写代码,上机运行程序3设计4编写实习报告阶段检查实习效果、编写实习报告半天验证四、课程设计的实验环境硬件环境:pc机、 软件环境:ms windows操作系统开发工具: visual c+。五、实验原理 计算机键盘通常采用行列扫描法来确定按下键所在的行列位置。所谓行列扫描法是指,把键盘按键排列成n行m列的n*m行列点阵,把行、列线分别连接到两个 并行接口双向传送的连接线上,点阵上的键一旦被按动,该键所在的行列点阵信号就被认为已接通。按键所排列成的矩阵,需要用硬件或软件的方法轮转顺序地对其 行、列分别进行扫描,以查询和确认是否有键按动。如有键按动,键盘就会向主机发送被按键所在的行列点阵的位置编码,称为键扫描码。单片机通过周期性扫描 行、列线,读回扫描信号结果,判断是否有键按下,并计算按键的位置以获得扫描码。键被按下时,单片机分两次将位置扫描码发送到键盘接口:按下一次,叫接通 扫描码;按完释放一次,叫断开扫描码。这样,通过硬件或软件的方法对键盘分别进行行、列扫视,就可以确定按下键所在位置,获得并输出扫描位置码,然后转换 为ascii码,经过键盘i/o电路送入主机,并由显示器显示出来。 六、课程设计的源码及运行1、 源代码:头文件:(共3个)onscreenkeyboard.h #if !defined(afx_onscreenkeyboard_h_efe558f9_fb84_11d3_8d1d_00c0f0405b24_included_)#define afx_onscreenkeyboard_h_efe558f9_fb84_11d3_8d1d_00c0f0405b24_included_#if _msc_ver = 1000#pragma once#endif / _msc_ver = 1000#ifndef _afxwin_h_#error include stdafx.h before including this file for pch#endif#include resource.h/ main symbolsclass conscreenkeyboardapp : public cwinapppublic:conscreenkeyboardapp();public:virtual bool initinstance();declare_message_map();#endif onscreenkeyboarddlg.h#if !defined(afx_focustestdlg_h_efe558fb_fb84_11d3_8d1d_00c0f0405b24_included_)#define afx_focustestdlg_h_efe558fb_fb84_11d3_8d1d_00c0f0405b24_included_#if _msc_ver = 1000#pragma once#endif / _msc_ver = 1000#include afxtempl.h/键结构struct keydefchar cnormal;/键值char cshifted;/系统键值int cwidth;/键宽;class conscreenkeyboarddlg : public cdialog/ constructionpublic:int pkeywidth;/键宽int pkeyheight;/键高ctypedptrlist ckeys;/保存所有键int ccurrentkeystate;/描述当前键的状态hwnd gfocus;/系统当前激活的窗口句柄void addkey(char pnormal,char pshifted,int pwidth);void calcwidthheight();void drawkey(cdc * dc, crect & rc, keydef * key, bool chilight=false);void sendkey(keydef * key);void releasefocus();int describekeystate();void drawkeyboard();conscreenkeyboarddlg(cwnd* pparent = null); alog ;public:virtual bool pretranslatemessage(msg* pmsg);protected:virtual void dodataexchange(cdataexchange* pdx);protected:hicon m_hicon;virtual bool oninitdialog();afx_msg void onsyscommand(uint nid, lparam lparam);afx_msg void onpaint();afx_msg hcursor onquerydragicon();afx_msg void onlbuttondown(uint nflags, cpoint point);afx_msg void onlbuttondblclk(uint nflags, cpoint point);afx_msg void onrbuttondblclk(uint nflags, cpoint point);afx_msg void onrbuttondown(uint nflags, cpoint point);afx_msg void onrbuttonup(uint nflags, cpoint point);afx_msg bool onmousewheel(uint nflags, short zdelta, cpoint pt);afx_msg void onlbuttonup(uint nflags, cpoint point);afx_msg void onsize(uint ntype, int cx, int cy);virtual void onok();virtual void oncancel();afx_msg void onshowwindow(bool bshow, uint nstatus);afx_msg void ontimer(uint nidevent);afx_msg void ondestroy();declare_message_map();#endif resource.h#define idm_aboutbox 0x0010#define idd_aboutbox 100#define ids_aboutbox 101#define idd_onscreenkeyboard_dialog 102#define idr_mainframe 128#define idr_tray_menu 129#ifdef apstudio_invoked#ifndef apstudio_readonly_symbols#define _aps_next_resource_value 130#define _aps_next_command_value 32774#define _aps_next_control_value 1000#define _aps_next_symed_value 101#endif#endif源文件(2个)onscreenkeyboard.cpp#include stdafx.h#include onscreenkeyboard.h#include onscreenkeyboarddlg.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endifbegin_message_map(conscreenkeyboardapp, cwinapp)on_command(id_help, cwinapp:onhelp)end_message_map()conscreenkeyboardapp:conscreenkeyboardapp()conscreenkeyboardapp theapp;bool conscreenkeyboardapp:initinstance()afxenablecontrolcontainer();#ifdef _afxdllenable3dcontrols();#elseenable3dcontrolsstatic();#endifconscreenkeyboarddlg dlg;m_pmainwnd = &dlg;int nresponse = dlg.domodal();if (nresponse = idok)else if (nresponse = idcancel)return false;onscreenkeyboarddlg.cpp#include stdafx.h#include onscreenkeyboard.h#include onscreenkeyboarddlg.h#include #ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif#define timer_id 101/定时器id/定义特殊系统键的键值#define tab 0x02#define capslock 0x03#define shift 0x04#define ctrl 0x05#define bspace 0x06#define enter 0x07#define alt 0x08#define window 0x9#define left 0x0a#define right 0x0b#define up 0x0c#define down 0x0d#define esc 0x0e#define pup 0x0f#define pdn 0x10#define home 0x11#define end 0x12#define ins 0x13#define del 0x14#define www 0x15class caboutdlg : public cdialogpublic:caboutdlg();enum idd = idd_aboutbox ;protected:virtual void dodataexchange(cdataexchange* pdx); protected:declare_message_map();caboutdlg:caboutdlg() : cdialog(caboutdlg:idd)void caboutdlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);begin_message_map(caboutdlg, cdialog)end_message_map()conscreenkeyboarddlg:conscreenkeyboarddlg(cwnd* pparent /*=null*/): cdialog(conscreenkeyboarddlg:idd, pparent)m_hicon = afxgetapp()-loadicon(idr_mainframe);void conscreenkeyboarddlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);begin_message_map(conscreenkeyboarddlg, cdialog)on_wm_syscommand()on_wm_paint()on_wm_querydragicon()on_wm_lbuttondown()on_wm_lbuttondblclk()on_wm_rbuttondblclk()on_wm_rbuttondown()on_wm_rbuttonup()on_wm_mousewheel()on_wm_lbuttonup()on_wm_size()on_wm_showwindow()on_wm_timer()on_wm_destroy()end_message_map()bool conscreenkeyboarddlg:oninitdialog()cdialog:oninitdialog();assert(idm_aboutbox & 0xfff0) = idm_aboutbox);assert(idm_aboutbox appendmenu(mf_separator);psysmenu-appendmenu(mf_string, idm_aboutbox, straboutmenu);seticon(m_hicon, true);seticon(m_hicon, false);/将所有键加到链表中保存起来addkey(0x00,0x00,0); addkey(0x00,esc,10);for(int fnkey = 0x70; fnkey 0x7c; fnkey+)addkey(0x00,fnkey & 0xff,10);addkey(0x00,ins,14);addkey(0x00,del,-10);/第一行的键/改变键盘行的标志addkey(0x00,0x00,1);addkey(,10);addkey(1,!,10);addkey(2,10);addkey(3,#,10);addkey(4,$,10);addkey(5,%,10);addkey(6,10);addkey(7,&,10);addkey(8,*,10);addkey(9,(,10);addkey(0,),10);addkey(-,_,10);addkey(=,+,10);addkey(0x00,bspace,14); /backspaceaddkey(0x00,pup,-12);/第二行的键/改变键盘行的标志addkey(0x00,0x00,2); addkey(0x00,tab,14); /tabaddkey(q,q,10);addkey(w,w,10);addkey(e,e,10);addkey(r,r,10);addkey(t,t,10);addkey(y,y,10);addkey(u,u,10);addkey(i,i,10);addkey(o,o,10);addkey(p,p,10);addkey(,10);addkey(,10);addkey(,|,10);addkey(0x00,pdn,-12);/第三行的键/改变键盘行的标志addkey(0x00,0x00,3); addkey(0x00,capslock,18); /caps lockaddkey(a,a,10);addkey(s,s,10);addkey(d,d,10);addkey(f,f,10);addkey(g,g,10);addkey(h,h,10);addkey(j,j,10);addkey(k,k,10);addkey(l,l,10);addkey(;,:,10);addkey(,10);addkey(0x00,enter,16); /enteraddkey(0x00,home,-10);/第四行的键/改变键盘行的标志addkey(0x00,0x00,4);addkey(0x00,shift,22); /shiftaddkey(z,z,10);addkey(x,x,10);addkey(c,c,10);addkey(v,v,10);addkey(b,b,10);addkey(n,n,10);addkey(m,m,10);addkey(,10);addkey(/,?,10);addkey(0x00,shift,22); /shiftaddkey(0x00,end,-10);/第五行的键/改变键盘行的标志addkey(0x00,0x00,5); addkey(0x00,ctrl,12); /ctrladdkey(0x00,window,12); /windowaddkey(0x00,alt,12); /altaddkey( , ,60);addkey(0x00,left,12); /leftaddkey(0x00,up,12); /upaddkey(0x00,down,12); /downaddkey(0x00,right,12); /rightaddkey(0x00,www,-10); /http:/www/获得键宽和键高calcwidthheight();/打开定时器settimer(timer_id,250,null);return true; /计算键的宽度和高度void conscreenkeyboarddlg:calcwidthheight()pkeywidth = 0;pkeyheight = 0;keydef * key;position pos = ckeys.getheadposition();long totalwidth = 0;long longest = 0;long rows = 0;while(pos)key = ckeys.getnext(pos);/是换行的标志键if(key-cnormal = 0x00) & (key-cshifted = 0x00)/增加行数rows+;if(totalwidth longest)/获得总长最长的行longest = totalwidth;totalwidth = 0;/正确的键else/计算每行键的总长度totalwidth += abs(key-cwidth);crect rect;getclientrect(rect);pkeyheight = rect.height() / rows;pkeywidth = (int)(double)rect.width() / (double)(longest) / 10);/增加一个键,保存起来void conscreenkeyboarddlg:addkey(char pnormal,char pshifted,int pwidth)keydef * key = new keydef;key-cnormal = pnormal;key-cshifted = pshifted;key-cwidth = pwidth;ckeys.addtail(key);void conscreenkeyboarddlg:onsyscommand(uint nid, lparam lparam)if (nid & 0xfff0) = idm_aboutbox)caboutdlg dlgabout;dlgabout.domodal();elsecdialog:onsyscommand(nid, lparam);/画一个键void conscreenkeyboarddlg:drawkey(cdc * dc, crect & rc, keydef * key, bool chilight)/不是高亮度显示,设置颜色if(!chilight)rc.deflaterect(1,1);dc-fillsolidrect(rc,getsyscolor(color_3dface);dc-draw3drect(rc,getsyscolor(color_3dshadow),getsyscolor(color_3ddkshadow);rc.deflaterect(1,1);dc-draw3drect(rc,getsyscolor(color_3dlight),getsyscolor(color_3dshadow);/是高亮度显示,设置不同的颜色elserc.deflaterect(1,1);dc-fillsolidrect(rc,getsyscolor(color_3dlight);dc-draw3drect(rc,getsyscolor(color_3dlight),getsyscolor(color_3dshadow);rc.deflaterect(1,1);dc-draw3drect(rc,getsyscolor(color_3dshadow),getsyscolor(color_3ddkshadow);rc.deflaterect(3,1);/不是普通键if(key-cnormal = 0x00)/获得键名字符串cstring label = ;bool special = false;if(key-cshifted 0x6f)int fkeynum = key-cshifted - 0x6f;label.format(f%d,fkeynum);elseswitch(key-cshifted)case tab: / 0x02label = tab-;break;case capslock: / 0x03label = caps;break;case shift: / 0x04label = shift;break;case ctrl: / 0x05label = ctrl;break;case bspace: / 0x06label = moveto(cx+siz, cy);dc-lineto(cx-siz, cy);dc-lineto(cx-siz + (siz*4)/5, cy - siz/2);dc-moveto(cx-siz, cy);dc-lineto(cx-siz + (siz*4)/5, cy + siz/2);break;case right: / 0x0bspecial = true;int cx = (rc.left + rc.right)/2;int cy = (rc.top + rc.bottom)/2;int siz = rc.width()/3;dc-moveto(cx-siz, cy);dc-lineto(cx+siz, cy);dc-lineto(cx+siz - (siz*4)/5, cy - siz/2);dc-moveto(cx+siz, cy);dc-lineto(cx+siz - (siz*4)/5, cy + siz/2);break;case up: / 0x0cspecial = true;int cx = (rc.left + rc.right)/2;int cy = (rc.top + rc.bottom)/2;int siz = rc.width()/3;dc-moveto(cx, cy+siz);dc-lineto(cx, cy-siz);dc-lineto(cx - siz/2, cy-siz + (siz*4)/5);dc-lineto(cx, cy-siz);dc-lineto(cx + siz/2, cy-siz + (siz*4)/5);break;case down: / 0x0dspecial = true;int cx = (rc.left + rc.right)/2;int cy = (rc.top + rc.bottom)/2;int siz = rc.width()/3;dc-moveto(cx, cy-siz);dc-lineto(cx, cy+siz);dc-lineto(cx - siz/2, cy+siz - (siz*4)/5);dc-lineto(cx, cy+siz);dc-lineto(cx + siz/2, cy+siz - (siz*4)/5);break;case pup: /0x0flabel = pgup;break;case pdn: /0x10label = pgdn;break;case home: /0x11label = home;break;case end: /0x12label = end;break;case ins: /0x13label = ins;break;case del: /0x14label = del;break;case www:label = www;break;default:assert(false);label = #err#;break;/不是特殊键if(!special)csize tsize;tsize = dc-gettextextent(label);dc-textout(rc.left + rc.right)/2) - (tsize.cx/2), (rc.top + rc.bottom)/2) - (tsize.cy/2), label);/是普通键else/画键if(key-cshifted = a) & (key-cshifted gettextextent(key-cshifted);dc-textout(rc.left + rc.right)/2) - (tsize.cx/2), (rc.top + rc.bottom)/2) - (tsize.cy/2), key-cshifted);elsecsize tsize;tsize = dc-gettextextent(m);dc-textout(rc.left, rc.top, key-cshifted);dc-textout(rc.right - tsize.cx, rc.bottom - tsize.cy,key-cnormal);void conscreenkeyboarddlg:onpaint() if (isiconic()cpaintdc dc(this); sendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);int cxicon = getsystemmetrics(sm_cxicon);int cyicon = getsystemmetrics(sm_cyicon);crect rect;getclientrect(&rect);int x = (rect.width() - cxicon + 1) / 2;int y = (rect.height() - cyicon + 1) / 2;dc.drawicon(x, y, m_hicon);elsecdialog:onpaint();/画键盘drawkeyboard();hcursor conscreenkeyboarddlg:onquerydragicon()return (hcursor) m_hicon;/处理一个按键消息void conscreenkeyboarddlg:sendkey(keydef * keydef)/没有普通键被按if(keydef-cnormal = 0x00)int vk;bool uptoo = true;if(keydef-cshifted 0x6f) vk = keydef-cshifted;elseswitch(keydef-cshifted)case tab: / 0x02vk = vkkeyscan(0x09) & 0xff;break;case capslock: / 0x03vk = vk_capital;break;case shift: / 0x04vk = vk_shift;if(getkeystate(vk) & 0xf000) return;uptoo = false;break;case ctrl: / 0x05vk = vk_control;if(getkeystate(vk) & 0xf000) return;uptoo = false;break;case bspace: / 0x06vk = vk_back;break;case enter: / 0x07vk = vkkeyscan(0x0d) & 0xff;break;case alt: / 0x08vk = vk_menu;break;case window: / 0x9vk = vk_lwin;break;case left: / 0x0avk = vk_left;break;case right: / 0x0bvk = vk_right;break;case up: / 0x0cvk = vk_up;break;case down: / 0x0dvk = vk_down;break;case pup: /0x0fvk = vk_prior;break;case pdn: /0x10vk = vk_next;break;case home: /0x11vk = vk_home;break;case end: /0x12vk = vk_end;break;case ins: /0x13vk = vk_insert;break;case del: /0x14vk = vk_delete;break;case www:keydef key;key.cnormal = key.cshifted = h;sendkey(&key);key.cnormal = key.cshifted = t;sendkey(&key);sendkey(&key);key.cnormal = key.cshifted = p;sendkey(&key);key.cnormal = key.cshifted = :;sendkey(&key);key.cnormal = key.cshifted = /;sendkey(&key);sendkey(&key);key.cnormal = key.cshifted = w;sendkey(&key);sendkey(&key);sendkey(&key);vk = vkkeyscan(.) & 0xff;break;default:assert(false);break;keybd_event(vk,0,0,0);if(uptoo)keybd_
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离职员工知识产权转让与保密协议书
- 知识产权保护与保密协议范本(适用于动漫产业)
- 上市公司高管离职补偿金及离职后竞业限制协议
- 离婚申请书模板及子女抚养权及赡养费支付合同
- 数字化转型对区域经济发展协调性的作用
- 2025年烧结理论考试试题及答案
- 电炉炉前工考试题及答案
- 西双版纳活动拓展策划方案
- 连续电镀考试题库及答案
- 陕西省石泉县江南高级中学高中体育教学设计:立定三级跳
- (高清版)DG∕TJ 08-2251-2018 消防设施物联网系统技术标准
- 钣金生产安全培训
- 《解剖学课件:人体解剖学概要》
- T∕CACM 1096-2018 中医治未病技术操作规范 熏蒸
- 2024年浦东新区社区工作者招聘笔试真题
- 花艺沙龙合同协议
- 糖尿病酮症酸中毒课件
- 集团内部资金管理制度
- 电力系统安全风险评估报告
- 股权投资意向协议书范本7篇
- 软件测试师面试题及答案
评论
0/150
提交评论