Autor Tema: Unresolved Extern Sprintf  (Leído 2895 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado D1to

  • PIC10
  • *
  • Mensajes: 39
Unresolved Extern Sprintf
« en: 29 de Enero de 2017, 21:18:55 »
Hola a todos,  Alguien podra ayudarme con el siguiente error, el compilador que uso es mikroC pro en un 16f877a. Cuando intento compilar el siguiente cod (lineas abajo), obtengo "unresolved extern sprintf" como error. Gracias de antemano.

Código: [Seleccionar]
// Conexiones del Modulo LCD
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;

void sprintf(char *buffer, const code char *f,...) ;

float variable ;
char buffer [5] ;
void main(){
 LCD_INIT();
 LCD_CMD(_LCD_CLEAR);
 variable = 123.542 ;

 while (1){
 sprintf(buffer, "%.1f",123.542);
 Lcd_Out(1, 1, buffer);
 delay_ms(10) ;
 }
}

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Unresolved Extern Sprintf
« Respuesta #1 en: 30 de Enero de 2017, 00:05:31 »
Para hacertela simple y concreta.

Código: C
  1. #include <stdio.h>
  2.  
  3. // Conexiones del Modulo LCD
  4. sbit LCD_RS at RB7_bit;
  5. sbit LCD_EN at RB6_bit;
  6. sbit LCD_D4 at RB5_bit;
  7. sbit LCD_D5 at RB4_bit;
  8. sbit LCD_D6 at RB3_bit;
  9. sbit LCD_D7 at RB2_bit;
  10. sbit LCD_RS_Direction at TRISB7_bit;
  11. sbit LCD_EN_Direction at TRISB6_bit;
  12. sbit LCD_D4_Direction at TRISB5_bit;
  13. sbit LCD_D5_Direction at TRISB4_bit;
  14. sbit LCD_D6_Direction at TRISB3_bit;
  15. sbit LCD_D7_Direction at TRISB2_bit;
  16.  
  17. float variable ;
  18. char buffer [5] ;
  19. void main(){
  20.  LCD_INIT();
  21.  LCD_CMD(_LCD_CLEAR);
  22.  variable = 123.542 ;
  23.  
  24.  while (1){
  25.  sprintf(buffer, "%.1f",123.542);
  26.  Lcd_Out(1, 1, buffer);
  27.  delay_ms(10) ;
  28.  }
  29. }

Le quite ese prototipo que le pusiste y le agregue el include. Por que la funcion sprintf es de stdio.h :

https://www.tutorialspoint.com/c_standard_library/stdio_h.htm

Desconectado D1to

  • PIC10
  • *
  • Mensajes: 39
Re:Unresolved Extern Sprintf
« Respuesta #2 en: 30 de Enero de 2017, 01:36:07 »
Ya había intentado hacerlo así y obtuve el siguiente error "Undeclared identifier 'sprintf' in expression", tal vez olvide algo, alguna idea?

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Unresolved Extern Sprintf
« Respuesta #3 en: 30 de Enero de 2017, 02:12:37 »
Revisando por internet dice esto:

Citar
Note: format string must be in the CONST area. sprintf function is not supported for p12 and p16 PIC MCU families.

Es decir que para PIC12xxxx y PIC16xxx no viene implementada la funcion sprintf.

Desconectado D1to

  • PIC10
  • *
  • Mensajes: 39
Re:Unresolved Extern Sprintf
« Respuesta #4 en: 30 de Enero de 2017, 02:23:02 »
Ouch, eso explicaría por q nada de lo que he intentado da resultados, que podría hacer en ese caso? mi objetivo es mostrar en pantalla números decimales por ejemplo 10.6 en función de una variable obviamente

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Unresolved Extern Sprintf
« Respuesta #5 en: 30 de Enero de 2017, 11:00:38 »
Podrias tratar de crear tu propia funcion.. Ejemplo:

Código: C
  1. float variable = 123.456;
  2. int entero;                     // Esto es 16bits
  3. char texto[10];                 // Aunque me paso tengo que darle lugar a el maximo numero que puede albergar con la coma, y posiblemente el signo.
  4. short int i;
  5.  
  6. // Supongo solo 1 decimal!
  7. entero = variable * 10;         // Esto me lo convierte en 1234 y lo guarda en entero.
  8. itoa(entero,texto);             // Ahora en texto tendria los valores {'1','2','3','4','\0'}, necesito agregarle la coma y estaria.
  9. i = strlen(texto);              // Largo del texto o posicion del '\0'
  10. texto[i] = texto[i-1];          // Corro mi decimal una posicion mas. Es decir quedaria: {'1','2','3','4','4'}
  11. texto[i-1] = '.';               // Le agrego el punto, quedando: {'1','2','3','.','4'}
  12. texto[i+1] = '\0';              //Finalmente le agrego el '\0', quedando: {'1','2','3','.','4','\0'}

itoa es de stdlib.h, espero que lo posea :P, sino hay que hacer la funcion de pasarlo de entero a ascii tambien.
Esta todo comentado para que entiendas que quise hacer.

Desconectado D1to

  • PIC10
  • *
  • Mensajes: 39
Re:Unresolved Extern Sprintf
« Respuesta #6 en: 30 de Enero de 2017, 17:01:19 »
Muchas gracias, voy a estudiar tu codigo y crear mi propia función.  :o  :o


 

anything