cant display correct values on lcd

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
kshehaly
Posts: 6
Joined: 30 Jun 2015 01:57

cant display correct values on lcd

#1 Post by kshehaly » 30 Jun 2015 02:04

when i run this code in proteus the hours digits doesnt appear
i use pic16f877a with 4mhz crystal

this is mycode:

// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

//constans
unsigned int minute;
unsigned int hour;
unsigned int second;
char mins[6];
char hours[6];

//interrupt routine
void interrupt(){

if(PIR1.TMr1IF){

if(second==10){
second=0;
minute=minute+1;
}
if(minute==60){
minute=0;
second=0;
hour=hour+1;
}
if(hour==24){
hour=0;
minute=0;
second=0;
}
second=second+1;
PIR1.TMr1IF=0;
}

}

// main routine
void main() {

trisb=0;
portb=0;

Lcd_init();
Lcd_cmd(_LCD_CURSOR_OFF);
Lcd_cmd(_LCD_CLEAR);
Lcd_out(1,3,ltrim(":"));

INTCON.GIE=1;
INTCON.PEIE=1;

PIR1.TMr1IF=0;
PIE1.TMR1IE=1;

TMR1H=0xFB;
TMR1L=0x1E;

T1CON.T1CKPS1=1;
T1CON.T1CKPS0=1;
T1CON.T1OSCEN=1;
T1CON.T1SYNC=0;
T1CON.TMR1CS=0;
T1CON.TMR1ON=1;

while(1){
ByteToStr(minute,mins);
ByteToStr(hour,hours);
Lcd_out(1,1,ltrim(hour));
Lcd_out(1,4,ltrim(mins));
}
}

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: cant display correct values on lcd

#2 Post by Aleksandar.Mitrovic » 30 Jun 2015 10:10

Hi,

Can you tell me do you use some development system or some custom hardware?
I believe that you didn't initialize your LCD properly. Please double check you initialization of LCD.

Note that Proteus is not officially supported by mikroElektronika, and we suggest our users to test their examples on real hardware.

Best regards,
Aleksandar

kshehaly
Posts: 6
Joined: 30 Jun 2015 01:57

Re: cant display correct values on lcd

#3 Post by kshehaly » 30 Jun 2015 10:36

i use custom hardware. but what do u believe is wrong in initializing the lcd ?
thank you

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: cant display correct values on lcd

#4 Post by Dany » 30 Jun 2015 10:51

Hi,

ltrim is not a function. So, use

Code: Select all

ltrim(hour);
Lcd_out(1,1,hour);
ltrim(mins)
Lcd_out(1,4,mins);
in stead of

Code: Select all

Lcd_out(1,1,ltrim(hour));
Lcd_out(1,4,ltrim(mins));
Also this wont work:

Code: Select all

Lcd_out(1,3,ltrim(":"));
Leave the ltrim out:

Code: Select all

Lcd_out(1,3,":");
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”