Autor Tema: LCD PICDEM 2 PLUS  (Leído 5496 veces)

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

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
LCD PICDEM 2 PLUS
« en: 16 de Mayo de 2008, 11:39:16 »
Hola de nuevo amigos;

Tengo una placa de entrenamiento PICDEM 2 PLUS y llevo varios dias intentando hacer funcionar el LCD pero no hay manera, he mirado los exemplos de examples, un monton en la red y no hay manera de que aparezca texto en el lcd no se si es culpa de que solo son 4 bits de datos o que pero la cuestion es que no se por donde empezar.

Hos detallo las caracteristicas del motaje:

PIC 16F877a (40 patillas)
PICDEM 2 PLUS DEMO BOARD
MPLAB  8.0, MPLAB ICD 2

LCD:

Dos lineas de 16 caracteres cada una.
Tres lineas de control (RD4, RD5, RD6) que son (RS, R/W, E) respectivamente.
Cuatro lineas de datos (RD0, RD1, RD2, RD3).

Haber si alguien que haya programado en el lcd de esta placa me puede enviar un ejemplo, cualquier cosa, para que pueda introducir texto y verlo por el lcd.

Muchas gracias.

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #1 en: 16 de Mayo de 2008, 12:31:41 »
Saludos.

Con que compilador trabajas?
La configuracion de los pines para el uso de la LCD en la libreria del C18 es diferente a la del CCS.

Si la LCD no muestra nada de nada, debes probar mover el potenciometro de contraste que trae la tarjeta y si al dar el contraste maximo en la primera linea aparecen todos los cuadritos negritos, es porque el programa esta mal hecho ( habria que revisar los pines conectados con los de la libreria).

Chao
El papel lo aguanta todo

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
Re: LCD PICDEM 2 PLUS
« Respuesta #2 en: 17 de Mayo de 2008, 04:34:00 »
Gracias por la respuesta.

Utilizo CCS C Compiler.

No es lo del potenciometro para regular el contraste del lcd ya lo probé.

Lo que busco es alguien que me pueda pasar un programa a modo de ejemplo que sepa que funciona con esta placa y este PIC para poder ver yo como se hace, me bastaria con un programa que mandará un "hola" al lcd.

Gracias de nuevo.

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #3 en: 17 de Mayo de 2008, 12:45:31 »
Hola

Prueba con lo que te envio a ver que pasa.

Saludos.
El papel lo aguanta todo

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
Re: LCD PICDEM 2 PLUS
« Respuesta #4 en: 18 de Mayo de 2008, 05:47:57 »
Gracias compañero, pero me sigue sin funcionar, por ejemplo en este que me has enviado me aparecen los siguientes errores al intentarlo compilar:


#include<18F452.h>
#fuses XT
#use delay(clock=4M)

#include "LCDD.C"

#define SYMBOL_1   0
#define SYMBOL_2   1
#define SYMBOL_3   2
#define S_RIGHT      3
#define S_LEFT      4
#define S_UP      5
#define S_DOWN      6

char data_symbol_1[7]       = {0b11111, 0b10001, 0b1010, 0b100, 0b1110, 0b11111, 0b11111};
char data_symbol_2[7]      = {0x0e, 0x07, 0x03, 0x01, 0x03, 0x07, 0x0e};
char data_symbol_3[7]       = {0x00, 0x0f, 0x1f, 0x01, 0x1f, 0x0f, 0x00};
char data_symbol_right[7]    = {0x08, 0x0c, 0x0e, 0x0f, 0x0e, 0x0c, 0x08};
char data_symbol_left[7]    = {0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02};
char data_symbol_up[7]       = {0x00, 0x04, 0x04, 0x0e, 0x0e, 0x0e, 0x1f};
char data_symbol_down[7]    = {0x1f, 0x0e, 0x0e, 0x0e, 0x04, 0x04, 0x00};

void simbolos (void)
{
   int8 i;

   lcd_init();
   lcd_command(LCD_OFF);
   lcd_putc(SYMBOL_1);
   lcd_command(CGRAM);
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_1);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_2);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_3);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_right);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_left);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_up);   }
   for(i=0;i<=7;i++)
   {   lcd_send_byte(1, data_symbol_down);   }
}

void main (void)
{
   simbolos();
   lcd_init();
 while(true)
 {
   lcd_gotoxy(1,1);
   lcd_putc("W/c");
   lcd_putc(SYMBOL_1);
   lcd_putc(SYMBOL_2);
   lcd_putc(SYMBOL_3);
   lcd_putc(S_RIGHT);
   lcd_putc(S_LEFT);
   lcd_putc(S_UP);
   lcd_putc(S_DOWN);
 }
}






