《DSP设计科学计算器实验报告.docx》由会员分享,可在线阅读,更多相关《DSP设计科学计算器实验报告.docx(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、DSP设计科学计算器实验报告基于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
2、为9,k13为清零键,k21为“=”键,k22为+,k23为-。 三、综合设计的程序分析 LED显示过程 循环扫描进入模块 键值输入 程序框图 #include “DSP28_Device.h“ 引脚定义: #define Key1 GpioDataRegs.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 #def
3、ine Key5 GpioDataRegs.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 ro
4、w2 GpioDataRegs.GPBDAT.bit.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 0x0
5、8 #define dot 0x0D unsigned char ScanKey(void); int num(void); unsigned int Enter(void); int ifdot(void); /Relative to spi_receive,not use rightnow unsigned int Spi_VarRx100; unsigned int i,j,key; extern unsigned int Int_Flag; 主函数如下: void main(void) unsigned int countnum,shownum, countnum1, countnum
6、2,count=0,co,step=1,math=0; int noun=-1,dot1=0; countnum = 0;countnum1 = 0;countnum2 = 0;co=0; while(1) noun=num();/键值 key=ScanKey(); dot1=ifdot(); if(key!=0)noun=key; /输入第一个数 if(noun>=0noun<=9) if(dot1=0) if(step=1) if(count<4) count+; countnum1= noun+countnum1*10; else count=0;countnum1=0
7、; countnum=countnum1; shownum = BIN2BCD(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;
8、countnum1=0; countnum=countnum1; shownum = 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
9、=2; else if(noun=Clear) countnum=0;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(countn
10、um); ShowBCD(shownum); math=0; countnum1=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.b
11、it.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=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
12、 int c10,c20,c30,c21,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=
13、1)k22 =1; if(c21=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,c31
14、; 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=1
15、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; unsign
16、ed 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;/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=1 c20=0)k12=1; if(k12)x=1;/小数格式 else x=0; return x;