Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
on
BY
Department of
Electronics Engineering
Examiner:______
H.O.D: ________
Acknowledgement
The above image shows the block diagram of the ACCELEROMETER BASED MOUSE.
The main components used are:
1. Accelerometer MMA7361.
2. Atmega 16 Microcontroller.
3. MAX232 serial communication to PC.
4. The LCD display.
The basic working of all these components will be explained later in the report.
1. Accelerometer MMA7361
Connections:
Pin Configurations
Pin# Pin name Description
1 XOUT X direction output Voltage
2 YOUT Y direction output Voltage
3 ZOUT Z direction output Voltage
4 Vss Supply Ground
5 Vdd 3.3V supply voltage
6 Sleep (Active Low) Logic input pin for sleep mode
7 0g-Detect Freefall digital logic output signal
8 g-select Logic input pin to select G level
9 ST Self-test (logic 0: normal mode; logic 1: self-
test)
10 NC Leave Unconnected
Pin Descriptions:
XOUT: This provides the change in acceleration in X direction in terms of analog voltage
YOUT: This provides the change in acceleration in Y direction in terms of analog voltage
ZOUT: This provides the change in acceleration in Z direction in terms of analog voltage
Vss: Supply Ground: This is the supply ground pin for system.
Vdd: Supply voltage: apply the 3.3 v supply to this pin.
Sleep(Active Low): This is control input pin, logic High for normal mode where system
consume only 400μA current and logic low for Sleep mode where system consume only
10μA current.
0g-Detect: The sensor offers a 0g-Detect feature that provides a logic high signal when all
three axes are at 0g. This feature enables the application of Linear Freefall protection if the
signal is connected to an interrupt pin or a poled I/O pin on a microcontroller.
G-select: The G-Select feature allows for the selection between two sensitivities.
Depending on the logic input placed on this pin, the device internal gain will be changed
allowing it to function with a 1.5g or 6g sensitivity.
G-Select (logic level) G-Range Sensitivity
0 1.5G 800mV/G
1 6G 206mV/G
ST(Self-test): Self Test allows the verification of the mechanical and electrical integrity of
the accelerometer at any time before or after installation.
Circuit Diagram:
The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced
RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16
achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize
power consumption versus processing speed.
Pin Configurations
Pin Descriptions
The MAX 232 is to connect a serial port device to a serial port which uses the RS232 standard. The serial port
device is usually a UART, but that is often incorporated into a microprocessor chip.
The RS232 standard specifies the voltage levels that represent the signalling and data lines in the interface. The
standard is that the lines have a source impedance around 300 ohms, the minimum voltage is +/- 6V, the
maximum voltage is +/-22V, the minimum load is 3000 ohms and so on. The logic states are therefore plus or
minus 6V, and it is common to use plus/minus 12V.
The logic level devices that create the RS232 signal work at 0 and +5V (in this case anyway). TheMAX232
provides the interface, which involves a logic voltage inversion. It is two line drivers(outputs) that convert logic
level to +/- RS232 and two line receivers (inputs) that receive +/- RS232and convert then to logic level.
The MAX232 is popular because it also generates the extra voltages for the +/- 12V, using the +5V as a
supply. There is no need for separate supplies just for this purpose. The voltage is generated by electronic
switches which charge capacitors in parallel then discharge them in series.
Low cost systems sometimes dispense with these, as RS232 usually works with 0V and +5V logic levels too,
although this is not specified. I have to say that it doesn't always work, or it may only work at slower speeds on
longer lines etc. It is still necessary to provide a logic level inversion with most devices, as they are designed to
work with an inverting line driver. This could be a transistor or an unused gate device from a package.
4. The LCD display
In this application note liquid crystal display JHD 162A is used to interfacing with
microcontroller.
Function of JHD162A:
Pin no. Name Function Use
1 Vss Ground
2 Vdd +ve supply 5V regulated DC
3 Vee Contrast This is used to set the contrast
4 RS Register set Register select signal:Instruction
register (when writing) Busy flag &
address counter (Whenreading):Data
register(when writing & reading)
5 R/W Read / Write Read/Write select signal for reading
and for writing.
6 E Enable Operation ( data read/ write) enable
CIRCUIT DIAGRAM
The above image shows the complete circuit diagram of the ACCELEROMETER
CONTROLLED MOUSE.
It shows all the connections between the microcontroller ATMEGA16, accelerometer
MMA7361L, MAX232 serial connection to computer as well as the LCD JHD162A.
SOFTWARE
void usart_init()
{
UCSRA=0;
UCSRB=0;
UCSRC=0;
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the
low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value
into the high byte of the UBRR register
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception
circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character
sizes
int main(void)
{
MCUCSR=0x80;
MCUCSR=0x80;
DDRA=0x00;
DDRB=0xFF;
PORTA=0x00;
PORTB=0xFF;
DDRC=0xFF;
PORTC=0x00;
ADCSRA=0x00;
ADMUX=0x00;
lcd_init();
usart_init();
while(1)
{
ADMUX&=0xF0;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
x=byte;
ADMUX|=0x01;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
y=byte;
ADMUX&=0xF0;
ADMUX|=0x02;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
z=byte;
lcd_cmd(1);
_delay_ms(20);
x1=x; y1=y; z1=z;
//lcd_string(" ");
//_delay_ms(250);
lcd_string(" x:");
lcd_char(x/100+48);
x=x%100;
lcd_char(x/10+48);
lcd_char(x%10+48);
lcd_string(" y:");
lcd_char(y/100+48);
y=y%100;
lcd_char(y/10+48);
lcd_char(y%10+48);
lcd_cmd(LINE2);
lcd_string(" z:");
lcd_char(z/100+48);
z=z%100;
lcd_char(z/10+48);
lcd_char(z%10+48);
if ((x1<50)&(y1<80)&(y1>68)) \\up
UDR=0x02;
else if ((x1>80)&(y1<80)&(y1>68)) \\down
UDR=0x0F;
else if((y1<62)&(x1<70)&(x1>55)) \\right
UDR=0xC0;
else if ((y1>80)&(x1<70)&(x1>55)) \\left
UDR=0xFF;
return 0;
}
ISR(ADC_vect)
{
count++;
byte=ADCH;
}
The following program is written for the mouse for matlab software:
clc
clear all
import java.awt.Robot;
mouse = Robot;
s1 = serial('COM1');
set(s1,'BaudRate',9600);
fopen(s1);
mouse.mouseMove(512, 384);
i=512; j=384;
load m;
t=0;
while s1.BytesAvailable>100
temp=fread(s1, s1.BytesAvailable-1);
end
tic;
while t<40
if s1.BytesAvailable>1
temp = fread(s1, s1.BytesAvailable-1,'uint8');
=mean(temp);
if (temp>100)&(temp<180)
i=i-10;
if j<0 j=768; end
if j>765 j=0; end
mouse.mouseMove(i,j);
end
if temp>200
i=i+10;
if j<0 j=768; end
if j>765 j=0; end
mouse.mouseMove(i,j);
end
if (temp<7)
j=j-10;
if i<0 j=1024; end
if i>765 j=0; end
mouse.mouseMove(i,j);
end
if (temp>7)&(temp<temp20)
j=j+10;
if i<0 j=1024; end
if i>765 j=0; end
mouse.mouseMove(i,j);
end
end
t=toc;
end
fclose(s1);