Autor Tema: codigo para mandar datos del pic24f al hyperterminal y al reves  (Leído 9336 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
codigo para mandar datos del pic24f al hyperterminal y al reves
« en: 17 de Agosto de 2009, 08:13:25 »
hola buenas:

necesito que me ayudeis a hacer un programa, del que no encuentro ningun ejemplo parecido con mi micro.

Estoy trabajando con el Explorer 16 y el micro pic24fj128ga010, lo que tengo que hacer es un programa en lenguaje C, que envíe datos desde el micro y me los muestre por pantalla en el hyperterminal, previamente ya lo tengo conectado con el db9 del puerto rs232 (uart).

un ejemplo sería que yo codifique mi placa para que ponga hola y en la pantalla del hyperterminal me aparezca hola.


Tambien me vendría muy bien saber como hacer para escribir algo en el hyperterminal y que me aparezca en la pantalla lcd del Explorer 16.

Alguien me puede echar una mano por favor?

muchas gracias

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #1 en: 17 de Agosto de 2009, 08:15:06 »
si quereis tambien me podeis contestar al email: anabelen208@hotmail.com

Desconectado MLO__

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 4581
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #2 en: 17 de Agosto de 2009, 11:53:48 »
Desde mi absoluta ignorancia: Que es el Explorer 16?
El papel lo aguanta todo

Desconectado jhozate

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1698
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #3 en: 17 de Agosto de 2009, 12:14:38 »
es una placa de desarollo...y  de lujo
Ser Colombiano es un Premio, Saludos desde CALI-COLOMBIA

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #4 en: 17 de Agosto de 2009, 12:14:45 »
Desde mi absoluta ignorancia: Que es el Explorer 16?
Edit: Ya te lo indicaron :mrgreen:

anabelenir  revisa la siguiente página, hay varios ejemplos y alguno puede serte útil.


Saludos!
« Última modificación: 17 de Agosto de 2009, 12:16:57 por Suky »
No contesto mensajes privados, las consultas en el foro

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #5 en: 18 de Agosto de 2009, 05:02:09 »
esa pagina la tengo ya aburrida,jejeje. muchas gracias de todas formas, lo que pasa es que con el pic24f no hay ningun ejemplo que use el puerto uart, aunque en algun ejemplo ponga que si, de todas formas intento dar a compilar y me da fallo, y eso que es el ejemplo sacado directamente de ahi, no se que pasa.
podeis probar alguno a ver si a vosotros tambien os dice que no compila o solo es a mi? porque implicaria que tengo algo mal conectado o algo asi.

los ejemplos que he sacado yo de ahi que me valieran para mi pic estan en esa misma pagina poniendo en la tercera columna pic24f y bajando un poquito hay tres ejemplos que pone wire UART, son el CE315, CE316 Y CE317

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #6 en: 18 de Agosto de 2009, 05:15:14 »
Aquí está mi Explorer 16 y QVGA: Primeros Pasos (la parte en que hago la comunicación serie con el PC y un 33FJ256GP710)

Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #7 en: 18 de Agosto de 2009, 06:00:19 »
Muchas gracias RedPic, voy a echarle un vistazo,
de todas formas, si tengo alguna duda, os aviso

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #8 en: 18 de Agosto de 2009, 07:43:41 »
a ver, este es el codigo que llevo hasta ahora, se parece mucho al tuyo, puesto que kiero que haga exactamente lo mismo, lo malo que no manejo mucho el pic24f .
Cuando compilo me da fallos, como no, pero es que no se donde declarar las variables que me dice ni como porque tu en tu programa no las tienes declaradas y no te dice nada

Esto es lo que me sale al compilar:


Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Archivos de programa\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=24FJ128GA010 -x c -c   "prueba.c" -o"prueba.o" -D__DEBUG -g -Wall
prueba.c: In function 'InitClock':
prueba.c:33: error: 'PLLFBD' undeclared (first use in this function)
prueba.c:33: error: (Each undeclared identifier is reported only once
prueba.c:33: error: for each function it appears in.)
prueba.c:34: error: 'CLKDIVBITS' has no member named 'PLLPOST'
prueba.c:35: error: 'CLKDIVBITS' has no member named 'PLLPRE'
prueba.c: In function 'InitPorts':
prueba.c:99: error: 'AD1PCFGHbits' undeclared (first use in this function)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\proyectos mios AB\uart\nuevo\prueba.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Tue Aug 18 12:36:56 2009
----------------------------------------------------------------------
BUILD FAILED




y esto es el codigo que he hecho hasta ahora:



#include "p24fxxxx.h"
#include "delay.h"


// JTAG/Code Protect/Write Protect/Clip-on Emulation mode
// Watchdog Timer/ICD pins select
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
// Disable CLK switch and CLK monitor, OSCO or Fosc/2, HS oscillator,
// Primary oscillator
_CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)


