找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2435|回复: 13
打印 上一主题 下一主题
收起左侧

PIC单片机存储不足问题

[复制链接]
跳转到指定楼层
楼主
ID:990881 发表于 2021-12-16 09:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用的单片机型号为PIC12F1571,代码大概300多行,删掉一个调用的比较多的函数之后,能编译成功,用的MPLAB X IDE5.05,XC8(v2.30)


interrupt_manager.c:52:: warning: (1421) ignoring argument "high_priority" used by "__interrupt" attribute/specifier
:0:: error: (1347) can't find 0x13 words (0x13 withtotal) for psect "text16" in class "CODE" (largest unused contiguous range 0xA)
Non line specific message::: advisory: (1493) updated 32-bit floating-point routines might trigger "can't find space" messages appearing after updating to this release; consider using the smaller 24-bit floating-point types
:0:: error: (1347) can't find 0x10 words (0x10 withtotal) for psect "text20" in class "CODE" (largest unused contiguous range 0xA)
:0:: error: (1347) can't find 0x9 words (0x9 withtotal) for psect "text18" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x8 words (0x8 withtotal) for psect "text15" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x7 words (0x7 withtotal) for psect "text17" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x6 words (0x6 withtotal) for psect "text14" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x4 words (0x4 withtotal) for psect "text12" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x3 words (0x3 withtotal) for psect "text8" in class "CODE" (largest unused contiguous range 0x1)

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:979299 发表于 2021-12-16 11:16 | 只看该作者
光删除子函数不删除主函数里的调用会报错的,因为它找不到了,删除了不能保证程序的完整性还能用吗,只能精简部份,或者用外部存储,比如24C系列
回复

使用道具 举报

板凳
ID:401564 发表于 2021-12-16 12:43 | 只看该作者
程序内存不够你就删除函数?那要这函数来干嘛?
难道你是复制别人的代码吗?
PIC的编译环境很难搞,报错的话,你很多时候是不会像Keil那样能找到的
你只有严格按照C语言标准来写
回复

使用道具 举报

地板
ID:990881 发表于 2021-12-16 13:08 | 只看该作者
兴安xa 发表于 2021-12-16 11:16
光删除子函数不删除主函数里的调用会报错的,因为它找不到了,删除了不能保证程序的完整性还能用吗,只能精 ...

下面的报错,我复制百度之后,是因为存储不够的原因,如果我不用那个调用的函数程序功能就实现不了了,精简的话以我目前的水平已经到了极限了,代码真的很简单了,感谢您的建议,我会再去尝试精简代码的
回复

使用道具 举报

5#
ID:401564 发表于 2021-12-16 13:32 | 只看该作者
这个"CODE" 是怎么回事?不会是用了code来声明了吧?
回复

使用道具 举报

6#
ID:990881 发表于 2021-12-16 14:14 | 只看该作者
Y_G_G 发表于 2021-12-16 13:32
这个"CODE" 是怎么回事?不会是用了code来声明了吧?

:0:: error: (1347) can't find 0x10 words (0x10 withtotal) for psect "text20" in class "CODE" (largest unused contiguous range 0xA)
:0:: error: (1347) can't find 0x9 words (0x9 withtotal) for psect "text18" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x8 words (0x8 withtotal) for psect "text15" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x7 words (0x7 withtotal) for psect "text17" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x6 words (0x6 withtotal) for psect "text14" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x4 words (0x4 withtotal) for psect "text12" in class "CODE" (largest unused contiguous range 0x1)
:0:: error: (1347) can't find 0x3 words (0x3 withtotal) for psect "text8" in class "CODE" (largest unused contiguous range 0x1)



这些错误表示ROM (=闪存)内存不足。
这意味着正在使用的 PIC 的代码太多
回复

使用道具 举报

