DSP设计科学计算器实验报告

来源:医生招聘 发布时间:2021-04-13 点击:

基于DSP的科学型计算器设计 一、题目要求:
基于DSP F2812利用实验箱及软件编程设计一款科学型计算器使其满足如下功能:
(1)
能够实现按键数值的识别,并在数码管上显示 (2)
能够进行简单的加减运算 (3)
能够进行小数运算 二、思路设计 1、TMS320X2812实验箱资源功能简介:
●采用TMS320X2812片上的GPIOA及GPIOB作为IO口接受实验箱上的按键值进行判断。同时设置两个IO口进行循环0,1发送给row1,row2实现键盘扫描,从而实现识别k11~k23的值。

●将箱上的k1~k8,k11~k23作为计算器键盘。k1~k8为0~7,k11为8,k12为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 #define 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 row2 GpioDataRegs.GPBDAT.bit.GPIOB2 //PWM9 #define col2 GpioDataRegs.GPBDAT.bit.GPIOB3 //PWM10 #define col3 GpioDataRegs.GPBDAT.bit.GPIOB4 //PWM11 /*k1~k8,k11~k23作为计算器键盘。k1~k8为0~7,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 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_VarRx[100]; 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=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 = 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;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=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(countnum); 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.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==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,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(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); } 分配0~7数字按键:
int num(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; 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 & 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;//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; }

推荐访问:
上一篇:2021年学期初中历史教学计划合集
下一篇:初级中学第一学期团委工作计划

Copyright @ 2013 - 2018 优秀啊教育网 All Rights Reserved

优秀啊教育网 版权所有