char mytext[]   ="dsPIC24FJ128GA010 en línea¡\r\nHola\r\n>\0";

void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void){   
// Lo que recibo vía UART2 lo pongo en el PORTA ...   
LATA = U2RXREG;   
// ... y lo devuelvo como Echo filtrando el 0x0D para añadir 0x0A
U2TXREG = U2RXREG;
   if(U2RXREG==0x0D){   
      U2TXREG = 0x0A;   
}    
IFS1bits.U2RXIF = 0;
}

void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void){
   IFS1bits.U2TXIF = 0;
}


void InitClock() {   
   PLLFBD             = 38;   // M  = 40   
   CLKDIVbits.PLLPOST   = 0;   // N1 =  2   
   CLKDIVbits.PLLPRE     = 0;   // N2 =  2   
   OSCTUN             = 0;   
   RCONbits.SWDTEN    = 0;
   // Clock switch to incorporate PLL   
   __builtin_write_OSCCONH(0x01);      // Initiate Clock Switch to FRC with PLL (NOSC=0b001)
   __builtin_write_OSCCONL(0x01);   // Start clock switching while (OSCCONbits.COSC != 0b001); Wait for Clock switch to occur   
   while(OSCCONbits.LOCK != 1) {};
}


void InitUART2(void)
{

   // The Explorer 16 board has a DB9 connector wired to UART2, so we will
   // be configuring this port only

   // configure U2MODE
   U2MODEbits.UARTEN = 0;   // Bit15 TX, RX DISABLED, ENABLE at end of func
   U2MODEbits.USIDL = 0;   // Bit13 Continue in Idle
   U2MODEbits.IREN = 0;   // Bit12 No IR translation
   U2MODEbits.RTSMD = 0;   // Bit11 Simplex Mode
   U2MODEbits.UEN = 0;      // Bits8,9 TX,RX enabled, CTS,RTS not
   U2MODEbits.WAKE = 0;   // Bit7 No Wake up (since we don't sleep here)
   U2MODEbits.LPBACK = 0;   // Bit6 No Loop Back
   U2MODEbits.ABAUD = 0;   // Bit5 No Autobaud (would require sending '55')
   U2MODEbits.RXINV = 0;   // Bit4 IdleState = 1
   U2MODEbits.BRGH = 0;   // Bit3 16 clocks per bit period
   U2MODEbits.PDSEL = 0;   // Bits1,2 8bit, No Parity
   U2MODEbits.STSEL = 0;   // Bit0 One Stop Bit
   
   // Load a value into Baud Rate Generator.  Example is for 9600.   
   // See section 19.3.1 of datasheet.   
   //  U2BRG = (Fcy/(16*BaudRate))-1   
   //  U2BRG = (37M/(16*9600))-1   
   //  U2BRG = 240
   U2BRG = 240;   // 40Mhz osc, 9600 baud

   // Load all values in for U1STA SFR
   U2STAbits.UTXISEL1 = 0;   //Bit15 Int when Char is transferred (1/2 config!)
   U2STAbits.UTXINV = 0;   //Bit14 N/A, IRDA config
   U2STAbits.UTXISEL0 = 0;   //Bit13 Other half of Bit15
   U2STAbits.UTXBRK = 0;   //Bit11 Disabled
   U2STAbits.UTXEN = 0;   //Bit10 TX pins controlled by periph
   U2STAbits.UTXBF = 0;   //Bit9 *Read Only Bit*
   U2STAbits.TRMT = 0;      //Bit8 *Read Only bit*
   U2STAbits.URXISEL = 0;   //Bits6,7 Int. on character recieved
   U2STAbits.ADDEN = 0;   //Bit5 Address Detect Disabled
   U2STAbits.RIDLE = 0;   //Bit4 *Read Only Bit*
   U2STAbits.PERR = 0;      //Bit3 *Read Only Bit*
   U2STAbits.FERR = 0;      //Bit2 *Read Only Bit*
   U2STAbits.OERR = 0;      //Bit1 *Read Only Bit*
   U2STAbits.URXDA = 0;   //Bit0 *Read Only Bit*

   IFS1bits.U2TXIF = 0;   // Clear the Transmit Interrupt Flag
   IEC1bits.U2TXIE = 1;   // Enable Transmit Interrupts
   IFS1bits.U2RXIF = 0;   // Clear the Recieve Interrupt Flag
   IEC1bits.U2RXIE = 1;   // Enable Recieve Interrupts

   U2MODEbits.UARTEN = 1;   // And turn the peripheral on

   U2STAbits.UTXEN = 1;
}

 void InitPorts() {   
AD1PCFGHbits.PCFG23 = 1;   // This is important.  RA7 is muxxed with AN23,      
                     // So we need to config the pin as DIGITAL   
TRISA = 0x0080;            // only 0th bit needs be output. A7 is input
}

