мой код...
CODE
/********************************************************************
********************************************************************/
#include "p24fxxxx.h"
#define LED1 PORTBbits.RB7
#define LED2 PORTBbits.RB8
#define LED3 PORTBbits.RB9
#define P6 PORTDbits.RD0
#define MAXLEN 255
/*****************************************************************************
* DEFINITIONS
*****************************************************************************/
// External oscillator frequency
#define SYSCLK 16000000
// Baudrate
#define BAUDRATE 19200
/*****************************************************************************
* U1BRG register value and baudrate mistake calculation
*****************************************************************************/
#define BAUDRATEREG SYSCLK/32/BAUDRATE-1
#if BAUDRATEREG > 255
#error Cannot set up UART1 for the SYSCLK and BAUDRATE.\
Correct values in main.h and uart2.h files.
#endif
#define BAUDRATE_MISTAKE 1000*(BAUDRATE-SYSCLK/32/(BAUDRATEREG+1))/BAUDRATE
#if (BAUDRATE_MISTAKE > 2)||(BAUDRATE_MISTAKE < -2)
#error UART baudrate mistake is too big for the SYSCLK\
and BAUDRATE. Correct values in uart.c file.
#endif[/code]
[code]/********************************************************************
FileName: main.c
Dependencies: See INCLUDES section
Processor: PIC18 or PIC24 USB Microcontrollers
Hardware: The code is natively intended to be used on the following
hardware platforms: PICDEMO FS USB Demo Board,
PIC18F87J50 FS USB Plug-In Module, or
Explorer 16 + PIC24 USB PIM. The firmware may be
modified for use on other USB platforms by editing the
HardwareProfile.h file.
Complier: Microchip C18 (for PIC18) or C30 (for PIC24)
Company: Microchip Technology, Inc.
********************************************************************
File Description:
Change History:
Rev Date Description
1.0 04/30/2008 Initial Release
Adapted from PIC18F87J50 HID Bootloader Firmware
as basis for BootApplication(). The rest of the
code was taken from the Simple HID Demo in
MCHPFSUSB v2.1.
********************************************************************/
#include "p24fxxxx.h"
#include "GenericTypeDefs.h"
#include "Hardware.h"
#include <PPS.h>
#include <uart.h>
_CONFIG1(FWDTEN_OFF & ICS_PGx1)
_CONFIG2(IESO_ON & FNOSC_PRI & FCKSM_CSECME & POSCMOD_HS)
_CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.
/** CONFIGURATION **************************************************/
// _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF)// & ICS_PGx3)
//_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRI)
// _CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.
// _CONFIG1(ICS_PGx1 & BKBUG_ON & COE_OFF & JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF)
//_CONFIG2( FNOSC_PRIPLL & POSCMOD_HS & FCKSM_CSDCMD)
//_CONFIG2( FNOSC_PRI & POSCMOD_HS)
// _CONFIG2( FNOSC_FRC )// 8 MHz internal
// _CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.
/** C O N S T A N T S **********************************************************/
#define t1 0.01
#define PREG SYSCLK/2*t1/1
#define USE_AND_OR /* To enable AND_OR mask setting */
/** ПЕРЕМЕННЫЕ ПРОЕКТА ********************************************************/
BYTE i,tmpRX1;
DWORD tick;
BYTE rx_buf[MAXLEN];
const BYTE buf[]="PIC24FJ test program....\0";
/** Прототипы*******************************************************************/
void Test_Led(void);
void wait_1s(void);
void Init_UART1 (void);
void puts1(const BYTE *a);
void Init(void);
int main(void);
void __attribute__((interrupt, auto_psv)) _T1Interrupt(void);
void __attribute__ ((interrupt,no_auto_psv)) _U1RXInterrupt(void);
void __attribute__ ((interrupt,no_auto_psv)) _U1TXInterrupt(void);
int main(void)
{Init();
Test_Led();
Init_UART1();
puts1((BYTE*)"\n\rTest programm for 24FJ128GB106...\r\n\0");
puts1((BYTE*)"___________________________________\r\n\0");
while(1){
while(BusyUART2()); /*Transmit data*/
puts1((BYTE*)"012345\r\n\0");
}
return(0);
}
/* Тест светодиодиков и друг***/
void Test_Led(void)
{LED1=0;
LED2=0;
LED3=0;
LED2=1;
LED3=1;
LED1=1;
}
void Init(void)
{
AD1PCFGL=0xFFFB; // AN2 - analog, all - digital
LED1=1;
LED2=1;
LED3=1;
TRISBbits.TRISB7=0;
TRISBbits.TRISB8=0;
TRISBbits.TRISB9=0;
Nop();
/******************* Timer I ********************************************/
TMR1=0;
T1CON=0b1000000000000000;
PR1=PREG;
_T1IF=0;
_T1IP=3;
_T1IE=1;
/******************* End Timer I *****************************************/
}
void Init_UART1 (void)
{
//*************************************************************
// Unlock Registers
//*************************************************************
PPSUnLock;
//************************************************************
// Configure Input Functions
// (See Table 30-1)
//*************************************************************
//*******************************
/* Configure Peripheral pin for UART2*/
iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP2);
//iPPSInput(IN_FN_PPS_U2CTS,IN_PIN_PPS_RPI32);
iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_U1TX);
//iPPSOutput(OUT_PIN_PPS_RP31,OUT_FN_PPS_U2RTS);
//*************************************************************
// Lock Registers
//*************************************************************
PPSLock;
U1MODEbits.UARTEN = 0;
IEC0bits.U1RXIE = 0;
IEC0bits.U1TXIE = 0;
IFS0bits.U1RXIF = 0;
IFS0bits.U1TXIF = 0; //dsiable UART if enabled previously
/*********************** UART 2 Configuration ****************************************************
*
* 9600 baudrate
* Low baud rate
* 8 bit transmission/reception
* No parity bit
* 1 stop bit
********************************************************************************
****************/
/*Enable UART intruupts*/
// ConfigIntUART1(UART_RX_INT_EN |UART_RX_INT_PR6 | UART_TX_INT_EN |UART_TX_INT_PR6);
// OpenUART1(UART_EN, UART_TX_ENABLE, 25); //configure UART and enable it
U1BRG=BAUDRATEREG;
//U1BRG=12;// 19200 8 bit 1 stop on 8MHz
//U1BRG=25;// 19200 8 bit 1 stop on 16MHz
//U1BRG=51;// 19200 8 bit 1 stop on 32MHz
U1MODEbits.BRGH=0;
U1MODEbits.RTSMD=1;
U1MODEbits.LPBACK=0;
U1MODEbits.UEN0=1;
U1MODEbits.UEN1=1;
U1MODEbits.ABAUD=0;
U1STAbits.UTXINV=0;
U1STAbits.UTXISEL0=0;
U1STAbits.UTXISEL1=0;
U1STAbits.URXISEL0=0;
U1STAbits.URXISEL1=0;
U1MODEbits.UARTEN=1;
U1STAbits.UTXEN=1;
IFS0bits.U1RXIF = 0;
//IFS0bits.U1TXIF = 0;
//IEC0bits.U1TXIE=1;
IEC0bits.U1RXIE=1;
}
/*
Печать строки из программной памяти в 1 компорт
*/
void puts1(const BYTE *buf)
{// посылает на 1 компорт
while(*buf!='\0')
{ while(U1STAbits.UTXBF); /* wait if the buffer is full */
U1TXREG = *buf++; /* transfer data byte to TX reg */
}
}
/*
*/
void __attribute__((interrupt, auto_psv)) _T1Interrupt(void)
{//вызывается с периодом 10 мс
TMR1=0;
if (tick>20) {LED1=~LED1;tick=0;
}
else tick++;
_T1IF=0;
}
void __attribute__ ((interrupt,no_auto_psv)) _U1RXInterrupt(void)
{ tmpRX1=U1RXREG;
switch (tmpRX1)
{case 0x0D : break;
case 0x0A : break;
default : {if (i==MAXLEN) i=0;
rx_buf[i++]=tmpRX1;}
}
//if (U1STAbits.FERR||U1STAbits.OERR) {CREN1=0;
// CREN1=1;}// если ошибка
U1RX_Clear_Intr_Status_Bit;
LED3=0;
}
void __attribute__ ((interrupt,no_auto_psv)) _U1TXInterrupt(void)
{
U1TX_Clear_Intr_Status_Bit;
}
void wait_1s(void)
{//tick=0;
//while(tick<100);
Nop();
}
Причина редактирования: Бездумно запихнутый в сообщение исходный текст