Page MenuHomec4science

main.c
No OneTemporary

File Metadata

Created
Fri, Nov 29, 19:29
/*
* Copyright (C) 2011-2013 Rico Moeckel, Alexandre Tuleu
*/
/**
* \defgroup main MAIN
* \brief Main file for the project.
* This is the main file.
* \author Rico Moeckel, Alexandre Tuleu
* \version 2.0
* \date 2013-05-14
*/
/*@{*/
/**
* \file main.c
* \brief Main file for the project.
*/
#include "config.h"
#include <p33Fxxxx.h>
#include "timer.h"
#include "uart.h"
#include "led.h"
#include "sbcp_host.h"
#include "sbcp_bus.h"
/*************************************************************************
* CONFIGURATION BITS
*
* With MPLAB X, microchip removed the ability to configure bits from
* the GUI, and asked to do it directly from the code. It seems to be
* a feature and not a lack of feature. So it will be better do to it
* all the time from now !
*************************************************************************/
//Disable watch dog
_FWDT(WDTPOST_PS32768 & WDTPRE_PR128 & WINDIS_OFF & FWDTEN_OFF)
//pic started by external clock.
_FOSC(POSCMD_NONE & OSCIOFNC_ON & FCKSM_CSECMD)
//external clock
_FOSCSEL(FNOSC_FRC & IESO_OFF)
/**
* \brief Initialization function for the clock of the microcontroller
*
* This function configures the clock system of the microcontroller to
* use the internal oscillator as well as the PLL to run the clock at
* maximum speed of 40MIPS.
*
*/
void clock_init() {
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD = 41; // M = 43
CLKDIVbits.PLLPOST=0; // N2 = 2
CLKDIVbits.PLLPRE=0; // N1 = 2
// Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
__builtin_write_OSCCONH(0x01);
__builtin_write_OSCCONL(0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC != 0b001){};
// Wait for PLL to lock
while(OSCCONbits.LOCK != 1) {};
}
/** \brief Main initialization function for the microcontroller This
* function calls all individual initialization functions of the
* submodules. Register your local init functions here. Be careful
* about the correct order of initializations. This function has to be
* called inside the main routine before any other funtions.
*
* \param no parameters
* \return no returns
*/
void main_init() {
clock_init();
ADPCFG = 0xffff; // Set all Analog ports as Digital I/O
TRISA = 0xffff; // Everything is input
TRISB = 0xffff; // Everything is input
timer_init();
TRISAbits.TRISA1 = 0;
led_init();
//init_sbcp_host();
//init_sbcp_bus();
}
/** \brief Main function
*
* This function is the main function. It calls the main_init()
* function and handles all main functions of the individual modules.
* \param no parameters
* \return int status
*/
int main() {
main_init();
ticks oflw = rtc_overflow();
while (1) {
if (oflw != rtc_overflow() ){
oflw = rtc_overflow();
// led_toggle(RED);
}
//sbcp_process_host_tx();
//sbcp_process_bus();
//sbcp_process_host_rx();
led_main();
}
return 0;
}
/*@}*/

Event Timeline