atmega128 optical rotary encoder lcd flash problems

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I made this code using codevision compiler for optical rotary encoder, but when i using this code, lcd flashes so fast and not only displayed (0,1) but also every part of lcd

 

i made for 10ms ovf, and using external interrupt to count rising edge of signal of encoder

 

 

 

/*
 * ecx.c
 *
 * Created: 2018-05-11 오후 7:27:19
 * Author: 최우용
 */

#include <mega128a.h>
#include <delay.h>
#include <lcd.h>
#include <stdio.h>
#asm
   .equ __lcd_port=0x15;
#endasm

void initial(void);

char sbuf[20];                              // lcd 파일 저장용
unsigned volatile int ecca;
unsigned volatile int eccb;
unsigned int time=0x0000;                  //

interrupt [EXT_INT0] void ext_int0_isr(void)
{  
     ecca++; 
}

interrupt [EXT_INT1] void ext_int1_isr(void)
{  
     eccb++;
}

interrupt [TIM1_OVF] void timer_int1(void)
{
     ecca = 0;
     eccb = 0;
 

TCNT1=time;                                // 오버플로우 시간설정
}

void initial(void)                              // 포트 초기화 portb, lcd를 통한 확인 portd 인터럽트, 나머지는 타이머 1 동작모드와 타이머 시간
{
      PORTB=0xff;   // initial value
      DDRB=0xff;     //  data direction as output
     
      PORTD=0xff;   // initial value
      DDRD=0x00;    // data direction as input
     
      TIMSK=0x04;         //0000 0100 TCNT1 overflow interrupt enable
      TCCR1A = 0x00;    //0000 0000  normal mode 0~ 0xFFFF
      TCCR1B = 0x01;    //00/0/0 0/100  N : 1
      TCCR1C = 0x00;    //0000 0000
      TCNT1 = time;     //tcnt1 = 0x8000;
}            

 

void main(void)
{
    initial();
   
    EICRA= 0x0f;    //0000 1111  E interrupt1 , E interrupt0  rising edge
    EIMSK = 0x21;  //0010 0001  interrupt 0, E interrupt5 enable,
    #asm("sei");                          // 전체 인터럽트 허용
   
while (1)
{       if ( ecca >= eccb )                             // lcd 표시용
       {lcd_init(20);
        sprintf(sbuf, "clock = +%d", ecca);
        lcd_gotoxy(0,0);
        lcd_puts(sbuf);  
        delay_ms(1000);
       }    
    
     else
       {
        lcd_init(20);
        sprintf(sbuf, "clock = -%d", ecca);
        lcd_gotoxy(0,1);
        lcd_puts(sbuf);
       delay_ms(1000); 
    }
}
}

Last Edited: Wed. May 16, 2018 - 01:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Only init the LCD once before entering the while loop.

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?