Executing: "C:\Program files\Picc\CCSC.exe" +FM "lcd.c" +DC +LN +T +A +M -Z +Y=9 +EA
*** Error 24 "C:\PROGRA~1\PICC\devices\18F452.h" Line 0(0,0): Unknown device type
*** Error 100 "lcd.c" Line 192(21,26): USE parameter value is out of range   Expecting number: 4M
*** Error 18 "lcd.c" Line 192(21,26): File can not be opened
    Not in local "D:\tarjeta\8 - LCD\LCDD.C"
    Not in "C:\PROGRA~1\PICC\devices\LCDD.C"
    Not in "C:\PROGRA~1\PICC\drivers\LCDD.C"
*** Error 12 "lcd.c" Line 27(1,9): Undefined identifier  lcd_init
*** Error 12 "lcd.c" Line 28(1,12): Undefined identifier  lcd_command
*** Error 12 "lcd.c" Line 29(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 30(1,12): Undefined identifier  lcd_command
*** Error 12 "lcd.c" Line 32(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 34(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 36(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 38(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 40(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 42(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 44(2,15): Undefined identifier  lcd_send_byte
*** Error 12 "lcd.c" Line 50(1,9): Undefined identifier  lcd_init
*** Error 12 "lcd.c" Line 53(1,11): Undefined identifier  lcd_gotoxy
*** Error 12 "lcd.c" Line 54(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 55(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 56(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 57(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 58(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 59(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 60(1,9): Undefined identifier  lcd_putc
*** Error 12 "lcd.c" Line 61(1,9): Undefined identifier  lcd_putc
      24 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Sun May 18 10:41:22 2008


No se que hacer,

Gracias!!

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #5 en: 18 de Mayo de 2008, 14:35:51 »
 :shock: :shock: :shock:

Ok... veamos
Citar
Error 24 "C:\PROGRA~1\PICC\devices\18F452.h" Line 0(0,0): Unknown device type
El primer error es porque no tienes el .h correspondiente al pic 18F452, me parece muy raro!!!!, normalmente esos archivos vienen con el compilador. Seria bueno que le heches una ojeada a la carpeta "devices" ( Q version del CCS tienes?? )

Citar
Error 100 "lcd.c" Line 192(21,26): USE parameter value is out of range   Expecting number: 4M
El segundo es porque no reconoce el factor 4M ( Q version del CCS tienes??  :mrgreen: )

Citar
Error 18 "lcd.c" Line 192(21,26): File can not be opened
El tercero dice que no puede abrir la libreria lcd.c y yo no estoy usando esa libreria, estoy usando la LCDD.C que te envie tambien.

Citar
Not in local "D:\tarjeta\8 - LCD\LCDD.C"
    Not in "C:\PROGRA~1\PICC\devices\LCDD.C"
    Not in "C:\PROGRA~1\PICC\drivers\LCDD.C"
No esta el archivo LCDD.C en la ruta que ahi dice y por eso te genera los demas errores, ya que dentro de esa libreria se definen todas las funciones que aparecen despues.

Citar
"C:\Program files\Picc\CCSC.exe" +FM "lcd.c" +DC +LN +T +A +M -Z +Y=9 +EA

Me parece raro que este "lcd.c" en esa ruta!!! no debe aparecer ahi!!!!! quitalo a ver que pasa. Esas letricas indican los archivos de salida que va a generar el CCS y me parece rarisimo que este ese "lcd.c" en esa ruta!!!!  :D Depronto fue que te metiste al "Inherit Global Settings" y por ahi soltaste el Ctrl+v y claro!!!!! se metio!!!!!.

Corrige esa ultima parte en el MPLAB y vuelve a compilar a ver que sucede.

Saludos
El papel lo aguanta todo

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #6 en: 18 de Mayo de 2008, 19:38:27 »
hola

Pues he compilado un ejemplo ( colocando mas atencion a la ventana de mensajes   :roll: ) y a mi me sale lo siguiente:

Executing: "C:\Archivos de programa\PICC\Ccsc.exe" +FH "lcd2x16.c" +DF +LN +T +A +M +Z +Y=9 +EA
      Memory usage:   ROM=3%      RAM=4% - 4%
      0 Errors,  0 Warnings.
Loaded D:\acces\ccs_c\lcd\lcd2x16\lcd2x16.cof.
BUILD SUCCEEDED: Sun May 18 17:34:58 2008



Olvida lo que te dije de revisar las opciones del "Inherit Global Settings", fue error mio el no prestar mas atencion al mensaje ( claro que la configuracion del compilador que tengo es diferente ). Pero si deberias revisar la carpeta de "devices" del compilador ya que pareciera que falta el archivo .h.

Saludos
El papel lo aguanta todo

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
Re: LCD PICDEM 2 PLUS
« Respuesta #7 en: 21 de Mayo de 2008, 15:00:32 »
Muchas gracias por las respuestas.

Al final lo consegui con esto, si a alguien le puede servir ahy esta;),solo hay que cambiar los pines de datos y control dependiendo de los que utilice nuestro lcd.




#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c"
   
//==========================

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_A1
#define LCD_RS    PIN_A3
#define LCD_RW    PIN_A2

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

#define USE_LCD_RW   1     

//========================================

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line


int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                    // Display on
 1,                      // Clear display
 6                       // Increment cursor
 };
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).
 output_bit(LCD_DB4, !!(nibble & 1));
 output_bit(LCD_DB5, !!(nibble & 2)); 
 output_bit(LCD_DB6, !!(nibble & 4));   
 output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 output_high(LCD_E);
 delay_us(2);
 output_low(LCD_E);
}

//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine.  For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.     

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3

retval = 0;
   
output_high(LCD_E);
delay_cycles(1);

retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
 
output_low(LCD_E);
   
return(retval);   
}   
#endif

//---------------------------------------
// Read a byte from the LCD and return it.

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;

output_high(LCD_RW);
delay_cycles(1);

high = lcd_read_nibble();

low = lcd_read_nibble();

return( (high<<4) | low);
}
#endif

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60); 
#endif

if(address)
   output_high(LCD_RS);
else
   output_low(LCD_RS);
     
 delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_E);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_E);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING);
   
    // If the R/W signal is not used, then
    // the busy bit can't be polled.  One of
    // the init commands takes longer than
    // the hard-coded delay of 60 us, so in
    // that case, lets just do a 5 ms delay
    // after all four of them.
    #ifndef USE_LCD_RW
    delay_ms(5);
    #endif
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}

//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;

lcd_gotoxy(x,y);

// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7)); 

output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);

return(value);
}
#endif

   
//Aqui el programa principal
 
