Codigo:
#define __dsPIC30F2010__
#include <p30fxxxx.h>
_FOSC(CSW_FSCM_OFF & HS);
int main ()
{unsigned char a,x,y;
TRISB=0;
uno:
PORTB=0x1;
retardo(x);
PORTB=0x0;
retardo(x); x++;
goto uno;
}
int retardo (int x)
{unsigned char a,b,c;
for(a=0; a< x; a++){
for (b=0 ; b < 255 ; b++){ for (c=0 ; c < 10 ; c++){} }
}
}
Codigo:
/****************************************/
/* DelayUs Microsegundos */
/****************************************/
void DelayUs(int v)
{
while(v != 0){ asm("nop"asm("nop"
; v--;}
}
/****************************************/
/* DelayMs MiliSegundos */
/****************************************/
void DelayMs(int v)
{
while (v != 0 ){ DelayUs(1000); v--;}
}
Escrito originalmente por Sispic
M¡ra que sois un poco vagoncetes
Pero va para el 30F2010:
Pin 18 -> PGC -> Clock
Pin 17 -> PGD -> Data
Pin 1 -> MCLR -> Vpp -> 13,25 v aproximado
Pin 8,19,27 -> Vss
Pin 13,20 -> Vdd
pin 28 AVdd -> a Vdd a traves de una resistencia de 100 aproximado.
Una Vdd min 4v5 bien filtrada , mejor un condensador electrolitico (10-100 micros) cerca del pic .
Cuentanos como te va .

Codigo:
// LCD HD44780U 4 bit mode.
// LCD tipos: 1x8, 2x8, 1x16, 2x16, 2x20, 4x16, 4x20
// Modificado para DsPic 30Fxxxx
/*
// USER"S ROUTINES DESCRIPTION:
LCD_INIT() ---> initilalize the LCD.
LCD_CLEAR() ---> Clears and Home LCD.
LCD_CMD("char") ---> Send a command to the LCD. See LCD datasheet for the complete list of commands.
LCD_GOTO(line,pos) ---> Set the Cursor to a specified Line and position. Lines available are from 1 to 4. Pos available starts from 1 to max available on your LCD.
LCD_PUTCH("char") ---> Write a character on LCD (ASCII representation).
LCD_PUTS("string" ) ---> Write a string on LCD.
LCD_PUTC("constant" ) ---> Write a const string on LCD.
LCD_PUTUN(unsigned long) ---> Write an Unsigned Number on LCD. It works both with INT (16bit) and CHAR (8bit). y (32bit) maximo 9 digitos
Set_CGRAM_address(char addr) --->
Ejemplo . escribe 2 caracteres predefinidos en direccion 0 y 1
LCD_INIT();
Set_CGRAM_address(0);
LCD_PUTCH(1);LCD_PUTCH(2);LCD_PUTCH(4);LCD_PUTCH(8);LCD_PUTCH(16);LCD_PUTCH(32);LCD_PUTCH(1);LCD_PUTCH(1);
LCD_PUTCH(9);LCD_PUTCH(10);LCD_PUTCH(1);LCD_PUTCH(1);LCD_PUTCH(1);LCD_PUTCH(1);LCD_PUTCH(1);LCD_PUTCH(1);
LCD_CLEAR();
LCD_PUTCH(0); LCD_PUTCH(1);
*/
/************************************************************************/
/* Use the following defines to set the lines as your hardware requires */
/* ...you can use ANY output line of the MCU, even on several ports*/
/************************************************************************/
#define LCD_ROWS 2 // valid numbers are: 1,2
#define LCD_COLS 20 // valid numbers are: 8,16,20 // (set to 2 for 2 or more rows)
/* PUERTOS */
#define LCD_RS PORTEbits.RE4 // Register select
#define LCD_EN PORTEbits.RE5 // Enable
#define LCD_D4 PORTEbits.RE0 // LCD data 4
#define LCD_D5 PORTEbits.RE1 // LCD data 5
#define LCD_D6 PORTEbits.RE2 // LCD data 6
#define LCD_D7 PORTEbits.RE3 // LCD data 7
/* TRIS */
#define LCD_RS_TRIS TRISEbits.TRISE4 // Register select
#define LCD_EN_TRIS TRISEbits.TRISE5 // Enable
#define LCD_D4_TRIS TRISEbits.TRISE0 // LCD data 4
#define LCD_D5_TRIS TRISEbits.TRISE1 // LCD data 5
#define LCD_D6_TRIS TRISEbits.TRISE2 // LCD data 6
#define LCD_D7_TRIS TRISEbits.TRISE3 // LCD data 7
/************************************************************************/
#define LCD_CLR 0x01 // Clear Display
#define LCD_HOME 0x02 // Cursor to Home position
// Entry mode set
// ejemplo: LCD_CMD( CURSOR_DIRECCTION_Decrement | NO_Accompanies_display_shift );
#define CURSOR_DIRECCTION_Increment 0x6
#define CURSOR_DIRECCTION_Decrement 0x4
#define Accompanies_display_shift 0x5
#define No_Accompanies_display_shift 0x4
// Display on/off control
// ejemplo: LCD_CMD( DISPLAY_ON | CURSOR_ON | CURSOR_BLINKING_OFF );
#define DISPLAY_ON 0x0C
#define DISPLAY_OFF 0x08
#define CURSOR_ON 0x0A
#define CURSOR_OFF 0x08
#define CURSOR_BLINKING_ON 0x09
#define CURSOR_BLINKING_OFF 0x08
// Cursor or display shift
// ejemplo: LCD_CMD( Cursor_move | Shift_to_the_left );
#define Display_shift 0x18
#define Cursor_move 0x10
#define Shift_to_the_right 0x14
#define Shift_to_the_left 0x10
/************************************************************************/
#if (LCD_COLS==20)
#define LCD_line1 0x80 // Line 1 position 1
#define LCD_line2 0xC0 // Line 2 position 1
#define LCD_line3 0x94 // Line 3 position 1 (20 char LCD)
#define LCD_line4 0xD4 // Line 4 position 1 (20 char LCD)
#else
#define LCD_line1 0x80 // Line 1 position 1
#define LCD_line2 0xC0 // Line 2 position 1
#define LCD_line3 0x90 // Line 3 position 1 (16 char LCD)
#define LCD_line4 0xD0 // Line 4 position 1 (16 char LCD)
#endif
/************************************************************************/
// const Font_3x6_0[8] = { 0,0,0,0,0x38,0x44,0x38,0}; /* 0 0x30 */
/****************************************/
/* DelayUs Microsegundos */
/****************************************/
void DelayUs(int v) // 40 MIPS
{
while(v != 0){
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
asm("nop" );asm("nop" );
/**/
v--;}
}
/****************************************/
/* DelayMs MiliSegundos */
/****************************************/
void DelayMs(int v)
{
while (v != 0 ){ DelayUs(1000); v--;}
}
/****************************************/
/* Enable LCD to read data */
/****************************************/
void LCD_STROBE (void)
{
LCD_EN = 1;
DelayUs(1);
LCD_EN = 0;
}
/****************************************/
/* Write a nibble to the LCD */
/****************************************/
void LCD_NIBBLE_OUT (unsigned char c ) {
LCD_D4=c ; c >>= 1;
LCD_D5=c; c >>= 1;
LCD_D6=c; c >>= 1;
LCD_D7=c;
LCD_STROBE();
}
/****************************************/
/* Write a byte to the LCD (4 bit mode) */
/****************************************/
void LCD_WRITE (unsigned char c)
{
LCD_NIBBLE_OUT(c >> 4);
LCD_NIBBLE_OUT(c);
DelayUs(50);
}
/****************************************/
/* send a command to the LCD */
/****************************************/
void LCD_CMD (char c) {
LCD_RS = 0; // write command
LCD_WRITE(c);
}
/****************************************/
/* GoTO specified line and position */
/****************************************/
void LCD_GOTO (char line,char pos) // Set DDRAM address
{
switch(line)
{
case 1: LCD_CMD((LCD_line1-1)+pos);
break;
case 2: LCD_CMD((LCD_line2-1)+pos);
break;
case 3: LCD_CMD((LCD_line3-1)+pos);
break;
case 4: LCD_CMD((LCD_line4-1)+pos);
}
}
/****************************************/
/* Clear and Home LCD */
/****************************************/
void LCD_CLEAR (void)
{
LCD_CMD(LCD_CLR);
DelayMs(3);
}
/****************************************/
/* Write one character to the LCD */
/****************************************/
void LCD_PUTCH (unsigned char c)
{
LCD_RS = 1; // write characters
LCD_WRITE(c);
}
/****************************************/
/* Write a string to the LCD */
/****************************************/
void LCD_PUTS ( char * s)
{
LCD_RS = 1; // write characters
while(*s)
LCD_WRITE(*s++);
}
/****************************************/
/* Write a const to the LCD */
/****************************************/
void LCD_PUTC ( const * s)
{
LCD_RS = 1; // write characters
while(*s)
LCD_WRITE(*s++);
}
/****************************************/
/* Set CGRAM address */
/****************************************/
void Set_CGRAM_address(unsigned char addr){
addr = addr & 0x3F;
LCD_CMD(0x40 | addr );
}
/************************************************/
/* Write a const to the LCD */
/* escribe un caracter predefinido en cgram */
/************************************************/
void LCD_SetCaracter (unsigned char posicion , const * s)
{ unsigned char a; a=8;
Set_CGRAM_address(posicion);
LCD_RS = 1; // write characters
while(a != 0){
LCD_WRITE(*s++); a--;}
}
/****************************************/
/* Escribe Valor numerico al LCD */
/* Max 1 a 9 digitos */
/* ceros a la izquierda blancos */
/* puno de miles y millones */
/****************************************/
/* ejemplo : 341.000.780 1.886 23 */
void LCD_PUTUN (unsigned char Digitos , unsigned long valor)
{
unsigned char t1,i,wrote;
unsigned long k;
wrote=0;
for (i=Digitos-1; i>=1; i--)
{
switch(i){
case 8: k=100000000;
break;
case 7: k=10000000;
break;
case 6: k=1000000;
break;
case 5: k=100000; if (Digitos > 6){ if (wrote==1){ LCD_PUTCH(".");} else { LCD_PUTCH(" ");}} // millones
break;
case 4: k=10000;
break;
case 3: k=1000;
break;
case 2: k=100; if (Digitos > 3){ if (wrote==1){ LCD_PUTCH(".");} else { LCD_PUTCH(" ");}} // miles
break;
case 1: k=10;
}
t1=valor/k;
if((wrote)||(t1!=0)){LCD_PUTCH(t1+"0"); wrote=1;}
else LCD_PUTCH(" "); // Ceros izquierda blanco
valor-=(t1*k);
}
LCD_PUTCH( valor +"0");
}
/****************************************/
/* Initialize LCD */
/****************************************/
void LCD_INIT (void)
{
/* Configura los TRIS como salidas */
LCD_RS_TRIS = 0; // Register select
LCD_EN_TRIS = 0; // Enable
LCD_D4_TRIS = 0; // LCD data 4
LCD_D5_TRIS = 0; // LCD data 5
LCD_D6_TRIS = 0; // LCD data 6
LCD_D7_TRIS = 0; // LCD data 7
LCD_RS = 0; // write control bytes
DelayMs(20); // power on delay
LCD_NIBBLE_OUT(0x04); // set 4 bit mode
DelayUs(100);
#if (LCD_ROWS==1)
LCD_CMD(0x20); // 4 bit mode, 1 line, 5x8 font (0b00100000);
#else
LCD_CMD(0x28); // 4 bit mode, 2 or more lines, 5x8 font (0b00101000);
#endif
LCD_CMD(DISPLAY_OFF);
LCD_CMD(DISPLAY_ON | CURSOR_OFF | CURSOR_BLINKING_OFF);
LCD_CMD( CURSOR_DIRECCTION_Increment | No_Accompanies_display_shift );
LCD_CLEAR();
}

Hola:
Yo tengo un 30F2010 y 30F4011 cortesia de Nocturno.. :mrgreen:, esos tipos de Dspic te podrian servir para experimentar.
#include <stdio.h> /* for fopen, fclose, */
/* printf,FILE, NULL, EOF */
int main(void)
{
FILE *myfile1;
int y;
// el archivo se llama afile1, w+ es escribir en el archivo, myfile1 es el valor retornado
if ((myfile1 = fopen("afile1", "w+")) == NULL)
printf("Cannot open afile1\n"); // con stdio.h si permite utilizar el printf
else
{
printf("afile1 was opened\n");
y = fclose(myfile1); // cierra el archivo afile1, el valor de retorno es puesto en y
if (y == EOF) // si retorna EOF ha ocurrido un error en el cierre
printf("afile1 was not closed\n"); // \n significa final de la línea
else
printf("afile1 was closed\n");
}
}
#include <p30f4011.h>
#include <uart.h>
#include <math.h> /* for acos */
#include <stdlib.h>
#include "utilities.c"
/* Received data is stored in array Buf */
char Buf[80];
void configUSART2()
{
// Holds the value of baud register. Holds the value of uart config reg
// Holds the information regarding uart TX & RX interrupt modes
unsigned int baudios, U1MODEvalue, U1STAvalue;
/* Configure uart1 receive and transmit interrupt */
ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR2 &
UART_TX_INT_DIS & UART_TX_INT_PR6);
// Configure UART1 module to transmit 8 bit data with one stopbit, 9600 baudios
baudios = 103;
//U1BRG=103; U1MODE=0x8000; U1STAbits.UTXEN=1;
U1MODEvalue = UART_EN & UART_IDLE_STOP & UART_RX_TX & UART_DIS_WAKE &
UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT;
U1STAvalue = UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL & UART_TX_ENABLE &
UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;
OpenUART2(U1MODEvalue, U1STAvalue, baudios);
}
void __attribute__((__interrupt__)) _U2RXInterrupt(void)
{
unsigned int j; //local variable
for (j=0;j<=12;j++)
{
while (DataRdyUART2()==0)
{
nop2();
}
Buf[j]=getcUART2();
}
putsUART2((unsigned int *)Buf);
IFS1bits.U2RXIF = 0;
}
int main(void)
{
char a[]="128";
char b[]="-12.85";
double x,y,z;
Buf[13]='\0';
_TRISF2=1; _TRISF3=0; _TRISD1=0;
char Txdata[] = {'M','i','c','r','o','c','h','i','p',' ','I','C','D','2',
' ','\13','\10','\0'};
configUSART2();
putsUART2((unsigned int *)Txdata);
// rutina matemática
x=2.0; y=3.0;
z=atoi(a); // demora 556 ciclos
z=atof(b); // demora 1782 ciclos
y=pow (x, y); // demora 4992 ciclos
y=2*2*2; // demora 4 ciclos
//
while (1)
{
toggle(_RD1);
delay20(); delay20(); delay20(); delay20(); delay20();
}
}
67: z=atoi(a); // demora 556 ciclos
13DA 200380 mov.w #0x38,0x0000
13DC 40000E add.w 0x0000,0x001c,0x0000
13DE 2000A2 mov.w #0xa,0x0004
13E0 EB0080 clr.w 0x0002
13E2 07F6D7 rcall 0x000192
13E4 DE80CF asr 0x0000,#15,0x0002
13E6 07FB91 rcall 0x000b0a
13E8 982760 mov.w 0x0000,[0x001c+76]
13EA 982771 mov.w 0x0002,[0x001c+78]
68: z=atof(b); // demora 1782 ciclos
13EC 2003C0 mov.w #0x3c,0x0000
13EE 40000E add.w 0x0000,0x001c,0x0000
13F0 B81160 mul.uu 0x0004,#0,0x0004
13F2 EB0080 clr.w 0x0002
13F4 07F761 rcall 0x0002b8
13F6 982760 mov.w 0x0000,[0x001c+76]
13F8 982771 mov.w 0x0002,[0x001c+78]
69: z=pow (x, y); // demora 5000 ciclos
13FA 90214E mov.w [0x001c+72],0x0004
13FC 9021DE mov.w [0x001c+74],0x0006
13FE 90202E mov.w [0x001c+68],0x0000
1400 9020BE mov.w [0x001c+70],0x0002
1402 07FBAE rcall 0x000b60
1404 982760 mov.w 0x0000,[0x001c+76]
1406 982771 mov.w 0x0002,[0x001c+78]
70: y=2*2*2; // demora 6 ciclos
1408 200000 mov.w #0x0,0x0000
140A 241001 mov.w #0x4100,0x0002
140C 982740 mov.w 0x0000,[0x001c+72]
140E 982751 mov.w 0x0002,[0x001c+74]
71: //y=asinf(x);
#include <p30f4011.h>
#include <uart.h>
void configUSART1()
{
unsigned int baudios, U1MODEvalue, U1STAvalue;
ConfigIntUART1(UART_RX_INT_DIS & UART_RX_INT_PR2 &
UART_TX_INT_DIS & UART_TX_INT_PR6);
baudios = 103;
U1MODEvalue = UART_EN & UART_IDLE_STOP & UART_RX_TX & UART_DIS_WAKE &
UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT;
U1STAvalue = UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL & UART_TX_ENABLE &
UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;
OpenUART1(U1MODEvalue, U1STAvalue, baudios);
}
int main(void)
{
float z;
_TRISD1=0;
configUSART1();
z=-12.85;
printf("Valor variable z: %.3f ",z);
while (1)
{
_RD1=1;
}
}
C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-coff-ld.exe
Error: A heap is required, but has not been specified
BUILD FAILED: Thu Feb 01 11:57:43 2007Source Files.- pruebas.c
Header Files.- uart.h
Library Files.- libpic30-coff.a libp30f4011-coff.a libpic30f4011-elf.a
linker Scripts.- p30f40011.gld- Es posible usar el printf con el USART2 a alguién le ha salido..?
#include <p30f4011.h>
#include <uart.h>
extern int __C30_UART;
void configUSART2()
{
unsigned int baudios, U1MODEvalue, U1STAvalue;
ConfigIntUART2(UART_RX_INT_DIS & UART_RX_INT_PR2 &
UART_TX_INT_DIS & UART_TX_INT_PR6);
baudios = 103; //9600 baudios a 16MIPS
U1MODEvalue = UART_EN & UART_IDLE_STOP & UART_RX_TX & UART_DIS_WAKE &
UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT &
UART_1STOPBIT;
U1STAvalue = UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL & UART_TX_ENABLE &
UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;
OpenUART2(U1MODEvalue, U1STAvalue, baudios);
}
int main(void)
{
float x,z;
_TRISD1=0;
configUSART2();
x=3.85;
z=-12.85;
__C30_UART=2; //Para utilizar la USART2.
printf("Valor variable x: %.2f \n",x);
printf("Valor variable z: %.2f \n",z);
while (1)
{
_RD1=1;
}
}
spi_data_wait : This is the time-out count for which the module
has to wait before return.
If the time-out count is ‘N’, the actual time out
would be about (19 * N – 1) instruction cycles.
//mis macros
//consigue direcciones del float
#define Lmbyteptr(var32) ((unsigned char*)(&var32)) //returns address of Lm byte
#define LMbyteptr(var32) ((unsigned char*)(&var32)+1) //returns address of LM byte
#define Hmbyteptr(var32) ((unsigned char*)(&var32)+2) //returns address of Hm byte
#define HMbyteptr(var32) ((unsigned char*)(&var32)+3) //returns address of HM byte
//descompone el float
#define getLmbyte(var32) ((unsigned char)(*Lmbyteptr(var32))) //
#define getLMbyte(var32) ((unsigned char)(*LMbyteptr(var32))) //
#define getHmbyte(var32) ((unsigned char)(*Hmbyteptr(var32))) //
#define getHMbyte(var32) ((unsigned char)(*HMbyteptr(var32))) //
//arma float
#define setLmbyte(var32,var8) {(unsigned char)(*Lmbyteptr(var32)=var8);} //
#define setLMbyte(var32,var8) {(unsigned char)(*LMbyteptr(var32)=var8);} //
#define setHmbyte(var32,var8) {(unsigned char)(*Hmbyteptr(var32)=var8);} //
#define setHMbyte(var32,var8) {(unsigned char)(*HMbyteptr(var32)=var8);} //
float x=-12.85, y;
char dummy1, dummy2, dummy3, dummy4;
//desarmar float
dummy1=getLmbyte(x);
dummy2=getLMbyte(x);
dummy3=getHmbyte(x);
dummy4=getHMbyte(x);
//armar float
setLmbyte(y,dummy1);
setLMbyte(y,dummy2);
setHmbyte(y,dummy3);
setHMbyte(y,dummy4);
#define setLmbyte(var32,var8) {(unsigned char)(*Lmbyteptr(var32)=var8);} //
void GetCom(unsigned int k, float *z)
{
float f;
char *p=(char *)&f; // puntero "p" apunta a la dirección de "f", "p" tiene 4 bytes
unsigned int m;
for(m=0;m<k;m++)
{
while (DataRdySPI1()==0); // el registro SPIRB (SPIBUF) está vacio
*p=getcSPI1(); // Valor que será guardado en la dirección localizada o apuntada por "p"
p++; // Incrementa la dirección localizada en "p" en uno.
}
*z=f; // "f" será guardado en la dirección localizada o apuntada por "z", o sea en "y"
}
int main (void)
{
configSPI();
float y;
...
GetCom(sizeof(y),&y); //sizeof(y)=4 "bytes" porque es flotante
... //&y dirección del dato y
}
SendCom(sizeof(data),(char *)&data);
void SendCom(unsigned int k, char *p)
{
for(;k;--k)
{
while(BusyUART1()==1);
//while(SPI1STATbits.SPITBF==1);
putcUART1(*p);
//putcSPI1(*p);
p++;
}
}
GetCom(sizeof(data),(char *)&data);
void GetCom(unsigned int k, char *p)
{
for(;k;--k)
{
while(DataRdyUART1()==0);
//while(DataRdySPI1==0);
*p=getcUART1();
//*p=getcSPI1();
p++;
}
}
#include "p30f4011.h"
/*
RB0 verde
RB1 ámbar
RB2 amarillo
*/
void __attribute__((__interrupt__)) _T1Interrupt(void)
{
IFS0bits.T1IF=0; //borra flag de interrupción
if(PORTBbits.RB0==1) //rojo
PORTB=2; //prende ámbar
if(PORTBbits.RB1==1) //ámbar
PORTB=4; //prende verde
if(PORTBbits.RB2==1) //verde
PORTB=1; //prende rojo
}
int main()
{
VisualInitialization(); //usa lo configurado en el VI
PORTB=1; //valor inicial
while(1)
asm("clrwdt"); //borra watchdog
return 0;
}
Clean: Deleting intermediary and output files.
Clean: Deleted file "D:\santiago\PICs\programas\dspic semaforo\init_dsPIC30F4011.o".
Clean: Deleted file "D:\santiago\PICs\programas\dspic semaforo\semaforo.o".
Clean: Deleted file "D:\santiago\PICs\programas\dspic semaforo\dspic adc.cof".
Clean: Deleted file "D:\santiago\PICs\programas\dspic semaforo\dspic adc.hex".
Clean: Done.
Executing: "C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=30F4011 -c "Generated Files\VDIInit\init_dsPIC30F4011.s" -o"init_dsPIC30F4011.o" -Wa,-g
Executing: "C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=30F4011 -x c -c "semaforo.c" -o"semaforo.o" -g -Wall
semaforo.c: In function '_T1Interrupt':
semaforo.c:10: warning: PSV model not specified for '_T1Interrupt';
assuming 'auto_psv' this may affect latency
semaforo.c: In function 'main':
semaforo.c:23: warning: implicit declaration of function 'VisualInitialization'
Executing: "C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=30F4011 "init_dsPIC30F4011.o" "semaforo.o" -o"dspic adc.cof" -Wl,-L"C:\Archivos de programa\Microchip\MPLAB C30\lib",-Tp30F4011.gld,-Map="dspic adc.map",--report-mem
Program Memory Usage
section address length (PC units) length (bytes) (dec)
------- ------- ----------------- --------------------
.reset 0 0x4 0x6 (6)
.ivt 0x4 0x7c 0xba (186)
.aivt 0x84 0x7c 0xba (186)
.text 0x100 0x13a 0x1d7 (471)
.dinit 0x23a 0x2 0x3 (3)
.isr 0x23c 0x2 0x3 (3)
__FOSC 0xf80000 0x2 0x3 (3)
__FWDT 0xf80002 0x2 0x3 (3)
__FBORPOR 0xf80004 0x2 0x3 (3)
Total program memory used (bytes): 0x360 (864) 1%
Data Memory Usage
section address alignment gaps total length (dec)
------- ------- -------------- -------------------
Total data memory used (bytes): 0 (0)
Dynamic Memory Usage
region address maximum length (dec)
------ ------- ---------------------
heap 0 0 (0)
stack 0x800 0x800 (2048)
Maximum dynamic memory (bytes): 0x800 (2048)
Executing: "C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-bin2hex.exe" "D:\santiago\PICs\programas\dspic semaforo\dspic adc.cof"
Loaded D:\santiago\PICs\programas\dspic semaforo\dspic adc.cof.
BUILD SUCCEEDED: Fri Jul 18 13:12:03 2008
Acerca de getsSPI, spi_data_wait
Yo creo que se trata de un tiempo limite, es decir, si no se han recibido las n cadenas en el tiempo especificado, entonces, la funcion retorna (para no quedarse estancada)
; Feature=fuses - fuses (DCR) configuration
config __FOSC, 0xC707
; Feature=Oscillator - Oscillator configuration
MOV.B #0x03, W0
MOV.B #0x78, W1
MOV.B #0x9A, W2
MOV.W #OSCCON, W3
MOV.B W1, [W3+1]
MOV.B W2, [W3+1]
MOV.B W0, [W3+1]
CLR.B W0
MOV.B #0x46, W1
MOV.B #0x57, W2
MOV.B W1, [W3+0]
MOV.B W2, [W3+0]
MOV.B W0, [W3+0]
# include "p30f3013.h"
#include "libpic30.h"
_FOSC(CSW_FSCM_OFF & XT_PLL16); // CONFIGURACIÓN DEL OSCILADOR A 7.37MHz con PLL 16
_FWDT(WDT_OFF);
_FGS(CODE_PROT_OFF & GWRP_OFF); // NO PROTECCIÓN DEL CODIGO
#define FCY 29000000UL // Si no me equivoco se debe definir los MIPS a los que trabaja el PIC
void main(){
TRISB=0x0000; // Configuramos RB9-RB0 como salidas.
while(1){
LATBbits.LATB9=0x0;
__delay_ms(500);
LATBbits.LATB9=0x0;
__delay_ms(500);
}
}void __attribute__((__interrupt__, __shadow__)) _U1RXInterrupt(void){
/*****************************************************************
NIUTON
Fecha: 4-3-2010
Descripción: Parpadeo de led en PIN RB9
Oscilador: cristal XT a 7.37MHZ con PLL16
/*****************************************************************/
#include "p30f3013.h"
#include "stdlib.h"
#include "libpic30.h" // LIBRERIA PARA DELAYS
// FUSES DE CONFIGURACIÓN
_FOSC(CSW_FSCM_OFF & XT_PLL16); // CONFIGURACIÓN DEL OSCILADOR A 7.37MHz con PLL 16
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF & PWRT_OFF);
_FGS(CODE_PROT_OFF & GWRP_OFF); // NO PROTECCIÓN DE CODIGO
// DEFINICIONES DE CONSTANTES
#define FCY 29480000UL // VALOR DE LOS MIPS PARA LA FUNICON DELAY Y BAUDIOS
/* MAIN ********************************************************************************************* ** */
int main(void){
int i=0;
TRISB=0x0000; // Configuramos RB9-RB0 como salidas.
while(i==0){
LATBbits.LATB9=0x1;
__delay_ms(500);
LATBbits.LATB9=0x0;
__delay_ms(500);
}
}/*****************************************************************
NIUTON
Fecha: 4-3-2010
Descripción: Comunicación de recepción mediante RS232 a 19200baudios
Oscilador: cristal XT a 7.37MHZ con PLL16
/*****************************************************************/
#include "p30f3013.h"
#include "stdlib.h"
#include "libpic30.h" // LIBRERIA PARA DELAYS
#include "uart.h" // LIBRERIAS PARA RS232
// FUSES DE CONFIGURACIÓN
_FOSC(CSW_FSCM_OFF & XT_PLL16); // CONFIGURACIÓN DEL OSCILADOR A 7.37MHz con PLL 16
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF & PWRT_OFF);
_FGS(CODE_PROT_OFF & GWRP_OFF); // NO PROTECCIÓN DE CODIGO
// VARIABLES
unsigned char bufferRX[4]; //buffer donde voy almacenar los elementos de la pila
unsigned char *Ptro_bufferRX=NULL; //inicializacion del buffer
unsigned char index_byte=0; //contador que me indica las veces que se ha leido un dato
// DEFINICIONES DE CONSTANTES
#define FCY 29480000UL // VALOR DE OS MIPS PARA LA FUNICON DELAY Y BAUDIOS
#define BAUDRATE 19200 // VALOR DE BAUDE RATE DE COMUNICACIÓN
#define BRGVAL ((FCY/BAUDRATE)/16)-1
#define ALTIOVAL 1 //=1 INDICA U1ATX/RX, =0 INDICA U1TX/RX,
/* INTERRUPCIONES *********************************************************************************** ** */
void __attribute__((__interrupt__, no_auto_psv)) _U1RXInterrupt(void){
IFS0bits.U1RXIF = 0; //borramos flag de interrupcion
if((U1STAbits.PERR==0) && (U1STAbits.FERR==0)) //compruebo errores
{
while(U1STAbits.URXDA==1) //lee mientras haya datos en la pila este bit indica que hay datos y pueden ser leidos
{
*(Ptro_bufferRX) = U1RXREG;
Ptro_bufferRX++;
index_byte++; //se incrementa
}
}
if(U1STAbits.OERR) U1STAbits.OERR=0; //si hay error de overflow es borrado
}
/* FUNCIONES **************************************************************************************** ** */
// Inicialización del modulo RS232
void inicializar_RS232(void){
unsigned int U1MODEvalue;
unsigned int U1STAvalue;
CloseUART1(); //Turn off UART1module
//Configuramos interrupciones de UART1, recepcion
ConfigIntUART1(UART_TX_INT_DIS & UART_RX_INT_EN & UART_RX_INT_PR7);
//configuramos los registros UMODE y USTA
U1MODEbits.ALTIO= ALTIOVAL; //Se define los pines alternativos o normales
U1MODEvalue= UART_EN & UART_IDLE_CON & UART_DIS_WAKE & UART_DIS_LOOPBACK &
UART_DIS_ABAUD & UART_ODD_PAR_8BIT & UART_1STOPBIT;
U1STAvalue= UART_INT_TX & UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL & UART_TX_DISABLE &
UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;
OpenUART1(U1MODEvalue, U1STAvalue, BRGVAL); //activamnos el uart con la configuracion seleccionada
Ptro_bufferRX= &bufferRX[0]; //el puntero apunta al primer elemento del buffer
}
/* MAIN ********************************************************************************************* ** */
int main(void){
int i=0;
Ptro_bufferRX= &bufferRX[0]; //apuntar al primer elemento del buffer
TRISB=0x0000; // Configuramos RB9-RB0 como salidas.
TRISC=0x0000; // Configuramos RB9-RB0 como salidas.
PORTCbits.RC13= 0;
PORTCbits.RC14= 1;
inicializar_RS232();
while(i==0){
if(index_byte==4) //se acede cuando se han leido cuatro bytes
{
Ptro_bufferRX= &bufferRX[0]; //vuelvo apuntar al primer elemento del buffer
index_byte=0; //inicializo contador
}
LATBbits.LATB9=0x1;
__delay_ms(20);
LATBbits.LATB9=0x0;
__delay_ms(20);
}
}/*****************************************************************
NIUTON
Fecha: 7-3-2010
Descripción: Comunicación mediante I2C a 400KHz
Oscilador: cristal XT a 7.37MHZ con PLL16
/*****************************************************************/
#include "p30f3013.h"
#include "stdlib.h"
#include "stdio.h"
#include "libpic30.h" // LIBRERIA PARA DELAYS
#include "uart.h" // LIBRERIAS PARA RS232
#include "i2c.h" // LIBRERIAS PARA I2C
// FUSES DE CONFIGURACIÓN
_FOSC(CSW_FSCM_OFF & XT_PLL16); // CONFIGURACIÓN DEL OSCILADOR A 7.37MHz con PLL 16
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF & PWRT_OFF);
_FGS(CODE_PROT_OFF & GWRP_OFF); // NO PROTECCIÓN DE CODIGO
unsigned char ack = 0, no_ack=1;
unsigned char datos_int_reg = 0;
// DEFINICIONES DE CONSTANTES
#define FCY 29480000UL // VALOR DE OS MIPS PARA LA FUNICON DELAY Y BAUDIOS
#define FSCL_I2C 400000 // VALOR DE BAUDE RATE DE COMUNICACIÓN I2C
#define I2CBRGVAL ((FCY/FSCL_I2C)-(FCY/1111111))-1
void inicializar_I2C(void){
unsigned int config2, config1;
CloseI2C(); // Cierra el modulo I2C
ConfigIntI2C(MI2C_INT_OFF & SI2C_INT_OFF); //COnfiguracion de interrupciones
config2 = I2CBRGVAL; //Configuración de la velocidad en el bus I2C 400KHz
// Configure I2C for 7 bit address mode
config1 = (I2C_ON & I2C_IDLE_CON & I2C_CLK_HLD
& I2C_IPMI_DIS & I2C_7BIT_ADD
& I2C_SLW_EN & I2C_SM_DIS
& I2C_GCALL_DIS & I2C_STR_DIS
& I2C_NACK & I2C_ACK_DIS & I2C_RCV_DIS
& I2C_STOP_DIS & I2C_RESTART_DIS
& I2C_START_DIS);
OpenI2C(config1, config2);
IdleI2C(); //Antes de hacer una escritura en el I2C debe estar en modo IDLE
}
int main(void){
int i=0;
char address_W;
// VARIABLES
address_W = 0x64; // Dirección para escritura
TRISB=0x0011; // Configuramos RB9-RB0 como salidas.
TRISC=0x0000; // Configuramos RB9-RB0 como salidas.
inicializar_I2C();
LATBbits.LATB9 = 0x1; // ACTIVAR LED
while(i==0){
__delay_ms(500);
IdleI2C(); // Realiza una espera hasta que el I2C esté listo para usarse
StartI2C();
while(I2CCONbits.SEN); //ESPERO QUE SE COMPLETE START
MasterWriteI2C(address_W);
while(I2CSTATbits.ACKSTAT == no_ack);
MasterWriteI2C(0x01); // valor = 0x01 para empezar a medir
while(I2CSTATbits.ACKSTAT == no_ack);
StopI2C();
while(I2CCONbits.PEN); //Espero a que termine la secuencia de stop
IdleI2C(); // Realiza una espera hasta que el I2C esté listo para usarse
StartI2C();
datos_int_reg = MasterReadI2C(); IdleI2C(); NotAckI2C();
StopI2C();
while(I2CCONbits.PEN); //Espero a que termine la secuencia de stop
printf("\r\n Registro interno: %d\n", datos_int_reg);
}
return(0);
}
Dejo algunos ejemplos simples para el PIC24FJ128GA010 ;-)
Titilar leds, modificación y utilización de delays en libpic30.hCódigo: C
#include <p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx2 & FWDTEN_OFF & WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768); _CONFIG2( FNOSC_PRI & FCKSM_CSDCMD & POSCMOD_HS ); #define FCY 10000000UL #include <libpic30.h> /* ** Modificando en libpic30.h ** */ /* #if !defined(FCY) extern void __delay_ms(unsigned long); extern void __delay_us(unsigned long); #else #define __delay_ms(d) __delay32( (unsigned long long) (d)*(FCY)/1000) #define __delay_us(d) __delay32( (unsigned long long) (d)*(FCY)/1000000) #define __delay_s(d) __delay32( (unsigned long) (d)*(FCY)) #endif */ int main (int argc, char * argv[]){ TRISF=0xFFF3; LATFbits.LATF2=0; LATFbits.LATF3=0; while(1){ LATFbits.LATF2=0; __delay_ms(500); LATFbits.LATF2=1; __delay_ms(500); } }
Configuración de timer 2y3 para formar timer de 32-bits, más interrupción:Código: C
#include <p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx2 & FWDTEN_OFF & WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768); _CONFIG2( FNOSC_PRI & FCKSM_CSDCMD & POSCMOD_HS ); /*#define FCY 20000000UL #include <libpic30.h>*/ #include <timer.h> /* ***************************************************************** */ void __attribute__((__interrupt__, __shadow__)) _T3Interrupt(void){ LATDbits.LATD8=~LATDbits.LATD8; // Cambiamos de estado pin F2.- _T3IF = 0; //Borramos flag. } int main (int argc, char * argv[]){ TRISD=0xF0FF; OpenTimer23(T23_ON & T2_IDLE_STOP & T2_GATE_OFF & T2_PS_1_1 & T2_SOURCE_INT,0x004C4B40); ConfigIntTimer23(T3_INT_PRIOR_1 & T3_INT_ON); WriteTimer23(0x00); while(1){ } }
Configuración UART más interrupción:Código: C
#include <p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx2 & FWDTEN_OFF & WINDIS_OFF & FWPSA_PR128 & WDTPS_PS32768); _CONFIG2( FNOSC_PRI & FCKSM_CSDCMD & POSCMOD_HS ); #include <uart.h> char DataUART; char KbhitUART; /* ** *********************************************************************************** ** */ // Definciones para calculo de Baud Rate.- #define FCY 10000000 // MHz #define BAUDRATE 9600 #define BRGHigh 1 #if BRGHigh #define BRGVAL ((FCY/BAUDRATE)/4)-1 #else #define BRGVAL ((FCY/BAUDRATE)/16)-1 #endif //__attribute__ ((__section__ (".text"), __space__(prog))) const char Texto[]= "Probando comunicación serial...\r\nPIC24FJ128GA010 xD ...\r\n"; /* ** *********************************************************************************** ** */ void __attribute__((__interrupt__, __shadow__)) _U2RXInterrupt(void){ DataUART=getcUART2(); KbhitUART=1; _U2RXIF=0; // Borramos flag. } /* ** *********************************************************************************** ** */ int main (int argc, char * argv[]){ /* ** Utilizando las funciones definidas en C30 ** */ OpenUART2(UART_EN & UART_IDLE_STOP & UART_IrDA_DISABLE & UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE & UART_DIS_LOOPBACK & UART_UXRX_IDLE_ONE & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_BRGH_FOUR & UART_1STOPBIT, 0xFFFF & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR, BRGVAL); ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR1 & UART_TX_INT_DIS & UART_TX_INT_PR0 ); /*U2MODEbits.USIDL=1; // Al pasar al modo Sleep, apagar modulo. U2MODEbits.IREN=0; // Codificacion/decodificacion IrDA deshabilitado. U2MODEbits.RTSMD=1; // RTS en modo simple. U2MODEbits.UEN=0b00; // Tx/Rx habilitado, CTS/RTS deshabilitados. U2MODEbits.WAKE=0; // Wake-up deshabilitado. U2MODEbits.LPBACK=0; // Modo LoopBack deshabilitado. U2MODEbits.ABAUD=0; // Auto-Baud rate deshabilitado. U2MODEbits.RXINV=0; // Modo normal de pin RX, en reposo = 1. U2MODEbits.BRGH=BRGHigh; // Mode seleccionado en define.- U2MODEbits.PDSEL=0b00; // 8 bits- sin paridad. U2MODEbits.STSEL=0; // 1 bit de Stop. U2STAbits.UTXISEL1=1; // Interrupcion por transimision no usada. U2STAbits.UTXISEL0=1; // Interrupcion por transimision no usada. U2STAbits.UTXINV=0; // Pin Tx en reposo igual a 1. U2STAbits.UTXBRK=0; // Break deshabilitado. U2STAbits.URXISEL=0b00; // Interrumpir cuando se recibe un caracter. U2STAbits.ADDEN=0; // Auto-Address deshabilitado. U2STAbits.OERR=0; // Borramos bits de error por overflow. U2BRG =BRGVAL; // Baud Rate determinado en defines. IPC7bits.U2RXIP=0b01; // Fijamos nivel de prioridad. IFS1bits.U2RXIF=0; // Borramos flag. IEC1bits.U2RXIE=1; // habilitamos interrupcion por recepción. U2MODEbits.UARTEN=1;// Encendemos modulo. U2STAbits.UTXEN=1; // Transmision habilitada.*/ KbhitUART=0; putsUART2(Texto); while(1){ if(KbhitUART==1){ KbhitUART=0; putcUART2(DataUART); } } }
Para probarlos arme una PICCard para la MultiBoardPicTrainer de Felixls :-)(http://img594.imageshack.us/img594/3576/imagen020.jpg)
Si alguien necesita el PCB me avisa ;-)
Saludos!
Excelente aportación Suky, muchas gracias.
Deberías proteger esa PCB tan chula contra el óxido.
Sobre esa PCB y con adaptadores no podremos trabajar con los PIC32?? :shock: :shock:
justo la librería de retardos que andaba buscando, la podes dejar por acá por favor, querido amigo suky?
ese micro es de 100pines :shock: que bien manejas la plancha, a ver si algún día pillo la maña para sacar esos tqfp.
esa misma librería de retardos servirá para C18, porque contar ciclos a veces enreda :D
saludos
File Name: TimeDelay.c
Dependencies: None
Processor: PIC18/PIC24/dsPIC30/dsPIC33/PIC32
Compiler: C30 v3.12
Company: Microchip Technology, Inc.#if defined(__PIC32MX__)
#include <plib.h>
#endif
#include "HardwareProfile.h"
#include "TimeDelay.h" Supuestamente la librería TimeDelay.c funciona para cualquier PIC según su contenido...
C:\Microchip Solutions\Microchip\CommonCódigo: [Seleccionar]File Name: TimeDelay.c
Dependencies: None
Processor: PIC18/PIC24/dsPIC30/dsPIC33/PIC32
Compiler: C30 v3.12
Company: Microchip Technology, Inc.
Tiene un par de includes...Código: [Seleccionar]#if defined(__PIC32MX__)
#include <plib.h>
#endif
#include "HardwareProfile.h"
#include "TimeDelay.h"
... los cuáles se encuentran dentro de la Microchip Applications Library.
void config_UART(void) {
U1MODE=0x2420;
U1STA=0x8000;
BAUD=9600;
U1BRG=(1875000/BAUD)-1;
}
void SendUART(unsigned int k, char *p) {
for(;k;--k) {
while(BusyUART1());
putcUART1(*p);
p++;
}
Buenas,
estoy utilizando las funciones que elaboró en su día Renatox para el envio de datos por la UART getcom y sendcom. La cuestión es que las simulo (utilizo MPLAB) y mirando los tiempos con el Stopwatch me tarda 3ms en enviar un simple float. Teoricamente tengo la UART configurada a 9600 (micro a 30MIPS) y utilizo los pines alternativos para la UART1. Cuelgo codigo de inicializacion de la UART y de la función (que en principio, lo único que he hecho es cambiar el nombre).Código: [Seleccionar]void config_UART(void) {
U1MODE=0x2420;
U1STA=0x8000;
BAUD=9600;
U1BRG=(1875000/BAUD)-1;
}
void SendUART(unsigned int k, char *p) {
for(;k;--k) {
while(BusyUART1());
putcUART1(*p);
p++;
}
Hay algo mal o es que no simula bien los envios por este canal??
gracias, saludos
Aqui les dejo un enlace mui interesante_la verdad si es mui bueno_nos enseña a programar los dspic con mplap tanto en asm como en c.
Consta de un libro i un cd aparte dond hai una serie d aplicaciones q c an explicando en la segunda parte del libro.
M gustaria saber tambien si alguien sabe como reproducir archivos wav desde una memoria sd con un dspic_si alguien sabe mandeme informacion les estare muy agradecidos.
//#include <p33FJ128GP804.h>
#define __dsPIC33FJ32MC202__
#include <p33fj32mc202.h>
#include <libpic30.h>
#include <uart.h>
#include <stdio.h>
//#include "utilities.c"
#include "mylibs.h"
char string[] = "Wiii un string xD";
int main (){
OSCCONbits.NOSC = 0b011;
//FOSCbits.POSCMD =0b01;
CLKDIVbits.PLLPRE = 0b00000; //Clock/2
CLKDIVbits.PLLPOST = 0b10; //Clock/2
PLLFBDbits.PLLDIV = 32; //Clock*32
RPINR18bits.U1RXR = 9; //Asignamos pin recepción UART1 a RP9.-
RPOR4bits.RP8R = 0b00011; // Asignamos RP8 al pin de transmisión UART1.
//Configuración del USART 1 (Usado para debug y bootloader)
OpenUART1(UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_SIMPLEX & UART_UEN_00 & UART_EN_WAKE &
UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & SPEED_MODE & UART_1STOPBIT,
UART_TX_ENABLE & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR, BAUDIOS);
printf("Hello Torno!! Con C30 y dsPIC!! Adentro AVR!! -> %s",string);
while(1){}
}PLLFBDbits.PLLDIV = 30; // M=32
CLKDIVbits.PLLPOST = 0; // N1=2
CLKDIVbits.PLLPRE = 0; // N2=2
OSCTUN = 0; // Tune FRC oscillator, if FRC is used
RCONbits.SWDTEN=0; // Disable Watch Dog Timer
while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock
TRISA = 0xFF; TRISB = 0xFFFF;
T2CONbits.TON = 0; //Apago Timer2
T3CONbits.TON = 0; //Apago Timer3
T2CONbits.T32 = 1; //T2 y T3 forman un timer de 32 bits
T2CONbits.TSIDL = 0; //Se apaga en moo IDLE
T2CONbits.TGATE = 0; //Tgate apagado (sirve para medir período)
T2CONbits.TCKPS = 0b00; //Preescaler 1:1
T2CONbits.TCS = 1; //Clock externo
while(1){
WriteTimer23(0); //Reinicio timer
T2CONbits.TON = 1; //Enciendo el timer
__delay32(40000000); //Delay de 1 segundo exacto a 40MIPS
T2CONbits.TON = 0; //Apago el timer
FRECC = ReadTimer23(); //Leo el valor del timer (que al estar muestreando durante un segundos son los Hz)
PERIODO = 1.0 / (float)FRECC; //Tomo el período de la frecuenciaFor input mapping only, the Peripheral Pin Select (PPS) functionality does not have priority over the TRISx settings. Therefore, when configuring the RPn pin for input, the corresponding bit in the TRISx register must also be configured for input (i.e., set to ‘1’).....y además el printf de CCS lo mandas a donde quieras no sólo el usart es la única crítica que le hago por lo demás es excelente...