Last active
December 16, 2015 11:49
-
-
Save 3Nigma/5430254 to your computer and use it in GitHub Desktop.
Codul-lipici complet ce testează modulul PS/2-Mouse (ps2m) prezentat în numărul 2 al revistei "Electronica Azi Hobby" (eAh) / Aprilie '13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Aplicatie test pentru Modulul de comunicatii AVR-PS/2 Mouse | |
* Copyright (c) 2013, Victor ADASCALITEI, [email protected] | |
* | |
* Eliberez aceste surse sub licenta CC de tip BY-NC-SA 3.0 . Pentru mai multe informatii, va invit sa accesati | |
* urmatoarea adresa : http://creativecommons.org/licenses/by-nc-sa/3.0/ro/ . | |
*/ | |
#include <avr/io.h> | |
#include "ps2mouse.h" | |
/* introducem in aplicatie LED-urile de stare */ | |
#define LED_DIR_X _BV(PB3) | |
#define LED_BT_STANGA _BV(PB0) | |
int main(void) { | |
ps2m_st_date dtMouse; | |
/* initializam legatura ps/2 */ | |
ps2m_init(); | |
/* si interfata de LED-uri */ | |
DDRB |= (LED_DIR_X | LED_BT_STANGA); | |
PORTB &= ~(LED_DIR_X | LED_BT_STANGA); | |
while(1) { | |
if (ps2m_citeste_deplasamente(&dtMouse) == PS2M_OK) { | |
/* citirea s-a realizat cu succes */ | |
if (ps2m_este_buton_stanga_apasat(&dtMouse)) { | |
PORTB |= LED_BT_STANGA; | |
} else { | |
PORTB &= ~LED_BT_STANGA; | |
} | |
if (ps2m_obtine_val_deplasament_brut_x(&dtMouse) > 0) { | |
/* sigur exista o miscare pe axa X. Aprinde LED-ul corespunzator directiei */ | |
if (ps2m_obtine_dir_deplasament_x(&dtMouse) == PS2M_DT_DX_STANGA) { | |
PORTB |= LED_DIR_X; | |
} else { | |
PORTB &= ~LED_DIR_X; | |
} | |
} else { | |
/* nu a existat nicio deplasare pe Ox in aceasta secventa de verificare. | |
Pastreaza LED-ul in starea data de directia ultimei deplasari */ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment