完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
12F63FoSC 8MHZI是一个C程序员,有29年的经验。这12F63是迄今为止我做过的最小的设备。附加固件是在XC8上用专业许可证开发的。它使用了97%的可用内存。在过去的3-4个星期里,我已经分配了很多东西来获得更多的空间。我已经用完很多次空间了,我把自己累坏了。我不能重新汇编整个项目-但我可以评论OutC代码行,并替换在线装配,以节省一些空间在这里和那里。如果你有一个XC8 PRO许可证,并编译了这个方法,并找到了一些方法来实际获得一些代码空间,我会欣赏一个消息。这个固件工作很复杂。它具有双向软UART,因此12F可以与另一微控制器集成。这是200000个微型逆变器已经制造和部署给业主的公司倒闭了。这个固件是非常复杂的。我花了6个月的时间才把它开发出来,它能工作。如果我能获得5到10%的代码空间,而不放弃当前编译的特性,那就太好了。也许还有一些事情可以做?我知道ASCII字符串占用代码空间——我从EPROM表中获取大部分代码空间。也许有人会看到一些可以获得更多空间的东西?此外,它的价值。我也有XC18编译器,但从来没有花时间看看它是否会编译得更好。我假设XC8是为那些像12F63这样的小芯片制造的。但如果你知道一些东西,我不想大声说出来。我还想指出一些关于ISR HANDER的事情,它正在把函数调用到另外3个子例程中。这些子例程不是出于两个原因而编排的。一个是它更容易阅读代码的方式。两个我测试了代码内联,它的大小差别不大。因为这个代码工作得不到任何好处,把它内联起来,用回传指令消除3个函数调用——代码空间是百分之一的1/2——如果我真的绝望了,那么我将使它内联。任何有用的反馈都会被赏识。丹尼斯路易斯密苏里美国
以上来自于百度翻译 以下为原文 12F683 FOSC 8mhz I'm a C programmer with 29 years experience this 12F683 is by far the smallest device I have ever done C work on. The attached firmware was deveoped on XC8 with a professional license. It uses 97% of available memory. Over the last 3-4 weeks I have already done allot of things to get more space. I have run out of space so many times that I have worn myself out cutting corners. I cant recode the whole project in assembly- But I can comment out C code lines and replace with in line assembly to save some space here and there. If you have an XC8 pro license and have compiled this and have found ways to actually gain some code space I'd appreciate a message with the changes. BTW this firmware works and is quite complicated. It has a bi directional soft UART so the 12F can be integrated with another micro controller. This is for 200,000 micro inverters already manufactured and deployed to home owners by a company that went out of business. This firmware is by far very complicated. It took 6 months of time to get this developed and it works. If I can gain 5 to 10% more code space without giving up the current features compiled in that would be nice. Maybe there are a few things that can be done? I know Ascii strings eat up code space - I'm getting most of them from an EPROM table. Maybe somebody will see some things that can gain some more space? Also, for what its worth. I also have the XC18 compiler but have never taken the time to see if it will compile any better. I am assuming the XC8 is made for these really small chips like the 12F683. But if you know something I don't please speak up. I would also like to point out something about the ISR hander It is making function calls to three other sub routines. Those sub routines are not compiled inline for for two reasons. One is its easier to read the code the way it is. Two I tested with the code inline and it made little difference in size. Since this code works great its not going gain anything putting it inline to eliminate 3 function calls with return instructions - The code space is 1/2 of one percent - If I get really desperate then I will make it inline. Any helpful feedback would be appreciated. Dan St Louis Missouri USA Attachment(s) LV_B_40.zip (91.98 KB) - downloaded 59 times |
|
相关推荐
19个回答
|
|
如果您想看到完全优化,可以激活EVE模式。此外,您可以租用完整的专业版,每月30美元。你可以得到一个更大的PIN兼容PIC,如果满足项目。
以上来自于百度翻译 以下为原文 You can activate eval mode if you want to see full optimization. Additionally you can rent the full pro version for $30 per month. You could just get a bigger pin compatible PIC if that satisfies the project. |
|
|
|
范数,1)我已经拥有专业版本2了,不可能有硬件更改。其中300000个小部件的制造成本为30000000(3000万美元),其中2/3个作为太阳能微型逆变器被出售并部署到全世界的家庭拥有者,这意味着仅仅是一个Flash更新。
以上来自于百度翻译 以下为原文 Norm, 1) I already have the professional version 2) There can be no hardware changes. 300,000 of these widgets were manufactured at a cost of 30,000,000 (30 million dollars), and 2/3 of them were sold and deployed to home owners all over the world as solar micro inverters This means to be a flash update only. |
|
|
|
尽可能保持清洁和简化代码。之后,转到汇编程序。
以上来自于百度翻译 以下为原文 Keep cleaning and simplifying the code while you can. After that, go to assembler. |
|
|
|
ASM或查看具有更多闪存的PIC12F1XXX。
以上来自于百度翻译 以下为原文 ASM or look into the PIC12F1xxx that has more flash memory. |
|
|
|
|
|
|
|
XC18?你是说C18吗?只有PIC18,所以PIC12就出来了。来自ISR的函数调用要求ISR存储更多的上下文加上调用和返回,因为您在搜索阶段,将代码直接放在ISR中可能是值得的。
以上来自于百度翻译 以下为原文 XC18? Do you mean C18? It's only for pic18 so the pic12 is right out. Function calls from an ISR require the ISR to store more context plus the call and return, and since you're at the scrounging stage it's probably worth it to put the code directly in the ISR |
|
|
|
第一个XC8不是为像PIC12F63这样的小内存目标做的,它只不过比大多数内存少。这是你所知道但已经忘记的:“PrtTF”的标准C库实现是对资源有限的目标的不合理的Buffice软件。因此,编写自己的PrtTF实现,只支持您需要的格式说明符。XC8将相同的常数字符串组合到单个对象中,因此尽可能避免使用几乎相同的字符串常量。将实现拆分为单独的语句。示例:并在可能的情况下减少或消除字符串常量。
以上来自于百度翻译 以下为原文 First XC8 is not made for small memory targets like the PIC12F683 it just sucks less than most. This is something you know but have forgotten: The standard C library implementation of "printf" is ungodly bloatware for resource limited targets. So write your own implementation of printf that supports only the format specifiers you need. XC8 will combine identical constant strings to a single object so avoid using nearly identical string constants when possible. Split the implementation in to separate statements. Example:/* Change this: */ printf("Volts: [%d]n",PV_volts); printf("Amps : [%d]n",PV_current); printf("Watts: [%d]n",PV_power); /* To this: */ printf("%s: [%d]n","Volts",PV_volts); printf("%s: [%d]n","Amps ",PV_current); printf("%s: [%d]n","Watts",PV_power); And where possible reduce or eliminate string constants. |
|
|
|
我只是很肤浅地看了一下,我的建议听起来可能很傻,但也许你可以节省一些空间,不需要在键盘部分中几乎两个相同的功能。当然,优化器不能区分你的PrTrF只有“…”的区别。
以上来自于百度翻译 以下为原文 I just took a very superficial look and my suggestion might sound silly, but maybe you can save some space by not needing 2x almost identical functions in the keyboard section. For sure the optimizer is not able to distinguish your printf having as only difference the "...". |
|
|
|
如果这是函数调用的唯一地方,XC8中的“全知”优化器只会嵌入代码。这就是为什么丹没有注意到这两个版本之间有很大差别的原因。
以上来自于百度翻译 以下为原文 If that's the only place the function is called, the "Omniscient" optimiser in XC8 will just inline the code. That will be why Dan didn't notice much difference between the two versions. |
|
|
|
事实上,通过重写这两个实例,实际上只从LV-Prim.CSO两个地方调用了Prtff。您可以节省5.6%的代码空间。&编辑;Gt;从POST 17中添加了这个建议:然后,在LVILeRevEnStrug中调用了库函数STRSTR。代码空间的3.6%。
以上来自于百度翻译 以下为原文 As it turns out printf is actually invoked from only two places in LV-Print.c So by rewriting those two instances you can save 5.6% of code space. /* Memory Summary: (Before modification) Program space used 7C1h ( 1985) of 800h words ( 96.9%) Data space used 6Bh ( 107) of 80h bytes ( 83.6%) EEPROM space used 100h ( 256) of 100h bytes (100.0%) Configuration bits used 0h ( 0) of 1h word ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) Memory Summary: (After modification) Program space used 73Ah ( 1850) of 800h words ( 90.3%) Data space used 5Fh ( 95) of 80h bytes ( 74.2%) EEPROM space used 100h ( 256) of 100h bytes (100.0%) Configuration bits used 0h ( 0) of 1h word ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) */ /* Functions in LV_Print.c that were modified */ void Eprom_Print_Value16(Uint8 pos, Uint16 value) { #if defined(USE_OLD_CODE) #else unsigned char v[5]; unsigned char vx; #endif put_eprom_str(pos); if (print_char) { putch('-'); putch(print_char); print_char = 0; } #if defined(USE_OLD_CODE) printf(":%d ",value); #else putch(':'); vx = 0; do { v[vx++] = '0' + (value % 10); value = value / 10; } while(value); do { putch(v[--vx]); } while(vx); putch(' '); #endif if (rcb1.POK) { Print_CR1(); PrintOK(); } rcb1.POK = 0; } void Print_Str() { #if defined(USE_OLD_CODE) printf("%s ",rxStr); #else char * pC; pC = rxStr; while (*pC) { putch(*pC); pC++; } #endif } Added this suggestion from post #17: Then there is the library function strstr invoked in LV_Receive_String.c Rewriting this instance you can save 3.6% of code space. /* Memory Summary: (Before modification) Program space used 73Bh ( 1851) of 800h words ( 90.4%) Data space used 5Fh ( 95) of 80h bytes ( 74.2%) EEPROM space used 100h ( 256) of 100h bytes (100.0%) Configuration bits used 0h ( 0) of 1h word ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) Memory Summary: (After modification) Program space used 6E1h ( 1761) of 800h words ( 86.0%) Data space used 5Fh ( 95) of 80h bytes ( 74.2%) EEPROM space used 100h ( 256) of 100h bytes (100.0%) Configuration bits used 0h ( 0) of 1h word ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) */ /* Functions in LV_Receive_String.c that were modified */ Uint8 str_compare(const char *s) { #if defined(USE_OLD_CODE) if (strstr(rxStr, s)==0) return 0; return 1; #else Uint8 Result = 0; const char *s2 = rxStr; while (!Result) { if(*s) { if(*s2) { Result = (*s++ == *s2++)?0:1; } else { Result = 1; } } else { break; } } return Result; #endif } |
|
|
|
XC8已经为你做到了这一点。在上面的代码中,将%d的不必要的使用更改为%u,并注意代码大小的减少。%s不是免费的,所以你必须权衡一下,看看它是否有帮助。
以上来自于百度翻译 以下为原文 XC8 already does that for you. In the above code, change the unnecessary use of %d to %u and notice the code size reduction. Maybe. %s is not free, so you'd have to do a trade-off to see if it helped. |
|
|
|
我还看到了一些其他的事情:在使用无符号字符的循环中不使用简单的“int”。许多特定的延迟例程,可以用编译器的内置例程来代替。使用位字段,节省RAM,但增加代码大小。
以上来自于百度翻译 以下为原文 Some other things I see: inappropriate use of plain "int" in loops where unsigned char could be used. Lots of ad-hoc delay routines that might be able to replaced with the compiler's built-in routine. Use of bit-fields, which save RAM, but increase code size. |
|
|
|
OPS代码有很多方法可以从大小循环迭代变量适当地改进到更高效的函数实现方法。但是,我确实反对使用编译器内置延迟程序的建议。在我的经验中,XC8内置延迟使用每个实例的代码空间,并且延迟时间必须是常数。需要多于一个延迟时间的应用程序或从多个函数中使用的XC8内置延迟会浪费代码空间。
以上来自于百度翻译 以下为原文 There are many ways that the OPs code could be improved from sizing loop iteration variables appropriately to more efficient function implementation methods. But I do take exception to your suggestion to use the compiler's built-in delay routine. In my experience the XC8 built-in delay uses code space for each instance and the delay time must be a constant. An application that needs more that one delay time or is used from more than one function the XC8 built-in delay wastes code space. |
|
|
|
不确定是否有用,黑客的一点……在StruxCube()中,而不是使用STRSTR,你只能比较几个字符,比如说第一个、第三个和最后一个(例如,调试用的dBG,RAMP1的RM1……查找第一个字符匹配并比较REST 2。当然,这意味着D?B?G将匹配调试,就像我说它是一个黑客毕竟。显示粗略更改后的92%个用法
以上来自于百度翻译 以下为原文 Not sure if helpful, bit of a hack... In str_compare() instead of using strstr you could compare only a few chars, lets say the first, third and last (e.g. DBG for DEBUG, RM1 for RAMP1... look for first char match and compare rest two). Of course this means the D?B?G would match DEBUG, like I said it a hack after all. Shows 92% usage for me after rough changes |
|
|
|
你可以尝试从10到8改变样本数,这样平均值可以用3个位置的简单移位来计算。或者直接使用10个样本的和。它仍然适合一个最大值为10230的整数。我也不确定你在这里做什么,但是任何可以避免数学函数的地方都可以节省空间:
以上来自于百度翻译 以下为原文 You might try changing NUMBER_OF_SAMPLES from 10 to 8, so that the average can be calculated with a simple shift of 3 places. Or maybe use the sum of 10 samples directly. It would still fit an integer with maximum value of 10230. Also I'm not sure what you are doing here, but anyplace you can avoid math functions can save space: // DGA calulate PV voltage from ADC reading - 72 cell potential divider less cbyte.tmpIntA = 460; if (pv_adc < 122) cbyte.tmpIntA = 450; cbyte.tmpIntB = (pv_adc *100) / cbyte.tmpIntA; |
|
|
|
去掉Struts()会有一个很好的保存:原件:修改(未经测试,确保PARAM S终止,而不是用终止符开始): 以上来自于百度翻译 以下为原文 Getting rid of strstr() results in an a good saving: Original:Program space used 7B8h ( 1976) of 800h words ( 96.5%) Data space used 6Bh ( 107) of 80h bytes ( 83.6%) Uint8 str_compare(const char *s) { if (strstr(rxStr, s)==0) return 0; return 1; } Modified (untested, make sure param s is terminated and does not start with a terminator):Program space used 751h ( 1873) of 800h words ( 91.5%) Data space used 6Bh ( 107) of 80h bytes ( 83.6%) Uint8 str_compare(const char *s) { const char * s2 = rxStr; do { if (*s == ' |