Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void send_keyboard_command(unsigned char command)
- {
- // EIMSK &= ~(1 << INT0); // Disable clock interrupts
- PORTD &= ~(1 << PIND2); // Bring CLK low
- _delay_us(300); // Waaaait for it...
- /* The start bit, always clear */
- PORTD &= ~(1 << PIND3); // Bring DATA low
- PORTD |= (1 << PIND2); // Pull CLK high again
- while(bit_is_set(PIND, KBD_CLOCK_PIN)); // Wait for keyboard to bring CLK low
- unsigned char i;
- unsigned char parity = 1;
- for(i = 0; i < 8; i++)
- {
- /* Output bit on DATA line */
- if((command & 0x01) != 0)
- PORTD |= (1 << PIND3); // Data bit is set
- else
- PORTD &= ~(1 << PIND3); // Data bit is cleared
- while(bit_is_clear(PIND, KBD_CLOCK_PIN)); // Wait for CLK to be set
- while(bit_is_set(PIND, KBD_CLOCK_PIN)); // Wait for CLK to be clear
- parity = parity ^ (command & 0x01);
- command >>= 1;
- }
- /* Parity bit */
- if(parity == 0)
- PORTD &= ~(1 << PIND3);
- else
- PORTD |= (1 << PIND3);
- while(bit_is_clear(PIND, KBD_CLOCK_PIN)); // Wait for CLK to be set
- while(bit_is_set(PIND, KBD_CLOCK_PIN)); // Wait for CLK to be clear
- /* Stop bit - always set */
- PORTD |= (1 << PIND3);
- while(bit_is_set(PIND, KBD_CLOCK_PIN)); // Wait for CLK to be clear
- // Wait for keyboard-send-to-host mode
- while((bit_is_clear(PIND, KBD_CLOCK_PIN)) || ((bit_is_clear(PIND, PIND3))));
- // EIMSK = 1 << INT0; // Re-enable clock interrupts
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement