打印

改写的程序想让LED灯输出9999,结果不对

[复制链接]
1670|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
恬蔚|  楼主 | 2013-11-9 16:58 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
结果是6666,而且还是下面少一横的6,求解!!
#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
/********************************宏定义数码管位选 IO 接口*******************************************/
#define  SET_BIT4        GpioDataRegs.GPBSET.bit.GPIO58         = 1                 //与外设板 8_LEDS 端子的 IO52 对应                                       
#define  RST_BIT4        GpioDataRegs.GPBCLEAR.bit.GPIO58 = 1                //与外设板 8_LEDS 端子的 IO52 对应
#define  SET_BIT3   GpioDataRegs.GPBSET.bit.GPIO59         = 1                //与外设板 8_LEDS 端子的 IO53 对应
#define  RST_BIT3        GpioDataRegs.GPBCLEAR.bit.GPIO59 = 1                //与外设板 8_LEDS 端子的 IO53 对应
#define  SET_BIT2   GpioDataRegs.GPBSET.bit.GPIO62         = 1                //与外设板 8_LEDS 端子的 IO54 对应
#define  RST_BIT2        GpioDataRegs.GPBCLEAR.bit.GPIO62 = 1                //与外设板 8_LEDS 端子的 IO54 对应
#define  SET_BIT1   GpioDataRegs.GPBSET.bit.GPIO63         = 1                //与外设板 8_LEDS 端子的 IO55 对应
#define  RST_BIT1        GpioDataRegs.GPBCLEAR.bit.GPIO63 = 1                //与外设板 8_LEDS 端子的 IO55 对应
/*****************************************************************************************************/


/*********************************************函数申明************************************************/
void delay(Uint32 t);
void DisData_Trans(Uint16 data);
void Sellect_Bit(Uint16 i);
void Init_LEDS_Gpio(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void delay(Uint32 t);
/*****************************************************************************************************/

/************************************定义相关变量*********************************************/
unsigned char msg[10]={0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};        //段码:0~9
unsigned char DisData_Bit[4] = {0};                                                                                        //存放拆分后的四位数字
Uint16 DisData = 0;                                                                                                                        //显示的数字
Uint16 Loop = 0;                                                                                                                        //循环扫描变量

/*****************************************************************************************************/

/******************************数码管位选 IO 接口初始化*******************************************/
  
void Init_LEDS_Gpio(void)
{  
    EALLOW;
   
       
        GpioCtrlRegs.GPBPUD.bit.GPIO58= 0;                                           // Enable pullup on GPIO11
    GpioDataRegs.GPBSET.bit.GPIO58 = 1;                                           // Load output latch
    GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 0;                                          // GPIO16 = GPIO
    GpioCtrlRegs.GPBDIR.bit.GPIO58 = 1;                                           // GPIO16 = output

        GpioCtrlRegs.GPBPUD.bit.GPIO59= 0;                                           // Enable pullup on GPIO11
    GpioDataRegs.GPBSET.bit.GPIO59 = 1;                                           // Load output latch
    GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 0;                                          // GPIO16 = GPIO
    GpioCtrlRegs.GPBDIR.bit.GPIO59 = 1;                                           // GPIO16 = output
   
        GpioCtrlRegs.GPBPUD.bit.GPIO62 = 0;                                           // Enable pullup on GPIO11
    GpioDataRegs.GPBSET.bit.GPIO62 = 1;                                           // Load output latch
    GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0;                                          // GPIO17 = GPIO
    GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1;                                           // GPIO17 = output
   
        GpioCtrlRegs.GPBPUD.bit.GPIO63 = 0;                                           // Enable pullup on GPIO11
    GpioDataRegs.GPBSET.bit.GPIO63 = 1;                                           // Load output latch
    GpioCtrlRegs.GPBMUX2.bit.GPIO63 = 0;                                          // GPIO19 = GPIO
    GpioCtrlRegs.GPBDIR.bit.GPIO63 = 1;                                           // GPIO19 = output   

    EDIS;  
   
    RST_BIT1;
    RST_BIT2;
    RST_BIT3;
    RST_BIT4;   
}
/*****************************************************************************************************/


/******************************数码管位选函数(从低位到高位扫描)***************************************************/
void Sellect_Bit(Uint16 i)
{
        switch(i)
        {
                case 0:
                        RST_BIT4;                                                                        //关断数码管第四位       
                        SET_BIT1;                                                                        //选通数码管第一位
                        break;

                case 1:
                        RST_BIT1;                                                                        //关断数码管第一位
                        SET_BIT2;                                                                        //选通数码管第二位
                        break;

                case 2:
                        RST_BIT2;                                                                        //关断数码管第二位
                        SET_BIT3;                                                                        //选通数码管第三位
                        break;

                case 3:
                        RST_BIT3;                                                                        //关断数码管第三位
                        SET_BIT4;                                                                        //选通数码管第四位
                        break;

                default:
                        break;
        }
}
/*****************************************************************************************************/

/************************** 拆分要显示的四位数保存到数组DisData_Trans【】*****************************/
void DisData_Trans(Uint16 data)
{
        DisData_Bit[3] = data / 1000;                                                //千位数
        DisData_Bit[2] = data % 1000 / 100 ;                                //百位数
        DisData_Bit[1] = data % 100 / 10;                                        //十位数
        DisData_Bit[0] = data % 10;                                                        //个位数
}
/*****************************************************************************************************/



/*********************************************延时函数************************************************/
void delay(Uint32 t)
{
        Uint32 i = 0;
        for (i = 0; i < t; i++) {};
}
/*****************************************************************************************************/

/*********************************************Spi初始化************************************************/

void spi_init()
{   
        SpiaRegs.SPICCR.all =0x004F;                                             // Reset on, rising edge, 16-bit char bits
                                                                             //0x000F对应Rising Edge,0x004F对应Falling Edge  
        SpiaRegs.SPICTL.all =0x0006;                                                 // Enable master mode, normal phase,
                                                                         // enable talk, and SPI int disabled.
        SpiaRegs.SPIBRR =0x007F;                                                                       
    SpiaRegs.SPICCR.all =0x00DF;                                                 // Relinquish SPI from Reset   
    SpiaRegs.SPIPRI.bit.FREE = 1;                                        // Set so breakpoints don't disturb xmission
}
/*****************************************************************************************************/

/****************************************Spi模块FIFO设置**********************************************/
void spi_fifo_init()                                                                               
{
// Initialize SPI FIFO registers
    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x204f;
    SpiaRegs.SPIFFCT.all=0x0;
}  

/*****************************************************************************************************/

/*********************************************Spi发送************************************************/

void spi_xmit(Uint16 a)
{
    SpiaRegs.SPITXBUF=a;
}   
/*****************************************************************************************************/


void main(void)
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the DSP280x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example  
// Setup only the GP I/O only for SPI-A functionality
   EALLOW;
   GpioCtrlRegs.GPAMUX1.all = 0x0;    // GPIO pin
   GpioCtrlRegs.GPADIR.all = 0xFF;     // Output pin
   GpioDataRegs.GPADAT.all =0xFF;     // Close LEDs
   EDIS;


   InitSpiaGpio();                                                                                                  //2802  SPIB
   Init_LEDS_Gpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.  
// This function is found in the DSP280x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;
   
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).  
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP280x_DefaultIsr.c.
// This function is found in DSP280x_PieVect.c.
   InitPieVectTable();
       
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP280x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   spi_fifo_init();          // Initialize the Spi FIFO
   spi_init();                  // init SPI

        for(;;)
        {
               
                DisData_Trans(DisData);                                                                        //拆分四位数
                for(Loop=0;Loop<4;Loop++)                                                                //分别显示四位
                {
                        Sellect_Bit(Loop);                                   //选择要扫描的数码管位
                    if(DisData_Bit[4]==9)
                    spi_xmit(msg[DisData_Bit[Loop]]);                  //串行输出要显示的数字
                        delay(25000);                                                                                //延时配合人眼反应时间
                }

                DisData++;                                                                                                //显示数字自加
                if(DisData > 9999)                                                                                //防止溢出 归零
                DisData = 0;
        }


}        


