Loading ...
Sorry, an error occurred while loading the content.

Re: LCD Program

Expand Messages
  • s.holder123@btinternet.com
    Aditya, I sent you a file last night, checked it this morning and there were some bugs in it (it was late), use the code below, this should get you up and
    Message 1 of 8 , Apr 28, 2009
    • 0 Attachment
      Aditya,

      I sent you a file last night, checked it this morning and there were some bugs in it (it was late), use the code below, this should get you up and running

      Regards


      #define F_CPU 12000000ul //Change the F_CPU value to that you're using in your hardware
      #include <avr/io.h>
      #include <util/delay.h>
      #include<avr/delay.h>

      /*! Sets a specified Port Bit High. */
      #define bit_set_hi(Port,Bit) Port |=_BV(Bit)
      /*! Sets a specified Port Bit Low. */
      #define bit_set_low(Port,Bit) Port &= ~(_BV(Bit))
      /*!
      \def NOP
      \brief NO Operation Macro.
      */
      #define NOP() asm volatile ("nop\n\t"::);

      #define LCD_DELAY _delay_us(2)

      #define Dataport PORTC
      #define Commport PORTD
      #define RS PD4
      #define WR PD5
      #define EN PD6

      void LCD_init(void) ;
      void LCD_SendData(void);
      void wrcomm(uint8_t) ;
      void wrdata(uint8_t) ;
      void Busy_Wait(void);

      int main(void)
      {
      PORTC = 0x00;
      DDRC = 0xFF;

      PORTD = 0x00;
      DDRD = 0x70;

      LCD_init();
      LCD_SendData();

      while(1)
      {
      // Main program loop



      }
      return 1;
      }

      void LCD_init()
      {
      uint8_t Cnt = 0;

      // Power Up Routine.
      //Step 1:
      _delay_ms(10); _delay_ms(10);
      //step 2 send repeated data
      for(Cnt = 0; Cnt < 3; Cnt++)
      {
      /*! <!-- set "E" line. and set the Output. --> */
      bit_set_hi(PORTD,EN);NOP();
      PORTC = 0x30;
      LCD_DELAY;LCD_DELAY;
      /*! <!-- Clear "E" line. --> */
      bit_set_hi(PORTD,EN);NOP();
      _delay_ms(5);
      }

      // Now we can send 8 bit data
      //init. LCD 2 lines, 5x7 matrix
      wrcomm(0x38);

      /*! <!-- set display to oFF. --> */
      wrcomm(0x08);

      /*! <!-- Turn on Display with blink and cursor. --> */
      wrcomm(0x0F);

      /*! <!-- set entry mode. --> */
      wrcomm(0x06);

      /*! <!-- move cursor to home. --> */
      wrcomm(0x02);

      /*! <!-- clear LCD. --> */
      wrcomm(0x01);

      // Clear Control And data port
      PORTC = 0;NOP();
      PORTD &= 0x8F;NOP();

      return;
      }

      /*********** **** <<Sending Data To LCD Display>> ************ ***/
      void LCD_SendData(void)
      {
      unsigned char j[] = "LCD Display";
      uint8_t i;
      for(i = 0; i < sizeof j ; i++)
      {
      wrdata(j[i]);
      }
      return;
      }

      /******* <<Righting the command byte to command register>> ********/
      void wrcomm(uint8_t Data)
      {
      Busy_Wait();

      bit_set_low(PORTD,RS);NOP();
      bit_set_low(PORTD,WR);NOP();

      /*! <!-- set "E" line. and set the Output. --> */
      bit_set_hi(PORTD,EN);NOP();
      Dataport = Data;NOP();
      // wait
      LCD_DELAY;LCD_DELAY;
      /*! <!-- Clr "E" line. and delay. --> */
      bit_set_low(PORTD,EN);NOP();
      //wait
      LCD_DELAY;LCD_DELAY;

      PORTC = 0;NOP();
      PORTD &= 0x8F;NOP();

      return ;
      }

      /********** <<Righting the Data byte to Data register>> **********/
      void wrdata(uint8_t Data)
      {

      Busy_Wait();

      bit_set_hi(PORTD,RS);NOP();
      bit_set_low(PORTD,WR);NOP();

      /*! <!-- set "E" line. and set the Output. --> */
      bit_set_hi(PORTD,EN);NOP();
      Dataport = Data;NOP();
      // wait
      LCD_DELAY;LCD_DELAY;
      /*! <!-- Clr "E" line. and delay. --> */
      bit_set_low(PORTD,EN);NOP();
      //wait
      LCD_DELAY;LCD_DELAY;

      PORTC = 0;NOP();
      PORTD &= 0x8F;NOP();

      return;
      }

      void Busy_Wait(void)
      {

      uint8_t Busy_Byte = 0;

      /*! <!-- set RS to "control". Set R/W to "read --> */
      bit_set_hi(PORTD,WR);NOP();
      bit_set_low(PORTD,RS);NOP();


      /*! <!-- Set data I/O lines to input Set pull-ups --> */
      PORTC = 0xFF;NOP();
      DDRC = 0x00;NOP();
      do
      { /*! <!-- set "E" line. --> */
      bit_set_hi(PORTD,EN);NOP();
      LCD_DELAY;LCD_DELAY;

      /*! <!-- Read the Port. --> */
      Busy_Byte = PINC;

      /*! <!-- Clear "E" line. --> */
      bit_set_low(PORTD,EN);NOP();
      LCD_DELAY;LCD_DELAY;

      }
      while((Busy_Byte & 0x80));

      /*! <!-- Set data I/O lines to OUTPUT Set pull-ups --> */
      PORTC = 0xFF;NOP();
      DDRC = 0xFF;NOP();
      PORTC = 0x00;NOP();
      PORTD &= 0x8F;NOP();
      }

      --- In booksbybibin@yahoogroups.com, ADITYA SHARMA <aditya_sharmahi@...> wrote:
      >
      > Sorry I just forgot to mention that, i already tried that also by changing 0x07 to 0x70, but then also it didn't worked, I have checked my LCD on other circuit, thr LCD is fine and all circuit connections are also alright, i am not even getting a cursor, what could be the reason, please reply soon i am on with my project.
      >
      >
      > Explore your hobbies and interests. Go to http://in.promos.yahoo.com/groups/
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.