lcd displays wrong digits

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

lcd displays wrong digits

#1 Post by kshehaly » 01 Jul 2015 02:19

i am trying to make a digital clock displayed on a 16x2 lcd using an interrupt. it worked until for example the seconds reaches 59. it then holds the right digit and updates the left digit. then after a while it holds the left digit and update the right digit. please can you help me on this
thanks in advance

My Code:


// 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=0;
unsigned int hour=0;
unsigned int second=0;
unsigned int msec=0;

//interrupt routine
void interrupt(){
if(PIR1.TMR1IF){

if (msec==1000)
{
second++;
msec=0x00;
}

if(second==15)
{
minute++;
second=0x00;
}

if(minute==15)
{
hour++;
minute=0x00;
}

if(hour==24)
{
hour= 0x00;
}

msec++;

}

TMR1H=0xFC;
TMR1L=0x17;
PIR1.TMR1IF=0;
}

// main routine
void main() {

char mins[6];
char hours[6];

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

trisb=0;
portb=0x00;

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

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

TMR1H=0xFC;
TMR1L=0x17;

T1CON=0b00001001;

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

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: lcd displays wrong digits

#2 Post by janni » 01 Jul 2015 02:43

It's mikroPascal forum and a beta-testing to boot. Don't you think you'll have more luck at mC forum?

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

Re: lcd displays wrong digits

#3 Post by Dany » 01 Jul 2015 13:00

Hi, see also here: http://www.mikroe.com/forum/viewtopic.php?f=86&t=64917. Was that no solution?
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”