EDF - OnePIC MCU  v1.1.0
source/base/main16.c
Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2011 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    PIC24 EDF One PIC board
00005  *  FileName:        main16.c
00006  *  Processor:       PIC24FJ256GA106
00007  *  Compiler:        C30(3.30vb) 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 
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include "OnePIC_int.h"
00058 #include "OnePIC_timer.h"
00059 #include "OnePIC_lcd.h"
00060 #include "OnePIC_led.h"
00061 #include "OnePIC_isr.h"
00062 #include "OnePIC_switch.h"
00063 #include "OnePIC_pot.h"
00064 #include "OnePIC_i2c.h"
00065 #include "Compiler.h"
00066 
00067 #include "mTouch.h"
00068 //#include "Controller.h"
00069 
00070 #include "OnePIC_mtouch.h"
00071 #include "OnePIC_rtcc.h"
00072 #include "TimeDelay.h"
00073 
00074 _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx2 & FWDTEN_OFF)
00075 _CONFIG2(IESO_OFF & FNOSC_FRCPLL & FNOSC_PRIPLL & FCKSM_CSDCMD & IOL1WAY_OFF & POSCMOD_HS)
00076 
00077 extern uint8_t printed; //used in OnePIC_mtouch.c
00078 
00086 int main(void) {
00087     uint16_t potReading;
00088 
00089 
00090     EDF_TMR_ClockSourceSelect(TMR_1, TMR_SOURCE_INS_CLK);
00091     EDF_TMR_StopInIdleDisable(TMR_1);
00092     EDF_TMR_GateDisable(TMR_1);
00093     EDF_TMR_PrescalerSet(TMR_1, TMR_PRESCALE_1_8);
00094     EDF_INT_SourceEnable(INT_TMR_1);
00095     EDF_INT_SourceFlagClear(INT_TMR_1);
00096     EDF_mTouchInit();
00097 
00098 
00099 #if !defined(WIRELESS_DEMO)
00100     I2CInit();
00101     RTCCInit();
00102 #endif
00103     LCDInit();
00104     EDF_LEDInit();
00105     sprintf(LCDBuffer[0], "   MICROCHIP    ");
00106     sprintf(LCDBuffer[1], "  One PIC MCU   ");
00107     LCDUpdate();
00108     _pbState = 1;
00109     _swState = SW_PRESSED;
00110     DelayMs(1000);
00111     sprintf(LCDBuffer[0], "PIC24FJ256GA106");
00112     uint8_t tick;
00113     potReading = 1000;
00114 
00115 
00116     EDF_TMR_Start(TMR_1); //Enable Touch now
00117 #if defined(WIRELESS_DEMO)
00118     demo_main_loop();
00119 #endif
00120 
00121     //while (1) {
00122     //   Nop();
00123 #if !defined(WIRELESS_DEMO)
00124     RTCCProcessEvents();
00125 #endif
00126 
00127     _bannerState = BANNER_POT; //start by printing the POT value
00128     potReading = 0; //init to 0
00129     EDF_pot2bar(potReading); //take the reading
00130     while (1) {
00131 
00132         potReading = EDF_potRead(); //read the POT
00133         if (_pbState == 1)
00134             EDF_pot2bar(potReading);
00135         else
00136             EDF_pot2bar(0x00); //if button is in it's DOWN state, don't light up the LEDs
00137 
00138         EDF_TMR_Stop(TMR_1);
00139         RTCCProcessEvents(); //get the time
00140         EDF_TMR_Start(TMR_1);
00141         if (_bannerState != BANNER_CAP) {
00142             sprintf(LCDBuffer[1], "%4d    %8s", potReading, _time_str); //print the POT reading
00143         } else
00144             sprintf(LCDBuffer[1], "%-5s   %8s", p_capString, _time_str); //print what button was pressed
00145 
00146         LCDUpdate();
00147         if (printed != 0) //use this so we don't miss the update even for the slightest touch
00148             printed--;
00149         switchTasks(); //poll the button
00150     }
00151     return 1;
00152 }