void main()
{
lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}


Esta extraido de http://www.ccsinfo.com.

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
Re: LCD PICDEM 2 PLUS
« Respuesta #8 en: 21 de Mayo de 2008, 15:12:09 »
Ahora me surge otro problema, tengo el conversor analogico digital, y deseo que la lectura que hace del potenciometro (de 0 a 5V) se vea reflejada en el LCD, he desarollado el programa que pongo a continucacion pero no se como mandar la lectura al lcd, alguien me puede ayudar?

Saludos

#include <16f877a.h>

#fuses XT,NOWDT,PUT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NOWRT

#use delay (clock = 4000000)

#define LCD_POWER  PIN_D7


#define LCD_EN        PIN_D6
#define LCD_RS        PIN_D4
#define LCD_DB4       PIN_D0
#define LCD_DB5       PIN_D1
#define LCD_DB6       PIN_D2
#define LCD_DB7       PIN_D3
#define LCD_RW         PIN_D5

#define lcd_type 2                                   // 0=5x7, 1=5x10, 2=2 lineas
#define lcd_line_two 0x40                              // LCD RAM direccion para la 2ª linea.

int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2),                            // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                                               // Display on
 1,                                                 // Clear display
 6                                                  // Increment cursor
 };

void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).
 output_bit(LCD_DB4, !!(nibble & 1));
 output_bit(LCD_DB5, !!(nibble & 2)); 
 output_bit(LCD_DB6, !!(nibble & 4));   
 output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 output_high(LCD_EN);
 delay_us(2);
 output_low(LCD_EN);
}

void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60); 
#endif

if(address)
   output_high(LCD_RS);
else
   output_low(LCD_RS);
     
 delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_EN);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_EN);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING);
   
    // If the R/W signal is not used, then
    // the busy bit can't be polled.  One of
    // the init commands takes longer than
    // the hard-coded delay of 60 us, so in
    // that case, lets just do a 5 ms delay
    // after all four of them.
    #ifndef USE_LCD_RW
    delay_ms(5);
    #endif
   }

}
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}
       
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;

lcd_gotoxy(x,y);

// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7)); 

output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);

return(value);
}
#endif


#use fast_io(A)
#use fast_io(B)

int a;                                 //definimos las variables como numeros enteros.

