CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

rs232 in header
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 15, 2020 11:35 am     Reply with quote

You control which pin by the APFCON register.
If you look at the 'pin allocation table', you'll see 'Note 1:....." under the table.

Check out chapter 12.... Alternate pin functions. It will explain how to do it.

Jay
sebalitter



Joined: 05 May 2015
Posts: 47

View user's profile Send private message Send e-mail

out of rom
PostPosted: Tue Feb 18, 2020 9:04 am     Reply with quote

I have a restricted ROM. Someone has any ideas to solve this issue ?
Everything in the code is strictly necessary.
Quote:

Error#71 Out of ROM, A segment or the program is too large MAIN
Seg 00042-007FF, 0009 left, need 0009A
Seg 00000-00002, 0000 left, need 0009A Reserved
Seg 00003-00003, 0000 left, need 0009A
Seg 00004-00041, 0000 left, need 0009A Reserved


main.c //trifasic voltimeter with SMS alert.
Code:

#include "fases_header.h"
           
#INT_RDA
void  RDA_isr(void)
{
   dato_recibido[con_recepcion] = getchar(SERIAL_GSM);
   con_recepcion++;
   if(con_recepcion>30)
       con_recepcion=0;
}

#INT_EXT
void ext_isr()
{
   if(!alarma_disparada)        // if button action and was not pressed
   {
      alarma_disparada=TRUE;    // the button is now down
      sleep_mode=TRUE;        // activate sleep
      ext_int_edge(L_TO_H);   // change so interrupts on release
   }
   else                       // if button action and was pressed
   {
      alarma_disparada=FALSE;   // the button is now up
      sleep_mode=FALSE;       // reset sleep flag
      ext_int_edge(H_TO_L);   // change so interrupts on press
   }
   if(!input(ALARMA))         // keep button action sychronized with alarm flag
      alarma_disparada=FALSE;
   delay_ms(100);             // debounce button
}


