Page 359 - Programming Microcontrollers in C
P. 359

344    Chapter 6  Large Microcontrollers

                          putchar(0xd);
                          putchar(0xa);
                   }

                   }
                   int handle_data(int new_data)
                   {
                       static int i=63;
                       data[i—]=new_data;
                       i &=63;
                       return (i==63)?0:i+1;
                   }
                              Listing 6-13: Test Program For The Circular Convolution

                              Then the code to send the data to the circular_conv() is
                          modified slightly to that shown below.
                   for(i=0;i<64;i++)
                   {
                   /* get new data — use 0x100 for this test */

                       ip=data+handle_data(0x100);
                       point[i]=circular_conv(64,ip,32,coef);
                   }
                              The value 0x100 is sent into the function handle_data , and
                          the return is the index into the array where the data was stored in the
                          array data. When this integer is added to data, which is a pointer to a
                          type int, the pointer ip will point to the location into the array where
                          the latest value was stored in memory. Under normal circumstances,
                          this piece of code would be entered under control of a clock and the
                          data sent into the routine handle_data() would be new input from
                          an analog to digital converter. Also, the for statement is not expected
                          in a practical application. The output from this program is:

                            2  4  6  8 10 12 14 16
                          18 20 22 24 26 28 30 32
                          34 36 38 40 42 44 46 48
                          50 52 54 56 58 60 62 64
                          64 64 64 64 64 64 64 64
                          64 64 64 64 64 64 64 64
                          64 64 64 64 64 64 64 64
                          64 64 64 64 64 64 64 64
   354   355   356   357   358   359   360   361   362   363   364