void putUART2( char c){   
   while ( U2STAbits.UTXBF); // wait while Tx buffer full   
   U2TXREG = c;
}

void putsUART2( char *s){   
   unsigned int i=0;   
   while(s)          // loop until *s == ‘\0’, end of string   
   putUART2(s[i++]);    // send the character and point to the next one
}

int main(void) {      
   InitClock();   // This is the PLL settings   
   InitUART2();   // Initialize UART2 for 9600,8,N,1 TX/RX
   InitPorts();   // LEDs outputs

   Delay(Delay_5mS_Cnt * 100);   
   putsUART2(mytext);    

   while(1) {      // The ever versatile Infinite Loop! Do Nothing
   }
}



Tengo creados el delay.c y delay.h a parte tal como los tienes tu en la pagina que me has dicho.


Alguien puede ayudarme un poco porfa?

muchisimas gracias

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #9 en: 18 de Agosto de 2009, 09:45:28 »
esa pagina la tengo ya aburrida,jejeje. muchas gracias de todas formas, lo que pasa es que con el pic24f no hay ningun ejemplo que use el puerto uart, aunque en algun ejemplo ponga que si, de todas formas intento dar a compilar y me da fallo, y eso que es el ejemplo sacado directamente de ahi, no se que pasa.
podeis probar alguno a ver si a vosotros tambien os dice que no compila o solo es a mi? porque implicaria que tengo algo mal conectado o algo asi.

los ejemplos que he sacado yo de ahi que me valieran para mi pic estan en esa misma pagina poniendo en la tercera columna pic24f y bajando un poquito hay tres ejemplos que pone wire UART, son el CE315, CE316 Y CE317

Si tienes el C30 instalado y seleccionas el dispositivo para el cual fue hecho el código, no da problemas. Yo he probado varios pero para la serie 18F  :mrgreen:
No contesto mensajes privados, las consultas en el foro

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #10 en: 20 de Agosto de 2009, 05:23:39 »
buenas, e probado a cambiar el dispositivo y ese era el fallo, aunq ponga q es el pic 24f, tienen seleccionado un pic32... y por eso no me compilaba.ahora compila y consigo ver las letras q me salen ahi, pero si las cambio no se me cambian, me siguen saliendo en el hyperterminal las mismas

Desconectado anabelenir

  • PIC10
  • *
  • Mensajes: 7
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #11 en: 21 de Agosto de 2009, 04:52:55 »
hola de nuevo, sigo teniendo problemas.
uno de los ejemplos que me dan en la pagina tiene el siguiente codigo:


