caramoan tour package

caramoan tour package

Author Topic: PIC16877a with LCD 4x20 BLACK BOXES helpp  (Read 233 times)

Offline JTecophil

  • LR44 Battery
  • *
  • Posts: 4
  • Pogi/Ganda Points: 0
PIC16877a with LCD 4x20 BLACK BOXES helpp
« on: January 29, 2012, 12:49:40 PM »
Hi guys could anyone help me with this problem. I have before interfaced my lcd using pic16f877a and it has worked several times. but now ayaw na gumana even ung mga luma kong codes. kahit bumili nako ng bagong LCD hnd parin gumagana anyone pls help thanks. btw it also works in proteus


#include<htc.h>
#include"delay.h"

#define RS RA3      
#define RW RA2
#define E  RA1
#define DATA PORTD


__CONFIG( HS & WDTDIS & LVPDIS);


void TMR_init(){

   OPTION = 0x02;             // initialize prescaler
   TMR0=0;                // initialize TMR0
      
}
void delayms(unsigned int x){

   unsigned int i,j=0;
   TMR0 = 0;
   for ( i = 0 ; i<=x; i++){
         j = 0;
         TMR0 = 0;
         
         while(j<=625){
            while (TMR0<= 125);
         
               j = j+ TMR0;
               TMR0 = 0;

            
            

            };         
   

   }
   


}


void startinit()
{

   DATA = 0x30;         // 1st LCD initialize
   E = 1;
   NOP();
   NOP();
   NOP();
   E = 0;
   delayms(5);

}



void lcd_cmd(char x){
   DATA & = 0x00;
   DATA = x;
   RW = 0;
   RS = 0;
   E = 1;
   NOP();
   NOP();
   NOP();
   E = 0;
   delayms(5);
   

}

void lcd_init(){

   DATA & = 0x00;
   RW = 0;
   RS = 0;
   E = 0;
 
   delayms(100);

   startinit();
   startinit();
   startinit();

   lcd_cmd(0x38);         // 2 lines , 5 by 7 dots
   lcd_cmd(0x08);         
   lcd_cmd(0x01);         // clear screen
   lcd_cmd(0x06);         // increment mode, shift off
   lcd_cmd(0x0C);         // turn on

}

void lcd_displaychar(char a){

   RW = 0;
   RS = 1;
   DATA & = 0x00;
   DATA = a;
   E = 1;
   NOP();
   NOP();
   NOP();
   E = 0;
   RS = 0;
   delayms(1);
}

void lcd_displaystring( const char *str){

   while(*str){
      
      lcd_displaychar(*str);
         str++;
   }
   
}

void lcd_intdisp(unsigned int value){
   
   char x[5]={0,0,0,0,0},i=0,j=0;
      
   
      if (value == 0){lcd_displaychar(0x30);}
   while (value){
   
    x= value%10;
   value = value /10;   
   i++;
   
   }
   
   ;
   for (j = i-1;j<=(i);j--){

   lcd_displaychar(0x30 + x[j]);
   }      

}


void lcd_floatdisp( long int value){
   
   long int x[5] = {0,0,0,0,0};
   char i=0,j=0,k=0;

      value = 5000*value;
      value = value/1023 ;
   
      if (value == 0){lcd_displaychar(0x30);}
   while (value){
   
    x= value%10;
   value = value/10;   
   i++;
   
   }
   
   ;
   for (j =i-1 ;j <= i;j--){
   
   if (k==(i-3)){lcd_displaychar('.');};
   lcd_displaychar(0x30 + x[j]);
   k++;
   }      

}

void lcd_goto(unsigned char row, unsigned char col){
      
   switch(row){

   case 1: lcd_cmd( 0x80 + col);break;
   case 2: lcd_cmd( 0xC0 + col);break;
   case 3: lcd_cmd( 0x94 + col);break;
   case 4: lcd_cmd( 0xD4 + col);break;
   default:break;
   }
   
}      
void lcd_clear(){

   lcd_cmd(0x01);

}   

main(){
char x=0,y=0,z=0;
TRISB = 0;
PORTB = 0;
TRISD = 0;
PORTD = 0;
   TRISA = 0x01;
ADCON0 = 0x01;
ADCON1 = 0x0E; // AN0 = analog; RA1 to RA3 = digital
TMR_init();
lcd_init();


   while(1){

   lcd_displaystring("Good Morning");

   delayms(500);
   lcd_clear();


}
}

Philippine Electronics Forum

PIC16877a with LCD 4x20 BLACK BOXES helpp
« on: January 29, 2012, 12:49:40 PM »

Offline sephiroh

  • Size AA Battery
  • ****
  • Posts: 110
  • Pogi/Ganda Points: 0
  • Y.A.
Re: PIC16877a with LCD 4x20 BLACK BOXES helpp
« Reply #1 on: January 30, 2012, 01:42:42 PM »
check niu po ung hinang.. hehe :P

Philippine Electronics Forum

Re: PIC16877a with LCD 4x20 BLACK BOXES helpp
« Reply #1 on: January 30, 2012, 01:42:42 PM »

Offline Gwenda

  • Size D Battery
  • ******
  • Posts: 301
  • Pogi/Ganda Points: 24
  • Gender: Female
Re: PIC16877a with LCD 4x20 BLACK BOXES helpp
« Reply #2 on: January 31, 2012, 03:55:41 PM »
Problems like this, better to have a simple set-up and program to check the power-up status of the LCD.  Baka lang wiring problem and not the code.

 :-\BLACK BOXES:  you mean instead of characters ay black rectangles ang nasa display?  Looks like a contrast adjustment problem.  Check your pin 3 on the LCD, normally connected to a pot between +5 and gnd.

Philippine Electronics Forum

Re: PIC16877a with LCD 4x20 BLACK BOXES helpp
« Reply #2 on: January 31, 2012, 03:55:41 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com