Optical Mouse Embedded System

Share Embed


Descrição do Produto

Sanzhar Askaruly

Nazarbayev University, School of Engineering

Midterm Exam – Optical Mouse In the exam, I wrote that there is no need in serial connection. However, 8051 always needs it. Mouse sends information in three packets. Each packet consists of 11 bits. As I understand, apart from 8 control bits, there should be 3 signaling bits. Most significant bits are sent first. The port numbers can be interchanged, since I do not exactly remember which port I connected during the midterm exam.

L

Left Button State (1 for pressed)

R

Right Button State (1 for pressed)

X0-X7 X direction movement Y0-Y7 Y direction movement XS

Movement direction in the X axis (1 for UP)

YS

Movement direction in the X axis (1 for LEFT)

XV,YV Overflow of the movement data bits (1 if overflow occurred)

Sanzhar Askaruly

Nazarbayev University, School of Engineering

#include

//library for 8051 registers

#include

//library

#include

//library

#define X_LED_array P1

//port 1 definition for x coordinates

#define Y_LED_array P3

//port 3 definition for x coordinates

signed int X_position = 0;

//position of x initialized

signed int Y_position = 0;

//position of y initialized

signed int X_direction;

//x direction of mouse (can be positive/negative)

signed int Y_direction;

//y direction of mouse (can be positive/negative)

int X_add;

//integer for x operation

int Y_add;

//integer for y operation

int data[33];

//each packet consists of 11 bits. Apart from 8 control, there are 3 signalling bits (eg. start and end)

sbit LED_Left_Button = P2^0;

//definition of LED pin for left button

sbit LED_Right_Button = P2^1;

//definition of LED pin for right button

void small_delay() {

//delay should be very small

unsigned int x; for(x=0;x
Lihat lebih banyak...

Comentários

Copyright © 2017 DADOSPDF Inc.