基于dsp28335的SPI经MAX7219点亮数码管的程序 求大神帮忙,现在无法点亮
时间:10-02
整理:3721RD
点击:
程序配置都没问题可就是点不亮,求大神帮忙看看是不是程序有问题
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
/*初始化芯片*/
void Init_MAX7219(void)
{
spi_xmit(0x0900); //译码方式:不译码0900
spi_xmit(0x0a04); //亮度0a03
spi_xmit(0x0b07); //扫描界限;8个数码管显示0b07
spi_xmit(0x0c01); //掉电模式:0,普通模式:1 0c01
spi_xmit(0x0f00); //显示测试:1;测试结束,正常显示:0 0f00
}
//void error(void);
Uint16 table[16]={
0x013f,0x0106,0x015b,0x014f, //0-1-2-3
0x0166,0x016d,0x017d,0x0107, //4-5-6-7
0x017f,0x016f,0x0177,0x017c, //8-9-a-d
0x0139,0x015e,0x0179,0x0171 //c-d-e-f
};
void main(void)
{
InitSysCtrl();
InitXintf16Gpio(); //zq
InitSpiaGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI
Init_MAX7219(); //初始化7219
while(1)
{ int k=0;
for(k=0;k<16;k++)//16个数
{
if(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=1)
{
spi_xmit(0X015B);
}
DELAY_US(100);
}
}
}
void delay_loop()
{
long j;
for (j = 0; j < 1000000; j++) {}
}
//void error(void)
//{
// asm(" ESTOP0"); // Test failed! Stop!
// for (;;);
//}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0008; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x000E; //6,E // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x0066; //波特率 LSPCLK/(SPIBRR+1)=0.295M LSPCLK=37.5M
SpiaRegs.SPICCR.all =0x008F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
DELAY_US(50);
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}
//===========================================================================
// No more.
//===========================================================================
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
/*初始化芯片*/
void Init_MAX7219(void)
{
spi_xmit(0x0900); //译码方式:不译码0900
spi_xmit(0x0a04); //亮度0a03
spi_xmit(0x0b07); //扫描界限;8个数码管显示0b07
spi_xmit(0x0c01); //掉电模式:0,普通模式:1 0c01
spi_xmit(0x0f00); //显示测试:1;测试结束,正常显示:0 0f00
}
//void error(void);
Uint16 table[16]={
0x013f,0x0106,0x015b,0x014f, //0-1-2-3
0x0166,0x016d,0x017d,0x0107, //4-5-6-7
0x017f,0x016f,0x0177,0x017c, //8-9-a-d
0x0139,0x015e,0x0179,0x0171 //c-d-e-f
};
void main(void)
{
InitSysCtrl();
InitXintf16Gpio(); //zq
InitSpiaGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI
Init_MAX7219(); //初始化7219
while(1)
{ int k=0;
for(k=0;k<16;k++)//16个数
{
if(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=1)
{
spi_xmit(0X015B);
}
DELAY_US(100);
}
}
}
void delay_loop()
{
long j;
for (j = 0; j < 1000000; j++) {}
}
//void error(void)
//{
// asm(" ESTOP0"); // Test failed! Stop!
// for (;;);
//}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0008; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x000E; //6,E // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x0066; //波特率 LSPCLK/(SPIBRR+1)=0.295M LSPCLK=37.5M
SpiaRegs.SPICCR.all =0x008F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
DELAY_US(50);
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}
//===========================================================================
// No more.
//===========================================================================