7#
ID:401564 发表于 2021-12-16 14:52 | 只看该作者
东方木青龙 发表于 2021-12-16 14:14
:0:: error: (1347) can't find 0x10 words (0x10 withtotal) for psect "text20" in class "CODE" (larg ...

搞半天咋就不把代码文件上传呢,我去运行试一下
回复

使用道具 举报

8#
ID:990881 发表于 2021-12-17 08:41 | 只看该作者
Y_G_G 发表于 2021-12-16 12:43
程序内存不够你就删除函数?那要这函数来干嘛?
难道你是复制别人的代码吗?
PIC的编译环境很难搞,报错的话, ...

我删除函数是因为排除编译器的问题,如果它什么都不写也报这个错误呢,是吧?程序确实不是我写的,我只是要改程序而已
回复

使用道具 举报

9#
ID:990881 发表于 2021-12-17 08:42 | 只看该作者
Y_G_G 发表于 2021-12-16 14:52
搞半天咋就不把代码文件上传呢,我去运行试一下

分块的,行我给弄一个文件里面
回复

使用道具 举报

10#
ID:990881 发表于 2021-12-17 08:58 | 只看该作者
#pragma config FOSC = INTOSC    // ->INTOSC oscillator; I/O function on CLKIN pin
#pragma config WDTE = ON    // Watchdog Timer Enable->WDT enabled
#pragma config PWRTE = OFF    // Power-up Timer Enable->PWRT disabled
#pragma config MCLRE = ON    // MCLR Pin Function Select->MCLR/VPP pin function is MCLR
#pragma config CP = OFF    // Flash Program Memory Code Protection->Program memory code protection is disabled
#pragma config BOREN = ON    // Brown-out Reset Enable->Brown-out Reset enabled
#pragma config CLKOUTEN = OFF    // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin

// CONFIG2
#pragma config WRT = OFF    // Flash Memory Self-Write Protection->Write protection off
#pragma config PLLEN = OFF    // PLL Enable->4x PLL disabled
#pragma config STVREN = ON    // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
#pragma config BORV = LO    // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.
#pragma config LPBOREN = OFF    // Low Power Brown-out Reset enable bit->LPBOR is disabled
#pragma config LVP = ON    // Low-Voltage Programming Enable->Low-voltage programming enabled

#include <xc.h>
//1. big board vishy mos
//2. small board Ao mos
#include "mcc.h"
static uint16_t adc_data=0;
static uint8_t adc_voltage=0;
static uint16_t pwm_data0=0;
static uint16_t power_data=0;
static uint16_t power_voltage=0;


uint16_t timer_100ms_flag=0;
uint8_t timer_10ms_flag=0;



void delay_proces (uint32_t delaytime)
{
     uint32_t cnt;
     cnt=delaytime;
     while(cnt--)
     {
          CLRWDT();
     }
}
void adc_process(void)
{
    uint16_t k;
    uint8_t i;
    k=0;
    for (i=0;i<16;i++)
    {
     k+=ADC1_GetConversion(3);
      CLRWDT();
         NOP();NOP();NOP();NOP();NOP();NOP();NOP();   
    }
   adc_data = k >> 4;
}
void power_process(void)
{
    uint32_t kk;
    kk = (uint32_t)adc_data * (uint32_t)33 * (uint32_t)25 * (uint32_t)10 / (uint32_t)1024;
    power_voltage = (uint16_t)(kk+80) / 10;
}


