So I'm writing a program in MikroC that prints a text on a LCD and shifts it every 13 ms right. When the text is fully shifted to the right it shifts it to the left and it goes like that back and forth whenever the first interrupt is handled. On the second interrupt there is no shifting and the text just stays there.
sbit LCD_RS at RA4_bit;
sbit LCD_EN at RA5_bit;
sbit LCD_D4 at RA0_bit;
sbit LCD_D5 at RA1_bit;
sbit LCD_D6 at RA2_bit;
sbit LCD_D7 at RA3_bit;
sbit LCD_RS_Direction at TRISA4_bit;
sbit LCD_EN_Direction at TRISA5_bit;
sbit LCD_D4_Direction at TRISA0_bit;
sbit LCD_D5_Direction at TRISA1_bit;
sbit LCD_D6_Direction at TRISA2_bit;
sbit LCD_D7_Direction at TRISA3_bit;
char text[25], broj[50];
int i, turn, flag;
void interrupt(){
if(intf_bit==1){
if(flag==0) flag=1;
else flag=0;
intf_bit=0;
}
}
void main(){
i=0;
turn=1;
ANSEL=0;
ANSELH=0;
TRISB.B0=1;
strcpy(text, "Random Text That Has Some");
flag=0;
intcon=0x90;
LCD_init();
LCD_CMD(_LCD_Cursor_Off);
lcd_cmd(_lcd_clear);
lcd_out(1, 1, text);
while(1){
if(flag==1){
if(turn==1) {
LCD_cmd(_lcd_shift_right);
i++;
}
if(turn==0){
lcd_cmd(_lcd_shift_left);
i--;
}
if(i==11){
turn=0;
}
if(i==0){
turn=1;
}
delay_ms(13);
}
}
}
However when I run the program on the simulator when It's done shifting right it doesn't shift back left. It just shifts right until the first letter comes again and it goes full circle.
Any ideas?