Society of Robots - Robot Forum

Software => Software => Topic started by: hendrachubby on August 31, 2009, 06:59:35 AM

Title: Displaying Encoder Count on LCD
Post by: hendrachubby on August 31, 2009, 06:59:35 AM
hELLo,

I wrote a simple program to display encoder count on my LCD, but it did'nt work, any body can help me ?, here is the code

Code: [Select]

#include <mega2560.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <lcd.h>

#define MAX 0xFF

int count1;
unsigned char lcd1[5];

void LCD_Setting()
{
    /*
    LCD Configuration
    */
       
    #asm
    .equ __lcd_port=0x08 ;PORTC
    #endasm
}

void Oscillator_Setting()
{
    /*
    Crystal Division Factor : 1
    */
   
    #pragma optsize-
    CLKPR=0x80;
    CLKPR=0x00;
    #ifdef _OPTIMIZE_SIZE_
    #pragma optsize+
    #endif
}

   
void Ports_Setting()
{
   
    PORTD= 0b00000000;
    DDRD = 0b00000000;
   
}
   
 
void Interrupt_Setting()
{
   
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x03;
EICRB=0x00;
EIMSK=0x01;
EIFR=0x01;



 // External Interrupt 0 service routine
    interrupt [INT0] void ext_int0_isr(void)
    {
        delay_ms(60);
        count1++;   
    }

void main(void)

    Oscillator_Setting();
    Ports_Setting();
    LCD_Setting();
    Interrupt_Setting();
   
    lcd_init(16);
   
    #asm("sei")
   
    while(1)
    {     
        lcd_gotoxy(0,0);
        lcd_putsf("PLS = ");
        lcd_puts(lcd1);
        itoa (count1,lcd1);;
    }
       
}




Title: Re: Displaying Encoder Count on LCD
Post by: Ro-Bot-X on August 31, 2009, 08:25:11 PM
You should have no delay_ms() in the ISR.