void get_pwm_data(void)
{
    uint32_t kk;//,kkm;
    if(timer_100ms_flag < 50)
    {
        kk = (uint32_t)((uint32_t)58 * (uint32_t)799);
        kk = ((uint32_t)kk / (uint32_t)power_voltage);
        //kk=((uint32_t)kk*(uint32_t)20/(uint32_t)10)+((uint32_t)power_voltage/90); //34W
        kk = ((uint32_t)kk * (uint32_t)16 / (uint32_t)10) + ((uint32_t)power_voltage / 90); //34W
        pwm_data0 = (uint16_t)kk + 2;  
        if( pwm_data0 > 799 )
        {
            pwm_data0 = 800;                     //full power pwm
        }
        if(power_voltage < 70)
        {           
           pwm_data0 = 0;
           kk = (power_voltage & 0x0f);
           delay_proces(kk * 16667);
           timer_100ms_flag = 0;
        }
        else if(power_voltage < 120)
        {
            pwm_data0 = 800;                           //full power pwm
        }
    }         
    else
    {     
        kk = (uint32_t)((uint32_t)131 * (uint32_t)799);
        kk = ((uint32_t)kk / (uint32_t)power_voltage) * (uint32_t)23 / (uint32_t)100 * (uint32_t) 2;
        if(power_voltage < 50)
        {
            if(timer_10ms_flag > 6)
            {
               PWM3_DutyCycleSet(0);
            }
        }
        else
        {
            timer_10ms_flag = 0;
            if( power_voltage < 122)
             {
                 kk = kk + 3 + 2 + 2;
             }  
            else if( power_voltage < 160)
            {
                kk = kk + 2 + 2;
            }
            else if( power_voltage < 246)
            {
                kk = kk + 2;
            }
            else if(power_voltage > 460 && power_voltage < 730)
            {
                kk = kk + 4;
            }
            else if(power_voltage >= 730)
            {
                pwm_data0=0;
            }  
            pwm_data0=kk+9;                                                        //?????????????
            if(pwm_data0>799)
            {
               pwm_data0=800;                       //full power pwm
            }
        }   
    }
}
void main(void)
{
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();

    while((power_voltage < 84) || (power_voltage > 730))
    {
      adc_process();                          //gather 16 adc-data,get the average
      PWM3_DutyCycleSet(pwm_data0);                        //get the power_voltage
      CLRWDT();
    }
    timer_100ms_flag = 0;
    while(timer_100ms_flag < 2)
    {
        CLRWDT();
    }
     //timer_2ms_flag=1;
    timer_100ms_flag = 0;
    while (1)
    {
        CLRWDT();  
        adc_process();
        power_process();
        get_pwm_data();
        PWM3_DutyCycleSet(pwm_data0);
    }
}
回复

使用道具 举报

11#
ID:415064 发表于 2021-12-17 09:45 | 只看该作者
就这么一点应该不至于
回复

使用道具 举报

12#
ID:962286 发表于 2021-12-17 09:54 | 只看该作者
东方木青龙 发表于 2021-12-17 08:58
#pragma config FOSC = INTOSC    // ->INTOSC oscillator; I/O function on CLKIN pin
#pragma config WD ...

PIC12F1571这颗料没有硬件乘法器,你代码中有一大堆大字节变量乘除法,非常占空间;另外你的XC8是不是lite模式的?
回复

使用道具 举报

13#
ID:990881 发表于 2021-12-17 16:44 | 只看该作者
MCU_FANS 发表于 2021-12-17 09:54
PIC12F1571这颗料没有硬件乘法器,你代码中有一大堆大字节变量乘除法,非常占空间;另外你的XC8是不是lit ...

没错,是这个原因
我将void get_pwm_data(void)函数中的大字节变量乘除法屏蔽之后,编译能通过
/*  kk = ((uint32_t)kk / (uint32_t)power_voltage);
      
        kk = ((uint32_t)kk * (uint32_t)16 / (uint32_t)10) + ((uint32_t)power_voltage / 90); //34W
      */
回复

使用道具 举报

14#
ID:990881 发表于 2021-12-17 16:54 | 只看该作者
MCU_FANS 发表于 2021-12-17 09:54
PIC12F1571这颗料没有硬件乘法器,你代码中有一大堆大字节变量乘除法,非常占空间;另外你的XC8是不是lit ...

我把所有常数的乘除法运算算好之后,再写入代码,就可以编译成功了,感谢大佬
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表