/**********************************************************************
* ?2008 Microchip Technology Inc.
*
* FileName:        main.c
* Dependencies:    uart2.h
* Processor:       PIC24F
* Compiler:        MPLAB?C30
* Tested On:      PIC24F Explorer 16
*
* SOFTWARE LICENSE AGREEMENT:
* Microchip Technology Incorporated ("Microchip") retains all ownership and
* intellectual property rights in the code accompanying this message and in all
* derivatives hereto.  You may use this code, and any derivatives created by
* any person or entity by or on your behalf, exclusively with Microchip's
* proprietary products.  Your acceptance and/or use of this code constitutes
* agreement to the terms and conditions of this notice.
*
* CODE ACCOMPANYING THIS MESSAGE IS SUPPLIED BY MICROCHIP "AS IS".  NO
* WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
* TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE APPLY TO THIS CODE, ITS INTERACTION WITH MICROCHIP'S
* PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
*
* YOU ACKNOWLEDGE AND AGREE THAT, IN NO EVENT, SHALL MICROCHIP BE LIABLE, WHETHER
* IN CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY),
* STRICT LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, SPECIAL,
* PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF
* ANY KIND WHATSOEVER RELATED TO THE CODE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN
* ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
* ALLOWABLE BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO
* THIS CODE, SHALL NOT EXCEED THE PRICE YOU PAID DIRECTLY TO MICROCHIP SPECIFICALLY TO
* HAVE THIS CODE DEVELOPED.
*
* You agree that you are solely responsible for testing the code and
* determining its suitability.  Microchip has no obligation to modify, test,
* certify, or support the code.
*
* REVISION HISTORY:
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Author            Date         Comments on this revision
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Albert Z.         12/26/08    Original Release
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ADDITIONAL NOTES:
* Small, bare bones program to guide designers with UART implementation
* To run the example, plug DB9 cable to Terminal (9600,8,N,1) -
* Data sent from TERMINAL will be represented as binary equivalent
* of ASCII on 7 LSB LEDs of Explorer 16 development board
*
* Data is sent from Explorer 16 by pressing S3 - S6.  A single letter will
* be transmitted upon each keypress.
*
* Peripheral Library was not utilized, Bit Addressing was used in order
* to show all details involved in initialization of UART.
*
* This code example has been tested on Explorer 16 Development Board
* with PIC24FJ128GA010, PIC24FJ256GA110 and PIC24FJ256GB110 PIMs.
**********************************************************************/
#include "p24fxxxx.h"
#include "uart2.h"

#if defined (__PIC24FJ256GB110__)   //Defined by MPLAB when using 24FJ256GB110 device
    _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
    _CONFIG2( IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI & PLLDIV_DIV2 & IOL1WAY_ON)
    _CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS)      //Disable erase/write protect of all memory regions.
#elif defined (__PIC24FJ256GA110__)   //Defined by MPLAB when using 24FJ256GA110 device
    _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2 )
    _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI & IOL1WAY_ON)
    _CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS)      //Disable erase/write protect of all memory regions.
#elif defined (__PIC24FJ128GA010__)
   // JTAG/Code Protect/Write Protect/Clip-on Emulation mode
   // Watchdog Timer/ICD pins select
   _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
   // Disable CLK switch and CLK monitor, OSCO or Fosc/2, HS oscillator,
   // Primary oscillator
   _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)
#endif

#define TRUE   1
#define FALSE   0

unsigned char S3Flag, S4Flag, S5Flag, S6Flag;

void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void) {
   LATA = U2RXREG;
   IFS1bits.U2RXIF = 0;
}
void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void) {
   IFS1bits.U2TXIF = 0;
}


