原创 CCS 编译器的数组下标不能大于128 的解决方法

2009-4-5 13:27 4288 6 8 分类: MCU/ 嵌入式

一数组有172个元素,在CCS平台下要分两个数组才能完整查找:例子如下


#include <16F877A.h>
#device adc="8"


#FUSES NOWDT        //No Watch Dog Timer
#FUSES HS              //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected


#use delay(clock=4000000)
#use rs232(UART1,baud=9600,parity=N,bits=8)


const unsigned int16 sinetable1[] =


    {999,201,401,602,803,1003,1204,1404,1605,1805,
    2005,2206,2406,2606,2806,3006,3205,3405,3605,3804,4003,4202,4401,4600,
    4799,4997,5195,5393,5591,5789,5986,6183,6380,6577,6773,6970,7166,7361,
    7557,7752,7947,8141,8335,8529,8723,8916,9109,9302,9494,9686,9877,10068,
    10259,10449,10639,10829,11018,11207,11395,11583,11771,11958,12144,
    12331,12516,12701,12886,13070,13254,13437,13620,13802,13984,14165,
    14346,14526,14706,14885,15063,15241,15419,15595,15772,15947,16122,
    16297,16470,16643,16816,16988,17159,17330,17500,17669,17838,18006,
    18173,18340,18506,18671,18835,18999,19162,19325,19487,19647,19808,
    19967,20126,20284,20441,20598,20753,20908,21062,21216,21368,21520,
    21671,21821,21970,22119,22266,22413,22559,22704,22848,22992};


const unsigned int16 sinetable2[] =


    {23134,23276,23417,23557,23696,23834,23971,24107,24243,24377,24511,


    24644,24776,24906,25036,25165,25293,25420,25547,25672,25796,25919,


    26042,26163,26283,26403,26521,26638,26755,26870,26984,27098,27210,


    27321,27431,27541,27649,27756,27862,27967,28071,28174,28276,28377};


unsigned int16 Speed,Amplitude;
unsigned int8 Phase;


void main()
{


   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);



   Speed="64";

   while(TRUE){
   delay_ms(80);
  
   Phase +=Speed;
   if (Phase>171) Phase="Phase-171";
   if (Phase >=128 )
         Amplitude="sinetable2"[Phase-128];
   if (Phase<128)
         Amplitude="sinetable1"[Phase];
   printf("\r\n");
   printf("Phase %u  ",Phase);
   printf("Amplitude %Lu\r\n",Amplitude);
  }


}

PARTNER CONTENT

文章评论2条评论)

登录后参与讨论

michael_xing 2013-11-21 08:54

看看这篇写的如何?借鉴一下,原创不是我哦。http://blog.sina.com.cn/s/blog_68d730130100jr5s.html

michael_xing 2013-11-21 08:49

我感觉,应该有更好的方法来解决这个问题的。比如说将数据换个地方存储。
相关推荐阅读
用户816647 2013-04-15 08:43
PIC16F877A I2C 24C02 24C01 模拟端口
  #include <16F877A.h> #device adc=8   #FUSES NOWDT                    //No Watch Do...
用户816647 2011-11-14 10:35
三菱FX系列PLC手册
工控下载 - 首页 http://down.ymmfa.com/?type=fx 资料名称及链接 所需积分 ...
用户816647 2011-06-25 11:25
六个元件取3V---50V
其中你想要多少电压,D3  D4  选用相应的稳压二极管就可以。...
用户816647 2011-06-17 17:11
成功开发EMC扫频仪
扫频范围  2G  ...
用户816647 2011-04-24 22:01
网友的 USB 开发相关资料
PIC USB 相关网站 主要是mcuee网友收集的。 http://forum.microchip.com/tm.aspx?m=123533 PIC USB related web sites 转贴...
用户816647 2011-04-22 10:05
关于 CHM 文件不能打开或打开后没有索引列表的解决方法
总结方法可以尝试 regsvr32 hhctrl.ocx regsvr32 itss.dll regsvr32 itircl.dll      //  这个很重要,是关于全文搜索的...
EE直播间
更多
我要评论
2
6
关闭 站长推荐上一条 /3 下一条