PIC LCD Code not running on Proteus 8

3.6k views Asked by At

I'm learning how to program PIC controllers using the CCS PCWHD IDE C Compiler. I'm trying to display a message on an LCD display in Proteus 8 using C code.

The code I've written compiles and the .HEX and .COF files are generated without problem. However, when I try to simulate this code on Proteus 8, all I see is the LCD screen switching on. No blinking cursor or text appears. I've triple-checked the connections and the Proteus schematic but couldn't find any problems there.

I'm using a PIC16F877A micro-controller with a 4MHz external crystal The LCD display I'm using is LM016L (16x2 LCD display). I can't understand if the problem is with Proteus, the C compiler or my code?

The code I've written is given below:

#include <16F877A.h>      

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=4000000)         //4MHz Crystal

#use fast_io(b)

#byte ADCON1=0x9F 

//Implementing the LCD onto Port B
#define PORTB=0x06        
#define LCD_ENABLE_PIN PIN_B2                    
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA_PORT PORTB
#define  LCD_DATA4    PIN_B4                  
#define  LCD_DATA5    PIN_B5
#define  LCD_DATA6    PIN_B6
#define  LCD_DATA7    PIN_B7                 
#define LCD_TYPE 2        //2 Line display  

#include <lcd.c>      // LCD library

void main()
{ 
   set_tris_b(0x00);  //Port B is completely output
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   //TODO: User Code

 lcd_init();
 delay_ms(10);
   while (TRUE)
   {    
       lcd_send_byte(0,0x0e);  //Blinking Cursor
       delay_ms(10);
       printf(lcd_putc,"\fHello");
       printf(lcd_putc,"\nWorld");                                           
       delay_ms(1000);                 
       printf(lcd_putc,"\fMy");            
       printf(lcd_putc,"\nFirst");   
       delay_ms(1000); 
       lcd_gotoxy(5,1); //Row 1, Column 5
       delay_ms(10);
       printf(lcd_putc,"\fPIC");                        
       lcd_gotoxy(1,2); //Row 2 column 5   
       delay_ms(10);
       printf(lcd_putc,"Project");   
       delay_ms(1000);                                       


   }
}     
1

There are 1 answers

0
Amol Saindane On
  • You have to initialise micro-controller clock (OSCCON), which is not there in given code.

  • You want to disable ADC so you used setup_adc_ports(NO_ANALOGS);

    So, next setup_adc(ADC_CLOCK_DIV_2); code of line is not required.

  • Make sure that your R\W pin is connected to ground.

  • Contrast Adjustment resistor should be there

Please check below image for connections :

enter image description here

This link have code in Micro C, for your reference