void InitUART2(void)
{
   // This is an EXAMPLE, so brutal typing goes into explaining all bit sets

   // The Explorer 16 board has a DB9 connector wired to UART2, so we will
   // be configuring this port only

   // configure U2MODE
   U2MODEbits.UARTEN = 0;   // Bit15 TX, RX DISABLED, ENABLE at end of func
   U2MODEbits.USIDL = 0;   // Bit13 Continue in Idle
   U2MODEbits.IREN = 0;   // Bit12 No IR translation
   U2MODEbits.RTSMD = 0;   // Bit11 Simplex Mode
   U2MODEbits.UEN = 0;      // Bits8,9 TX,RX enabled, CTS,RTS not
   U2MODEbits.WAKE = 0;   // Bit7 No Wake up (since we don't sleep here)
   U2MODEbits.LPBACK = 0;   // Bit6 No Loop Back
   U2MODEbits.ABAUD = 0;   // Bit5 No Autobaud (would require sending '55')
   U2MODEbits.RXINV = 0;   // Bit4 IdleState = 1
   U2MODEbits.BRGH = 0;   // Bit3 16 clocks per bit period
   U2MODEbits.PDSEL = 0;   // Bits1,2 8bit, No Parity
   U2MODEbits.STSEL = 0;   // Bit0 One Stop Bit
   
   U2BRG = BAUDRATEREG2;   // baud rate

   // Load all values in for U1STA SFR
   U2STAbits.UTXISEL1 = 0;   //Bit15 Int when Char is transferred (1/2 config!)
   U2STAbits.UTXINV = 0;   //Bit14 N/A, IRDA config
   U2STAbits.UTXISEL0 = 0;   //Bit13 Other half of Bit15
   U2STAbits.UTXBRK = 0;   //Bit11 Disabled
   U2STAbits.UTXEN = 0;   //Bit10 TX pins controlled by periph
   U2STAbits.UTXBF = 0;   //Bit9 *Read Only Bit*
   U2STAbits.TRMT = 0;      //Bit8 *Read Only bit*
   U2STAbits.URXISEL = 0;   //Bits6,7 Int. on character recieved
   U2STAbits.ADDEN = 0;   //Bit5 Address Detect Disabled
   U2STAbits.RIDLE = 0;   //Bit4 *Read Only Bit*
   U2STAbits.PERR = 0;      //Bit3 *Read Only Bit*
   U2STAbits.FERR = 0;      //Bit2 *Read Only Bit*
   U2STAbits.OERR = 0;      //Bit1 *Read Only Bit*
   U2STAbits.URXDA = 0;   //Bit0 *Read Only Bit*

   IFS1bits.U2TXIF = 0;   // Clear the Transmit Interrupt Flag
   IEC1bits.U2TXIE = 1;   // Enable Transmit Interrupts
   IFS1bits.U2RXIF = 0;   // Clear the Recieve Interrupt Flag
   IEC1bits.U2RXIE = 1;   // Enable Recieve Interrupts

   U2MODEbits.UARTEN = 1;   // And turn the peripheral on

   U2STAbits.UTXEN = 1;
}

void InitPorts(void)
{
   // S3 (portD Pin 6, chosen as trigger for sending 'M' to UART)
   // S6 (portD Pin 7, chosen as trigger for sending 'C' to UART)
   // S5 (portA Pin 7, chosen as trigger for sending 'H' to UART)
   // S4 (portD Pin 13, chosen as trigger for sending 'P' to UART)

   TRISD = 0x20C0;   // D6,7,13 inputs
   TRISA = 0x0080;   // only 0th bit needs be output. A7 is input
   S3Flag = S4Flag = S5Flag = S6Flag = 0;   // Some Debounce Flags
}

void SoftwareDebounce(void)
{
   if(PORTDbits.RD6 == FALSE) {
      if( S3Flag == FALSE ) {
         S3Flag = TRUE;
      }
   } else {
      if ( S3Flag == TRUE ) {
         U2TXREG = 'M';
         S3Flag = FALSE;
      }   
   }

   if(PORTDbits.RD7 == FALSE) {
      if( S6Flag == FALSE ) {
         S6Flag = TRUE;
      }
   } else {
      if ( S6Flag == TRUE ) {
         U2TXREG = 'C';
         S6Flag = FALSE;
      }   
   }

   if(PORTAbits.RA7 == FALSE) {
      if( S5Flag == FALSE ) {
         S5Flag = TRUE;
      }
   } else {
      if ( S5Flag == TRUE ) {
         U2TXREG = 'H';
         S5Flag = FALSE;
      }   
   }

   if(PORTDbits.RD13 == FALSE) {
      if( S4Flag == FALSE ) {
         S4Flag = TRUE;
      }
   } else {
      if ( S4Flag == TRUE ) {
         U2TXREG = 'P';
         S4Flag = FALSE;
      }   
   }
}

