JMECE108
Newbie level 2
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();
}
}
#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();
}
}