Main.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /***************************************************************************//**
  2. * @file Main.c
  3. * @brief Implementation of the program's main function.
  4. * @author DNechita
  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: 499
  41. *******************************************************************************/
  42. /******************************************************************************/
  43. /* Include Files */
  44. /******************************************************************************/
  45. #include "YRDKRL78G13.h" // YRDKRX62N definitions.
  46. #include "ST7579.h" // ST7579 definitions.
  47. #include "AD7793.h" // AD7793 definitions.
  48. /******************************************************************************/
  49. /* Option Bytes */
  50. /******************************************************************************/
  51. #pragma location = "OPTBYTE"
  52. __root const uint8_t opbyte0 = 0x00U;
  53. #pragma location = "OPTBYTE"
  54. __root const uint8_t opbyte1 = 0xFFU;
  55. #pragma location = "OPTBYTE"
  56. __root const uint8_t opbyte2 = 0xE8U;
  57. #pragma location = "OPTBYTE"
  58. __root const uint8_t opbyte3 = 0x04U;
  59. /******************************************************************************/
  60. /* Security ID */
  61. /******************************************************************************/
  62. #pragma location = "SECUID"
  63. __root const uint8_t secuid[10] =
  64. {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
  65. /******************************************************************************/
  66. /* Variables Declarations */
  67. /******************************************************************************/
  68. const unsigned char adiLogo [2 * 19] =
  69. { 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x07, 0x07,
  70. 0x0F, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F,
  71. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0,
  72. 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC,
  73. 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF }; // ADI Logo.
  74. unsigned long value = 0; // value read from the ADC
  75. /***************************************************************************//**
  76. * @brief Creates a delay of seconds.
  77. *
  78. * @param mSeconds - time in miliseconds.
  79. *
  80. * @return None.
  81. *******************************************************************************/
  82. void DelayMs(unsigned long mSeconds)
  83. {
  84. unsigned long time = 0;
  85. R_TAU0_Channel0_Start();
  86. while(time < mSeconds)
  87. {
  88. if(TMIF00 == 1)
  89. {
  90. time++;
  91. TMIF00 = 0;
  92. }
  93. }
  94. R_TAU0_Channel0_Stop();
  95. }
  96. /***************************************************************************//**
  97. * @brief Main function.
  98. *
  99. * @param None.
  100. *
  101. * @return None.
  102. *******************************************************************************/
  103. void main(void)
  104. {
  105. YRDKRL78G13_Init();
  106. ST7579_Init();
  107. ST7579_Image(2,0,adiLogo,19,16);
  108. ST7579_String(2,21,"ANALOG");
  109. ST7579_String(3,21,"DEVICES");
  110. ST7579_String(4,0,"wiki.analog.com");
  111. DelayMs(2000);
  112. ST7579_Clear();
  113. ST7579_Image(0,0,adiLogo,19,16);
  114. ST7579_String(0,22,"ST7579 OK");
  115. /* Reset AD7793 to bring the SPI interface in a known state */
  116. AD7793_Reset();
  117. if(AD7793_Init())
  118. {
  119. ST7579_String(1,22,"AD7793 OK");
  120. }
  121. else
  122. {
  123. ST7579_String(1,22,"AD7793 Err");
  124. }
  125. /* AD7793 setup */
  126. AD7793_SetGain(AD7793_GAIN_1); // set gain to 1
  127. AD7793_SetChannel(AD7793_CH_AIN1P_AIN1M); // use AIN1(+) - AIN1(-)
  128. AD7793_SetIntReference(AD7793_REFSEL_INT); // select internal 1.17V reference
  129. AD7793_Calibrate(AD7793_MODE_CAL_INT_ZERO,
  130. AD7793_CH_AIN1P_AIN1M); // Internal Zero-Scale Calibration
  131. /* A 20 samples average is displayed. */
  132. ST7579_String(3,0,"AVG:");
  133. value = AD7793_ContinuousReadAvg(20);
  134. ST7579_HexNumber(3,70,value,4);
  135. while(1)
  136. {
  137. value = AD7793_SingleConversion();
  138. ST7579_String(5,2,"AIN1(+)-AIN1(-)");
  139. ST7579_String(4,0,"Data:");
  140. ST7579_HexNumber(4,75,value,4);
  141. if(value > 0x800000)
  142. {
  143. value -= 0x800000;
  144. value = ((value * 1170) >> 15);
  145. ST7579_String(6,10,"+");
  146. }
  147. else
  148. {
  149. value = 0x800000 - value;
  150. value = ((value * 1170) >> 15);
  151. ST7579_String(6,10,"-");
  152. }
  153. ST7579_Number(6,55,value,5);
  154. ST7579_String(6,65,"mV");
  155. DelayMs(250);
  156. }
  157. }