EDF - OnePIC MCU  v1.1.0
source/base/main32.c
Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2011 Microchip Technology Inc.
00003  *
00004  *  Project Name:    PIC32 EDF One PIC board
00005  *  FileName:        main32.c
00006  *  Processor:       PIC32MX795F512L
00007  *  Compiler:        C32(2.01) or later
00008  *  IDE:             MPLABX® IDE v1.00 or later
00009  *  Hardware:        One PIC Microcontroller Platform
00010  *************************************************************************/
00011 /*************************************************************************
00012  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and
00013  * any derivatives created by any person or entity by or on your behalf,
00014  * exclusively with Microchip's products in accordance with applicable
00015  * software license terms and conditions, a copy of which is provided for
00016  * your referencein accompanying documentation. Microchip and its licensors
00017  * retain all ownership and intellectual property rights in the
00018  * accompanying software and in all derivatives hereto.
00019  *
00020  * This software and any accompanying information is for suggestion only.
00021  * It does not modify Microchip's standard warranty for its products. You
00022  * agree that you are solely responsible for testing the software and
00023  * determining its suitability. Microchip has no obligation to modify,
00024  * test, certify, or support the software.
00025  *
00026  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
00027  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
00028  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
00029  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH
00030  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY
00031  * APPLICATION.
00032  *
00033  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY,
00034  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT
00035  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT,
00036  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE,
00037  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE,
00038  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY
00039  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW,
00040  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS
00041 // * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID
00042  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
00043  *
00044  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF
00045  * THESE TERMS.
00046  *************************************************************************/
00047 
00048 
00049 
00059 #include <stdio.h>
00060 #include <stdlib.h>
00061 #include <string.h>
00062 #include "OnePIC_int.h"
00063 #include "OnePIC_timer.h"
00064 #include "OnePIC_lcd.h"
00065 #include "OnePIC_led.h"
00066 #include "OnePIC_isr.h"
00067 #include "OnePIC_switch.h"
00068 #include "OnePIC_pot.h"
00069 #include "OnePIC_i2c.h"
00070 #include "Compiler.h"
00071 #include "mTouchCapAPI.h"
00072 #include "mTouchConfig.h"
00073 #include "mTouchCapLED.h"
00074 #include "mTouchCapApp_DirectKeys.h"
00075 #include "OnePIC_mtouch.h"
00076 #include "OnePIC_rtcc.h"
00077 #include "TimeDelay.h"
00078 
00079 #pragma config FNOSC    = FRCPLL   // Oscillator Selection: Internal FRC with PLL
00080 #pragma config FPLLIDIV = DIV_2    // PLL Input Divider: Divide by 2
00081 #pragma config FPLLMUL  = MUL_20   // PLL Multiplier: Multiply by 20
00082 #pragma config FPLLODIV = DIV_4    // PLL Output Divider: Divide by 1
00083 #pragma config POSCMOD  = HS       // Primary Oscillator: HS oscillator
00084 #pragma config FCKSM    = CSDCMD   // Clock Switching & Fail Safe Monitor: Clock Switching Disabled, Clock Monitoring Disabled
00085 #pragma config OSCIOFNC = OFF      // CLKO Enable: Disabled
00086 #pragma config IESO     = OFF      // Internal/External Switch-over: Disabled
00087 #pragma config FSOSCEN  = OFF      // Secondary Oscillator Enable: Disabled
00088 #pragma config FPBDIV   = DIV_1    // Peripheral Clock divisor: Divide by 1
00089 #pragma config UPLLEN   = OFF      // USB PLL Disabled
00090 #pragma config UPLLIDIV = DIV_2    // USB PLL Input Divider
00091 #pragma config FWDTEN   = OFF       // Watchdog Timer: Disabled
00092 #pragma config WDTPS    = PS1      // Watchdog Timer Postscale: 1:1
00093 #pragma config CP       = OFF      // Code Protect: OFF
00094 #pragma config BWP      = OFF      // Boot Flash Write Protect: OFF
00095 #pragma config PWP      = OFF      // Program Flash Write Protect: OFF
00096 #pragma config ICESEL   = ICS_PGx2 // ICE/ICD Comm Channel Select: ICE pins shared with PGC1,PGD1
00097 #pragma config DEBUG    = OFF      // Background Debugger Enable: OF
00098 
00106 int main(void) {
00107     uint16_t reading = 0;
00108     uint16_t tick = 0;
00109 
00110     EDF_mTouchInit();
00111     LCDInit();
00112 
00113 
00114     EDF_LEDInit();
00115     sprintf(LCDBuffer[0], "   MICROCHIP    ");
00116     sprintf(LCDBuffer[1], "  One PIC MCU   ");
00117     LCDUpdate();
00118     DelayMs(1000);
00119     sprintf(LCDBuffer[0], "PIC32MX795F512L");
00120     I2CInit();
00121     RTCCInit();
00122     _pbState = 1;
00123     _swState = SW_PRESSED;
00124 
00125     while (1) {
00126 
00127         if (tick++ == 30) { //30
00128             tick = 0;
00129             reading = EDF_potRead();
00130             switchTasks();
00131             RTCCProcessEvents();
00132             if (_pbState == 1) {
00133                 EDF_pot2bar(reading);
00134             } else {
00135                 EDF_pot2bar(0x00);
00136             }
00137 
00138             if (_bannertest == 0) {
00139                 sprintf(LCDBuffer[1], "%4d    %8s", reading, _time_str);
00140                 EDF_LEDClr(LED_UP);
00141                 EDF_LEDClr(LED_DOWN);
00142                 EDF_LEDClr(LED_LEFT);
00143                 EDF_LEDClr(LED_RIGHT);
00144                 LCDUpdate();
00145             } else if (_bannertest == 1) {
00146                 if (edf_u == 1) {
00147                     sprintf(LCDBuffer[1], "%-5s   %8s", "Up", _time_str);
00148                 } else if (edf_d == 1) {
00149                     sprintf(LCDBuffer[1], "%-5s   %8s", "Down", _time_str);
00150                 } else if (edf_l == 1) {
00151                     sprintf(LCDBuffer[1], "%-5s   %8s", "Left", _time_str);
00152                 } else if (edf_r == 1) {
00153                     sprintf(LCDBuffer[1], "%-5s   %8s", "Right", _time_str);
00154                 } else if (edf_e == 1) {
00155 
00156                     sprintf(LCDBuffer[1], "%-5s   %8s", "Enter", _time_str);
00157                 }
00158                 RTCCProcessEvents();
00159                 _bannertest = 0;
00160                 LCDUpdate();
00161             }
00162         }
00163         mTouchTasks();
00164         DelayMs(1); //requried delay for ADC from mtouch
00165 
00166         //  }
00167 
00168 
00169     } //end while (1)
00170 } // end main()