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

no display on LCD..

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

no display on LCD..
PostPosted: Wed Feb 01, 2006 9:34 pm     Reply with quote

I decided to upgrade my PIC16f877 to PIC18F452 but then my circuit did not work...what need to be done to my code for it to work?? its working fine with my old PIc but after i upgrade, it did not display anything on my LCD...all my device power up properly...i hope u can help and heres my code..

Code:
#include <18F452.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)

#include <lCD420.c>

//===============================
void main()
{
int16 result;

lcd_init();

setup_adc_ports(AN0);

setup_adc(ADC_CLOCK_DIV_8);

set_adc_channel(0);

while(1)
  {
   result = read_adc();
   lcd_gotoxy(1,1);
   printf(lcd_putc, "%04LX", result);
   delay_ms(100);
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 01, 2006 10:37 pm     Reply with quote

Those two PICs are in different series and the Port addresses are
not the same for each series. See this thread. It will show you
what to modify in the LCD420.C file.
http://www.ccsinfo.com/forum/viewtopic.php?t=24499
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 02, 2006 12:16 am     Reply with quote

my lcd still not working...ive done few changes to my lCD420.c...heres the code...hope u can help..

Code:

#define use_portd_lcd TRUE
struct lcd_pin_map {
           BOOLEAN rs;          // Pin D0
           BOOLEAN enable;      // Pin D1
           BOOLEAN rw;          // Pin D2
           BOOLEAN unused;
           int     data : 4;    // Pins D4-D7
        } lcd;
#if defined(__PCH__) // if PIC18 family compiler
#if defined use_portd_lcd     // if LCD is connect to PORTB
   #byte lcd = 8                   // this is the address used by the struct in the driver
#else                                        // else
   #byte lcd = 0xF83                   // this one is the address
#endif
#else // else, if PIC16 family compiler
#if defined use_portb_lcd    // if LCD is connect to PORTB
   #byte lcd = 6                  // LCD is on to port B (at address 6)
#else
   #byte lcd = 8                 // else it is on to port D (at address 8)
#endif
#endif


#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


BYTE lcdline;

BYTE lcd_read_byte() {
      BYTE low,high;

      set_tris_d(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_d(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;

    set_tris_d(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0, LCD_INIT_STRING[i]);
}


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

   switch(y) {
     case 1 : address=0x80;break;
     case 2 : address=0xc0;break;//0xc0
     case 3 : address=0x94;break;//0x94
     case 4 : address=0xd4;break;
   }
   address+=x-1;
   lcd_send_byte(0,address);
}

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

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2006 12:22 am     Reply with quote

You changed the compiler dependent code so it's now incorrect.

You should read that thread, because they explain why the ports
must change when you change the compiler (or PIC series, actually).

Also, what port are you using for the LCD ?
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 02, 2006 12:35 am     Reply with quote

im using port D...im sori but i think im confuse..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2006 12:42 am     Reply with quote

The important point is that you must use the correct port address
for your PIC. I was trying to teach you something by having you
read that other post, but I guess not.

Delete all that code that you put in there, and then change
the lcd address line in LCD420.C to the following:
Code:
#byte lcd = 0xF83   // Address of Port D for the 18F452


If this doesn't work, then I suspect you have a hardware problem.
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 02, 2006 1:10 am     Reply with quote

yeah it works...do u mind looking at my 485 code...?
im using to PIC,master/slave...to comunicate with each other...i got this source code from this forum...but still i doesnt work..hope u can help..

i try the master to send and the slave to receive first..

Code:
//master
#include<18f452.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_C5)
#define RS485_ID  0x10                 // The device's RS485 master address
#define RS485_USE_EXT_INT TRUE        // Select asynchronous serial interrupt

#include<RS485.c>
#include <lCD420.c>
#include <kbd.c>
int buffer[40];
int next_in  = 0;
int next_out = 0;

#INT_RDA
void serial_isr()
{
   int t;

   buffer[next_in] = fgetc(RS485);
   t = next_in;
   next_in = (next_in+1) % sizeof(buffer);
   if(next_in == next_out)
   next_in=t;        // Buffer full !!
}

void main(void)
{

   int j;
   char k;
   int data_received[32];
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   lcd_init();
   rs485_init();
   kbd_init();

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);


   rs485_init();
   //lcd_putc("\fReady...\n");

while(1)
{

   rs485_wait_for_bus(FALSE);

                   //send address=0x11, length = 1, msg=3

if(rs485_send_message(0x11, 1, 3))
{

   k=kbd_getc();
   if(k!=0)
   if(k=='*')
   lcd_putc('\f');
   else
   lcd_putc(k);
         /*output_low(PIN_B1);
         delay_ms(100);
         output_high(PIN_B1);
         delay_ms(100);
         output_low(PIN_B1);*/

         //lcd_gotoxy(1,3);
         //printf(lcd_putc, "\n\rADC (V):test\r\n");
         //delay_ms(100);
}

      delay_ms(5);


      /*if(rs485_get_message(data_received, FALSE))
      {
         for(j=0;  j<3; ++j)
                  data_received[j] = buffer[j];


               if(data_received[2]==6)         //if slave receives the number 3 successfully
         {                    //slave will send back number 6
            lcd_gotoxy(1,4);
            printf(lcd_putc, "\n\rADC (V):test\r\n");
            delay_ms(100);

            /*output_low(PIN_B2);
            delay_ms(100);
            output_high(PIN_B2);
            delay_ms(100);
            output_low(PIN_B2);
         }
      }*/

         }
}


/
Code:
/slave
#include<18f452.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_C5)
#define RS485_ID  0x11                 // The device's RS485 slave address or ID
#define RS485_USE_EXT_INT TRUE        // Select asynchronous serial interrupt

#include<RS485.c>
#include <lCD420.c>
#include <kbd.c>
int buffer[40];
int next_in  = 0;
int next_out = 0;

#INT_RDA
void serial_isr()
{
   int t;

   buffer[next_in] = fgetc(RS485);
   t = next_in;
   next_in = (next_in+1) % sizeof(buffer);
   if(next_in == next_out)
   next_in=t;        // Buffer full !!
}

void main()
{

   int j;
   char k;
   int data_received[32];
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   lcd_init();
   rs485_init();
   kbd_init();
   //lcd_putc("\fReady...\n");

while(1)
{

if(rs485_get_message(data_received, TRUE))
{

for(j=0;  j<3; ++j)
   data_received[j] = buffer[j];


if(data_received[0] == 0x11)
{

   k=kbd_getc();
   if(k!=0)
   if(k=='*')
   lcd_putc('\f');
   else
   lcd_putc(k);
            //lcd_gotoxy(1,4);
            //printf(lcd_putc, "\n\rADC (V):test\r\n");
            //delay_ms(100);

            /*output_low(PIN_B2);
            delay_ms(100);
            output_high(PIN_B2);
            delay_ms(100);
            output_low(PIN_B2);*/


   rs485_wait_for_bus(FALSE);



            //after receive successfully, respond to master by sending number 6
            /*if(rs485_send_message(0x10, 1, 6))
            {

               lcd_putc("\fReadyAfsdfsd...\n");
               //lcd_gotoxy(1,3);
               //printf(lcd_putc, "\n\rADC (V):test\r\n");
               //delay_ms(100);

               /*output_low(PIN_B1);
               delay_ms(100);
               output_high(PIN_B1);
               delay_ms(100);
               output_low(PIN_B1);

            }*/
           
           
         }
      }

 }
}
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Sat Feb 04, 2006 9:47 am     Reply with quote

anybody wanna help wit my 485?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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