| 1 | /***************************************************************************//** |
| 2 | * @file Main.c |
| 3 | * @brief Implementation of the program's main function. |
| 4 | * @author Mihai Bancisor([email protected]) |
| 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: $WCREV$ |
| 41 | *******************************************************************************/ |
| 42 | |
| 43 | /******************************************************************************/ |
| 44 | /***************************** Option Bytes ***********************************/ |
| 45 | /******************************************************************************/ |
| 46 | #pragma location = "OPTBYTE" |
| 47 | __root const unsigned char opbyte0 = 0x6E; // Watchdog timer settings. |
| 48 | #pragma location = "OPTBYTE" |
| 49 | __root const unsigned char opbyte1 = 0xFF; // Low voltage detector settings. |
| 50 | #pragma location = "OPTBYTE" |
| 51 | __root const unsigned char opbyte2 = 0xE8; // Flash op. mode and osc. settings. |
| 52 | #pragma location = "OPTBYTE" |
| 53 | __root const unsigned char opbyte3 = 0x85; // On-chip Debug Option Byte. |
| 54 | |
| 55 | /******************************************************************************/ |
| 56 | /***************************** Include Files **********************************/ |
| 57 | /******************************************************************************/ |
| 58 | #include "RDKRL78G14.h" // RDKRL78G14 definitions. |
| 59 | #include "ST7579.h" // ST7579 definitions. |
| 60 | #include "TIME.h" // TIME definitions. |
| 61 | #include "AD7303.h" // AD7303 definitions. |
| 62 | |
| 63 | /******************************************************************************/ |
| 64 | /************************ Variables Definitions *******************************/ |
| 65 | /******************************************************************************/ |
| 66 | const unsigned char sinetable[250] = |
| 67 | { |
| 68 | 128, 131, 134, 137, 140, 143, 147, 150, 153, 156, |
| 69 | 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, |
| 70 | 189, 192, 194, 197, 200, 202, 205, 208, 210, 212, |
| 71 | 215, 217, 219, 222, 224, 226, 228, 230, 232, 233, |
| 72 | 235, 237, 238, 240, 241, 243, 244, 245, 247, 248, |
| 73 | 249, 250, 251, 251, 252, 253, 253, 254, 254, 255, |
| 74 | 255, 255, 255, 255, 255, 255, 255, 254, 254, 253, |
| 75 | 253, 252, 251, 251, 250, 249, 248, 247, 245, 244, |
| 76 | 243, 241, 240, 238, 237, 235, 233, 232, 230, 228, |
| 77 | 226, 224, 222, 219, 217, 215, 212, 210, 208, 205, |
| 78 | 202, 200, 197, 194, 192, 189, 186, 183, 180, 177, |
| 79 | 174, 171, 168, 165, 162, 159, 156, 153, 150, 147, |
| 80 | 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, |
| 81 | 112, 108, 105, 102, 99, 96, 93, 90, 87, 84, |
| 82 | 81, 78, 75, 72, 69, 66, 63, 61, 58, 55, |
| 83 | 53, 50, 47, 45, 43, 40, 38, 36, 33, 31, |
| 84 | 29, 27, 25, 23, 22, 20, 18, 17, 15, 14, |
| 85 | 12, 11, 10, 8, 7, 6, 5, 4, 4, 3, |
| 86 | 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, |
| 87 | 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, |
| 88 | 6, 7, 8, 10, 11, 12, 14, 15, 17, 18, |
| 89 | 20, 22, 23, 25, 27, 29, 31, 33, 36, 38, |
| 90 | 40, 43, 45, 47, 50, 53, 55, 58, 61, 63, |
| 91 | 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, |
| 92 | 96, 99, 102, 105, 108, 112, 115, 118, 121, 124 |
| 93 | }; |
| 94 | unsigned char ct1 = 0; |
| 95 | unsigned short ct2 = 0; |
| 96 | |
| 97 | /***************************************************************************//** |
| 98 | * @brief Draws the ADI logo and displays the name of ADI component. |
| 99 | * |
| 100 | * @param componentName - The name of the ADI component. |
| 101 | * |
| 102 | * @return None. |
| 103 | *******************************************************************************/ |
| 104 | void ADI_Component(unsigned char* string) |
| 105 | { |
| 106 | const unsigned char adiComponent[7] = |
| 107 | { |
| 108 | 0xFE, 0xFE, 0x82, 0xC6, 0xEE, 0xFE, 0xFE |
| 109 | }; |
| 110 | ST7579_Image(0, 0, adiComponent, 7, 8); |
| 111 | ST7579_String(0, 9, string, 0); |
| 112 | } |
| 113 | |
| 114 | /***************************************************************************//** |
| 115 | * @brief Main function. |
| 116 | * |
| 117 | * @return None. |
| 118 | *******************************************************************************/ |
| 119 | void main(void) |
| 120 | { |
| 121 | /* Initialize RDKRL78G14. */ |
| 122 | RDKRL78G14_Init(); |
| 123 | |
| 124 | /* Enable interrupts. */ |
| 125 | __enable_interrupt(); |
| 126 | |
| 127 | /* Initialize timer. */ |
| 128 | TIME_Init(); |
| 129 | |
| 130 | /* Initialize the ST7579 Display. */ |
| 131 | ST7579_Init(); |
| 132 | |
| 133 | /* Initialize AD7303 device. */ |
| 134 | if(AD7303_Init() == 0) |
| 135 | { |
| 136 | ADI_Component("AD7303 OK"); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | ADI_Component("AD7303 Error"); |
| 141 | } |
| 142 | ST7579_String(2 ,0, "DAC A: ", 0); |
| 143 | ST7579_String(3, 10, "4 Hz Sinewave ", 0); |
| 144 | ST7579_String(4, 0, "DAC B: ", 0); |
| 145 | ST7579_String(5, 10, "One val/sec ", 0); |
| 146 | |
| 147 | while(1) |
| 148 | { |
| 149 | /* Output a sine wave on channel A. */ |
| 150 | AD7303_Write((AD7303_LDAC | AD7303_A), sinetable[ct1]); |
| 151 | /* After second 1 set the channel B output to zero scale. */ |
| 152 | if(ct2 < 1000) |
| 153 | { |
| 154 | AD7303_Write((AD7303_LDAC | AD7303_B), 0); |
| 155 | } |
| 156 | /* After second 2 set the channel B output to middle scale. */ |
| 157 | if((ct2 >= 1000) && (ct2 < 2000)) |
| 158 | { |
| 159 | AD7303_Write((AD7303_LDAC | AD7303_B), 128); |
| 160 | } |
| 161 | /* After second 2 set the channel B output to full scale. */ |
| 162 | if((ct2 >= 2000) && (ct2 < 3000)) |
| 163 | { |
| 164 | AD7303_Write((AD7303_LDAC | AD7303_B), 255); |
| 165 | } |
| 166 | if(ct1 < 249) |
| 167 | { |
| 168 | ct1++; |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | ct1 = 0; // After 250 while loops, reset ct1. |
| 173 | } |
| 174 | if(ct2 < 3000 ) |
| 175 | { |
| 176 | ct2++; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | ct2 = 0; // After 3 seconds, reset ct2. |
| 181 | } |
| 182 | TIME_DelayMs(1); |
| 183 | } |
| 184 | } |