Author Topic: Displaying Encoder Count on LCD  (Read 1656 times)

0 Members and 1 Guest are viewing this topic.

Offline hendrachubbyTopic starter

  • Full Member
  • ***
  • Posts: 49
  • Helpful? 0
    • My-Blog
Displaying Encoder Count on LCD
« 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);;
    }
       
}





Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Displaying Encoder Count on LCD
« Reply #1 on: August 31, 2009, 08:25:11 PM »
You should have no delay_ms() in the ISR.
Check out the uBotino robot controller!