semicolon
29.05.2006, 20:31
Hallo Leute
Ich habe ein Problem. Mein LCD läuft nicht.
Atmega32
PORTC7-PORTC4: Daten
PORTC3: E
PORTC2: RS
PORTC1:R/W
Habe folgenden Code geschrieben:
main.c
#include "io.h"
#include "iom32.h"
#include "delay.h"
#include "lcd_2x16.h"
void wait_s () {
int i;
for (i = 0; i <20000; i++) {
asm volatile("NOP");
}
}
//Variabeln
static int RS = 0;
//display löschen
void clrLCD() {
RS = 0;
lcd_send(clr);
wait_s();
RS = 1;
}
//Cursor auf home setzen
void homeDisplay() {
RS = 0;
lcd_send(home);
RS = 1;
}
//Display initialisieren
void initDisplay() {
_delay_ms(20); //warten bis Display parat
RS = 0;
PORTC = 0;
lcd_send(function_set | _8Bit);
_delay_ms(4.1);
lcd_send(function_set | _8Bit);
_delay_us(100);
lcd_send(function_set | _8Bit);
lcd_send(function_set | _4Bit);
lcd_send(function_set | _2line);
lcd_send(control | display_on |cursor_on | blink_on);
clrLCD();
homeDisplay();
RS = 1;
}
//Display auf zweite Zeile setzen
void second_row() {
RS = 0;
lcd_send(0x80 | 0x40);
RS = 1;
}
//Daten an LCD senden
void lcd_send(char c) {
int data = c;
//Hight - Nibble
PORTC = (RS<<2);
PORTC |= ((data & 0xF0));
PORTC |= (1<<3);
_delay_ms(1.6);
PORTC &= ~(1<<3);
//Low - Nibble
PORTC = 0;
PORTC = (RS<<2);
PORTC |= ((data & 0x0F)<<4);
PORTC |= (1<<3);
_delay_ms(1.6);
PORTC &= ~(1<<3);
PORTC= 0;
}
int main (void)
{
DDRB = (1<<DDB0) | (1<<DDB2);
DDRC = 0xFF;
DDRD = 0xFF;
wait_s();
initDisplay();
//disaeblen jtag
MCUCSR|=(1<<JTD);
MCUCSR|=(1<<JTD);
lcd_send(0x65);
while (1) {/* Note [6] */
wait_s();
PORTB = 1;
wait_s();
PORTB = 4;
}
return (0);
}
lcd_2x16.h
#include "io.h"
#define clr 0x01
#define home 0x02
#define display_on 0x04
#define blink_on 0x01
#define cursor_on 0x02
#define control 0x08
#define function_set 0x20
#define _4Bit 0x00
#define _8Bit 0x10
#define _2line 0x08
#define LCD PORTC
extern void clrLCD();
extern void lcd_send(char);
extern void homeDisplay();
extern void initDisplay();
extern void second_row();
extern void put_Data(const int *displayData);
extern void lcd_send(char c);
Ich seh den Fehler einfach nicht.[/code]
Ich habe ein Problem. Mein LCD läuft nicht.
Atmega32
PORTC7-PORTC4: Daten
PORTC3: E
PORTC2: RS
PORTC1:R/W
Habe folgenden Code geschrieben:
main.c
#include "io.h"
#include "iom32.h"
#include "delay.h"
#include "lcd_2x16.h"
void wait_s () {
int i;
for (i = 0; i <20000; i++) {
asm volatile("NOP");
}
}
//Variabeln
static int RS = 0;
//display löschen
void clrLCD() {
RS = 0;
lcd_send(clr);
wait_s();
RS = 1;
}
//Cursor auf home setzen
void homeDisplay() {
RS = 0;
lcd_send(home);
RS = 1;
}
//Display initialisieren
void initDisplay() {
_delay_ms(20); //warten bis Display parat
RS = 0;
PORTC = 0;
lcd_send(function_set | _8Bit);
_delay_ms(4.1);
lcd_send(function_set | _8Bit);
_delay_us(100);
lcd_send(function_set | _8Bit);
lcd_send(function_set | _4Bit);
lcd_send(function_set | _2line);
lcd_send(control | display_on |cursor_on | blink_on);
clrLCD();
homeDisplay();
RS = 1;
}
//Display auf zweite Zeile setzen
void second_row() {
RS = 0;
lcd_send(0x80 | 0x40);
RS = 1;
}
//Daten an LCD senden
void lcd_send(char c) {
int data = c;
//Hight - Nibble
PORTC = (RS<<2);
PORTC |= ((data & 0xF0));
PORTC |= (1<<3);
_delay_ms(1.6);
PORTC &= ~(1<<3);
//Low - Nibble
PORTC = 0;
PORTC = (RS<<2);
PORTC |= ((data & 0x0F)<<4);
PORTC |= (1<<3);
_delay_ms(1.6);
PORTC &= ~(1<<3);
PORTC= 0;
}
int main (void)
{
DDRB = (1<<DDB0) | (1<<DDB2);
DDRC = 0xFF;
DDRD = 0xFF;
wait_s();
initDisplay();
//disaeblen jtag
MCUCSR|=(1<<JTD);
MCUCSR|=(1<<JTD);
lcd_send(0x65);
while (1) {/* Note [6] */
wait_s();
PORTB = 1;
wait_s();
PORTB = 4;
}
return (0);
}
lcd_2x16.h
#include "io.h"
#define clr 0x01
#define home 0x02
#define display_on 0x04
#define blink_on 0x01
#define cursor_on 0x02
#define control 0x08
#define function_set 0x20
#define _4Bit 0x00
#define _8Bit 0x10
#define _2line 0x08
#define LCD PORTC
extern void clrLCD();
extern void lcd_send(char);
extern void homeDisplay();
extern void initDisplay();
extern void second_row();
extern void put_Data(const int *displayData);
extern void lcd_send(char c);
Ich seh den Fehler einfach nicht.[/code]