//===========================================================================
// No more.
//===========================================================================

相关帖子

沙发
zhangmangui| | 2013-11-11 23:57 | 只看该作者
较忙  代码没来得及看  结果对了没

使用特权

评论回复
板凳
xuexidsp| | 2013-11-12 08:41 | 只看该作者
还处于看书阶段。。

使用特权

评论回复
地板
zhangmangui| | 2013-11-12 09:07 | 只看该作者
xuexidsp 发表于 2013-11-12 08:41
还处于看书阶段。。

边看边练习  比较好

使用特权

评论回复
5
pinda_| | 2013-11-12 09:41 | 只看该作者
   if(DisData_Bit[4]==9)
   spi_xmit(msg[DisData_Bit[Loop]]);                  //串行输出要显示的数字

数码管只在51中做过,28335中没遇到过,只是第一眼就感觉到上面这句话有问题,你定义的DisData_Bit长度为4,那么,怎么取到DisData_Bit[4]的值呢?这里应该越界了吧。

使用特权

评论回复
6
hczsea| | 2013-11-12 16:22 | 只看该作者
pinda_ 发表于 2013-11-12 09:41
if(DisData_Bit[4]==9)
   spi_xmit(msg[DisData_Bit[Loop]]);                  //串行输出要显示的数 ...

5楼正解。看的真仔细啊,虽然这个界越的太明显了。

使用特权

评论回复
7
pinda_| | 2013-11-12 16:35 | 只看该作者
hczsea 发表于 2013-11-12 16:22
5楼正解。看的真仔细啊,虽然这个界越的太明显了。

:L:L

使用特权

评论回复
8
hczsea| | 2013-11-12 16:42 | 只看该作者
pinda_ 发表于 2013-11-12 16:35

:lol貌似楼主就改了那地方

使用特权

评论回复
9
恬蔚|  楼主 | 2013-11-12 18:39 | 只看该作者
pinda_ 发表于 2013-11-12 09:41
if(DisData_Bit[4]==9)
   spi_xmit(msg[DisData_Bit[Loop]]);                  //串行输出要显示的数 ...

我的意思是将这个数组中4个数字都为9时   运行一下结果    不对吗?这样

使用特权

评论回复
10
恬蔚|  楼主 | 2013-11-12 20:04 | 只看该作者
zhangmangui 发表于 2013-11-11 23:57
较忙  代码没来得及看  结果对了没

结果不对    我现在不太会建立project   不知道什么文件要link   也不知道要link的文件在哪里    是事先写好的?还是现编呢?

15.png (33.18 KB )

15.png

使用特权

评论回复
11
zhangmangui| | 2013-11-12 23:33 | 只看该作者
恬蔚 发表于 2013-11-12 20:04
结果不对    我现在不太会建立project   不知道什么文件要link   也不知道要link的文件在哪里    是事先 ...

缺少文件或者没有配置合适吧   
cmd等有没有缺

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

51

主题

147

帖子

1

粉丝