hay aloso ahbe ein Programm geschrieben welches mir über die Eingabe einer 4*4 keymap
Dezimal Zahlen bis 255 in Hexadezimal- und Binärzahlen ausgibt.
Leider gibt er mir nur blöcke auf dem Display aus und ich weiß nicht genau wo der Fehler liegt.
Die Umrechnung und ausgabe funktioniert ohne Probleme wenn ich ohne Die Tastatur arbeite d.h die Funktion Keyboard weglasse und die eingegebene Zahl vorher selbst definiere.
hier mal der code
y1-4 sind auf PORTC 2-5 angeschloßen
x1-4 sind auf PINB 0-3 angeschloßen
#include <avr/io.h>
#include "lcd-routines.h"
#include <stdio.h>
#include <util/delay.h>
int keyboard();
int main(void)
{
int i, Zahl, ergebnis = 0, key;
char Result[9], text[16], texxt[16], xxx[16];
lcd_init();
while( (key=keyboard()) == -1 );
ergebnis+= key*100;
do
{
_delay_ms(2);
}
while( keyboard() != -1 );
lcd_setcursor(0 ,1);
sprintf(xxx,"%d",ergebnis);
lcd_string(xxx);
while( (key=keyboard()) == -1 );
ergebnis+=key;
ergebnis+= key*10;
do
{
_delay_ms(2);
}
while( keyboard() != -1 );
lcd_setcursor(0 ,1);
sprintf(xxx,"%d",ergebnis);
lcd_string(xxx);
while( (key=keyboard()) == -1 );
ergebnis+= key;
do
{
_delay_ms(2);
}
while( keyboard() != -1 );
lcd_setcursor(0 ,1);
sprintf(xxx,"%d",ergebnis);
lcd_string(xxx);
Zahl = ergebnis;
if (Zahl > 255)
{ lcd_init();
lcd_setcursor(0, 1);
lcd_string("Zahl zu gross");
}
else
{
lcd_setcursor(0, 1);
lcd_string("Hex: ");
lcd_setcursor(8, 1);
sprintf(text,"%X",Zahl);
lcd_string(text);
for( i = 0; i < 8; ++i )
{
if( Zahl % 2 == 0 )
Result[ 7 - i ] = '0';
else
Result[ 7 - i ] = '1';
Zahl = Zahl / 2;
}
Result[8] = '\0';
lcd_setcursor( 0, 2);
lcd_string("Bin: ");
lcd_setcursor( 8, 2);
sprintf(texxt,"%s",Result);
lcd_string(texxt);
return 0;
}
}
int keyboard()
{
int taste = -1, x = 0;
DDRB = 0xF0;
PORTB = 0x0F;
for (x=0; x<1;)
{
DDRC = 0x40; // x1 auf ausgang
PORTC = 0x40; //x1 auf High
if(PINB & (1 << 0))
{taste = 1;
x++;}
if(PINB & ( 1<< 1))// ist y2 auf High
{taste = 2;
x++;}
if(PINB & ( 1<< 2)) // ist y3 auf High
{taste = 3;
x++;}
if(PINB & ( 1<< 3)) // ist y4 auf High
{taste = 0;
x++;}
DDRC = 0x20;
PORTC = 0x20;
if(PINB & (1 << 0))
{taste = 4;
x++;}
if(PINB & ( 1<< 1))
{taste = 5;
x++;}
if(PINB & ( 1<< 2))
{taste = 6;
x++;}
if(PINB & ( 1<< 3))
{taste = 0;
x++;}
DDRC = 0x10;
PORTC = 0x10;
if(PINB & (1 << 0))
{taste = 7;
x++;}
if(PINB & ( 1<< 1))
{taste = 8;
x++;}
if(PINB & ( 1<< 2))
{taste = 9;
x++;}
if(PINB & ( 1<< 3))
{taste = 0;
x++;}
DDRC = 0x08;
PORTC = 0x08;
if(PINB & (1 << 0))
{taste = 0;
x++;}
if(PINB & ( 1<< 1))
{taste = 0;
x++;}
if(PINB & ( 1<< 2))
{taste = 0;
x++;}
if(PINB & ( 1<< 3))
{taste = 0;
x++;}
}
return (taste);
}
Hoffe Ihr findet etwas sitze jetzt 4 Stunden dran ich kann mir eifnach selber nicht mehr helfen

MfG und ebsten Dank
