Electronic Circuits and Projects Forum



adxl330- code to pic16f877

12 Last »
  1. #1
    nachum nachum is offline

    adxl330- code to pic16f877

    Hi,


    I took the code from MikroElektronika and I make compiler,
    and I get error messages.
    Anyone know what changes to make to not receive error messages.

    I attached the message...

    Using driver C:\Program Files\HI-TECH Software\PICC\9.70\bin\picc.exe

    Make: The target "C:\Test\3\Start.p1" is out of date.
    Executing: "C:\Program Files\HI-TECH Software\PICC\9.70\bin\picc.exe" --pass1 C:\Test\3\Start.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    Warning [107] C:\Test\3\Start.c; 5.7 illegal # directive "device"
    Warning [107] C:\Test\3\Start.c; 6.7 illegal # directive "device"
    Warning [107] C:\Test\3\Start.c; 7.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 8.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 9.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 10.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 11.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 12.6 illegal # directive "FUSES"
    Warning [107] C:\Test\3\Start.c; 13.6 illegal # directive "FUSES"
    Warning [361] C:\Test\3\Start.c; 41.1 function declared implicit int
    Warning [361] C:\Test\3\Start.c; 50.10 function declared implicit int
    Warning [361] C:\Test\3\Start.c; 57.1 function declared implicit int
    Warning [356] C:\Test\3\Start.c; 103.23 implicit conversion of float to integer
    Warning [356] C:\Test\3\Start.c; 107.23 implicit conversion of float to integer
    Warning [356] C:\Test\3\Start.c; 111.24 implicit conversion of float to integer
    Make: The target "C:\Test\3\delay.p1" is up to date.
    Executing: "C:\Program Files\HI-TECH Software\PICC\9.70\bin\picc.exe" -oSensorFinal.cof -mSensorFinal.map --summary=default --output=default Start.p1 delay.p1 --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    Licensed for evaluation purposes only.
    This licence will expire on Sat, 10 Apr 2010.
    HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.70
    Copyright (C) 2009 Microchip Technology Inc.
    Error [500] ; 0. undefined symbols:
    _Adc_Read(SensorFinal.obj) _Usart_Write(SensorFinal.obj) _strConstCpy(SensorFinal.obj)

    ********** Build failed! **********

  2. #2
    Wilksey Wilksey is offline
    Unless you use the Mikro C Compiler you will not be able to compile the code, there are violations for directives, variable types and libraries.

    Your best bet is to re-write the code if you really need to use HITECH C.

    Unless you know your libraries it is not always easy to port code between compilers when it comes to MCU's

    HTH

    Wilksey
    0

  3. Thread Starter #3
    nachum nachum is offline
    I downloaded the compiler "mikroC PRO for PIC" from MikroElektronika and I still see error messages.
    I attached the messages.

    0 1 mikroCPIC1618.exe -MSF -DBG -pP16F877A -DL -O11111114 -fo8 -N"C:\Test\5\Read_Angles.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16\" -SP"C:\Test\5\" "Read_Angles1.c" "Read_Angles.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM.mcl" "__Lib_FLASH_RW.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl"
    0 1138 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
    0 304 C:/Test/5/Read_Angles1.c:26: error: Can't open include file "16f877a.h"
    0 304 #include <16F877A.h>
    0 304 C:/Test/5/Read_Angles1.c:27: error: Unknown #directive "device"
    0 304 #device *=16
    0 304 C:/Test/5/Read_Angles1.c:28: error: Unknown #directive "device"
    0 304 #device adc=10
    0 304 C:/Test/5/Read_Angles1.c:29: error: Unknown #directive "FUSES"
    0 304 #FUSES NOWDT
    0 304 C:/Test/5/Read_Angles1.c:30: error: Unknown #directive "FUSES"
    0 304 #FUSES HS
    0 304 C:/Test/5/Read_Angles1.c:31: error: Unknown #directive "FUSES"
    0 304 #FUSES NOPUT
    0 304 C:/Test/5/Read_Angles1.c:32: error: Unknown #directive "FUSES"
    0 304 #FUSES NOPROTECT
    0 304 C:/Test/5/Read_Angles1.c:33: error: Unknown #directive "FUSES"
    0 304 #FUSES NODEBUG
    0 304 C:/Test/5/Read_Angles1.c:34: error: Unknown #directive "FUSES"
    0 304 #FUSES NOBROWNOUT
    0 304 C:/Test/5/Read_Angles1.c:35: error: Unknown #directive "FUSES"
    0 304 #FUSES NOLVP
    0 304 C:/Test/5/Read_Angles1.c:36: error: Unknown #directive "use"
    0 304 #use delay(clock=20000000)
    0 304 C:/Test/5/Read_Angles1.c:37: error: Unknown #directive "use"
    0 304 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
    0 304 C:/Test/5/Read_Angles1.c:39: error: Can't open include file "kbd.c"
    0 304 #include <KBD.C>
    0 304 C:/Test/5/Read_Angles1.c:40: error: Can't open include file "ctype.h"
    0 304 #include <ctype.h>
    0 304 C:/Test/5/Read_Angles1.c:41: error: Can't open include file "float.h"
    0 304 #include <float.h>
    0 304 C:/Test/5/Read_Angles1.c:42: error: Can't open include file "math.h"
    0 304 #include <math.h>
    0 304 C:/Test/5/Read_Angles1.c:43: error: Can't open include file "string.h"
    0 304 #include <string.h>
    0 304 C:/Test/5/Read_Angles1.c:44: error: Can't open include file "lcd204.c"
    0 304 #include "LCD204.c"
    0 304 18 errors in preprocessor.
    0 304 C:/Test/5/Read_Angles.c:27: error: Can't open include file "16f877a.h"
    0 304 #include <16F877A.h>
    0 304 C:/Test/5/Read_Angles.c:28: error: Unknown #directive "device"
    0 304 #device *=16
    0 304 C:/Test/5/Read_Angles.c:29: error: Unknown #directive "device"
    0 304 #device adc=10
    0 304 C:/Test/5/Read_Angles.c:30: error: Unknown #directive "FUSES"
    0 304 #FUSES NOWDT
    0 304 C:/Test/5/Read_Angles.c:31: error: Unknown #directive "FUSES"
    0 304 #FUSES HS
    0 304 C:/Test/5/Read_Angles.c:32: error: Unknown #directive "FUSES"
    0 304 #FUSES NOPUT
    0 304 C:/Test/5/Read_Angles.c:33: error: Unknown #directive "FUSES"
    0 304 #FUSES NOPROTECT
    0 304 C:/Test/5/Read_Angles.c:34: error: Unknown #directive "FUSES"
    0 304 #FUSES NODEBUG
    0 304 C:/Test/5/Read_Angles.c:35: error: Unknown #directive "FUSES"
    0 304 #FUSES NOBROWNOUT
    0 304 C:/Test/5/Read_Angles.c:36: error: Unknown #directive "FUSES"
    0 304 #FUSES NOLVP
    0 304 C:/Test/5/Read_Angles.c:37: error: Unknown #directive "use"
    0 304 #use delay(clock=20000000)
    0 304 C:/Test/5/Read_Angles.c:38: error: Unknown #directive "use"
    0 304 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
    0 304 C:/Test/5/Read_Angles.c:40: error: Can't open include file "kbd.c"
    0 304 #include <KBD.C>
    0 304 C:/Test/5/Read_Angles.c:41: error: Can't open include file "ctype.h"
    0 304 #include <ctype.h>
    0 304 C:/Test/5/Read_Angles.c:42: error: Can't open include file "float.h"
    0 304 #include <float.h>
    0 304 C:/Test/5/Read_Angles.c:43: error: Can't open include file "math.h"
    0 304 #include <math.h>
    0 304 C:/Test/5/Read_Angles.c:44: error: Can't open include file "string.h"
    0 304 #include <string.h>
    0 304 C:/Test/5/Read_Angles.c:45: error: Can't open include file "lcd204.c"
    0 304 #include "LCD204.c"
    0 304 18 errors in preprocessor.
    0 102 Finished (with errors): 23 מרץ 2010, 17:05:16 Read_Angles.mcppi
    0

  4. #4
    Wilksey Wilksey is offline
    Do you have a link to the code or can you post the code files I have the Mikro C Compiler I can see if it will compile on my system.

    Wilksey
    0

  5. Thread Starter #5
    nachum nachum is offline

    CODE FOR THE ADXL330- Undeclared identifier 'Usart_Write'

    Hi,
    Thanks for your help
    I've included the code


    Why do I get Undeclared identifier ?

    0 1 mikroCPIC1618.exe -MSF -DBG -pP16F877A -DL -O11111114 -fo8 -N"C:\Test\2\Read_Angles.mcppi" -SP"C:\Program
    0 1138 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
    0 126 All files Preprocessed in 1 ms
    0 122 Compilation Started Read_Angles.c
    44 324 Undeclared identifier 'Usart_Write' in expression Read_Angles.c
    46 324 Undeclared identifier 'Usart_Write' in expression Read_Angles.c
    47 324 Undeclared identifier 'Usart_Write' in expression Read_Angles.c
    181 324 Undeclared identifier 'Usart_Init' in expression Read_Angles.c
    0 102 Finished (with errors): 24 מרץ 2010, 20:09:52 Read_Angles.mcppi

    Code :
    // * Project name:
    //     Read_Angles
    // * Copyright:
    //     (c) MikroElektronika, 2008.
    // * Description:
    //     This project demonstrates Calibration and Reading the Accel Board outputs
    //     using the ADConversion library.
    //     On transition to the next stage program waits for user 
    //     to bring the Vcc to RD0 pin.
    // * Test configuration:
    //     MCU:             PIC16F877A
    //     Dev.Board:       EasyPIC5
    //     Oscillator:      HS, 8.000 MHz
    //     Ext. Modules:    Accel board Xout=RA0, Yout=RA1 and Zout=RA2
    //     SW:              mikroC v8
    // * NOTES:
    //     - Usart jumpers = On
    //     - When connecting the Vcc and Gnd consult the board schematics -
    //       if you don't do this properly you may DAMAGE the Accel board !!!
    //     - Connect the X-out to RA0, Y-out to RA1 and Z-out to RA2.
    //     - PORTA LEDs and pull-up/down switches = Off 
    //     - pull-down PORTD and set the buttons jumper to Vcc
    //     - arcsin function return value range is [-pi/2, pi/2] or [-90 deg, 90 deg].
    // --- Messages---
    #include "built_in.h"
     
    const char *msg1="Board to pos    ";
    const char *msg2="and press RD0   ";
    const char *msg3="Zero G values : ";
    const char *msg4="One G values :  ";
    const char *msg5="Angles:";
    const char *msg6="X=     Y=     Z=    ";
     
    char positionNo=1;
     
    signed int x, y, zz;
    signed int zeroG_x, zeroG_y, zeroG_z;
    signed int oneG_x, oneG_y, oneG_z;
    signed int meas_x, meas_y, meas_z;
    char text[32];
     
    void Usart_Write_Text(char* wr_txt) {
      while (*wr_txt)
        Usart_Write(*wr_txt++);
     
      Usart_Write(10);
      Usart_Write(13);
    }
     
    // --- Copying strings from ROM to RAM
    void strConstCpy(char *dest, const char *source) {
      while(*source)
      *dest++ = *source++ ;
     
      *dest = 0 ;
    }
     
    void DoMeasureXYZ() {
      meas_x = Adc_Read(0);   // Measure X_out
      meas_y = Adc_Read(1);   // Measure Y_out
      meas_z = Adc_Read(2);   // Measure Z_out
    }
     
    void WriteXYZ(signed int wr_x, signed int wr_y, signed int wr_z) {
     
      strConstCpy(text,msg6);
     
      if (wr_x < 0) {
         text[2] = '-';
         wr_x = -wr_x;
         }
      else   
         text[2] = wr_x/1000+48;
     
      text[3] = (wr_x/100)%10+48;
      text[4] = (wr_x/10)%10+48;
      text[5] = wr_x%10+48;
     
     
      if (wr_y < 0) {
         text[9] = '-';
         wr_y = -wr_y;
         }
      else   
         text[9] = wr_y/1000+48;
     
      text[10] = (wr_y/100)%10+48;
      text[11] = (wr_y/10)%10+48;
      text[12] = wr_y%10+48;
     
     
      if (wr_z < 0) {
         text[16] = '-';
         wr_z = -wr_z;
         }
      else
         text[16] = wr_z/1000+48;
     
      text[17] = (wr_z/100)%10+48;
      text[18] = (wr_z/10)%10+48;
      text[19] = wr_z%10+48;
     
      Usart_Write_Text(text);
    }
     
    void Calibrate() {
     
      strConstCpy(text,msg1);         //  1__ Put the Accel board in the position 1 :
      text[13] = positionNo++ + 48;   //      parallel to earth's surface
      Usart_Write_Text(text);         //      Z_axis is vertical with Z label UP
      strConstCpy(text,msg2);         //      to measure the Zero Gravity values for X and Y
      Usart_Write_Text(text);         //      and 1G Z value
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      zeroG_x = meas_x;
      zeroG_y = meas_y;
      oneG_z  = meas_z;
      Delay_ms(1000);
     
     
      strConstCpy(text,msg1);         //  2__ Put the Accel board in the position 2 :
      text[13] = positionNo++ + 48;   //      X_axis is vertical with X label UP
      Usart_Write_Text(text);
      strConstCpy(text,msg2);         //      to measure the 1G X value
      Usart_Write_Text(text);         //      and Zero Gravity value for Z
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      oneG_x = meas_x;
      zeroG_z = meas_z;
      Delay_ms(1000);
     
      strConstCpy(text,msg1);         //  3__ Put the Accel board in the position 3 :
      text[13] = positionNo++ + 48;   //      Y_axis is vertical with Y label UP
      Usart_Write_Text(text);
      strConstCpy(text,msg2);         //      to measure the 1G Y value
      Usart_Write_Text(text);
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      oneG_y = meas_y;
     
      strConstCpy(text,msg3);         // Display ZeroG values
      Usart_Write_Text(text);
      WriteXYZ(zeroG_x, zeroG_y, zeroG_z);
      Delay_ms(3000);
     
      strConstCpy(text,msg4);         // Display OneG values
      Usart_Write_Text(text);
      WriteXYZ(oneG_x, oneG_y, oneG_z);
      Delay_ms(3000);
    }
     
    void Read_Angles() {
     double div_x, x_rad, div_y, y_rad, div_z, z_rad ;
     
      DoMeasureXYZ();
      div_x = (float)(meas_x-zeroG_x) / (oneG_x-zeroG_x);  // measured_G / one_G
      x_rad = asin( div_x );                               // x angle in radians
      x = (x_rad*180) / 3.14;                              // x angle in degrees
     
      div_y = (float)(meas_y-zeroG_y) / (oneG_y-zeroG_y);  // measured_G / one_G
      y_rad = asin( div_y );                               // y angle in radians
      y = (y_rad*180) / 3.14;                              // y angle in degrees
     
      div_z = (float)(meas_z-zeroG_z) / (oneG_z-zeroG_z);  // measured_G / one_G
      z_rad = asin( div_z );                               // z angle in radians
      zz = (z_rad*180) / 3.14;                             // z angle in degrees
     
      WriteXYZ(x, y, zz);
    }
     
    void main() {
      CMCON  = 7;
      ADCON1 = 0x00;      // configure VDD as Vref, RA0, RA1 and RA2 as analog inputs
      TRISA  = 0b00000111;
      PORTD = 0;          // configure RD0 is digital input
      TRISD = 1;
     
      Usart_Init(9600);   // Initialize USART module
      Delay_ms(100);
     
      Calibrate();
     
      strConstCpy(text,msg5);     // Display Angles
      Usart_Write_Text(text);
     
      //--- main loop
      while(1) {
        Read_Angles();
        Delay_ms(1000);
        }
    }
    0

  6. #6
    Wilksey Wilksey is offline
    The reason is it was designed for Mikro C, Mikro C Pro has changed it's libraries etc, it is a pain as it isn't backwards compatible.

    I have attached a zip file with the compiled code and a compilable example for MIKRO C PRO 1.65 (I hope they haven't changed anything since!)

    Regards

    Wilksey
    Attached Files
    0

  7. Thread Starter #7
    nachum nachum is offline
    Thank you for the speed


    How do I open the file?
    0

  8. #8
    Wilksey Wilksey is offline
    ZIP file? just download JZip or another freeware zip extractor.
    0

  9. Thread Starter #9
    nachum nachum is offline
    I opened the ZIP. I meant the file inside the ZIP I can not open it.
    0
    Last edited by nachum; 25th March 2010 at 12:31 PM.

  10. Thread Starter #10
    nachum nachum is offline

    miKroC converted to MPLAB

    Do you know what changes to make to work with MPLAB?

    Code :
    const char *msg1="Board to pos    ";
    const char *msg2="and press RD0   ";
    const char *msg3="Zero G values : ";
    const char *msg4="One G values :  ";
    const char *msg5="Angles:";
    const char *msg6="X=     Y=     Z=    ";
     
    char positionNo=1;
     
    signed int x, y, zz;
    signed int zeroG_x, zeroG_y, zeroG_z;
    signed int oneG_x, oneG_y, oneG_z;
    signed int meas_x, meas_y, meas_z;
    char text[32];
     
    void UART_Write_Text(char* wr_txt) {
      while (*wr_txt)
        UART1_Write(*wr_txt++);
     
      UART1_Write(10);
      UART1_Write(13);
    }
     
    // --- Copying strings from ROM to RAM
    void strConstCpy(char *dest, const char *source) {
      while(*source)
      *dest++ = *source++ ;
     
      *dest = 0 ;
    }
     
    void DoMeasureXYZ() {
      meas_x = Adc_Read(0);   // Measure X_out
      meas_y = Adc_Read(1);   // Measure Y_out
      meas_z = Adc_Read(2);   // Measure Z_out
    }
     
    void WriteXYZ(signed int wr_x, signed int wr_y, signed int wr_z) {
     
      strConstCpy(text,msg6);
     
      if (wr_x < 0) {
         text[2] = '-';
         wr_x = -wr_x;
         }
      else
         text[2] = wr_x/1000+48;
     
      text[3] = (wr_x/100)%10+48;
      text[4] = (wr_x/10)%10+48;
      text[5] = wr_x%10+48;
     
     
      if (wr_y < 0) {
         text[9] = '-';
         wr_y = -wr_y;
         }
      else
         text[9] = wr_y/1000+48;
     
      text[10] = (wr_y/100)%10+48;
      text[11] = (wr_y/10)%10+48;
      text[12] = wr_y%10+48;
     
     
      if (wr_z < 0) {
         text[16] = '-';
         wr_z = -wr_z;
         }
      else
         text[16] = wr_z/1000+48;
     
      text[17] = (wr_z/100)%10+48;
      text[18] = (wr_z/10)%10+48;
      text[19] = wr_z%10+48;
     
      UART1_Write_Text(text);
    }
     
    void Calibrate() {
     
      strConstCpy(text,msg1);         //  1__ Put the Accel board in the position 1 :
      text[13] = positionNo++ + 48;   //      parallel to earth's surface
      UART1_Write_Text(text);         //      Z_axis is vertical with Z label UP
      strConstCpy(text,msg2);         //      to measure the Zero Gravity values for X and Y
      UART1_Write_Text(text);         //      and 1G Z value
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      zeroG_x = meas_x;
      zeroG_y = meas_y;
      oneG_z  = meas_z;
      Delay_ms(1000);
     
     
      strConstCpy(text,msg1);         //  2__ Put the Accel board in the position 2 :
      text[13] = positionNo++ + 48;   //      X_axis is vertical with X label UP
      UART1_Write_Text(text);
      strConstCpy(text,msg2);         //      to measure the 1G X value
      UART1_Write_Text(text);         //      and Zero Gravity value for Z
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      oneG_x = meas_x;
      zeroG_z = meas_z;
      Delay_ms(1000);
     
      strConstCpy(text,msg1);         //  3__ Put the Accel board in the position 3 :
      text[13] = positionNo++ + 48;   //      Y_axis is vertical with Y label UP
      UART1_Write_Text(text);
      strConstCpy(text,msg2);         //      to measure the 1G Y value
      UART1_Write_Text(text);
      while (PORTD.F0 == 0);          //      Loop until RD0 becomes 1
     
      DoMeasureXYZ();
      oneG_y = meas_y;
     
      strConstCpy(text,msg3);         // Display ZeroG values
      UART1_Write_Text(text);
      WriteXYZ(zeroG_x, zeroG_y, zeroG_z);
      Delay_ms(3000);
     
      strConstCpy(text,msg4);         // Display OneG values
      UART1_Write_Text(text);
      WriteXYZ(oneG_x, oneG_y, oneG_z);
      Delay_ms(3000);
    }
     
    void Read_Angles() {
    double div_x, x_rad, div_y, y_rad, div_z, z_rad ;
     
      DoMeasureXYZ();
      div_x = (float)(meas_x-zeroG_x) / (oneG_x-zeroG_x);  // measured_G / one_G
      x_rad = asin( div_x );                               // x angle in radians
      x = (x_rad*180) / 3.14;                              // x angle in degrees
     
      div_y = (float)(meas_y-zeroG_y) / (oneG_y-zeroG_y);  // measured_G / one_G
      y_rad = asin( div_y );                               // y angle in radians
      y = (y_rad*180) / 3.14;                              // y angle in degrees
     
      div_z = (float)(meas_z-zeroG_z) / (oneG_z-zeroG_z);  // measured_G / one_G
      z_rad = asin( div_z );                               // z angle in radians
      zz = (z_rad*180) / 3.14;                             // z angle in degrees
     
      WriteXYZ(x, y, zz);
    }
     
    void main() {
      CMCON  = 7;
      ADCON1 = 0x00;      // configure VDD as Vref, RA0, RA1 and RA2 as analog inputs
      TRISA  = 0b00000111;
      PORTD = 0;          // configure RD0 is digital input
      TRISD = 1;
     
      Uart1_Init(9600);   // Initialize USART module
      Delay_ms(100);
     
      Calibrate();
     
      strConstCpy(text,msg5);     // Display Angles
      UART1_Write_Text(text);
     
      //--- main loop
      while(1) {
        Read_Angles();
        Delay_ms(1000);
        }
    }
    0

12 Last »
Tags
Similar Threads
Thread Starter Forum Replies Last Post
Pic16f877a-adxl330 nachum Microcontrollers 0 15th March 2010, 02:10 PM
Pwm Code Pic16f877 khatib Microcontrollers 2 14th February 2009, 05:04 AM
measure the tilt with ADXL330/202 + atmega8 sm0ker Electronic Projects Design/Ideas/Reviews 11 22nd November 2008, 08:46 AM
ADXL330 accelerometer with PIC18f452 erictham83 Electronic Projects Design/Ideas/Reviews 0 15th August 2006, 11:44 AM
some testing code.... of code of 89C51 for LCD kumar_3k Electronic Projects Design/Ideas/Reviews 0 5th November 2003, 05:23 PM
Electronic Circuits  |  Learning Electronics

Join our community with over 100,000 Members! It's free, easy and when you're logged in you have many more features! Click to register.
Page Time: 0.12446 seconds      Memory: 7,745 KB      Queries: 17      Templates: 0