Dear Rajat,
I follow the datasheet given for calibration also herewith I am giving you my code.
/*
------------------------------------------------------------------
This program is made for Testing the LCD and 5460 routins
------------------------------------------------------------------
*/
#include<avr/io.h>
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#include<util/delay.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include<avr/interrupt.h>
#include "LCD_dhruv.h"
#include "keypad_dhruv.h"
#define DDR_SPI DDRB
#define DD_MOSI DDB5
#define DD_SCK DDB7
#define CS_DDR DDRB
#define CS_PORT PORTB
#define CS_IC0 PB0
#define CS_IC1 PB1
#define CS_IC2 PB2
#define CS_IC3 PB3
#define CS_IC4 PB4
#define EN_CS0() (CS_PORT&=(~(1<<CS_IC0)))
#define EN_CS1() (CS_PORT&=(~(1<<CS_IC1)))
#define EN_CS2() (CS_PORT&=(~(1<<CS_IC2)))
#define EN_CS3() (CS_PORT&=(~(1<<CS_IC3)))
#define EN_CS4() (CS_PORT&=(~(1<<CS_IC4)))
#define DS_CS0() (CS_PORT|=(1<<CS_IC0))
#define DS_CS1() (CS_PORT|=(1<<CS_IC1))
#define DS_CS2() (CS_PORT|=(1<<CS_IC2))
#define DS_CS3() (CS_PORT|=(1<<CS_IC3))
#define DS_CS4() (CS_PORT|=(1<<CS_IC4))
void SPI_MasterInit(void);
void SPI_MasterTransmit(unsigned char cData);
unsigned char SPI_MasterReceive(void);
void spi_reinitilise(void);
unsigned long int SPI_Read_data(char cData);
void spi_data_write(char command,unsigned long int x);
int main(void)
{
unsigned long int x;
InitLCD(LS_BLINK|LS_ULINE);
SPI_MasterInit();
EN_CS2();
x=0x000081;
spi_data_write(0x00,x);
DS_CS2();
spi_reinitilise();
_delay_ms(500);
LCDClear();
LCDWriteString("Set 0 for DCOFF",0,0);
LCDWriteString("& then press F1",0,1);
while (Key_scan()!=F1);
LCDClear();
LCDWriteString("Please Wait...",0,0);
EN_CS2();
SPI_MasterTransmit(0xD9);
DS_CS2();
_delay_ms(500);
EN_CS2();
x=SPI_Read_data(0x06);
spi_data_write(0x06,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x02);
spi_data_write(0x02,x);
DS_CS2();
LCDClear();
EN_CS2();
x=SPI_Read_data(0x06);
DS_CS2();
LCDGotoXY(0,0);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
EN_CS2();
x=SPI_Read_data(0x02);
DS_CS2();
LCDGotoXY(0,1);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
_delay_ms(5000);
LCDClear();
LCDWriteString("Set 0 for ACOFF",0,0);
LCDWriteString("& then press F1",0,1);
while (Key_scan()!=F1);
LCDClear();
LCDWriteString("Please Wait...",0,0);
EN_CS2();
SPI_MasterTransmit(0xDD);
DS_CS2();
_delay_ms(500);
EN_CS2();
x=SPI_Read_data(0x22);
spi_data_write(0x22,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x20);
spi_data_write(0x20,x);
DS_CS2();
LCDClear();
EN_CS2();
x=SPI_Read_data(0x22);
DS_CS2();
LCDGotoXY(0,0);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
EN_CS2();
x=SPI_Read_data(0x20);
DS_CS2();
LCDGotoXY(0,1);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
_delay_ms(5000);
LCDClear();
LCDWriteString("Set MAX for GAIN",0,0);
LCDWriteString("& then press F1",0,1);
while (Key_scan()!=F1);
LCDClear();
LCDWriteString("Please Wait...",0,0);
EN_CS2();
SPI_MasterTransmit(0xDA);
DS_CS2();
_delay_ms(500);
EN_CS2();
x=SPI_Read_data(0x08
;
spi_data_write(0x08,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x04);
spi_data_write(0x04,x);
DS_CS2();
LCDClear();
EN_CS2();
x=SPI_Read_data(0x08
;
DS_CS2();
LCDGotoXY(0,0);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
EN_CS2();
x=SPI_Read_data(0x04);
DS_CS2();
LCDGotoXY(0,1);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
_delay_ms(5000);
EN_CS2();
SPI_MasterTransmit(0xE8
;
DS_CS2();
_delay_ms(500);
LCDClear();
for(;
{
EN_CS2();
x=SPI_Read_data(0x18
;
DS_CS2();
LCDGotoXY(0,0);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
/*EN_CS2();
x=SPI_Read_data(0x06);
DS_CS2();
LCDGotoXY(6,0);
LCDWriteInt(x>>8,5);
//LCDWritelong_Intdec(x,10,0);
*/
EN_CS2();
x=SPI_Read_data(0x16);
DS_CS2();
LCDGotoXY(0,1);
//LCDWriteInt(x>>8,5);
LCDWritelong_Intdec(x,10,0);
/*EN_CS2();
x=SPI_Read_data(0x02);
DS_CS2();
LCDGotoXY(6,1);
LCDWriteInt(x>>8,5);
//LCDWritelong_Intdec(x,10,0);
*/
}
} //MAIN OVER
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
CS_DDR|=(1<<CS_IC0 | 1<<CS_IC1 | 1<<CS_IC2 | 1<<CS_IC3 | 1<<CS_IC4);
CS_PORT|=(1<<CS_IC0 | 1<<CS_IC1 | 1<<CS_IC2 | 1<<CS_IC3 | 1<<CS_IC4);
}
void SPI_MasterTransmit(unsigned char cData)
{
char dummy;
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
dummy=SPDR;
}
unsigned char SPI_MasterReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)));
/* Return data register */
return SPDR;
}
void spi_reinitilise(void)
{
char dummy;
SPDR =0XFF;
while(!(SPSR & (1<<SPIF)))
dummy=SPDR;
SPDR =0XFF;
while(!(SPSR & (1<<SPIF)))
dummy=SPDR;
SPDR =0XFF;
while(!(SPSR & (1<<SPIF)))
dummy=SPDR;
SPDR =0XFE;
while(!(SPSR & (1<<SPIF)))
dummy=SPDR;
}
unsigned long int SPI_Read_data(char cData)
{
char spi_data1=0,spi_data2=0,spi_data3=0;
/* Start transmission */
spi_reinitilise();
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
spi_data3=SPDR;
SPDR = 0xff;
while(!(SPSR & (1<<SPIF)))
spi_data3=SPDR;
SPDR = 0xff;
while(!(SPSR & (1<<SPIF)))
spi_data2=SPDR;
SPDR = 0xff;
while(!(SPSR & (1<<SPIF)))
spi_data1=SPDR;
//__ser_rx_buffer[3]=spi_data2;
//__ser_rx_buffer[4]=spi_data1;
return (0x00FFFFFF & (((spi_data3*65536) & 0x00FF0000)|((spi_data2<<8
& 0x0000FF00)|(spi_data1& 0x000000FF)));
}
void spi_data_write(char command,unsigned long int x)
{
char dummy2,data_byte3,data_byte2,data_byte1;
data_byte3=x>>16;
data_byte2=x>>8;
data_byte1=x;
spi_reinitilise();
SPDR=command | 0x40;
while(!(SPSR & (1<<SPIF)))
dummy2=SPDR;
SPDR=data_byte3;
while(!(SPSR & (1<<SPIF)))
dummy2=SPDR;
SPDR=data_byte2;
while(!(SPSR & (1<<SPIF)))
dummy2=SPDR;
SPDR=data_byte1;
while(!(SPSR & (1<<SPIF)))
dummy2=SPDR;
}
/*for (;
{
temp = Key_scan();
_delay_ms(20);
temp1 = Key_scan();
if (temp == temp1 && temp != temp2)
{
display_hex(temp,13,0);
temp2 = temp;
} //if loop
} //for loop
*/