IC2 - LCD 16x2 - Atmega16

Hello there guys,

I just bought an lcd16x2 that has four pins: GND / VCC / SDA / SCL, so i can use it in my project… unfortunately, i am not allowed (by my microcontroller proffessor) to use arduino IDE. So i am using the AVRCodeVision… Also, i`m new to this kind of programming

This is the schematic i am using right now. As you can see, it`s a homemade microcontroller using atmega16…

The SDA pin is wired PC1 and the SCL pin is wired to PC0.

I talked with some friends and they told me that the SDA is bidirectional… i did not understand this…

I managed to configure the PORTC

// Port C initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=Out Bit2=Out Bit1=In Bit0=Out 
DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (1<<DDC3) | (1<<DDC2) | (0<<DDC1) | (1<<DDC0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=0 Bit2=0 Bit1=T Bit0=0 
PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

I looked up on some website with some tutorials for this LCD but none worked… Can you help me with a library that works, and tell me how to configure this IC2 or whatever its called... Ive been struggling for a couple of days, and no result…

Thanks! If you need other informations, tell me

Xeyow:
I just bought an lcd16x2 that has four pins: GND / VCC / SDA / SCL, so I can use it in my project… unfortunately, I am not allowed (by my microcontroller professor) to use Arduino IDE. So I am using the AVRCodeVision… Also, I’m new to this kind of programming

Looking bad

Xeyow:
Can you help me with a library that works, and tell me how to configure this IC2 or whatever it`s called… I’ve been struggling for a couple of days, and no result…

Well, we can suggest the library, but it sort of goes with the Arduino IDE …

I think you’re sort of screwed. :astonished:

By your professor. :grinning:

Deliberately. :roll_eyes:

Would he be monitoring this forum, just to check?

You are on the Arduino Forum. I suggest that you get your LCD working on a regular Arduino.
Verify the I2C address and wiring. i.e. copy-paste the constructor that you are using successfully.

It is a mystery why Professors are so bloody minded. The Arduino hardware (or software) is perfectly adequate. It is an excellent way to prototype projects.

You must understand how to read documentation and design and write up your project.
It is good "engineering practice" to use proven components.

I have posted Codevision an "lcd_i2c" library in the past (on Avrfreaks)
It provides the same library functions as the Codevision "alcd" library.

It is your school project. So you must do your own design work. I suggest that you get it all 100% running on the Arduino first. Translating the Arduino code to C on a mega16 with Codevision can be done as the final step. Providing you have done the design, we can help you with the final translation.

David.

. . . and tell me how to configure this IC2 or whatever it`s called…

The commonly used term is I2C or more correctly I2C.

If you look up I2C (Wikipedia is one place) you will find that the term means “Inter-Integrated Circuit” as it was designed for short distance communication between devices on a particular pc board.

The system was developed by Philips Semiconductor and I believe that they retain the rights to the term ‘I2C’ which is why you won’t find a section on I2C in the Atmel databook. The equivalent system on your ATMega328P ATMega16 is described in the databook section titled “2-wire Serial Interface”. Atmel uses the abbreviation TWI in place of I2C.

Don

This is the schematic i am using right now. As you can see, it`s a homemade microcontroller using atmega16...

It appears that you have posted a screen shot of your 'schematic'. Unfortunately on this snapshot the scroll bars do not work so we are unable to see the entire diagram.

The SDA pin is wired PC1 and the SCL pin is wired to PC0.

Did you make this choice or did your professor? If the choice was made by your professor then it looks like he may want you to 'bit-bang' the I2C interface. This means that you will have to implement the entire protocol yourself which, while not trivial, actually isn't exceptionally difficult either. Alternatively you may be able to find a library that implements a 'software I2C interface' and direct it to use those specific pins.
If you have a choice it would be easier to use the internal TWI interface described in the "2-wire Serial Interface" section of the databook. In that case you will wind up using PC5 for SCL and PC4 for SDA and you don't have to configure those pins as this is done for you when you set up the various registers. Any library that implements a 'hardware I2C interface' would use those two pins as well.

EDIT:

I just took a closer look at the partial schematic that you posted and I see that on your processor the hardware SCL and SDA pins are indeed on PC0 and PC1.

This means that you will not be relegated to bit-bashing and you can use the internal TWI interface, either by writing the code yourself or by means of an appropriate library.

You can still do your initial work on a regular Arduino as recommended by David. The TWI subsections are most likely very similar if not identical (I haven't checked). When you get all done it should be relatively simple (famous last words) to get it working on your homemade microcontroller.

Don

Yes, we know it is an ATmega16. It says so in the title.

Since this is an Arduino forum, I would guess that the OP owns a Uno or similar. So he can test his LCD and backpack with the proven libraries.

It would be far easier to develop with the Arduino.
He could go straight to the mega16 and Codevision if he wants. If so, he probably wants to ask questions on Avrfreaks or the CV Yahoo forum.

David.

David - It looks like you slipped your post in while I was doing my last edit. We essentially said the same thing.

Don

I can never understand why Professors are anti-Arduino.

Whether you use Arduino, CV, GCC, ... there will be existing libraries or prior code.

It is up to the student to find it, study it, inwardly digest. Then use it with appropriate credits, explanations, ...

I would be far happier driving a motor car over a bridge that uses certified bolts, components, construction.
Professors may prefer hand-turned bolts from unspecified steel. I don't care if it is hand-made. I do care if the bridge falls down.

The idle student waits until the last day before submission and hopes that someone will do her homework for her. It is pretty obvious to both teacher and professor which students have understood and which ones are plain lazy.

Unfortunately, employers do not discover which type until it is too late.

David.

david_prentice:
Since this is an Arduino forum, I would guess that the OP owns a Uno or similar. So he can test his LCD and backpack with the proven libraries.

I dont have an arduino anymore... Had one, but somehow, it doesnt work anymore... So i can not test the LCD on an arduino

Well, buy or borrow an Arduino.

I suspect that your mega16 board is only accessible in your school lab.
An Arduino can be used at home, on the bus, train, ... if you have a laptop PC.

You will find it easier to develop with the Arduino. OTOH, Codevision is pretty useful too. A lot depends on your personal setup.

David.

In fact, the mega16 board is mine. I made it, so i can use it whenever i want.

In which case, you will develop with Codevision.

I am already using AVR CodeVision, but i don`t know where to get the libraries i need...

I Googled for "Codevision lcd_twi library" and got an old post from me

The following posts show some examples.

I note that you have got real-life external pull-ups and are using the hardware TWI pins.
Shout if you have difficulties. It is hard-coded for a Slave address of 0x27 and the common PCF8574 wiring.

David.

This could be a bit of a XY problem: XyProblem - Greg's Wiki

What was the real task assignment?

Using i2c seems a bit too advanced for this this type of exercise.
i2c is extremely complicated and way too complex to expect anything from students but using a pre-written i2c library.

Was using an i2c LCD display really required? or was the task just to write some code to talk to a 16x2 LCD?
In other words, if i2c is not required, it becomes a much simpler manageable task not needing a pre-written library and would seem like a much more reasonable task for a student to complete as then the exercise becomes mainly about how to control an hd44780 interface with is not too difficult.

--- bill