Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Writting to Buffer for LEd display...

Status
Not open for further replies.
Hi again,

I want to add keyboard with this AT/2 6 pin..what will be the procedure? i am preparing code for PC keyboard .

#include<pic.h>
#define _XTAL_FREQ 20000000L
__CONFIG(0x3F18);

char displayPointer=0;
extern const char font[];

unsigned char buffer[26]; // buffer for screen

void interrupt ISR() // This just swaps the buffer to the display
{
if(TMR2IF) // make sure its the timer interrupt.
{
PORTB = 0; // clear old data first
if(displayPointer == 0 ) // 1st frame..
RC4 = 1; // Data = 1 on the first clock
RC3 = 1;
__delay_us(20); // Clock the shift registers
RC3 = 0;
RC4 = 0;
PORTB = buffer[displayPointer]; // Move buffer line by line
if(++displayPointer==24) // 24 LED columns
displayPointer = 0; // back to first..
}
TMR2IF = 0;
}

void display(const char* str)
{
int addr;
char x, y;
while(*str != 0) // while there is still characters
{
addr = (int) *str++ - 0x20; // get character
addr *=5;
for(y=0;y<5;y++) // 5x8 font so 5 columns
{
buffer[25] = font[addr++]; // put it in buffer
for(x=0;x<26;x++)
{
buffer[x] = buffer[x+1]; // shift all the columns <--
__delay_ms(5); // so you can see it
}
}
buffer[25] = 0; // This is the scpace between
for(x=0;x<26;x++) // the characters.. Or they will be too close
{
buffer[x] = buffer[x+1]; // shift the space in
__delay_ms(5);
} // NOTE!!! your array is 28 not 24 like mine
}
}


void main(void)
{
ADCON1 = 0x6;
T2CON = 0x1e;
PR2 = 129; // timer preload value
TMR2IE = 1; // enable timer 2 interrupt
PEIE = 1; // enable peripheral interrupt
GIE = 1; // enableglobal interrupt
TRISB = 0; // Port B as output...
TRISC = 0; // Port C as ouput...
while(1)
{
display("HELLO WORLD!!! "); // Here's the message
}
} // End main
 
With your abilities, as demonstrated by your website, you shouldn't need his code. It seems that you are very capable of writing it yourself.

Mike.

Should this be the standard reply to all Ritesh's posts?

Just curious.

Mike.
 
Hi again,

i am using this code for display keyboard char to terminal window at show 'k' as per testing serial comm. after that 0xFB is coming cont pressing keyboard is doing nothing,why???
 

Attachments

  • keyboard.txt
    2 KB · Views: 188
0xFB Scancode for key Set specific key to typematic/autorepeat only (scancode set 3 only)
but when i press any key then also it does not change why??
 
I have noticed one thing the uc is sending cont 0XFB ...
just for checking i have disconnected the Vcc from PS/2 and some time shorted the Data with gnd for testing to see some changes on terminal wind but nothing happen don't know why??

i think some problem is here it is not updating scan code from keyboard.
Code:
while(1)
   {



ch=Scan_Data;
 Hserout( ch);
__delay_ms(1000);

ch=0;

      
      Capture_init();//Initialise once again for next capture

   }

the problem is something else not keyboard it is in code i have cut three wire from ps/2 then also FB is coming...
 
Last edited:
You have misunderstood the protocol.. You need to issue commands to the keyboard to receive the correct results.

0xFB seems to be a error code.... If 0xFA is an "ack" I would think 0xFB would be a "nack" Error in receiving a command.

Here's a list of viable commands.

0xA7 (Disable mouse interface) - PS/2 mode only. Similar to "Disable keyboard interface" (0xAD) command.
0xA8 (Enable mouse interface) - PS/2 mode only. Similar to "Enable keyboard interface" (0xAE) command.
0xA9 (Mouse interface test) - Returns 0x00 if okay, 0x01 if Clock line stuck low, 0x02 if clock line stuck high, 0x03 if data line stuck low, and 0x04 if data line stuck high.
0xAA (Controller self-test) - Returns 0x55 if okay.
0xAB (Keyboard interface test) - Returns 0x00 if okay, 0x01 if Clock line stuck low, 0x02 if clock line stuck high, 0x03 if data line stuck low, and 0x04 if data line stuck high.
0xAD (Disable keyboard interface) - Sets bit 4 of command byte and disables all communication with keyboard.
0xAE (Enable keyboard interface) - Clears bit 4 of command byte and re-enables communication with keyboard.
0xAF (Get version)
0xC0 (Read input port) - Returns values on input port (see Input Port definition.)
0xC1 (Copy input port LSn) - PS/2 mode only. Copy input port's low nibble to Status register (see Input Port definition)
0xC2 (Copy input port MSn) - PS/2 mode only. Copy input port's high nibble to Status register (see Input Port definition.)
0xD0 (Read output port) - Returns values on output port (see Output Port definition.)
0xD1 (Write output port) - Write parameter to output port (see Output Port definition.)
0xD2 (Write keyboard buffer) - Parameter written to input buffer as if received from keyboard.
0xD3 (Write mouse buffer) - Parameter written to input buffer as if received from mouse.
0xD4 (Write mouse Device) - Sends parameter to the auxillary PS/2 device.
0xE0 (Read test port) - Returns values on test port (see Test Port definition.)
0xF0-0xFF (Pulse output port) - Pulses command's lower nibble onto lower nibble of output port (see Output Port definition.)
 
I am also working blind here.... I have never done a keyboard interface..... Maybe that's why he only waits until a specific character has been sent!!!

You'll have to go by trail and error... Also you are running twice as fast as he is...
 
Why not test the keyboard interface on an HD44780 LCD? It's the easiest, you punch in A, and if it's correct, it's an A in front.

After the PS2 interface is correct, it's much easier to hook it up to the LED board or whatever it is.
 
Why not test the keyboard interface on an HD44780 LCD? It's the easiest, you punch in A, and if it's correct, it's an A in front.

After the PS2 interface is correct, it's much easier to hook it up to the LED board or whatever it is.

i am not testing on led ,see the code i am testing on serial window.
 
Hi
The scandata function is giving fb only why what the problem in this function i have not connected the keyboard than also fb?
 
according to this he is not sending any command to ps.
**broken link removed**

HI,

i have noticed in this many problem i have wasted time on it here is some:

const unsigned char Key[]={"0F FFFFF FFFFt` as cQ1 ZSAW2 CXDE43 VFTR5 NBHGY6 MJU78 ,KIO09 ./L;P- ' [=\\"};
some other also....
any way the is not working at all..
I have just connected my serial to USB RS232 and watching whether PS/2 is working yes it is working.
on giving supply all 3 led blink and pressing key give serial output i don't have oscilloscope so, after changing baund rate data also changing....
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top