24 bit ADC LTC2400 C Code
Saturday, February 6th, 2010
24BIT ADC LTC2400 C CODE:
#include<REGLV51RD2.h> //Header file for Philips microcontroller 89v51RD2BN Version
#include<stdio.h> //Header file for standard input output
#include<string.h>//Header file for string manipulation
sbit ADC_CS=P1^4;//ADC Chip select is connected with 8051 port pin P1.5
sbit ADC_SD0=P1^6;//ADC serial data out signal is connected with 8051 port pin P1.6
sbit ADC_SCK=P1^7;//ADC serial clock signal is connected with 8051 port pin P1.7
xdata char *ptr_cmd = (xdata char *)0×0FFF8; // LCD comm, 0×0FFF8 is memory address for LCD comm write
xdata char *ptr_en = (xdata char *)0×0FFF9; //LCD Enable, 0×0FFF9 is memory address for LCD data write
unsigned long x1,x2,x3,x4,x5,s;//Global Declaration
unsigned long filter_ADC(void);//Protype Declaration for ADC conversion
unsigned long read_ADC1(void);//Protype Declaration for ADC conversion
void lcd_comm();//prototype Declaration
void delay1(); // ,,
void delay(); // ,,
void display(char *name);//,,
void disp(long int name1);// ,,
void init_lcd();//,,
void main() //Program starts for main funtion here
{
long d; //Declarations
unsigned long int t;//,,
unsigned char x,y;//,,
init_lcd();
t=s;
d=filter_ADC(); //return 2.5v adc value
printf(”%8ld\n”,s); //print the adc value display in hyperterminal
display(”24BIT ADC OUTPUT”);//display in LCD
lcd_comm(); // LCD command routine call function
*(ptr_en) = 0xc0;// LCD display for 2nd line 1st location
delay1(); //call for delay routine
{
disp(((s%100000000)/10000000)+48);// LCD display for corresponding digit mask
display(”.”); // and convert to ascii 0 for 48
disp(((s%10000000)/1000000)+48);// ,,
disp(((s%1000000)/100000)+48); // ,,
disp(((s%100000)/10000)+48); // ,,
disp(((s%10000)/1000)+48); // ,,
disp(((s%1000)/100)+48); // ,,
disp(((s%100)/10)+48); // ,,
disp((s%10)+48); // ,,
}
lcd_comm();//LCD command routine call
*(ptr_en)=0xc8;//LCD 2nd line 8th position
lcd_comm();//LCD command routine call
*(ptr_en) = 0×01;// LCD command for clear the display
delay1();//Delay routine call for some delay
}
unsigned long filter_ADC(void)//ADC function routine call
{
x5 = x4;
x4 = x3;
x3 = x2;
x2 = x1;
x1 = read_ADC1();
return ((((x1+x2+x3+x4+x5)/5)*148)/100);// x 148 E-9 convert to 2.59V
}
unsigned long read_ADC1(void)//Main funtion for ADC Routine
{
char k; //Declarations
unsigned long int n;//
n=0; //intialise n is assign to 0
ADC_CS = 0; //intialise ADC CHIP Select low
for(k=0; k<32; k++) //32 bits for adc conversion process
{
n<<= 1; //n value left shift by 1 time
ADC_SCK = 1; //SCK for HIGH
n |= ADC_SD0; //SD0 bitwise or with n
ADC_SCK = 0; // SCK for LOW
}
ADC_CS = 1; //ADC Chip Select is HIGH
n&=0×01fffffff; // maskout sign bit
n>>=4; // get 24-bit conversion result
s=n; // 24-bit conversion result is stored in temp variable
return n;// return the n value
}
void busy_check()//Function call for busy_check data send or not
{
*ptr_cmd = 0×02;
while((*ptr_en & 0×80) != 0×00){} //condition check for busy flag
}
void delay() //Function call for delay routine
{
unsigned int i =100000;
while(i–);
}
void delay1() //Function call for delay routine
{
unsigned int i =10;
while(i–);
}
void lcd_comm()
{
*(ptr_cmd) = 0×00;
}
void init_lcd()//Function call for initialisation for LCD
{
lcd_comm();
*(ptr_en) = 0×38; //LCD command for 2 lines and 5×7 matrix
delay();
busy_check();
lcd_comm();
*(ptr_en) = 0×0e; //LCD command for Display on,cursor blinking
busy_check();
delay();
lcd_comm();
*(ptr_en) = 0×80;//LCD command Force cursor to beginning of 1st line
busy_check();
delay();
lcd_comm();
*(ptr_en) = 0×01;//LCD command for clear display screen
busy_check();
delay();
}
void disp(long int name1) //LCD display routine for digits display
{
*(ptr_cmd) = 0×01;
*(ptr_en) = name1;
busy_check();
delay1();
}
void display(char *name) //LCD display routine for character display
{
int l = strlen(name);
int i;
for(i = 0;i < l;i++)
{
*(ptr_cmd) = 0×01;
*(ptr_en) = name[i];
busy_check();
delay1();
}
}