Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

character display in lcd using a tmega 16a microcontroller

Status
Not open for further replies.

ravi8820

Junior Member level 1
Joined
May 24, 2012
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,483
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--------------

Code:
  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


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#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

Code:
"> "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 .....................
 
Last edited by a moderator:

but on compiling it is giving the error
So you need to fix the error
even the cursor is not displaying on the lcd................
Does this surprise you? If the code does not compile, let me know, how do you expect the LCD to display anything?
main.c:140: error: expected declaration or statement at end of input
There's your answer. Fix the error. I have no idea what line 140 is, and since you've not formatted your
code, you've made it very difficult for people to help you, because it is difficult to inspect badly formatted code.

And, while I'm at it (I'm sorry, but you're asking for this), take a look at your code - doesn't it strike you as
rather silly that you've taken 60 lines or so to attempt to display a few characters on the screen?
I suggest you study C arrays. In fact, spend a day reading 'The C Programming Language'. It is an extremely
short book, and you will learn a few things from it that will make your code better. And, after a few lines,
you should have begun to suspect that a C compiler may have a simpler way to represent
numbers than in binary.
 
Last edited:

Your DDRB =0b11101111; setting is wrong. Make it DDRB =0b11110111; or DDRB =0b11111111;

One of the functions _delay_ms(10); or delay_ms(10); is wrong.

Change delay_ms(10); to _delay_ms(10); and see if it works.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top