CriGri
12.08.2007, 16:16
Hi liebe Gemeinde :)
Hab ein kleines Porgramm geschrieben welches die Daten einer PC Tastatur (PS/2 Schnittstelle) einliest. Zur Zeit schau ich mir das Empfangene auf einer Bargraphanzeige an. Später wird die Tastatur an ein GLCD angeschlossen. Vorgestern habe ich mal probiert die Tastencodes der Tastatur an zu zeigen was auch super funktioniert hat. Danach hab ich mir noch nen kleinen Buffer geschrieben und nu geht nichts mehr. Ich glaub der Fehler liegt im interrupt (da ich zum ersten mal damit arbeite). Vielleicht könnt ihr mir ja helfen.
C_File
#include <at892051.h>
#include <stdio.h>
#include "keyb.h"
#include "Func.h"
#include "MyTypes.h"
/* ---- Various variables ------------------------------------------------*/
char count = 11;
char dat = 0;
char mask = 1;
char *in, *out, buffcount;
char Key_Buffer[Buffsize];
/* ---- Key codes from Keyboard ------------------------------------------*/
u_char Key_Tab[][2] = { {0x15,'Q'},{0x1d,'W'},{0x24,'E'},{0x2d,'R'},{0x2c, 'T'},{0x1a,'Z'},{0x3c,'U'},
// {0x43,'I'},{0x44,'O'},{0x4d,'P'},{0x1c,'A'},{0x1b, 'S'},{0x23,'D'},{0x2b,'F'},
// {0x34,'G'},{0x33,'H'},{0x3b,'J'},{0x42,'K'},{0x4b, 'L'},{0x35,'Y'},{0x22,'X'},
// {0x21,'C'},{0x2a,'V'},{0x32,'B'},{0x31,'N'},{0x3a, 'M'},{0x54,'Ü'},{0x4c,'Ö'},
/* {0x52,'Ä'},*/{0,0}
};
/* ---- Interrupt initialization -----------------------------------------*/
void Init_INT0(void){
EA = EX0 = IT0 = 1; // ext.int 0 , falling edge
}
void Ext_INT0(void) interrupt 0{
SDA = 1; // Set Port to input
if(count > 2 && count < 11){ // only data bits
dat = SDA? (mask | dat) : dat; // get data byte
mask <<= 1; // check various bit
}
if(--count == 0){ // byte complet
mask = 1;
if(Decode(dat)); // if char is knowen
dat = 0;
count = 11;
}
}
/* ---- Decode key code --------------------------------------------------*/
u_int Decode(u_char key_code){
u_char a, i = 0;
a = Key_Tab[i][0];
while ((a) && (a != key_code))
a = Key_Tab[++i][0]; // search char
if (a == key_code){
a = Key_Tab[i][1]; // get char
WR_Buffer(a); // save char
return 1;
}
return 0; // if unknowen key code
}
/* ---- Buffer initialization --------------------------------------------*/
void Init_Buffer(void){
in = Key_Buffer; // point on first element
out = Key_Buffer;
buffcount = 0;
}
/* ---- Save char in buffer ----------------------------------------------*/
void WR_Buffer(char key){
if(buffcount++ < Buffsize)
*in = key; // save key
if(++in >= (Key_Buffer + Buffsize))
in = Key_Buffer; // point to first element
}
/* ---- Read char from buffer -------------------------------------------*/
char RD_Buffer(void){
char ch;
while(buffcount == 0); // wait for data
ch = *out;
buffcount--;
if(++out >= (Key_Buffer + Buffsize))
out = Key_Buffer; // point to first element
return ch;
}<at892051.h><stdio.h>
H_File
#include <AT892051.h>
#include "MyTypes.h" // u_char a.s.o.
#ifndef __KEYB__
#define __KEYB__
/* ---- Ports ------------------------------------------------------------*/
sbit SCL = P3^2;
sbit SDA = P3^7;
/* ---- Generell defines -------------------------------------------------*/
#define Buffsize 64
#define op_time 1
extern char Key_Buffer[];
/* ---- Prototypes -------------------------------------------------------*/
void Init_INT0 (void);
u_int Decode (u_char key_code);
void Init_Buffer (void);
void WR_Buffer (char key);
char RD_Buffer (void);
#endif<at892051.h>
Main_File
#include <at892051.h>
#include <stdio.h>
#include "Keyb.h"
#include "Func.h"
#include "MyTypes.h"
void main(void){
char ch;
Init_INT0();
Init_Buffer();
for(;;){
ch = RD_Buffer();
P1 = ~ch; // invers cause port is in sink mode
wait(1000); // hold time to see hex code on Bargraph
}
}
Vielen Dank im Voraus
lg Cri</stdio.h></at892051.h></at892051.h></stdio.h></at892051.h>
Hab ein kleines Porgramm geschrieben welches die Daten einer PC Tastatur (PS/2 Schnittstelle) einliest. Zur Zeit schau ich mir das Empfangene auf einer Bargraphanzeige an. Später wird die Tastatur an ein GLCD angeschlossen. Vorgestern habe ich mal probiert die Tastencodes der Tastatur an zu zeigen was auch super funktioniert hat. Danach hab ich mir noch nen kleinen Buffer geschrieben und nu geht nichts mehr. Ich glaub der Fehler liegt im interrupt (da ich zum ersten mal damit arbeite). Vielleicht könnt ihr mir ja helfen.
C_File
#include <at892051.h>
#include <stdio.h>
#include "keyb.h"
#include "Func.h"
#include "MyTypes.h"
/* ---- Various variables ------------------------------------------------*/
char count = 11;
char dat = 0;
char mask = 1;
char *in, *out, buffcount;
char Key_Buffer[Buffsize];
/* ---- Key codes from Keyboard ------------------------------------------*/
u_char Key_Tab[][2] = { {0x15,'Q'},{0x1d,'W'},{0x24,'E'},{0x2d,'R'},{0x2c, 'T'},{0x1a,'Z'},{0x3c,'U'},
// {0x43,'I'},{0x44,'O'},{0x4d,'P'},{0x1c,'A'},{0x1b, 'S'},{0x23,'D'},{0x2b,'F'},
// {0x34,'G'},{0x33,'H'},{0x3b,'J'},{0x42,'K'},{0x4b, 'L'},{0x35,'Y'},{0x22,'X'},
// {0x21,'C'},{0x2a,'V'},{0x32,'B'},{0x31,'N'},{0x3a, 'M'},{0x54,'Ü'},{0x4c,'Ö'},
/* {0x52,'Ä'},*/{0,0}
};
/* ---- Interrupt initialization -----------------------------------------*/
void Init_INT0(void){
EA = EX0 = IT0 = 1; // ext.int 0 , falling edge
}
void Ext_INT0(void) interrupt 0{
SDA = 1; // Set Port to input
if(count > 2 && count < 11){ // only data bits
dat = SDA? (mask | dat) : dat; // get data byte
mask <<= 1; // check various bit
}
if(--count == 0){ // byte complet
mask = 1;
if(Decode(dat)); // if char is knowen
dat = 0;
count = 11;
}
}
/* ---- Decode key code --------------------------------------------------*/
u_int Decode(u_char key_code){
u_char a, i = 0;
a = Key_Tab[i][0];
while ((a) && (a != key_code))
a = Key_Tab[++i][0]; // search char
if (a == key_code){
a = Key_Tab[i][1]; // get char
WR_Buffer(a); // save char
return 1;
}
return 0; // if unknowen key code
}
/* ---- Buffer initialization --------------------------------------------*/
void Init_Buffer(void){
in = Key_Buffer; // point on first element
out = Key_Buffer;
buffcount = 0;
}
/* ---- Save char in buffer ----------------------------------------------*/
void WR_Buffer(char key){
if(buffcount++ < Buffsize)
*in = key; // save key
if(++in >= (Key_Buffer + Buffsize))
in = Key_Buffer; // point to first element
}
/* ---- Read char from buffer -------------------------------------------*/
char RD_Buffer(void){
char ch;
while(buffcount == 0); // wait for data
ch = *out;
buffcount--;
if(++out >= (Key_Buffer + Buffsize))
out = Key_Buffer; // point to first element
return ch;
}<at892051.h><stdio.h>
H_File
#include <AT892051.h>
#include "MyTypes.h" // u_char a.s.o.
#ifndef __KEYB__
#define __KEYB__
/* ---- Ports ------------------------------------------------------------*/
sbit SCL = P3^2;
sbit SDA = P3^7;
/* ---- Generell defines -------------------------------------------------*/
#define Buffsize 64
#define op_time 1
extern char Key_Buffer[];
/* ---- Prototypes -------------------------------------------------------*/
void Init_INT0 (void);
u_int Decode (u_char key_code);
void Init_Buffer (void);
void WR_Buffer (char key);
char RD_Buffer (void);
#endif<at892051.h>
Main_File
#include <at892051.h>
#include <stdio.h>
#include "Keyb.h"
#include "Func.h"
#include "MyTypes.h"
void main(void){
char ch;
Init_INT0();
Init_Buffer();
for(;;){
ch = RD_Buffer();
P1 = ~ch; // invers cause port is in sink mode
wait(1000); // hold time to see hex code on Bargraph
}
}
Vielen Dank im Voraus
lg Cri</stdio.h></at892051.h></at892051.h></stdio.h></at892051.h>