Professional Documents
Culture Documents
****
* Mangalyaan.c
*
* Created: 17-11-2013 AM 01:43:58
* Author: Sid
!!!!!!!!!!!!!!!!!!!!!!!!!!IMPORTANT INSTRUCTIONS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!
All the LCD functions are included in LCD.h
The pin connections for the LCD remain the same.
LCD Pin 1 is the pin closest to the corner of the LCD board
The connections are:
1. GND
2. +5V
3. VEE(output of the middle pin of the 5k potentiometer)
LCD
4. RS
5. RW
6. E
7. DB0
8. DB1
9. DB2
10.DB3
11.DB4
12.DB5
13.DB6
14.DB7
15.NC
16.NC
Atmega32 board
PB0
PB1
PB2
PD0
PD1
PD2
PD3
PD4
PD5
PD6
PD7
You need to use a 5k potentiometer with one side pin at +5V, middle pin connect
ed to pin 3 of LCD and the other side pin connected to GND
Adjust the potentiometer to vary the contrast.
If you want to turn the backlight on, connect Pin 15 to +5V through a 270E resi
stor, Pin 16 to GND.
Attention: The resistor is a must! or you could end up burning the backlight LE
D.
///////////////////////////////////////////////////////////////////////////////
/////////
The ADXL345 accelerometer board connections are:
ADXL345board
ATmega board
5V---------------VCC
3V3--------------NC(No Connection)
GND--------------GND
VS---------------VCC
CS---------------VCC
INT1-------------NC
INT2-------------NC
SDO--------------NC
SDA--------------PC1(SDA)
SCL--------------PC0(SCL)
///////////////////////////////////////////////////////////////////////////////
//////////
The header file LCD.h and the i2chw folder must be copied to the folder where t
he C file is.
*******************************************************************************
***********/
#define F_CPU 11095200UL
#include
#include
#include
#include
#include
<avr/io.h>
<util/delay.h>
"i2chw/twimaster.c"
"LCD.h"
<math.h>
int digit;
for(int i=0; i<3; i++)
{
digit = read2%10;
morse_convert(digit);
read2 = read2/10;
_delay_ms(600);
}
_delay_ms(800);
}
}
void morse_convert(int data)
{
switch (data)
{
case 0:
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
break;
case 1:
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
break;
case 2:
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
break;
case 3:
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
break;
case 4:
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
break;
case 5:
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
break;
case 6:
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
break;
case 7:
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
break;
case 8:
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
break;
case 9:
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(600);
PORTB&=~(1<<3);
_delay_ms(200);
PORTB|=(1<<3);
_delay_ms(200);
PORTB&=~(1<<3);
break;
}
}
unsigned char TWI_read_one_byte(unsigned char device_address, unsigned char regi
ster_address) // i2c function to read a byte
{
unsigned char status;
i2c_start_wait(device_address);
i2c_write(register_address);
i2c_rep_start(device_address+1);
status=i2c_readNak();
i2c_stop();
return status;
}
void TWI_write_one_byte(unsigned char device_address, unsigned char register_add