/*
* File: main.c
* Author: BitPIC
*
* Created on 30 de diciembre de 2012, 20:55
*/
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <plib.h>
// PIC32MX110F016B Configuration Bit Settings
// DEVCFG3
// USERID = No Setting
#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
// SYSCLK = 10 MHz (10MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
#pragma config FPLLIDIV = DIV_10 // PLL Input Divider (10x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (PLL Divide by 2)
// DEVCFG1
#pragma config FNOSC = PRI // Oscillator Selection Bits (Primary Osc (XT,HS,EC))
#pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = HS // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1 // Watchdog Timer Postscaler (1:1)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WISZ_25 // Watchdog Timer Window Size (Window Size is 25%)
// DEVCFG0
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
#define SYS_FREQ (10000000) //le indicamos la frecuencia del sistema
#define config1 UART_EN | UART_IDLE_CON | UART_RX_TX | UART_DIS_WAKE | UART_DIS_LOOPBACK | UART_DIS_ABAUD | UART_NO_PAR_8BIT | UART_1STOPBIT | UART_IRDA_DIS | UART_DIS_BCLK_CTS_RTS| UART_NORMAL_RX | UART_BRGH_SIXTEEN
#define config2 UART_TX_PIN_LOW | UART_RX_ENABLE | UART_TX_ENABLE | UART_INT_TX | UART_INT_RX_CHAR | UART_ADR_DETECT_DIS | UART_RX_OVERRUN_CLEAR
#define DESIRED_BAUDRATE 9600
// Function Prototypes
int main(void);
void delay(int time);
int main(void) {
unsigned int pbClk;
pbClk = SYSTEMConfigPerformance(SYS_FREQ);
mPORTBSetPinsDigitalIn(BIT_11|BIT_2 | BIT_4);
mPORTBSetPinsDigitalOut(BIT_10 |BIT_12 | BIT_13 | BIT_14 | BIT_15);
//Configruación UART
U2RXRbits.U2RXR = 0b0011; // Set RX to RPB11
RPB10Rbits.RPB10R = 0b0010; // Set TX to RPB10
OpenUART2( config1, config2, pbClk/16/DESIRED_BAUDRATE-1); // calculate actual BAUD generate value.
while(1){
if(_RB2){
delay(10000);
if(!_RB2){
_RB12 = !_RB12;
}
}
while (U2STAbits.UTXBF);
putcUART2('a');
putcUART2(0x0A);
}
}
void delay(int time){
int i;
for(i=0;i<time;i++);
}