int main(void)
{
   unsigned char i;
   // Disable Watch Dog Timer
   RCONbits.SWDTEN = 0;
   
   // I/O remap, PPS
#if defined (__PIC24FJ256GB110__) || defined (__PIC24FJ256GA110__)
   // remap pins before intialising SPI2
   // Unlock Registers
   __builtin_write_OSCCONL(OSCCON & 0xbf);
   // Configure Input Functions **********************
   // Assign UART2RX To Pin RP10
   RPINR19bits.U2RXR = 10;
   // Configure Output Functions *********************
   // Assign UART2TX To Pin RP17
   RPOR8bits.RP17R = U2TX_IO;
   // Lock Registers
   __builtin_write_OSCCONL(OSCCON | 0x40);
#endif


   InitUART2();   // Initialize UART2 for 9600,8,N,1 TX/RX

   InitPorts();   // LEDs outputs, Switches Inputs

   while(1) {   // The ever versatile Infinite Loop!
      for (i = 0; i < 100; i++);
      SoftwareDebounce();
   }
}


con su correspondiente cabecera:


/*****************************************************************************
 *
 * UART Driver for PIC24.
 *
 *****************************************************************************
 * FileName:        uart2.h
 * Dependencies:   
 * Processor:       PIC24
 * Compiler:          MPLAB C30
 * Linker:          MPLAB LINK30
 * Company:         Microchip Technology Incorporated
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the "Company") is intended and supplied to you, the Company's
 * customer, for use solely and exclusively with products manufactured
 * by the Company.
 *
 * The software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * A simple UART polled driver
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Albert Z.         11/7/08      beta
 *****************************************************************************/
#include "p24fxxxx.h"
// External oscillator frequency
#define SYSCLK          8000000

// UART IOs
#if defined (__PIC24FJ64GA004__)
   #define UART2_TX_TRIS   TRISCbits.TRISC9
   #define UART2_RX_TRIS   TRISCbits.TRISC3
#else // PIC24FJ128GA010, PIC24FJ256GA110, PIC24FJ256GB110
   #define UART2_TX_TRIS   TRISFbits.TRISF5
   #define UART2_RX_TRIS   TRISFbits.TRISF4
#endif

//PPS Outputs
#ifndef __PIC24FJ128GA010__
   #define U2TX_IO      5
   #define U2RTS_IO   6
#endif

/*****************************************************************************
 * DEFINITIONS
 *****************************************************************************/
// Baudrate
#define BAUDRATE2      9600
/*****************************************************************************
 * U2BRG register value and baudrate mistake calculation
 *****************************************************************************/
#define BAUDRATEREG2 SYSCLK/32/BAUDRATE2-1

#if BAUDRATEREG2 > 255
#error Cannot set up UART2 for the SYSCLK and BAUDRATE.\
 Correct values in main.h and uart2.h files.
#endif

#define BAUDRATE_MISTAKE 1000*(BAUDRATE2-SYSCLK/32/(BAUDRATEREG2+1))/BAUDRATE2
#if (BAUDRATE_MISTAKE > 2)||(BAUDRATE_MISTAKE < -2)
#error UART2 baudrate mistake is too big  for the SYSCLK\
 and BAUDRATE2. Correct values in uart2.c file.
#endif

/*****************************************************************************
 * Function: UART2Init
 *
 * Precondition: None.
 *
 * Overview: Setup UART2 module.
 *
 * Input: None.
 *
 * Output: None.
 *
 *****************************************************************************/
extern void InitUART2(void);

/*****************************************************************************
 * Function: UART2PutChar
 *
 * Precondition: UART2Init must be called before.
 *
 * Overview: Wait for free UART transmission buffer and send a byte.
 *
 * Input: Byte to be sent.
 *
 * Output: None.
 *
 *****************************************************************************/
extern void  UART2PutChar(char );

