atmega8, HD44780 Desplay und umwandler, brauche Hilfe :(
Mittwoch, 23. Mai 2012
 
 

PIC Mikrocontroller Forum  |  PIC Mikrocontroller  |  Programmiersprache C  |  atmega8, HD44780 Desplay und umwandler, brauche Hilfe :( « vorheriges nächstes »
Seiten: [1] Nach unten Drucken
Autor Thema: atmega8, HD44780 Desplay und umwandler, brauche Hilfe :(  (Gelesen 296 mal)
 
simpson1991
Newbie
*
Offline Offline

Beiträge: 1


Profil anzeigen
« am: Februar 06, 2012, 19:07:08 »

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

Code:
#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 Traurig
MfG und ebsten Dank Smiley
« Letzte Änderung: Februar 06, 2012, 19:31:56 von simpson1991 » Gespeichert
Edson
Globaler Moderator
Sr. Member
*****
Offline Offline

Beiträge: 373



Profil anzeigen
« Antworten #1 am: Februar 07, 2012, 10:01:57 »

Hallo Jan,

vielleicht hast Du inzwischen bemerkt dass es sich in unserem Forum ausschließlich um PIC-Mikrocontroller dreht.
Falls sich doch jemand hierher verlaufen sollte, der sich deiner annehmen möchte, kann er sich hier hinzu gesellen:

http://www.mikrocontroller.net/topic/247672

Gruß,
Edson
Gespeichert
Seiten: [1] Nach oben Drucken 
« vorheriges nächstes »
Gehe zu:  

Powered by MySQL Powered by PHP Made for Mozilla (Firefox) Made for Internet Explorer
Seite erstellt in 0.032 Sekunden mit 17 Zugriffen.
 
Top! Top!