版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、基于DSP的科学型计算器设计一、题目要求:基于DSP F2812利用实验箱及软件编程设计一款科学型计算器使其满足如下功能:(1) 能够实现按键数值的识别,并在数码管上显示(2) 能够进行简单的加减运算(3) 能够进行小数运算二、思路设计 1、TMS320X2812实验箱资源功能简介:采用TMS320X2812片上的GPIOA及GPIOB作为IO口接受实验箱上的按键值进行判断。同时设置两个IO口进行循环0,1发送给row1,row2实现键盘扫描,从而实现识别k11k23的值。将箱上的k1k8,k11k23作为计算器键盘。k1k8为07,k11为8,k12为9,k13为清零键,k21为“=”键,k
2、22为+,k23为-。三、综合设计的程序分析LED显示过程循环扫描进入模块键值输入 程序框图#include "DSP28_Device.h"引脚定义:#define Key1GpioDataRegs.GPADAT.bit.GPIOA0 / 0#define Key2 GpioDataRegs.GPADAT.bit.GPIOA1 / 1#define Key3 GpioDataRegs.GPADAT.bit.GPIOA2 / 2#define Key4 GpioDataRegs.GPADAT.bit.GPIOA3 / 3 #define Key5 GpioDataRegs.
3、GPADAT.bit.GPIOA4 / 4#define Key6 GpioDataRegs.GPADAT.bit.GPIOA5 / 5#define Key7 GpioDataRegs.GPADAT.bit.GPIOA8 / 6#define Key8 GpioDataRegs.GPADAT.bit.GPIOA9 / 7*/#define row1 GpioDataRegs.GPBDAT.bit.GPIOB0 /PWM7 #define col1 GpioDataRegs.GPBDAT.bit.GPIOB1 /PWM8 #define row2 GpioDataRegs.GPBDAT.bit
4、.GPIOB2 /PWM9 #define col2 GpioDataRegs.GPBDAT.bit.GPIOB3 /PWM10#define col3 GpioDataRegs.GPBDAT.bit.GPIOB4 /PWM11 /*k1k8,k11k23作为计算器键盘。k1k8为07,k11为8,k12为9,k13为清零键,k21为“=”键,k22为+,k23为-#define Add 0x0A#define Sub 0x0B#define Clear 0x0C#define multi 0x04#define divi 0x08#define dot 0x0Dunsigned char S
5、canKey(void);int num(void);unsigned int Enter(void);int ifdot(void);/Relative to spi_receive,not use rightnowunsigned int Spi_VarRx100;unsigned int i,j,key;extern unsigned int Int_Flag;主函数如下:void main(void) unsigned int countnum,shownum, countnum1, countnum2,count=0,co,step=1,math=0;int noun=-1,dot1
6、=0; countnum = 0;countnum1 = 0;countnum2 = 0;co=0; while(1) noun=num();/键值 key=ScanKey(); dot1=ifdot(); if(key!=0)noun=key; /输入第一个数 if(noun>=0&&noun<=9) if(dot1=0) if(step=1) if(count<4) count+; countnum1= noun+countnum1*10; else count=0;countnum1=0; countnum=countnum1; shownum = BI
7、N2BCD(countnum); ShowBCD(shownum); else if(step=2) if(count<4) count+; countnum2= noun+countnum2*10; else count=0;countnum2=0; shownum = BIN2BCD(countnum2); ShowBCD(shownum); if(dot1=1) if(step=1) if(count<4) count+; countnum1= noun+countnum1*10; else count=0;countnum1=0; countnum=countnum1; s
8、hownum = BIN2BCD(countnum); ShowBCD1(shownum); else if(step=2) if(count<4) count+; countnum2= noun+countnum2*10; else count=0;countnum2=0; shownum = BIN2BCD(countnum2); ShowBCD1(shownum); if(noun=Add) step=2;count=0; math=1; else if(noun=Sub) step=2;count=0; math=2; else if(noun=Clear) countnum=0
9、;step=1; countnum1=0; countnum2=0; math=0; count=0; noun=-1; shownum = BIN2BCD(countnum); ShowBCD(shownum); else if(Enter()=1) switch (math) case 1:countnum=countnum1+countnum2;break; case 2:countnum=countnum1-countnum2;break; default:break; shownum = BIN2BCD(countnum); ShowBCD(shownum); math=0; cou
10、ntnum1=0;countnum2=0; step=1; /K11至K23的按键原理图如下(键盘扫描): "等于"按键分配函数如下:unsigned int Enter(void) unsigned int k11,k12,k13,k21,k22,k23; unsigned int c10,c20,c30,c21,c11,c31; k11=0;k12=0;k13=0;k21=0;k22=0;k23=0; GpioDataRegs.GPBDAT.bit.GPIOB2=1;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=0;/row1 c10=col
11、1; c20=col2;c30=col3; GpioDataRegs.GPBDAT.bit.GPIOB2=0;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=1;/row1 c11=col1; c21=col2;c31=col3; if(c11=0 & c10=1)k21=1; if(k21)return 1; else return 0; 分配加、减、清零及小数点的按键 :unsigned char ScanKey(void) unsigned int k11,k12,k13,k21,k22,k23; unsigned int c10,c20,c30,c21
12、,c11,c31; k11=0;k21=0;k12=0;k22=0;k21=0;k23=0;k13=0; GpioDataRegs.GPBDAT.bit.GPIOB2=1;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=0;/row1 c10=col1; c20=col2;c30=col3; GpioDataRegs.GPBDAT.bit.GPIOB2=0;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=1;/row1 c11=col1; c21=col2;c31=col3; if(c21=0 & c20=1)k22 =1; if(c
13、21=1 & c20=0)k12 =1; if(c31=0 & c30=1)k23 =1; if(c31=1 & c30=0)k13 =1; if(k22=1)KeyData=Add; else if(k23=1)KeyData=Sub; else if(k13=1)KeyData=Clear; else if(k12=1)KeyData=dot; else KeyData=0; return(KeyData); 分配07数字按键:int num(void) int x; unsigned int c10,c20,c30,k; unsigned int c11,c21,
14、c31; unsigned int k11,k12,k13,k21,k22,k23; k11=0;k12=0;k13=0;k21=0;k22=0;k23=0; GpioDataRegs.GPBDAT.bit.GPIOB2=1;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=0;/row1 c10=col1; c20=col2;c30=col3; GpioDataRegs.GPBDAT.bit.GPIOB2=0;/row2 GpioDataRegs.GPBDAT.bit.GPIOB0=1;/row1 c11=col1; c21=col2;c31=col3; if(c11
15、=1 & c10=0)k11=1; if(Key1=0)x=0; else if(Key2=0)x=1; else if(Key3=0)x= 2; else if(Key4=0)x= 3; else if(Key5=0)x=4; else if(Key6=0)x=5; else if(Key7=0)x=6; else if(Key8=0)x=7; else if(k11)x=8; else x=-1; return x; 分配小数点按键:int ifdot(void) int x; unsigned int c10,c20,c30,k; unsigned int c11,c21,c31; unsigned int k11,k12,k13,k21,k22,k23; k11=0;k12=0;k13=0;k21=0;k22=0;k23=0; for(k=0;k<2;k+) GpioDataRegs.GPBDAT.bit.GPIOB2=1;/ro
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广美考研理论试题及答案
- 中国医科大学《传播学教程》2025-2026学年期末试卷
- 丝麻毛纤维预处理工班组协作评优考核试卷含答案
- 磨料制造工岗前岗位适应能力考核试卷含答案
- 游泳指导员安全技能测试模拟考核试卷含答案
- 软件开发公司工作总结报告
- 营销员操作水平竞赛考核试卷含答案
- 讲解员安全操作知识考核试卷含答案
- 啤酒包装工操作规程知识考核试卷含答案
- 初二信息技术期中考试及答案
- 6S管理知识及现场培训课件
- 潍坊社科类课题申报书
- 患者身份识别管理标准WST840-2025学习解读课件
- 高架快速路道路巡查与日常养护服务方案投标文件(技术方案)
- 伐木工三级安全教育试卷及答案
- 危重症患者多学科协作救治与护理实践
- 幼儿园转岗教师培训讲座
- 绿色供应链技术创新与应用-洞察阐释
- 2025年广东省高考物理真题(含答案)
- 对外出租设备管理制度
- 天津市某中学2024-2025学年八年级(下)第一次月考物理试卷(含解析)
评论
0/150
提交评论