void main()
{
set_tris_a(0x3F);                        //Puerta A como entradas.
set_tris_b(0x00);                        //Puerta B con 8 E/S, las define como salidas.

output_B(0x00);                           //Ponemos todas las patillas de la puerta B a nivel bajo (0v.

   setup_adc_ports (RA0_ANALOG );            //Definimos solo la entrada RA0 como analogica.
   setup_adc(ADC_CLOCK_INTERNAL );            //Le asignamos el reloj interno.
   set_adc_channel (0);                  //Le asignamos el canal 0 (RA0/AN0)   


while(1)               //
{                     
   delay_ms( 100 );         //Es preciso esperar un corto espacio de tiempo despues de configurar el canal Esperamos 50 ms.
   a = read_adc ();         //ADC_START_AND_READ por defecto.
   
   delay_ms(5000);
   output_high(LCD_POWER);  // Turn on power to LCD
   output_low(LCD_RW);      // Set R/W pin on LCD to a low level

   lcd_init();              // Initialize the LCD

   lcd_putc("\"a"\n");
   
}
}


Fijaros a partir del while,  dentro del lcd_putc no se que tengo qeu poner.

Gracias de nuevo

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #9 en: 21 de Mayo de 2008, 17:00:04 »
Hola.

Mira, las funciones que estas colocando en el programa principal no deben ir ya que estan incluidas en la libreria ( ya lo he dicho antes )
Citar
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c" \\aqui ya estan definidas toooodas las funciones que colocas despues

Deberias quitarlas ya que las estas definiendo dos veces!!!!!!

Para sacar la info por la LCD usas el printf de la siguiente manera

Código: [Seleccionar]
void main (void)
{
 ....
 while(true)
 {
  a = read_adc();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "V = %3.1f v ", a * 0.01961);
 }
}

Estoy suponiendo que la conversion es a 8 bits, si no has configurado eso, debes hacerlo asi:

Código: [Seleccionar]
#include<16F877.h>
#device adc=8


El numero es la resolucion de la conversion, la cual esta definida por el voltaje de referencia y el numero de bits de resolucion.

resolucion = Vref / 2n

El " %3.1f" define el tipo de formato de salida f de float, 1 cifra decimal.

Saludos
El papel lo aguanta todo

Desconectado kcire

  • Colaborador
  • PIC12
  • *****
  • Mensajes: 84
Re: LCD PICDEM 2 PLUS
« Respuesta #10 en: 23 de Mayo de 2008, 16:59:44 »
carlekes con respecto a tu duda sobre el ADC, adjunto una simulación en Proteus que espero te
ayude bueno espero tus comentarios.

Saludos
"La imaginación es más rica que el lenguaje... sugiere con palabras, la imaginación podrá hacer el resto."

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: LCD PICDEM 2 PLUS
« Respuesta #11 en: 23 de Mayo de 2008, 17:04:45 »
carlekes con respecto a tu duda sobre el ADC, adjunto una simulación en Proteus que espero te
ayude bueno espero tus comentarios.

Saludos

Falto que lo pusieras en amarillo oscuro asi no lo ve nadie que tenga el fondo de ese color... :shock:
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado kcire

  • Colaborador
  • PIC12
  • *****
  • Mensajes: 84
Re: LCD PICDEM 2 PLUS
« Respuesta #12 en: 23 de Mayo de 2008, 18:02:03 »
Si MGLSOFT mil disculpas la verdad soy nuevo y lamentablemente no me fije bien.
Perdon procurare en otra no cometer el mismo error. Gracias por el comentario
"La imaginación es más rica que el lenguaje... sugiere con palabras, la imaginación podrá hacer el resto."

Desconectado carlekes

  • PIC10
  • *
  • Mensajes: 14
Re: LCD PICDEM 2 PLUS
« Respuesta #13 en: 26 de Mayo de 2008, 16:15:47 »
Hola.

Mira, las funciones que estas colocando en el programa principal no deben ir ya que estan incluidas en la libreria ( ya lo he dicho antes )
Citar
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#include "flex_lcd.c" \\aqui ya estan definidas toooodas las funciones que colocas despues

Deberias quitarlas ya que las estas definiendo dos veces!!!!!!

Para sacar la info por la LCD usas el printf de la siguiente manera

Código: [Seleccionar]
void main (void)
{
 ....
 while(true)
 {
  a = read_adc();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "V = %3.1f v ", a * 0.01961);
 }
}

Estoy suponiendo que la conversion es a 8 bits, si no has configurado eso, debes hacerlo asi:

