PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : I²C LCD mit ATmega8



MartinFunk
14.02.2007, 17:04
Hi,
ich habe in der letzen woche mal ein I²C LCD gebaut .
Es wird über einen ATmega8 als I²C Slave gesteuert.
Hier ein paar Bilder:
http://martin.roboterbastler.de/elektronik/images/I2C_LCD.jpg
http://martin.roboterbastler.de/elektronik/images/I2C_LCD_1.jpg
http://martin.roboterbastler.de/elektronik/images/I2C_LCD_2.jpg

Und hier das Hex-file:
http://martin.roboterbastler.de/elektronik/I2C_LCD.hex
(rechtsklick speichern unter)

Ansteuerung:
I2C Slave Adresse: 0x60
LCD_PUTC = 0x50
LCD_GOTOXY = 0x51
LCD_CLEAR = 0x52
LCD_HOME = 0x53
LCD_LIGHT = 0x54
Hier ein Beisiel zur ansteuerung:
http://martin.roboterbastler.de/elektronik/I2C_master.zip

Und hier noch der schaltplan:
http://martin.roboterbastler.de/elektronik/images/I2C%20LCD.JPG
Der Stecker des LCD's ist nach RN-Standart!

Mfg Martin

Jon
14.02.2007, 18:08
Gratulation!!
Hast du mal ein Bild, das zeigt, was das LCD anzeigt?

jon

MartinFunk
14.02.2007, 18:32
Danke,
Hier noch ein die Bilder:
http://martin.roboterbastler.de/elektronik/images/I2C_LCD_3.jpg
http://martin.roboterbastler.de/elektronik/images/I2C_LCD_4.jpg

Die Display beleuchtung wird an PORTD.4 angeschlossen und kann per pwm angesteuert werden.

MfG Martin

raoul4
15.02.2007, 13:44
Du betreibst die LCD Beleuchtung mit dem mega8? Ohne Treiber?

MartinFunk
15.02.2007, 14:43
Ja ich betreibe die Display beleuchtung ohne Treiber, also Anode an PORTD.4 und Katode an GND.

MfG Martin

Jon
15.02.2007, 14:47
Wie viel mA zieht denn die Beleuchtung?
Wird der ATMega nicht warm?

jon

raoul4
15.02.2007, 14:52
Das standart LCD (2x16 beim reichelt) braucht 130mA für die Hintergrundbeleuchtung. Damit würdest du das Limit vom mega8 um über das 6-fache übersteigen...

MartinFunk
15.02.2007, 14:53
Nein der mega wird nicht warm die beleuchtung zieht so um die 15 -20 mA

Martin

Jon
15.02.2007, 14:56
Sollte eigentlich etwas mehr ziehen...
Mit einem höheren Strom sollte es auch heller werden.

jon

MartinFunk
15.02.2007, 14:59
Das display ist hell genug bei voller leuchtkraft blendet es einen schon fast.

Martin

HannoHupmann
15.02.2007, 16:46
@MartinFunk kleiner Tipp, skalier die Bilder bevor du sie online stellst. Wenn es nicht gerade Detail sein müssen dann reicht leicht eine Auflösung von 800x600 und man kann sie sich schneller anschauen.

MartinFunk
15.02.2007, 17:48
OK werd ich machen!

Martin

MartinFunk
15.02.2007, 20:37
Hi,
kann mir jemand helfen die I2C adresse ins EEPROM zu schreiben.

Hier noch mein code:


#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <inttypes.h>
#include "lcd.c"
#include "TWI_Slave.c"

#define F_CPU 8000000UL
// Sample TWI transmission commands
#define LCD_PUTC 0x50
#define LCD_GOTOXY 0x51
#define LCD_CLEAR 0x52
#define LCD_GOHOME 0x53
#define LCD_LIGHT 0x54

//#define EEMEM __attribute__ ((section (".eeprom")))

unsigned char TWI_Act_On_Failure_In_Last_Transmission ( unsigned char TWIerrorMsg )
{
PORTB = TWIerrorMsg;
TWI_Start_Transceiver();

return TWIerrorMsg;
}

