16x4 lcd displays gibberish characters


#1

Hi.
I’m trying to program a pic18f4550 microcontroller, which receives data from the virtual terminal and display it on a 16x4 LCD display in Proteus. But it displays something like α α α α for all the keys I have passed via the virtual terminal.

My Compiler:: CCS C Compiler 5.015
HERE is my prgm:

#include <18f4550.h> 
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN 
#use delay(clock=48000000) 
#use rs232(baud=56000, xmit=PIN_C6,parity=N,rcv=PIN_C7,ERRORS,bits=8)            
#include <flex_lcd416.c> 

    void main()                                        
    { 
    for(;;) 
      { 
        lcd_init();                  
        lcd_setcursor_vb(1,1);    
        lcd_putc("Receving Data\n"); 
        delay_ms(1000);                                                                        
      
        if(kbhit()) 
        {    
        lcd_putc(getc());  
        output_high(PIN_A0); 
        delay_ms(500); 
        }                                
        else                                                        
        {                  
        output_low(PIN_A0); 
        delay_ms(100); 
        } 
    } 
                                                
    }

Here is my lcd output:

lcdoutput

Need some help!!


#2

Hi @Prototype, welcome to EngineersAsylum!
First of all proteus is not recommended due to the bugs involved. Whats the frequency of the crystal oscillator you are using? Its seems like their is some problem with your baud rate and fuses. 56000 is not a standard baud rate, its 57600. Update with your crystal frequency…!!


#3

Thanks for the response. The frequency of the crystal is 16MHz. I am expecting to make it work at 48Mhz clock frequency and 9600 baud rate.

Thanks


#4

In order to have a 48Mhz clock from a 16MHz, you need to have fuse HSPLL, PLL4, CPUDIV2
The baud rate 9600 is fine with 48Mhz clock since the error is only 0.16%. Try below pgm with updated fuses and update.

#include <18f4550.h> 
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL4,CPUDIV2,NOPBADEN 
#use delay(clock=48000000) 
#use rs232(baud=9600, xmit=PIN_C6,parity=N,rcv=PIN_C7,ERRORS,bits=8)            
#include <flex_lcd416.c> 

    void main()                                        
    { 
    for(;;) 
      { 
        lcd_init();                  
        lcd_setcursor_vb(1,1);    
        lcd_putc("Receving Data\n"); 
        delay_ms(1000);                                                                        
      
        if(kbhit()) 
        {    
        lcd_putc(getc());  
        output_high(PIN_A0); 
        delay_ms(500); 
        }                                
        else                                                        
        {                  
        output_low(PIN_A0); 
        delay_ms(100); 
        } 
    }                                                
    }

Regards


#5

Hello @Prototype. I think @Administrator solved 99% of the problem. Please change lcd_putc(“Receving Data\n”); to lcd_puts(“Receving Data\n”);.
Because lcd_putc only prints character and you need lcd_puts to print a string.

Best of Luck.


#6

Thanks you. The problem is now solved. I just changed the fuses as you mentioned and it worked.

Thanks @EEngineer for that insight.

Regards