void main (void)
{

    inicializacion();
   
    while(TRUE)
    {
        voltajes[0] = medir_voltaje(0);
        delay_ms(100);
        voltajes[1] = medir_voltaje(2);
        delay_ms(100);
        voltajes[2] = medir_voltaje(3);
        delay_ms(100);
       
        lcd_clear();  //Limpia el LCD
        lcd_gotoxy(0,1);
       
        printf(lcd_putc,"Vr %3.0lu  Vs %3.0lu  Vt %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
        delay_ms(3000);
           
        if(sleep_mode)          // if sleep flag set
            sleep();             // make processor sleep
       
        if(alarma_disparada)
            mandar_SMS();
    }
 
}

header.h
Code:

/*
 UART1 -> modulo GSM 
    Tx: Pin C4
    Rx: Pin C5

 * I2C display -> sda=PIN_C1 -  scl=PIN_C2
 
 */

#include <16F1823.h>

#device adc=10
//#device PASS_STRINGS = IN_RAM
 /*
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOMCLR                   //Master Clear pin enabled

#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
*/
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP,NOMCLR,LP

#use fast_io(A)
#use fast_io(C)

#use delay(clock=1M)            //Configuracion reloj interno

//#pin_select U1RX = PIN_C3

#use rs232(UART1, BAUD=9600, PARITY=N, BITS=8, stream=SERIAL_GSM , errors)
#use i2c(Master,Fast=100000, sda=PIN_C1, scl=PIN_C2,force_sw)

#include <i2c_Flex_LCD.c>

#define PROM 1500

#define ALARMA PIN_C3
#define BOTON PIN_C0

int16 voltajes[3];
char dato_recibido[10]; // Buffer de recepciĆ³n
int con_recepcion=0;
int16 cant_sms_mandados=0;
short sleep_mode, alarma_disparada = FALSE;

void inicializacionSIM800L(void)
{
    int cont;

    cant_sms_mandados=0;
    delay_ms(1000);
    puts("A",SERIAL_GSM);  //para sincronizar el baudrate del SIM 900
    delay_ms(300);
    putchar(0x0d,SERIAL_GSM);
    delay_ms(3000);

    for(cont=0;cont<5;cont++)   // mando varios AT para el autobauding
    {
        puts("AT",SERIAL_GSM);
        delay_ms(300);
        putchar(0x0d,SERIAL_GSM);
        delay_ms(200);
    }

    puts("AT+CMGF=1\r",SERIAL_GSM);  // configuro para que trabaje en modo texto
    delay_ms(1000);
    puts("AT+CREG=1\r",SERIAL_GSM);  // configuro para que trabaje en GSM
    delay_ms(1000);
   
    putchar(0x0d,SERIAL_GSM);
    delay_ms(4000);
    puts("AT+CREG?\r",SERIAL_GSM);  // Seleccionor modo
    delay_ms(400);
    puts("AT+CMEE?\r",SERIAL_GSM);  // Seleccionor modo texto
    delay_ms(400);
    puts("AT+CBAND=\"ALL_BAND\"\r",SERIAL_GSM);  // Seleccionor modo texto
}

void inicializacion(){
   
   //modificar pines I/O  ENTRADAS -> A0,A2,A4,C0,C3,C5,    SALIDAS -> C1,C2,C4, 
   set_tris_a(0b10101000);
   set_tris_c(0b10010100);
   
   ext_int_edge(H_TO_L);      // init interrupt triggering for alarm activation
   enable_interrupts(INT_EXT);// turn on interrupts
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_adc_ports(sAN0|sAN2|sAN3);     
   setup_adc(ADC_CLOCK_DIV_2);
   
   delay_ms(100);
 
    lcd_init();
    lcd_backlight_led(ON); //Enciende la luz de Fondo
    inicializacionSIM800L();
   
    lcd_clear();  //Limpia el LCD
   
    lcd_gotoxy(0,1);
    printf(lcd_putc," INICIANDO..");
}


void mandar_SMS() 
{   
    delay_ms(300);
    fprintf(SERIAL_GSM,"AT+CMGF=1\r\n");  //  text mode
    delay_ms(500); 
   
    fprintf(SERIAL_GSM, "AT+CMGS=\"1544556611\"\r");
   
    delay_ms(300);
   
    fprintf(SERIAL_GSM,"\n\r Vr: %3.0lu  \n\r Vs :%3.0lu \n\r Vt: %3.0lu",voltajes[0], voltajes[1], voltajes[2]);

    delay_ms(100);
    putchar(0x1a,SERIAL_GSM);
}

int16 medir_voltaje(int8 channel)
{
    int32 acum=0;
    int16 i=0;

    for(i=0;i<PROM;i++)
        { 
         set_adc_channel(channel);
         delay_us(100);
         acum+=read_adc();
        }   

    return ((acum/PROM)*3.594);
}
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 18, 2020 10:30 am     Reply with quote

re: #pin_select U1RX = PIN_C3

That PIC doe NOT have PIN SELECT feature !

Please see the datasheet...APFCON register... You simply set/clear the appropriate bit to change the pin usage.
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 18, 2020 11:31 am     Reply with quote

you might save some memory by creating a common 'delay' function.
..mydelayms( x);

where main() calls the function with a delay value

I'm assuming currently every delay_ms(nn) is creating inline code...
the listing will show what's happening....

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 18, 2020 11:31 am     Reply with quote

Quote:
void inicializacion(){

//modificar pines I/O ENTRADAS -> A0,A2,A4,C0,C3,C5, SALIDAS -> C1,C2,C4,
set_tris_a(0b10101000);
set_tris_c(0b10010100);

ext_int_edge(H_TO_L); // init interrupt triggering for alarm activation
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
setup_adc_ports(sAN0|sAN2|sAN3);
setup_adc(ADC_CLOCK_DIV_2);

According to the 16F1823 data sheet, the analog pins you have listed
above are on these pins:
sAN0 is on RA0
sAN2 is on RA2
sAN3 is on RA4

But you have setup the TRIS on those pins like this:
Quote:
set_tris_a(0b10101000);

The line above sets:
RA0 = digitial output
RA2 = digital output
RA4 = digital output

You can't read analog input voltage on pins setup as a digital outputs.
Fix the TRIS.

----------------------------------------
With regard to your ROM usage problem, I cut out the line in bold below
and then it compiles:
Quote:

void mandar_SMS()
{
delay_ms(300);
fprintf(SERIAL_GSM,"AT+CMGF=1\r\n"); // text mode
delay_ms(500);

fprintf(SERIAL_GSM, "AT+CMGS=\"1544556611\"\r");

delay_ms(300);

// fprintf(SERIAL_GSM,"\n\r Vr: %3.0lu \n\r Vs :%3.0lu \n\r Vt: %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
delay_ms(100);
putchar(0x1a,SERIAL_GSM);
}

Then the .LST file says at the top:
Quote:

CCS PCM C Compiler, Version 5.092, xxxxx 18-Feb-20 12:05

ROM used: 1938 words (95%)
Largest free fragment is 110
RAM used: 41 (32%) at main() level
92 (72%) worst case
Stack used: 8 locations (6 in main + 2 for interrupts)
Stack size: 16

So the fprintf() line takes up more space than is free above.
Your program needs to be shortened. By carefully looking at the .LST
file and finding some way to reduce certain routines, it may be possible
to fit your program in the 2K space. It would be easier to find a similar
PIC that has more ROM space than just the 2K in the 16F1823.
Ttelmah



Joined: 11 Mar 2010
Posts: 19730

View user's profile Send private message

PostPosted: Wed Feb 19, 2020 4:09 am     Reply with quote

You need to rethink what chip you are using.
Normally the answer can be to split code up to allow it to fit better.
However in this case you are simply running out of space. Compiling
without the fprintf here, gives 97% ROM used. No way the fprintf is
going to fit. You _need_ a bigger chip to do what you are trying to do.
At the end of the day the PIC18F1825 has 4* the ROM, while the PIC16F18324
has double the ROM and is actually cheaper.
As a comment you could save a little ROM if you changed your device
layout so the I2C was on the hardware PINs. Hardware functions use
less ROM that software functions.
temtronic



Joined: 01 Jul 2010
Posts: 9425
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 19, 2020 9:10 am     Reply with quote

Have to agree with Mr. T... go big or go home....

I always get the biggest PIC in the family or series,.currently I do 99% of my products with the 18F46K22. Yes, overkill, but there's ALWAYS more code to cut, just 2 more LEDs, a 2nd HW UART required.....clients think of this stuff AFTER you've got a month or two into the project. Sad
One benefit of using a 'too big PIC', is that after the final code is cut, THEN you can see IF a smaller PIC is worthwhile. Reducing a PCB by 1 or 2 square inches really doesn't save much money overall. Using a 'big PIC' does allow you to have a custom library of code you can easily use for other projects.

Now there may be ways to reduce your codespace to get to fit into that PIC but factor in the R&D cost (time) and a bigger PIC will almost always be cheaper.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group