سلام کسی میتونه برنامه روشن کردن ال ای دی های کیبرد کامپیوتر را با میکرو وبا استفاده از کانکتور ps2 بنویسه؟
خیلی ممنون میشم اگه کسی کمکم کنه.
خیلی ضروریه
خیلی ممنون میشم اگه کسی کمکم کنه.
خیلی ضروریه
#include <mega32.h>
#include <delay.h>
#include <stdio.h>
#include <defpin.h>
#include <scancodes.h>
#include <kbdio.h>
void main(void)
{
// Declare your local variables here
unsigned char kar;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0xa6;
UBRRH=0x00;
UBRRL=0x33;
data_byte=0xff;
hosto_d(data_byte); \\ Send Reset Command
show_byte(deviceto_h()); \\ Wait for 0xFA (ACK) Display it
putchar(','); \\ Display ,
show_byte(deviceto_h()); \\ Wait for 0xAA (Successful Reset)
putchar(','); \\ Display ,
data_byte=0xed;
hosto_d(data_byte); \\ Send LED Control Command
show_byte(deviceto_h()); \\ Wait for 0xFA (ACK) and Display it
data_byte=0x02; \\ Argument = Num Lock: On
hosto_d(data_byte); \\ Send Argument
show_byte(deviceto_h()); \\ Wait for 0xFA (ACK) and Display it
while(1)
{
}
}
#define data_pin PIND.2 //Pind.2 connect to data pin of AT keyboard #define clock_pin PIND.3 //Pind.3 connect to clock pin of AT keyboard #define data_pin_out PORTD.2 //define Portd.2 for output mode #define clock_pin_out PORTD.3 //define Portd.3 for output mode #define data_pin_reg DDRD.2 #define clock_pin_reg DDRD.3
// Declare your global variables here
bit parity_bit,data_bit,scroll_flag=0;
unsigned char data_byte;
unsigned char i;
void hosto_d(unsigned char c_char);
unsigned char deviceto_h();
unsigned char decode(unsigned char sc);
void show_byte(unsigned char scc);
void scroll(void);
/***************************************************************************************************************/
unsigned char deviceto_h()
{
unsigned char c_char;
begin1:
parity_bit=0;
data_byte=0;
data_pin_reg=0; //tow pin of port set to input mode
clock_pin_reg=0; //the host ready to recive data from atkeyboard
for(;;) if(clock_pin==1) break; //test clock pin if releas continue
for(;;) if(clock_pin==0) break; //wait until clock goes low , read start bit
if(data_pin!=0) goto begin1; //test start bit , It must be 0, if no zero replay
for(i=0;i<=7;i++) //read 8 bit data and save to data_byte variable
{
for(;;) if(clock_pin==1) break;
for(;;) if(clock_pin==0) break;
parity_bit^=data_pin; //genrate parity bit
c_char=data_pin;
c_char<<=i;
data_byte|=c_char;
}
parity_bit^=1; //genrate parity bit
for(;;) if(clock_pin==1) break;
for(;;) if(clock_pin==0) break;
if(data_pin!=parity_bit) goto begin1; //test parity bit , if no correct replay
for(;;) if(clock_pin==1) break;
for(;;) if(clock_pin==0) break;
if(data_pin!=1) goto begin1; //test stop bit , if zero replay
return data_byte;
}
/****************************************************************************************************************/
void hosto_d(unsigned char c_char)
{
parity_bit=0;
data_bit=0;
clock_pin_out=0; //clock pin of host set to output mode
clock_pin_reg=1; //and pulling it low about 100 microsec.
delay_us(100);
data_pin_out=0; //data pin set to output mode
data_pin_reg=1; //and held it down(start bit)
//delay_us(20);
clock_pin_out=1; //clock pin of host set to input mode
clock_pin_reg=0; //and releas it
for(i=0;i<=7;i++)
{
for(;;) if(clock_pin==0) break; //chek clock pin when it goes down
data_byte=c_char; //host will send first bit to device
data_byte>>=i; //and continue until final bit.
data_byte&=1;
if(data_byte==1) data_bit=1; else data_bit=0;
parity_bit^=data_bit; //genrate parity bit
data_pin_out=data_bit;
for(;;) if(clock_pin==1) break;
}
parity_bit^=1;
for(;;) if(clock_pin==0) break;
data_pin_out=parity_bit; //send parity bit to device
for(;;) if(clock_pin==1) break;
for(;;) if(clock_pin==0) break;
data_pin_out=1; //send end bit to device
for(;;) if(clock_pin==1) break;
for(;;) if(clock_pin==0) break;
data_pin_reg=1;
}
/*************************************************************************************************/
unsigned char decode(unsigned char sc)
{
static unsigned char exten=0,is_up=0, shift=0;
unsigned char i,k;
k=0;
if (!is_up) // Last data received was the up-key identifier
{
switch (sc)
{
case 0x7E : scroll() ; break;
case 0xE0 : exten = 1; break;
case 0xF0 : is_up = 1; break; // The up-key identifier
case 0x12 : shift = 1; break; // Left SHIFT
case 0x59 : shift = 1; break; // Right SHIFT
default:
if(!exten)
{
if(!shift) // If shift not pressed,
{ // do a table look-up
for(i = 0; unshifted[i][0]; i++)
if (unshifted[i][0] == sc)
{
//put_kbbuff(unshifted[i][1]);
k=unshifted[i][1];
break;
}
}
else
{ // If shift pressed
for(i = 0; shifted[i][0]; i++)
if (shifted[i][0] == sc)
{
//put_kbbuff(shifted[i][1]);
k=shifted[i][1];
break;
}
}
} //end of if(!exten)
else
{
if(sc==0x4a) k='/'; // decode "/" key and "enter" in keypad
else
if(sc==0x5a) k=13; else k=0;
}
} //end of switch
}
else
{
is_up = 0; // Two 0xF0 in a row not allowed
exten = 0;
switch (sc)
{
case 0x12 : shift = 0; break; // Left SHIFT
case 0x59 : shift = 0; break; // Right SHIFT
}
}
return k;
}
/**********************************************************************************************************************/
void show_byte(unsigned char scc)
{
unsigned char low_nible,high_nible;
high_nible=scc>>4;
if(high_nible<10) high_nible+=0x30; else high_nible+=0x37;
low_nible=scc&0x0f;
if(low_nible<10) low_nible+=0x30; else low_nible+=0x37;
putchar(high_nible);
putchar(low_nible);
}
/**********************************************************************************************************************/
void scroll(void)
{
unsigned char err=0,led_data=0x2;
st:
if(!scroll_flag) led_data=0x3;
data_byte=0xed;
hosto_d(data_byte);
if(deviceto_h()==0xFE) err=1;
hosto_d(led_data);
if(deviceto_h()==0xFE) err=1;
if(err==1) goto st;
scroll_flag^=1;
}
// Unshifted characters
const unsigned char unshifted[68][2] = {
0x0d,9,
0x0e,'`',
0x15,'q',
0x16,'1',
0x1a,'z',
0x1b,'s',
0x1c,'a',
0x1d,'w',
0x1e,'2',
0x21,'c',
0x22,'x',
0x23,'d',
0x24,'e',
0x25,'4',
0x26,'3',
0x29,' ',
0x2a,'v',
0x2b,'f',
0x2c,'t',
0x2d,'r',
0x2e,'5',
0x31,'n',
0x32,'b',
0x33,'h',
0x34,'g',
0x35,'y',
0x36,'6',
0x39,',',
0x3a,'m',
0x3b,'j',
0x3c,'u',
0x3d,'7',
0x3e,'8',
0x41,',',
0x42,'k',
0x43,'i',
0x44,'o',
0x45,'0',
0x46,'9',
0x49,'.',
0x4a,'/',
0x4b,'l',
0x4c,';',
0x4d,'p',
0x4e,'-',
0x52,'\'',
0x54,'[',
0x55,'=',
0x5a,13,
0x5b,']',
0x5d,'\\',
0x61,'<',
0x66,8,
0x69,'1',
0x6b,'4',
0x6c,'7',
0x70,'0',
0x71,'.',
0x72,'2',
0x73,'5',
0x74,'6',
0x75,'8',
0x79,'+',
0x7a,'3',
0x7b,'-',
0x7c,'*',
0x7d,'9',
0,0
};
// Shifted characters
const unsigned char shifted[68][2] = {
0x0d,9,
0x0e,'~',
0x15,'Q',
0x16,'!',
0x1a,'Z',
0x1b,'S',
0x1c,'A',
0x1d,'W',
0x1e,'@',
0x21,'C',
0x22,'X',
0x23,'D',
0x24,'E',
0x25,'$',
0x26,'#',
0x29,' ',
0x2a,'V',
0x2b,'F',
0x2c,'T',
0x2d,'R',
0x2e,'%',
0x31,'N',
0x32,'B',
0x33,'H',
0x34,'G',
0x35,'Y',
0x36,'^',
0x39,'L',
0x3a,'M',
0x3b,'J',
0x3c,'U',
0x3d,'&',
0x3e,'*',
0x41,'<',
0x42,'K',
0x43,'I',
0x44,'O',
0x45,')',
0x46,'(',
0x49,'>',
0x4a,'?',
0x4b,'L',
0x4c,':',
0x4d,'P',
0x4e,'_',
0x52,'"',
0x54,'{',
0x55,'+',
0x5a,13,
0x5b,'}',
0x5d,'|',
0x61,'>',
0x66,8,
0x69,'1',
0x6b,'4',
0x6c,'7',
0x70,'0',
0x71,',',
0x72,'2',
0x73,'5',
0x74,'6',
0x75,'8',
0x79,'+',
0x7a,'3',
0x7b,'-',
0x7c,'*',
0x7d,'9',
0,0
};
', '(', 0, 0, '>', '?', 'L', ':','P',
;
;#include <mega16.h>
unsigned int x;
interrupt [EXT_INT0] void ext_int0_isr(void)
{
switch (x)
{
case 0xFE: PORTC=0xFE;
break;
case 0xFD: PORTC=0xFE;
break;
case 0xFB: PORTC=0xFE;
break;
case 0xEF: PORTC=0xFD;
break;
case 0xDF: PORTC=0xFD;
break;
case 0xBF: PORTC=0xFD;
break;
default: PORTC=0xF8;
}
while (PORTA!=0xF7);
}
void main (void)
{
{
PORTA=0x00;
DDRA=0x00;
PORTC=0xF8;
DDRC=0xFF;
GICR=0x40;
MCUCR=0x01;
MCUCSR=0x00;
GIFR=0x40;
}
#asm("sei")
while (1)
{
x=PORTA;
PORTC=0xF8;
} ;
}

#include <mega16.h>
unsigned int x;
void main (void)
{
PORTA=0x00;
DDRA=0x00;
PORTC=0xF8;
DDRC=0xFF;
x=PORTA;
PORTC=0xF8;
while (1)
{
while (PORTA!=0xF7);
{
if (x>247);
{
PORTC=0xFE;
}
if (x<247);
{
PORTC=0xFD;
}
}
};
}

#include <mega16.h>
unsigned int x;
void main (void)
{
PORTA=0x00;
DDRA=0x00;
PORTC=0xF8;
DDRC=0xFF;
x=PORTA;
PORTC=0xF8;
while (1)
{
while (x!=0xF7)
{
if (x>0xF7);
{
PORTC=0xFE;
}
if (x<0xF7);
{
PORTC=0xFD;
}
};
};
}
oo:
)
#include<mega16.h>
unsigned int x;
unsigned int y;
void main (void)
{
DDRC = 0xFF;
PORTC= 0x00;
DDRA=0x00;
PORTA=0x00;
x=PORTA;
PORTC=y;
while(1)
{
if (x==0xF7)
{
y=0xF8;
}
else if ((x=0xF8) || (x=0xF9) || (x=0xFA) ||(x=0xFB) ||(x=0xFC) ||(x=0xFD) || (x=0xFE)) y=0xFE;
else if ((x=0x8F) || (x=0x9F) || (x=0xAF) ||(x=0xBF) ||(x=0xCF) ||(x=0xDF) || (x=0xEF)) y=0xFD;
else
{
y=0xF8;
}
}
}
دیدگاه