EDF - OnePIC MCU  v1.1.0
source/base/main8.c
Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2011 Microchip Technology Inc.
00003  *
00004  *  Project Name:    PIC16 EDF One PIC board
00005  *  FileName:        main8.c
00006  *  Processor:       PIC16LF1939
00007  *  Compiler:        HI-TECH PRO Ver. 9.83 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 #if defined(WIRELESS_DEMO)
00072 #include "OnePIC_8bit_demo_main.h" //Custom Demo
00073 #endif
00074 #include "OnePIC_mtouch.h"
00075 #include "OnePIC_rtcc.h"
00076 #include "TimeDelay.h"
00077 
00078 //config bits for the 8bit
00079 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
00080 __CONFIG(WRT_OFF & PLLEN_ON & STVREN_OFF & LVP_OFF);
00081 extern RTCC _time;
00082 extern uint8_t printed; 
00091 int main() {
00092     uint16_t potReading;
00093 
00094     EDF_mTouchInit();
00095     EDF_LEDInit();
00096     LCDInit();
00097     sprintf(LCDBuffer[0], "   MICROCHIP    ");
00098     sprintf(LCDBuffer[1], "  One PIC MCU   ");
00099     LCDUpdate();
00100     DelayMs(1000); //Pause for 1 sec for flash screen
00101     _pbState = 1;
00102     _swState = SW_PRESSED;
00103     sprintf(LCDBuffer[0], "  PIC16LF1939   ");
00104 
00105 
00106     EDF_TMR_ClockSourceSelect(TMR_2, TMR_SOURCE_INS_CLK); //if Change mTouch Timer Interrupt, must change it int mtouch_config/h
00107     EDF_TMR_StopInIdleDisable(TMR_2);
00108     //xxx    EDF_TMR_GateDisable(TMR_1);
00109     EDF_TMR_PrescalerSet(TMR_2, TMR246_PRESCALE_1_4);
00110     EDF_TMR_Start(TMR_2); //mTouch
00111     EDF_INT_SourceEnable(INT_TMR_2);
00112     EDF_INT_SourceFlagClear(INT_TMR_2);
00113     EDF_INT_Enable();
00114 #ifdef WIRELESS_DEMO
00115     //This is defined in the 8bit_IR configuration in MPLABX under compiler->preprocessor
00116     demo_main_loop(); //enter demo if building the demo
00117 #endif
00118     EDF_INT_SourceEnable(INT_SSP); //I2C
00119 
00120     I2CInit();  //I2C
00121     RTCCInit(); //RTC
00122 
00123     _bannerState = BANNER_POT;      //start by printing the POT value
00124     potReading = 0;                 //init to 0
00125     EDF_pot2bar(potReading);        //take the reading
00126     while (1) {
00127             //EDF_INT_SourceEnable(INT_TMR_2);
00128             potReading = EDF_potRead();     //read the POT
00129             if (_pbState == 1)
00130                 EDF_pot2bar(potReading);
00131             else
00132                 EDF_pot2bar(0x00);          //if button is in it's DOWN state, don't light up the LEDs
00133 
00134             //EDF_INT_SourceDisable(INT_TMR_2);
00135             RTCCProcessEvents();            //get the time
00136             if (_bannerState != BANNER_CAP) {
00137                 sprintf(LCDBuffer[1], "%4d    %8s", potReading, _time_str); //print the POT reading
00138             } else
00139                 sprintf(LCDBuffer[1], "%-5s   %8s", p_capString, _time_str); //print what button was pressed
00140 
00141             LCDUpdate();
00142 
00143             if(printed !=0) //use this so we don't miss the update even for the slightest touch
00144                 printed--;
00145         switchTasks(); //poll the button
00146     }
00147     return 1;
00148 }
00149