Main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /***************************************************************************//**
  2. * @file Main.c
  3. * @brief Implementation of the program's main function.
  4. * @author Bancisor Mihai
  5. ********************************************************************************
  6. * Copyright 2012(c) Analog Devices, Inc.
  7. *
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. * - Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * - Neither the name of Analog Devices, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. * - The use of this software may or may not infringe the patent rights
  22. * of one or more patent holders. This license does not release you
  23. * from the requirement that you obtain separate licenses from these
  24. * patent holders to use this software.
  25. * - Use of the software either in source or binary form, must be run
  26. * on or directly connected to an Analog Devices Inc. component.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
  29. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
  30. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  31. * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
  34. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. ********************************************************************************
  40. * SVN Revision: 381
  41. *******************************************************************************/
  42. /******************************************************************************/
  43. /* Include Files */
  44. /******************************************************************************/
  45. #include "YRDKRX62N.h" // YRDKRX62N definitions.
  46. #include "ST7579.h" // ST7579 definitions.
  47. #include "AD7793.h" // ADF4360 definitions.
  48. /******************************************************************************/
  49. /* Variables Declarations */
  50. /******************************************************************************/
  51. const unsigned char adiLogo [2 * 19] =
  52. { 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x07, 0x07,
  53. 0x0F, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F,
  54. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0,
  55. 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC,
  56. 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF };
  57. unsigned char periodEnd = 0; // Indicates when the OneShot period ends.
  58. unsigned long value = 0; // value read from the ADC
  59. /******************************************************************************/
  60. /* Functions Prototypes */
  61. /******************************************************************************/
  62. void DelaySeconds(float seconds);
  63. void OneShotCallback(void);
  64. /***************************************************************************//**
  65. * @brief Main function.
  66. *
  67. * @param None.
  68. *
  69. * @return None.
  70. *******************************************************************************/
  71. void main(void)
  72. {
  73. YRDKRX62N_Init();
  74. ST7579_Init();
  75. ST7579_Image(2,0,adiLogo,19,16);
  76. ST7579_String(2,21,"ANALOG");
  77. ST7579_String(3,21,"DEVICES");
  78. ST7579_String(4,0,"wiki.analog.com");
  79. DelaySeconds(2);
  80. ST7579_Clear();
  81. ST7579_Image(0,0,adiLogo,19,16);
  82. ST7579_String(0,22,"ST7579 OK");
  83. AD7793_Reset(); // Reset AD7793 to bring the SPI interface in a known state
  84. if(AD7793_Init())
  85. {
  86. ST7579_String(1,22,"AD7793 OK");
  87. }
  88. else
  89. {
  90. ST7579_String(1,22,"AD7793 Err");
  91. }
  92. /* AD7792 setup. */
  93. AD7793_SetGain(AD7793_GAIN_1); // set gain to 1
  94. AD7793_SetChannel(AD7793_CH_AIN1P_AIN1M); // use AIN1(+) - AIN1(-)
  95. AD7793_SetReference(AD7793_REFSEL_INT); // select internal 1.17V reference
  96. /* Print the value of the configuration register after setup */
  97. ST7579_String(3,0,"Conf Reg:");
  98. ST7579_HexNumber(3,70,AD7793_GetRegisterValue( AD7793_REG_CONF,2),2);
  99. while(1)
  100. {
  101. if(AD7793_Ready())
  102. {
  103. ST7579_String(5,2,"AIN1(+)-AIN1(-)");
  104. value = AD7793_GetRegisterValue( AD7793_REG_DATA,3);
  105. ST7579_String(4,0,"Data:");
  106. ST7579_HexNumber(4,75,value,4);
  107. if(value > 0x800000)
  108. {
  109. value -= 0x800000;
  110. value = ((value * 1170) >> 23);
  111. ST7579_String(6,10,"+");
  112. }
  113. else
  114. {
  115. value = 0x800000 - value;
  116. value = ((value * 1170) >> 23);
  117. ST7579_String(6,10,"-");
  118. }
  119. ST7579_Number(6,55,value);
  120. ST7579_String(6,65,"mV");
  121. }
  122. }
  123. }
  124. /***************************************************************************//**
  125. * @brief Creates a delay of seconds.
  126. *
  127. * @param None.
  128. *
  129. * @return None.
  130. *******************************************************************************/
  131. void DelaySeconds(float seconds)
  132. {
  133. periodEnd = 0;
  134. R_TMR_CreateOneShot(PDL_TMR_UNIT0,
  135. PDL_TMR_OUTPUT_OFF,
  136. seconds,
  137. OneShotCallback,
  138. 4);
  139. while(periodEnd == 0);
  140. }
  141. /***************************************************************************//**
  142. * @brief OneShot callback function.
  143. *
  144. * @param None.
  145. *
  146. * @return None.
  147. *******************************************************************************/
  148. void OneShotCallback(void)
  149. {
  150. periodEnd = 1;
  151. }