prathap reddy
Newbie level 4
the following program based on using pic16f887 and adxl330 type accelerometer to measure the tilt angle and displayed on LCD.but i am unable to get output. can any one help?
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
signed int x_acc,y_acc,z_acc;
signed int ZeroGx,OneGx,ZeroGy,OneGy;
signed int Counts_PerG_x,Counts_PerG_y;
float Gx,Gy,angle;
Read_Acceleration()
{
x_acc=Adc_Read(0);
y_acc=Adc_Read(1);
z_acc=Adc_Read(2);
}
Init_ADC()
{
ANSEL=0x07;
ANSELH=0;
TRISA=0x07;
ADCON0=0x81;
ADCON1=0x80;
}
void main()
{
Init_ADC();
Lcd_init();
ZeroGx=384;
OneGx=465;
ZeroGy=380;
OneGx=460;
Counts_PerG_x= OneGx -ZeroGx;
Counts_PerG_y= OneGy –ZeroGy;
for(;
{
Read_Acceleration();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"INCLINOMETER");
Gx=(float)(x_acc-ZeroGx)/ Counts_PerG_x;
Gy=(float)(y_acc-ZeroGy)/ Counts_PerG_y;
angle=atan2(Gy,Gx);
angle=angle*180.0/3.14;
FloatToStr(angle,txt+6);
Lcd_Out(2,1,txt);
Delay_Ms(500);
}
}
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
signed int x_acc,y_acc,z_acc;
signed int ZeroGx,OneGx,ZeroGy,OneGy;
signed int Counts_PerG_x,Counts_PerG_y;
float Gx,Gy,angle;
Read_Acceleration()
{
x_acc=Adc_Read(0);
y_acc=Adc_Read(1);
z_acc=Adc_Read(2);
}
Init_ADC()
{
ANSEL=0x07;
ANSELH=0;
TRISA=0x07;
ADCON0=0x81;
ADCON1=0x80;
}
void main()
{
Init_ADC();
Lcd_init();
ZeroGx=384;
OneGx=465;
ZeroGy=380;
OneGx=460;
Counts_PerG_x= OneGx -ZeroGx;
Counts_PerG_y= OneGy –ZeroGy;
for(;
{
Read_Acceleration();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"INCLINOMETER");
Gx=(float)(x_acc-ZeroGx)/ Counts_PerG_x;
Gy=(float)(y_acc-ZeroGy)/ Counts_PerG_y;
angle=atan2(Gy,Gx);
angle=angle*180.0/3.14;
FloatToStr(angle,txt+6);
Lcd_Out(2,1,txt);
Delay_Ms(500);
}
}