资源预览内容
第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
亲,该文档总共7页全部预览完了,如果喜欢就下载吧!
资源描述
基于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为“=”键,k22为+,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.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 /*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 ScanKey(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=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(count4) count+; countnum1= noun+countnum1*10; else count=0;countnum1=0; countnum=countnum1; shownum = BIN2BCD(countnum); ShowBCD(shownum); else if(step=2) if(count4) count+; countnum2= noun+countnum2*10; else count=0;countnum2=0; shownum = BIN2BCD(countnum2); ShowBCD(shownum); if(dot1=1) if(step=1) if(count4) count+; countnum1= noun+countnum1*10; else count=0;countnum1=0; countnum=countnum1; shownum = BIN2BCD(countnum); ShowBCD1(shownum); else if(step=2) if(count4) 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(k
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号