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

LCD+ADC ON PIC16F877a WORK FINE SIMULATION, BUT NOT IN BOARD
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

LCD+ADC ON PIC16F877a WORK FINE SIMULATION, BUT NOT IN BOARD
PostPosted: Tue May 25, 2010 2:44 pm     Reply with quote

hi, I need a help with my PIC program.
The program read ADC channel, and i need to send the value to lcd, what i can view the value on lcd?


This is my main code:
Code:

#include <16f877a.h>
#device adc=10
#use delay(clock=4000000)
#fuses XT,NOWDT,PUT
#include <mod_lcd2.c>

void inttoc(int aa){
   for (i=0;i=4;i++){
     

}
main(){
long int valor;
int32 val32;
setup_ADC_ports (RA0_Analog);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
   lcd_ini();
   while(TRUE){
   valor=read_adc();
   if (valor) valor +=1;
   val32= (valor*4+((int32)valor * 113)/128);
   lcd_escreve("\f");
   lcd_escreve("Valor: ");
   
   lcd_escreve(("%d",val32));
   delay_ms(2000);
   }
}

This is my library code:
Code:

/********************************************************/
/*  MOD_LCD.C - Biblioteca de manipulação de módulo LCD */
/*                                                      */
/*  Autor: Fábio Pereira                                */
/*                                                      */
/********************************************************/

// As definições a seguir são utilizadas para acesso aos pinos do display
#ifndef lcd_enable
   #define lcd_enable       pin_d1      // pino enable do LCD
   #define lcd_rs         pin_d0      // pino rs do LCD
   #define lcd_d4         pin_d4      // pino de dados d4 do LCD
   #define lcd_d5         pin_d5      // pino de dados d5 do LCD
   #define lcd_d6         pin_d6      // pino de dados d6 do LCD
   #define lcd_d7         pin_d7      // pino de dados d7 do LCD
#endif

#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 linhas
#define lcd_seg_lin 0x40    // Endereço da segunda linha na RAM do LCD

// a constante abaixo define a seqüência de inicialização do módulo LCD
byte CONST INI_LCD[4] = {0x20 | (lcd_type << 2), 0xf, 1, 6};

void lcd_envia_nibble( byte dado )
// envia um dado de quatro bits para o display
{
   // coloca os quatro bits nas saidas
   output_bit(lcd_d4,bit_test(dado,0));
   output_bit(lcd_d5,bit_test(dado,1));
   output_bit(lcd_d6,bit_test(dado,2));
   output_bit(lcd_d7,bit_test(dado,3));
   // dá um pulso na linha enable
   output_high(lcd_enable);
   output_low(lcd_enable);
}


void lcd_envia_byte( boolean endereco, byte dado )
{
   // coloca a linha rs em 0
   output_low(lcd_rs);
   // aguarda o display ficar desocupado
   //while ( bit_test(lcd_le_byte(),7) ) ;
   // configura a linha rs dependendo do modo selecionado
   output_bit(lcd_rs,endereco);
   delay_us(100);   // aguarda 100 us
   // caso a linha rw esteja definida, coloca em 0
   // desativa linha enable
   output_low(lcd_enable);
   // envia a primeira parte do byte
   lcd_envia_nibble(dado >> 4);
   // envia a segunda parte do byte
   lcd_envia_nibble(dado & 0x0f);
}


void lcd_ini()
// rotina de inicialização do display
{
   byte conta;
   output_low(lcd_d4);
   output_low(lcd_d5);
   output_low(lcd_d6);
   output_low(lcd_d7);
   output_low(lcd_rs);
   output_low(lcd_enable);
   delay_ms(15);
   // envia uma seqüência de 3 vezes 0x03
   // e depois 0x02 para configurar o módulo
   // para modo de 4 bits
   for(conta=1;conta<=3;++conta)
   {
      lcd_envia_nibble(3);
      delay_ms(5);
   }
   lcd_envia_nibble(2);
   // envia string de inicialização do display
   for(conta=0;conta<=3;++conta) lcd_envia_byte(0,INI_LCD[conta]);
}

void lcd_pos_xy( byte x, byte y)
{
   byte endereco;
   if(y!=1)
      endereco = lcd_seg_lin;
   else
      endereco = 0;
   endereco += x-1;
   lcd_envia_byte(0,0x80|endereco);
}

void lcd_escreve( char c)
// envia caractere para o display
{
   switch (c)
   {
     case '\f'    :   lcd_envia_byte(0,1);
              delay_ms(2);
            break;
     case '\n'   :
     case '\r'    :   lcd_pos_xy(1,2);
              break;
     case '\b'    :   lcd_envia_byte(0,0x10);
              break;
     default   :   lcd_envia_byte(1,c);
              break;
   }
}

Thanks for all!! Very Happy


Last edited by nachgot on Wed May 26, 2010 1:41 pm; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 25, 2010 2:55 pm     Reply with quote

Here is a sample program to read the ADC and display the voltage
on the LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1

Here is the Flex lcd driver used by the program above:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661

Try to make it work with that sample code and driver.
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

RESOLVED!
PostPosted: Tue May 25, 2010 3:13 pm     Reply with quote

PCM programmer wrote:
Here is a sample program to read the ADC and display the voltage
on the LCD:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1

Here is the Flex lcd driver used by the program above:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661

Try to make it work with that sample code and driver.


Thanks PCM!
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

library
PostPosted: Wed May 26, 2010 1:40 pm     Reply with quote

This code works fine in my simulation in Proteus.
But in my protoboard, doesn't work...
My LCD use a KS0066U microcontroller, and i use a PIC 16F877A for project. Sad
The LCD power up, but not appear the text.
I need a library for this microcontroller LCD or, a 8 bit library, for test in my protoboard again!
Thanks! Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 26, 2010 3:04 pm     Reply with quote

Check the connections between the PIC and the LCD.

Check the contrast voltage on the LCD. Set it for 0.4 volts.
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu May 27, 2010 6:21 am     Reply with quote

The connections between LCD and PIC, are all ok.
I used other port of PIC, with a LED, to test the clock too...And the led is blinking.
The contrast, i used a 10K potentiometer, and the LCD does not display characters...
My LCD display is: APEX AXSC162A, this library, works fine with my LCD?
I need the 8 bit library, to test again with my LCD.
Thank You!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 27, 2010 11:52 am     Reply with quote

1. Post a list of the connections between the PIC and the LCD.

2. Post the #define statements that you have at the top of the Flex lcd driveres.
Abdulla M.A.



Joined: 28 Mar 2010
Posts: 30
Location: Baghdad, Iraq

View user's profile Send private message Visit poster's website Yahoo Messenger

PostPosted: Thu May 27, 2010 12:05 pm     Reply with quote

When you turn on the circuit, is there any segments or cursor appear
on the LCD???
did you set the LCD setting, like
1-clear LCD.
2-set cursor at location 0.
3- number of used lines.
..........

Abdulla
_________________
"A scientist can discover a new star, but he cannot make one. He would have to ask an engineer to do that."
"For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu May 27, 2010 2:23 pm     Reply with quote

If i turn on the circuit, the lcd will turn on the backlight, and doesn't appear nothing...
Yes, i have set my LCD correctly...
RD4 -> D4
RD5 -> D5
RD6 -> D6
RD7 -> D7
RD0 -> RS
RD1 -> E
Ground -> D0,D1,D2,D3,RW
I don't have idea, whats the problem.
I tested with other 2 LCD Display 16x2, but anything is the same problem Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19563

View user's profile Send private message

PostPosted: Thu May 27, 2010 2:37 pm     Reply with quote

Look again at the bias connection. If you apply power to an LCD of this sort, with _nothing_ sent to it from a processor, it'll normally wake up displaying one line of black squares. If these are not visible, it implies the bias voltage is not right.
Do you have a data sheet for this display?. The only reference a quick search for ASXC162 returned, was for a graphical LCD, not a character LCD, which the driver you are trying to use is for....

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 27, 2010 2:38 pm     Reply with quote

Quote:
Ground -> D0,D1,D2,D3,RW

1. You don't have to connect pins D0-D3 to ground. The LCD has
internal pull-ups on those pins. They are not floating.

2. Did you edit the Flex LCD driver to comment out this line ?
Quote:
// #define USE_RW_PIN 1

If you ground the R/W pin, you must comment out that line,
as shown above.


For Ttelmah,
This link shows it's a 16x2 LCD:
http://www.apexdisplay.com/products/stn/character/162.php.htm
Ttelmah



Joined: 11 Mar 2010
Posts: 19563

View user's profile Send private message

PostPosted: Thu May 27, 2010 3:01 pm     Reply with quote

I'm only finding it in EE-Times Asia, as a 128*64.
Thanks for the link that it is a character display. :-)

Best Wishes
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu May 27, 2010 9:15 pm     Reply with quote

Ttelmah wrote:
Look again at the bias connection. If you apply power to an LCD of this sort, with _nothing_ sent to it from a processor, it'll normally wake up displaying one line of black squares. If these are not visible, it implies the bias voltage is not right.
Do you have a data sheet for this display?. The only reference a quick search for ASXC162 returned, was for a graphical LCD, not a character LCD, which the driver you are trying to use is for....

Best Wishes


The one line of black squares appear.
But only this.
AXSC162, uses KS066U controller. Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 27, 2010 10:17 pm     Reply with quote

Black squares means the LCD is not initialized, or is not initialized correctly.

1. Post the #define statements that you have at the top of the Flex lcd driver file.

2. Did you edit the Flex LCD driver to comment out this line ?
Quote:
// #define USE_RW_PIN 1

If you ground the R/W pin, you must comment out that line,
as shown above.
nachgot



Joined: 24 May 2010
Posts: 7

View user's profile Send private message

PostPosted: Fri May 28, 2010 2:35 pm     Reply with quote

#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define LCD_E PIN_D1
#define LCD_RS PIN_D0
//#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
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 1, 2  Next
Page 1 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