void init_timer2 (void)
{
cli(); // Interrupts sperren!
ASSR &= ~(1<<AS2);
TCCR2 |= (1<<CS21) | (1<<CS22); //Timer 2 auf CLK/1024 setzen
OCR2 = 255; // Output Compare
TCNT2= 0x00; // Timer2 auf 0 stellen
TIMSK |= (1<<OCIE2) | (1<<TOIE2); // Timer2 Output Compare Interrupt Enable aktivieren (Bit setzen) //
sei(); // Interrrupts freigeben!
}

SIGNAL(SIG_OUTPUT_COMPARE2)
{
char cSREG;
cSREG = SREG; // Statusregister puffern in Variable cSREG //
PORTD &= ~(1<<4);
SREG = cSREG; // Statusregister aus Variable cSREG retten //
}
SIGNAL(SIG_OVERFLOW2)
{
char cSREG;
cSREG = SREG; // Statusregister puffern in Variable cSREG //
PORTD |= (1<<4);
SREG = cSREG; // Statusregister aus Variable cSREG retten //
}

int main( void )
{
unsigned char messageBuf[3];
unsigned char TWI_slaveAddress = 0x60 ;
uint32_t loop = 0;
//uint8_t eeFooByte = 0x01;
//uint8_t eeFooByte1 = 0x02;

// timer init
init_timer2();



DDRD = 0xFF; // Set to ouput
DDRB = 0x00; // Set to input
DDRC = 0x00; // Set to input
PORTB = 0xff; //activate pullup's
PORTC = 0xff; //activate pullup's

// Own TWI slave address

TWI_slaveAddress = 0x60; //eeprom_read_byte(&eeFooByte);

// Initialise TWI module for slave operation. Include address and/or enable General Call.
TWI_Slave_Initialise( TWI_slaveAddress);

sei();

// Start the TWI transceiver to enable reseption of the first command from the TWI Master.
TWI_Start_Transceiver();

//LCD_init
lcd_init(LCD_DISP_ON);
lcd_clrscr();
lcd_home();
lcd_puts("I2C_LCD by\nMartin Funk V1.1");

while (loop < 500000) loop++;

lcd_clrscr();
lcd_home();
lcd_puts("martin.roboter\nbastler.de V1.1");

loop = 0;
while (loop < 500000) loop++;
lcd_clrscr();
lcd_home();

OCR2 = 0;

// This loop runs forever. If the TWI is busy the execution will just continue doing other operations.
while(1)
{
// Check if the TWI Transceiver has completed an operation.
if ( ! TWI_Transceiver_Busy() )
{
// Check if the last operation was successful
if ( TWI_statusReg.lastTransOK )
{
// Check if the last operation was a reception
if ( TWI_statusReg.RxDataInBuf )
{
TWI_Get_Data_From_Transceiver(messageBuf ,3);
// Check if the last operation was a reception as General Call
if ( !TWI_statusReg.genAddressCall )

{
// Take action dependant on what slave address that was used in the message
//if (messageBuf[0] == TWI_slaveAddress)
// {
//clear Display
if (messageBuf[0] == LCD_CLEAR) //lcd löschen
{
lcd_clrscr();
}
if (messageBuf[0] == LCD_GOTOXY) //lcd gotoxy
{
lcd_gotoxy(messageBuf[1],messageBuf[2]);;
}
if (messageBuf[0] == LCD_PUTC) //lcd put char
{
lcd_putc(messageBuf[1]);

}
if (messageBuf[0] == LCD_GOHOME) //lcd put char
{
lcd_home();

}
if (messageBuf[0] == LCD_LIGHT) //lcd put char
{
OCR2 = messageBuf[1];
}
}
}
// Check if the TWI Transceiver has already been started.
// If not then restart it to prepare it for new receptions.
if ( ! TWI_Transceiver_Busy() )
{
TWI_Start_Transceiver();
}
}
// Ends up here if the last operation completed unsuccessfully
else
{
TWI_Act_On_Failure_In_Last_Transmission( TWI_Get_State_Info() );
}

}
}
}



Mfg Martin