恬蔚 发表于 2013-11-9 16:58

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

结果是6666,而且还是下面少一横的6,求解!!
#include "DSP2833x_Device.h"   // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
/********************************宏定义数码管位选 IO 接口*******************************************/
#defineSET_BIT4        GpioDataRegs.GPBSET.bit.GPIO58       = 1                 //与外设板 8_LEDS 端子的 IO52 对应                                       
#defineRST_BIT4        GpioDataRegs.GPBCLEAR.bit.GPIO58 = 1                //与外设板 8_LEDS 端子的 IO52 对应
#defineSET_BIT3   GpioDataRegs.GPBSET.bit.GPIO59       = 1                //与外设板 8_LEDS 端子的 IO53 对应
#defineRST_BIT3        GpioDataRegs.GPBCLEAR.bit.GPIO59 = 1                //与外设板 8_LEDS 端子的 IO53 对应
#defineSET_BIT2   GpioDataRegs.GPBSET.bit.GPIO62       = 1                //与外设板 8_LEDS 端子的 IO54 对应
#defineRST_BIT2        GpioDataRegs.GPBCLEAR.bit.GPIO62 = 1                //与外设板 8_LEDS 端子的 IO54 对应
#defineSET_BIT1   GpioDataRegs.GPBSET.bit.GPIO63       = 1                //与外设板 8_LEDS 端子的 IO55 对应
#defineRST_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={0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};        //段码:0~9
unsigned char DisData_Bit = {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 = data / 1000;                                                //千位数
        DisData_Bit = data % 1000 / 100 ;                                //百位数
        DisData_Bit = data % 100 / 10;                                        //十位数
        DisData_Bit = 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();                                                                                                //2802SPIB
   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==9)
                  spi_xmit(msg]);                  //串行输出要显示的数字
                        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 static/image/common/back.gif
还处于看书阶段。。

边看边练习比较好

pinda_ 发表于 2013-11-12 09:41

   if(DisData_Bit==9)
   spi_xmit(msg]);                  //串行输出要显示的数字

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

hczsea 发表于 2013-11-12 16:22

pinda_ 发表于 2013-11-12 09:41 static/image/common/back.gif
if(DisData_Bit==9)
   spi_xmit(msg]);                  //串行输出要显示的数 ...

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

pinda_ 发表于 2013-11-12 16:35

hczsea 发表于 2013-11-12 16:22 static/image/common/back.gif
5楼正解。看的真仔细啊,虽然这个界越的太明显了。

:L:L

hczsea 发表于 2013-11-12 16:42

pinda_ 发表于 2013-11-12 16:35 static/image/common/back.gif


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

恬蔚 发表于 2013-11-12 18:39

pinda_ 发表于 2013-11-12 09:41 static/image/common/back.gif
if(DisData_Bit==9)
   spi_xmit(msg]);                  //串行输出要显示的数 ...

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

恬蔚 发表于 2013-11-12 20:04

zhangmangui 发表于 2013-11-11 23:57 static/image/common/back.gif
较忙代码没来得及看结果对了没

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

zhangmangui 发表于 2013-11-12 23:33

恬蔚 发表于 2013-11-12 20:04 static/image/common/back.gif
结果不对    我现在不太会建立project   不知道什么文件要link   也不知道要link的文件在哪里    是事先 ...

缺少文件或者没有配置合适吧   
cmd等有没有缺
页: [1]
查看完整版本: 改写的程序想让LED灯输出9999,结果不对