题目求:
基DSP F2812利实验箱软件编程设计款科学型计算器满足功:
(1) 够实现键数值识数码显示
(2) 够进行简单加减运算
(3) 够进行数运算
二思路设计
1TMS320X2812实验箱资源功简介:
●采TMS320X2812片GPIOAGPIOB作IO口接受实验箱键值进行判断时设置两IO口进行循环01发送row1row2实现键盘扫描实现识k11~k23值
●箱k1~k8k11~k23作计算器键盘k1~k80~7k118k129k13清零键k21键k22+k23
三综合设计程序分析
LED显示程
循环扫描进入模块
键值输入
●程序框图
#include DSP28_Deviceh
引脚定义:
#define Key1 GpioDataRegsGPADATbitGPIOA0 0
#define Key2 GpioDataRegsGPADATbitGPIOA1 1
#define Key3 GpioDataRegsGPADATbitGPIOA2 2
#define Key4 GpioDataRegsGPADATbitGPIOA3 3
#define Key5 GpioDataRegsGPADATbitGPIOA4 4
#define Key6 GpioDataRegsGPADATbitGPIOA5 5
#define Key7 GpioDataRegsGPADATbitGPIOA8 6
#define Key8 GpioDataRegsGPADATbitGPIOA9 7*
#define row1 GpioDataRegsGPBDATbitGPIOB0 PWM7
#define col1 GpioDataRegsGPBDATbitGPIOB1 PWM8
#define row2 GpioDataRegsGPBDATbitGPIOB2 PWM9
#define col2 GpioDataRegsGPBDATbitGPIOB3 PWM10
#define col3 GpioDataRegsGPBDATbitGPIOB4 PWM11
*k1~k8k11~k23作计算器键盘k1~k80~7k118k129k13清零键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_receivenot use rightnow
unsigned int Spi_VarRx[100]
unsigned int ijkey
extern unsigned int Int_Flag
函数:
void main(void)
{ unsigned int countnumshownum countnum1 countnum2count0costep1math0
int noun1dot10
countnum 0countnum1 0countnum2 0co0
while(1)
{
nounnum()键值
keyScanKey()
dot1ifdot()
if(key0)nounkey
输入第数
if(noun>0&&noun<9)
{ if(dot10)
{if(step1)
{
if(count<4)
{
count++
countnum1 noun+countnum1*10
}
else
{
count0countnum10
}
countnumcountnum1
shownum BIN2BCD(countnum)
ShowBCD(shownum)
}
else if(step2)
{
if(count<4)
{
count++
countnum2 noun+countnum2*10
}
else
{
count0countnum20
}
shownum BIN2BCD(countnum2)
ShowBCD(shownum)
}
}
if(dot11)
{
if(step1)
{
if(count<4)
{
count++
countnum1 noun+countnum1*10
}
else
{
count0countnum10
}
countnumcountnum1
shownum BIN2BCD(countnum)
ShowBCD1(shownum)
}
else if(step2)
{ if(count<4)
{
count++
countnum2 noun+countnum2*10
}
else
{
count0countnum20
}
shownum BIN2BCD(countnum2)
ShowBCD1(shownum)
}
}
}
if(nounAdd)
{ step2count0
math1
}
else if(nounSub)
{
step2count0
math2
}
else if(nounClear)
{
countnum0step1
countnum10
countnum20
math0
count0
noun1
shownum BIN2BCD(countnum)
ShowBCD(shownum)
}
else if(Enter()1)
{
switch (math)
{
case 1countnumcountnum1+countnum2break
case 2countnumcountnum1countnum2break
defaultbreak
}
shownum BIN2BCD(countnum)
ShowBCD(shownum)
math0
countnum10countnum20
step1
}
}
}
K11K23键原理图(键盘扫描):
等键分配函数:
unsigned int Enter(void)
{
unsigned int k11k12k13k21k22k23
unsigned int c10c20c30c21c11c31
k110k120k130k210k220k230
GpioDataRegsGPBDATbitGPIOB21row2
GpioDataRegsGPBDATbitGPIOB00row1
c10col1 c20col2c30col3
GpioDataRegsGPBDATbitGPIOB20row2
GpioDataRegsGPBDATbitGPIOB01row1
c11col1 c21col2c31col3
if(c110 & c101)k211
if(k21)return 1
else return 0
}
分配加减清零数点键 :
unsigned char ScanKey(void)
{ unsigned int k11k12k13k21k22k23
unsigned int c10c20c30c21c11c31
k110k210k120k220k210k230k130
GpioDataRegsGPBDATbitGPIOB21row2
GpioDataRegsGPBDATbitGPIOB00row1
c10col1 c20col2c30col3
GpioDataRegsGPBDATbitGPIOB20row2
GpioDataRegsGPBDATbitGPIOB01row1
c11col1 c21col2c31col3
if(c210 & c201)k22 1
if(c211 & c200)k12 1
if(c310 & c301)k23 1
if(c311 & c300)k13 1
if(k221)KeyDataAdd
else if(k231)KeyDataSub
else if(k131)KeyDataClear
else if(k121)KeyDatadot
else KeyData0
return(KeyData)
}
分配0~7数字键:
int num(void)
{ int x
unsigned int c10c20c30k
unsigned int c11c21c31
unsigned int k11k12k13k21k22k23
k110k120k130k210k220k230
GpioDataRegsGPBDATbitGPIOB21row2
GpioDataRegsGPBDATbitGPIOB00row1
c10col1 c20col2c30col3
GpioDataRegsGPBDATbitGPIOB20row2
GpioDataRegsGPBDATbitGPIOB01row1
c11col1 c21col2c31col3
if(c111 & c100)k111
if(Key10)x0
else if(Key20)x1
else if(Key30)x 2
else if(Key40)x 3
else if(Key50)x4
else if(Key60)x5
else if(Key70)x6
else if(Key80)x7
else if(k11)x8
else x1
return x }
分配数点键:
int ifdot(void)
{
int x
unsigned int c10c20c30k
unsigned int c11c21c31
unsigned int k11k12k13k21k22k23
k110k120k130k210k220k230
for(k0k<2k++)
{
GpioDataRegsGPBDATbitGPIOB21row2
GpioDataRegsGPBDATbitGPIOB00row1
c10col1 c20col2c30col3
GpioDataRegsGPBDATbitGPIOB20row2
GpioDataRegsGPBDATbitGPIOB01row1
c11col1 c21col2c31col3
if(c211 & c200)k121
}
if(k12)x1数格式
else x0
return x
}
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档