微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > DSP学习交流 > 利用定时器0做一个秒表,芯片为28027,数码管不能显示

利用定时器0做一个秒表,芯片为28027,数码管不能显示

时间:10-02 整理:3721RD 点击:

程序编译没有错误,但是数码管不能刷新显示。在Debug 的时候按下暂停键就会刷新一下显示最新的计数值CpuTimer0.InterruptCount。求大神解答,程序如下
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
// Prototype statements for functions found within this file.
interrupt void cpu_timer0_isr(void);
interrupt void cpu_timer1_isr(void);
interrupt void cpu_timer2_isr(void);
void InitTimerGpio(void);
interrupt void spiTxFifoIsr(void);
interrupt void spiRxFifoIsr(void);
void spi_fifo_init(void);
void delay_loop(void);
Uint16 Led_lib[] = {0x42, 0xf3, 0x86, 0xa2, 0x33, 0x2a, 0x0a, 0xf2, 0x02, 0x22, \
                                        0x40, 0xf1, 0x84, 0xa0, 0x31, 0x28, 0x08, 0xf0, 0x00, 0x20, \
                                        0x1e, 0x0e, 0x0f, 0xbf, 0x23, 0x9b, 0x8b}; //小LED字库
Uint16 Voltage1[512];
Uint16 Voltage2[512];
Uint32 Voltage = 0;
Uint16 Adc_Isr_Count;
Uint16 sdata[2];     // Send data buffer
Uint16 rdata[2];     // Receive data buffer
Uint16 rdata_point;  // Keep track of where we are
                     // in the data stream to check received data
Uint16 sdata_point;
Uint16 sdata_point_unm;
int m=0;
void main(void)
{
        int i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2802x_SysCtrl.c file.
   InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example
   InitTimerGpio();
   InitSpiaGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;
// Initialize the 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 DSP2802x_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 DSP2802x_DefaultIsr.c.
// This function is found in DSP2802x_PieVect.c.
   InitPieVectTable();
   spi_fifo_init();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;    // This is needed to disable write to EALLOW protected registers
   EALLOW;        // This is needed to write to EALLOW protected registers
   PieVectTable.SPIRXINTA = &spiRxFifoIsr;
   PieVectTable.SPITXINTA = &spiTxFifoIsr;
   EDIS;   // This is needed to disable write to EALLOW protected registers
   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
   PieCtrlRegs.PIEIER6.bit.INTx1=1;     // Enable PIE Group 6, INT 1
   PieCtrlRegs.PIEIER6.bit.INTx2=1;     // Enable PIE Group 6, INT 2
   IER |= 0x20;                         // Enable CPU INT6
//   EINT;                                                          // Enable Global interrupt INTM
//   ERTM;                                                          // Enable Global realtime interrupt DBGM
// Step 4. Initialize the Device Peripheral. This function can be
//         found in DSP2802x_CpuTimers.c
   InitCpuTimers();   // For this example, only initialize the Cpu Timers
#if (CPU_FRQ_60MHZ)
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 60MHz CPU Freq, 1 second Period (in uSeconds)
   ConfigCpuTimer(&CpuTimer0, 60, 1000000);
#endif

// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2802x_CpuTimers.h), the
// below settings must also be updated.
   CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
// Step 5. User specific code, enable interrupts:
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
   IER |= M_INT1;

// Enable TINT0 in the PIE: Group 1 interrupt 7
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
   for(;;)
   {
           if(CpuTimer0.InterruptCount>m)
           {
                   Voltage=CpuTimer0.InterruptCount;
                   sdata[1] = (Led_lib[Voltage%100/10])*256 + Led_lib[Voltage%10];
                   sdata[0] = (Led_lib[(Voltage/1000)])*256 + Led_lib[Voltage%1000/100];
                   delay_loop();
                   if(CpuTimer0.InterruptCount==0xFFFF)
                   {
                           CpuTimer0.InterruptCount=0;
                   }
                   m=CpuTimer0.InterruptCount;
           }
   }
}
void delay_loop()
{
    long      i;
    for (i = 0; i < 10000; i++) {}
}
interrupt void cpu_timer0_isr(void)
{
   CpuTimer0.InterruptCount++;
   GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1;
   GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
   // Acknowledge this interrupt to receive more interrupts from group 1
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
void InitTimerGpio(void)
{
        EALLOW;
        GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
        GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
        GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;
        GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
        EDIS;
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
   SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
   SpiaRegs.SPICCR.all=0x000F;       //16-bit character, Loopback mode
   SpiaRegs.SPICTL.all=0x0017;       //Interrupt enabled, Master/Slave XMIT enabled
   SpiaRegs.SPISTS.all=0x0000;
   SpiaRegs.SPIBRR=0x0063;           // Baud rate
   SpiaRegs.SPIFFTX.all=0xC022;      // Enable FIFO's, set TX FIFO level to 2
   SpiaRegs.SPIFFRX.all=0x0022;      // Set RX FIFO level to 2
   SpiaRegs.SPIFFCT.all=0x00;
   SpiaRegs.SPIPRI.all=0x0010;
   SpiaRegs.SPICCR.bit.SPISWRESET=1;  // Enable SPI
   SpiaRegs.SPIFFTX.bit.TXFIFO=1;
   SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;
}
interrupt void spiTxFifoIsr(void)
{
         Uint16 i;
         GpioDataRegs.GPADAT.bit.GPIO19 = 1;
         for(i=0;i<2;i++)
         {
                 SpiaRegs.SPITXBUF=sdata;      // Send data
         }
         GpioDataRegs.GPADAT.bit.GPIO19 = 0;
//    sdata_point++;
    SpiaRegs.SPIFFTX.bit.TXFFINTCLR=1;  // Clear Interrupt flag
        PieCtrlRegs.PIEACK.all|=0x20;                  // Issue PIE ACK
}
interrupt void spiRxFifoIsr(void)
{
    Uint16 i;
    for(i=0;i<2;i++)
    {
            rdata=SpiaRegs.SPIRXBUF;                // Read data
        }
//        rdata_point++;
        SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1;  // Clear Overflow flag
        SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1;         // Clear Interrupt flag
        PieCtrlRegs.PIEACK.all|=0x20;       // Issue PIE ack
}

顶个帖。

看一串没什么注释的别人的代码好痛苦,你的意思是debug按暂停跑数码管显示是正常的,全速的话显示不正常,显示上一个值不刷新吗?

对!主要程序是for 循环那里。初始化那些是从TI的给的例程里面复制过来的

啊!没人吗?还是这芯片太落后的原因

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top