display "hello world" on the jhd 162a lcd using ATMEGA 16A

Discussion in 'Embedded Systems and Microcontrollers' started by ravi8820, Dec 5, 2012.

  1. ravi8820

    Thread Starter New Member

    Sep 21, 2012
    4
    0
    I am trying to display "hello world" on the jhd 162a lcd using
    ATMEGA 16A. I am writing the attached code in winavr but on compiling it is giving the error. lcd is connected with the microcontroller in 4 bit mode.
    connection diagram is--------------

    PB 7: Data 7
    PB 6: Data 6
    PB 5: Data 5
    PB 4: Data 4
    PB 3: N/A
    PB 2: Enable
    PB 1: R/W
    PB 0: Register Select

    even the cursor is not displaying on the lcd................


    the code is

    "#include <avr/io.h>
    #include <stdlib.h>
    #include <util/delay.h>
    #include <stdio.h>

    //Define functions
    //==========================================================
    void io_init(void); //Initializes IO
    void send_nibble(unsigned char __rs, unsigned char __data);

    //==========================================================

    int main (void)
    {
    //io_init();
    DDRB =0b11101111;
    PORTB = 0b01111111;
    delay_ms(10);
    PORTB = 0b00100010; // xsending command
    delay_ms(10);
    PORTB = 0b00000010;
    delay_ms(10);
    PORTB = 0b00101000; // xsending command
    delay_ms(10);
    PORTB = 0b00001000;
    delay_ms(10);
    PORTB = 0b10100100; // xsending data ‘H’
    delay_ms(10);
    PORTB = 0b10000100;
    delay_ms(10);
    PORTB = 0b10101000; // sending data
    delay_ms(10);
    PORTB = 0b10001000;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘E’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10100101; // sending data
    delay_ms(10);
    PORTB= 0b10000101;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘L’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10101100; // sending data
    delay_ms(10);
    PORTB= 0b10001100;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘L’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10101100; // sending data
    delay_ms(10);
    PORTB= 0b10001100;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘O’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10101111; // sending data
    delay_ms(10);
    PORTB= 0b10001111;
    delay_ms(10);
    PORTB= 0b10100010; // sending data ‘SPACE’
    delay_ms(10);
    PORTB= 0b10000010;
    delay_ms(10);
    PORTB=0b10100000; // sending data
    delay_ms(10);
    PORTB=0b10000000;
    delay_ms(10);
    PORTB= 0b10100101; // sending data ‘W’
    delay_ms(10);
    PORTB= 0b10000101;
    delay_ms(10);
    PORTB= 0b10100111; // sending data
    delay_ms(10);
    PORTB= 0b10000111;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘O’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10101111; // sending data
    delay_ms(10);
    PORTB= 0b10001111;
    delay_ms(10);
    PORTB= 0b10100101; // sending data ‘R’
    delay_ms(10);
    PORTB= 0b10000101;
    delay_ms(10);
    PORTB= 0b10100010; // sending data
    delay_ms(10);
    PORTB= 0b10000010;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘L’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10101100; // sending data
    delay_ms(10);
    PORTB= 0b10001100;
    delay_ms(10);
    PORTB= 0b10100100; // sending data ‘D’
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);
    PORTB= 0b10100100; // sending data
    delay_ms(10);
    PORTB= 0b10000100;
    delay_ms(10);

    return(0);
    }

    void io_init (void)
    {
    /*
    PB 7: Data 7
    PB 6: Data 6
    PB 5: Data 5
    PB 4: Data 4
    PB 3: N/A
    PB 2: Enable
    PB 1: R/W
    PB 0: Register Select
    */

    DDRB =0b11101111;
    }

    void send_nibble(unsigned char __rs, unsigned char __data)
    {
    PORTB = (__rs<<4) | __data | 0b00100000; // Set RS & Data. Set EN=High
    _delay_ms(10);
    PORTB = (__rs<<4) | __data; // Set RS & Data. Set EN=Low
    _delay_ms(10);
    "

    the error is

    "> "make.exe" all

    -------- begin --------
    avr-gcc (WinAVR 20100110) 4.3.3
    Copyright (C) 2008 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


    Compiling C: main.c
    avr-gcc -c -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o
    main.c: In function 'main':
    main.c:18: warning: implicit declaration of function 'delay_ms'
    main.c: In function 'send_nibble':
    main.c:140: error: expected declaration or statement at end of input
    make.exe: *** [main.o] Error 1

    > Process Exit Code: 2
    > Time Taken: 00:01
    "

    Please help .....................
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,415
    3,354
    Good heavens! You have a ton of problems.

    Why send out "HELLO WORLD" when you cannot even send "H".

    Problem 1:
    DDRB = 0b11111111;

    Problem 2:
    You need two routines, one to send a command, another to send data. Read the manual.

    Problem 3:
    You need to initialize the LCD. Read the manual.

    Problem 4:
    Learn to program in C.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    I have to agree with the above. OP your code is an absolute mess, there are far easier ways to do this.

    For one check your compiler libraries. Changes are one already exists to write to the LCD.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Inside int main (void) you comment out //io_init(); so one may ask how DO you init the I/O?

    Looks like your send_nibble() routine is missing the last bracket } character to complete the function. Now since you did #include <util/delay.h> (where I would expect this function to live) and still got that error I would guess you have the name wrong. Check the documentation, or just scan delay.h to find what functions it does define.

    Next, the warning "warning: implicit declaration of function 'delay_ms'" means the compiler has no idea what this function is.

    I do expect you will have further errors once you fix those, but keep at it.
     
Loading...