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?