Let's take a look at the entire program source code of the first experiment ·
Some comments have been modified.
1/* external data Ram Test Program */2 # include "Global. C "3 void systeminit (); 4 void ram_test (); 5 void kickdog (); 6 7 main () 8 {9 10 systeminit (); /* system initialization */11 12 mcra = mcra & 0xc0ff; // IOPB0-6 set to IO port mode 13 pbdatdir = 0xffc2; // All LEDs = 0 14 pbdatdir = pbdatdir | 0x003c; // The led connected to the pb0 port is out, and then the following is 4 seconds. 15 // The Source Code does not enter the while loop unless "! = "16 // change to" = "17 18 ram_test (); 19 20 while (1); 21 22} 23 24 void systeminit () 25 {26 27 ASM ("SETC intm");/* close the total interrupt */28 ASM ("clrc sxm "); /* disable symbol bit extensions */29 ASM ("clrc CNF");/* map B0 blocks to on-chip daram */30 ASM ("clrc OVM "); /* the result of the accumulators overflows normally */31 scsr1 = 0x83fe;/* system clock clkout = 20*2 = 40 m */32/* Open ADC, Eva, EVB, can and Sci clock, system clock clkout = 40 m */33 wdcr = 0x006f;/* disables the watchdog, And the watchdog clock is divided into 64 frequencies */34 kickdog (); /* initialize the watchdog */35 IFR = 0 XFFFF;/* clear interrupt flag */36 IMR = 0x0000;/* Open interrupt 2 */37 38} 39 40 void ram_test () 41 {42 43 unsigned int I = 0, j = 0, T = 0; 44 unsigned int * ADDR = (unsigned int *) 0x8000; 45 46 for (I = 0x7fff; I <0 xFFFF; I ++) 47 {48 49 * ADDR = 0x5555; 50 while (* ADDR )! = 0x5555) 51 {52 If (T % 1000) = 0) 53 {54 if (pbdatdir & 0x0001) = 0x0001) 55 pbdatdir = pbdatdir & 0 xfffe; // iopb0 = 0; led destroy 56 else57 pbdatdir = pbdatdir | 0x0101; // iopb0 = 1; led bright 58} 59 T ++; 60} 61 ADDR ++; 62 for (j = 0; j <50; j ++ ); 63 64} 65 66 pbdatdir = pbdatdir | 0x0101; // iopb0 = 1; LED light 67 68} 69 70 void kickdog () /* play the dog */71 {72 wdkey = 0x5555; 73 wdkey = 0 xaaaa; 74}
Note: 1. Unsigned int * ADDR = (unsigned int *) 0x8000; to store the address "0x8000") into the unsigned integer pointer variable ADDR.
2. * ADDR = 0x5555; write "0x5555" to this address"
3,
1 While (* ADDR )! = 0x5555) 2 {3 if (T % 1000) = 0) // modify the value, adjust the flashing frequency of the LED light corresponding to pb0 4 {5 If (pbdatdir & 0x0001) = 0x0001) 6 pbdatdir = pbdatdir & 0 xfffe; // iopb0 = 0; control led off 7 else 8 pbdatdir = pbdatdir | 0x0101; // iopb0 = 1; led on 9} 10 t ++; 11}
The above program is a switch, that is, if the value "0x5555" is successfully written into RAM, it will be dropped into the while loop (of course, put the "! = ).
4. The source program is initially terminated by the LED lamp connected by pb0, and then turned on again after 4 seconds. Here, the 4 seconds is the software latency. Generally, the for cycle of a C statement is eight machine cycles, and the lf2407 clock frequency is 40 MHz, that is
The clock cycle is 25ns, And you can calculate it by yourself. Another method is to use the profiler function of the CCS software to measure the execution time of a program. The usage is as follows:
Click here and click my CCS debugging and code running time statistics and this CCS to view the DSP running time
5. source code comments are a bit problematic. The comments given in this article have been modified.