Código: [Seleccionar]
#include<16F877.h>
#device adc=8


El numero es la resolucion de la conversion, la cual esta definida por el voltaje de referencia y el numero de bits de resolucion.

resolucion = Vref / 2n

El " %3.1f" define el tipo de formato de salida f de float, 1 cifra decimal.

Saludos

Muchas gracias Nilo, el tema de la resolucion de 8 bits no lo publique bien pero asi lo tenia, pero no entiendo una cosa, yo si pongo #include "flex_lcd.c" a la hora de compilar me sale un error que dice que yo no tengo esas librerias, utilizo el compilador CCs PIC C version 3.15, que es lo que tengo que utilizar?

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: LCD PICDEM 2 PLUS
« Respuesta #14 en: 26 de Mayo de 2008, 16:46:42 »
Hola amigo.

Lo que tienes que hacer es copiar todas esas funciones de la LCD en otro archivo al que llamaras flex_lcd.C y este archivo debe ir en la misma carpeta donde esta tu archivo principal, el main.

Si esta bien posteada, la libreria de la LCD seria lo siguiente:

Código: [Seleccionar]
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7

#define LCD_RS PIN_C0
#define LCD_RW PIN_C1
#define LCD_E  PIN_C2

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

#define USE_LCD_RW 1

//========================================

#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line


int8 const LCD_INIT_STRING[4] =
{
  0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
  0xc, // Display on
  1, // Clear display
  6 // Increment cursor
};


//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
  // Note: !! converts an integer expression
  // to a boolean (1 or 0).
  output_bit(LCD_DB4, !!(nibble & 1));
  output_bit(LCD_DB5, !!(nibble & 2));
  output_bit(LCD_DB6, !!(nibble & 4));
  output_bit(LCD_DB7, !!(nibble & 8));

  delay_cycles(1);
  output_high(LCD_E);
  delay_us(2);
  output_low(LCD_E);
}

//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
  int8 retval;
  // Create bit variables so that we can easily set
  // individual bits in the retval variable.
  #bit retval_0 = retval.0
  #bit retval_1 = retval.1
  #bit retval_2 = retval.2
  #bit retval_3 = retval.3

  retval = 0;

  output_high(LCD_E);
  delay_cycles(1);

  retval_0 = input(LCD_DB4);
  retval_1 = input(LCD_DB5);
  retval_2 = input(LCD_DB6);
  retval_3 = input(LCD_DB7);

  output_low(LCD_E);

  return(retval);
}
#endif

//---------------------------------------
// Read a byte from the LCD and return it.

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
  int8 low;
  int8 high;

  output_high(LCD_RW);
  delay_cycles(1);

  high = lcd_read_nibble();

  low = lcd_read_nibble();

  return( (high<<4) | low);
}
#endif

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
  output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif

  if(address)
  output_high(LCD_RS);
  else
  output_low(LCD_RS);

  delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

  output_low(LCD_E);

  lcd_send_nibble(n >> 4);
  lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
  int8 i;

  output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

  output_low(LCD_E);

  delay_ms(15);

  for(i=0 ;i < 3; i++)
  {
    lcd_send_nibble(0x03);
    delay_ms(5);
  }

  lcd_send_nibble(0x02);

  for(i=0; i < sizeof(LCD_INIT_STRING); i++)
  {
    lcd_send_byte(0, LCD_INIT_STRING[i]);

    // If the R/W signal is not used, then
    // the busy bit can't be polled. One of
    // the init commands takes longer than
    // the hard-coded delay of 60 us, so in
    // that case, lets just do a 5 ms delay
    // after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
  int8 address;

  if(y != 1)
  address = lcd_line_two;
  else
  address=0;

  address += x-1;
  lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
  switch(c)
  {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;

    case '\n':
      lcd_gotoxy(1,2);
      break;

    case '\b':
      lcd_send_byte(0,0x10);
      break;

    default:
      lcd_send_byte(1,c);
      break;
  }
}

//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
  char value;

  lcd_gotoxy(x,y);

  // Wait until busy flag is low.
  while(bit_test(lcd_read_byte(),7));

  output_high(LCD_RS);
  value = lcd_read_byte();
  output_low(lcd_RS);

  return(value);
}
#endif

void lcd_setcursor_vb(short visible, short blink) {
  lcd_send_byte(0, 0xC|(visible<<1)|blink);
}


Todo ese codigo lo guardas en otro archivo pero en la misma carpeta donde tienes el archivo del tu programa principal.

Pruebalo y me cuentas vale?

Saludos
El papel lo aguanta todo