/*****************************************************************************
 * Function: UART2PutDec
 *
 * Precondition: UART2Init must be called before.
 *
 * Overview: This function converts decimal data into a string
 * and outputs it into UART.
 *
 * Input: Binary data.
 *
 * Output: None.
 *
 *****************************************************************************/
extern void  UART2PutDec(unsigned char );



pues bien, compilando eso y dandole a los pulsadores del explorer16, cada pulsador va a estar correspondido con una de las 4 letras que vienen en el codigo, es decir, el pulsador s3 se corresponde con la M, el S6 con la C, el S5 con la H y el S4 con la P. para que en vez de aparecer esas letras aparecieran otras, simplemente deberíamos cambiar las letras ¿no es asi?

Pues aunque las cambie por H O L A, cada una en un pulsador, cuando pulso los botones en el hyperterminal me sigue saliendo M C H P, a alguien le a pasado eso alguna vez? ?por qué pasa?

Desconectado Enrique_86

  • PIC12
  • **
  • Mensajes: 62
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #12 en: 15 de Octubre de 2009, 14:07:56 »
Hola, no se si ya resolviste tu problema pero aqui te adjunto un extracto del codigo (configuracion para el UART1) que hize para el PIC24FJ256GA108.. Estoy utilizando los cuatro UARTs y los configuro con los pines RP.. Saludos.  :)

Código: [Seleccionar]

void UART1_Init(void)
{
//Configuracion de puertos para el MAX3323
TRISBbits.TRISB11=0; //RB11: output SHDN
  TRISBbits.TRISB12=0; //RB12: output RENABLE
   TRISBbits.TRISB13=0; //RB13: output TXENABLE
  TRISBbits.TRISB14=0; //RB14: output TX1 RP14
  TRISBbits.TRISB15=1; //RB15: input RX1 RP29

LATBbits.LATB11=1;
LATBbits.LATB12=0;
LATBbits.LATB13=0;
  
//Asignacion de pines al periferico
RPOR7bits.RP14R=3; //RP14 como U1Tx
RPINR18bits.U1RXR=29; //RP29 como U1Rx

//Configuracion del UART
OpenUART1( //UxMODE Register
UART_EN &
UART_IDLE_STOP &
UART_IrDA_DISABLE &
UART_MODE_FLOW &
UART_UEN_10 &
UART_DIS_WAKE &
UART_DIS_LOOPBACK &
UART_DIS_ABAUD &
UART_UXRX_IDLE_ONE &
UART_NO_PAR_9BIT &
UART_BRGH_SIXTEEN &
UART_1STOPBIT,
//UxSTA Register
UART_INT_TX &
UART_IrDA_POL_INV_ZERO &
UART_SYNC_BREAK_DISABLED &
UART_TX_ENABLE &
UART_INT_RX_CHAR &
UART_ADR_DETECT_DIS,
//UxBRG Register
12);     //(4000000/(16*19200))-1 = 12

//configure UART1 interrupt
  ConfigIntUART1( UART_RX_INT_EN &
               UART_RX_INT_PR2 &
               UART_TX_INT_DIS &
               UART_TX_INT_PR1);
        
LATBbits.LATB12=1;
LATBbits.LATB13=1;
}




PD: Alguien me podria ayudar en almacenar datos provinientes del UART en una cadena??  :mrgreen:
« Última modificación: 15 de Octubre de 2009, 14:10:20 por Enrique_86 »
...enrique  :-)

Desconectado oteros2000

  • PIC10
  • *
  • Mensajes: 4
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #13 en: 04 de Febrero de 2010, 06:05:08 »
amigos..  

tengo un problema..

alguien puede enviarme el fichero 24fxxxx.h?? no lo encuentro en ningun sitio.. gracias..

en concreto necesito el 24f08ka101.. gracias


antonio@relequick.com
« Última modificación: 04 de Febrero de 2010, 06:08:05 por oteros2000 »

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: codigo para mandar datos del pic24f al hyperterminal y al reves
« Respuesta #14 en: 04 de Febrero de 2010, 09:05:26 »
Al instalar C30 el archivo lo tienes en ...Microchip/MPLAB C30/Support/PIC24F/h


Saludos!
No contesto mensajes privados, las consultas en el foro