예제 #1
0
파일: compUart.c 프로젝트: kunal15595/pic
//=================================================================================================
//	Function name: UARTDeviceInit	
//	-----------------------------
//	Description:
//
//	Low leven UART initialization
//=================================================================================================
//
static void UARTDeviceInit(void)
{
	//---------------------------------------------------------------------------------------------
	// Initialize UART module 2 for sending and receiving
	//---------------------------------------------------------------------------------------------
	OpenUART2
		(	UART_EN					&	
			UART_IDLE_CON			&
			UART_EN_WAKE			&
			UART_DIS_LOOPBACK		&
			UART_UEN_00				&
			UART_DIS_ABAUD			&
			UART_NO_PAR_8BIT		&
			UART_1STOPBIT			&
			UART_IrDA_DISABLE		&
			UART_MODE_SIMPLEX		&
			UART_UXRX_IDLE_ONE		&
			UART_BRGH_FOUR
			,
			UART_INT_TX_BUF_EMPTY	&
			UART_IrDA_POL_INV_ZERO	&	// When no character, line is high!
			UART_TX_ENABLE			&
			UART_INT_RX_CHAR		&
			UART_ADR_DETECT_DIS		&
			UART_RX_OVERRUN_CLEAR
			,
			((avix_DEVICE_CLOCKhz/(4L * 115200)) - 1));	
			

	SetPriorityIntU2TX(3);
	DisableIntU2TX; 
	SetPriorityIntU2RX(2);
	EnableIntU2RX;
}	
예제 #2
0
파일: uart_stdio.c 프로젝트: sbalula/mola
void config_uart2(void){
	CloseUART2();
	unsigned int UMODEvalue, U2STAvalue, config;
	
	UMODEvalue = UART_EN &
		UART_DIS_WAKE &
		UART_DIS_LOOPBACK &
		UART_DIS_ABAUD &
		UART_IDLE_CON &
		UART_NO_PAR_8BIT &
		UART_1STOPBIT;

	U2STAvalue = UART_INT_TX &
		UART_TX_PIN_NORMAL &
		UART_TX_ENABLE &
		UART_INT_RX_BUF_FUL &
		UART_RX_OVERRUN_CLEAR &
		UART_ADR_DETECT_DIS;

	config = UART_TX_INT_DIS &
		UART_RX_INT_EN &
		UART_INT_RX_BUF_FUL &
		UART_RX_INT_PR4;

	__C30_UART = 2;

	ConfigIntUART2(config);
	OpenUART2(UMODEvalue, U2STAvalue, (int) ((double) ((FCY/16.)*1000/BAUD_RATE-1) + 0.5));

	Serial.receiveddata = Serial.rbuf;
}
void setup_UART2 (unsigned int pb_clock) //UART associated with the PmodCLS
{
	// OpenUART2( config1, config2, ubrg)
	OpenUART2 (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_MODE_FLOWCTRL | UART_DIS_BCLK_CTS_RTS | UART_NORMAL_RX | UART_BRGH_SIXTEEN,
               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, 
			  mUARTBRG(pb_clock, DESIRED_BAUD_RATE));




	UARTEnable(UART2, UART_DISABLE_FLAGS(UART_RX ));
}
예제 #4
0
void SetupUART2(void)
{
    /// UART2 for RS-232 w/PC @ 230400, 8bit, No parity, 1 stop bit
    unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
    U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                  UART_MODE_FLOW & UART_UEN_10 & UART_DIS_WAKE &
                  UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                  UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT;
    U2STAvalue  = UART_INT_TX & UART_INT_RX_CHAR &UART_SYNC_BREAK_DISABLED &
                  UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                  UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
    U2BRGvalue  = 43; // (Fcy / ({16|4} * baudrate)) - 1
    OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);
}
예제 #5
0
void UART2_Config(void){

    OpenUART2((
            UART_EN &                   //Enable UART Module
            UART_IDLE_CON &             //Work while idle
            UART_IrDA_DISABLE &         //Disable Infared decoder
            UART_MODE_SIMPLEX &         //UART Simplex mode (RTS pin)
            UART_UEN_00 &               //TX/RX pins configured all other latched
            UART_DIS_WAKE &             //Disable wake on Start bit
            UART_DIS_LOOPBACK &         //Disable loopback
            UART_DIS_ABAUD &            //Disable Auto Baud
            UART_UXRX_IDLE_ONE &        //Receive idle is 1
            UART_BRGH_SIXTEEN &         //16 clocks per bit period
            UART_NO_PAR_8BIT &          //No parity bit
            UART_1STOPBIT               //One stop bit
            ),
            (
            UART_INT_TX_LAST_CH &       //Interrupt when last character shifted out
            UART_IrDA_POL_INV_ZERO &    //IrDA encoded, UxTX Idel state is '0'
            UART_SYNC_BREAK_DISABLED &  //Sync break transmission disabled or completed
            UART_TX_ENABLE &            //Transmit enable
            UART_TX_BUF_NOT_FUL &       //Transmit buffer is not full
            UART_INT_RX_CHAR &          //Interrupt on every char received
            UART_ADR_DETECT_DIS &       //address detect disable
            UART_RX_OVERRUN_CLEAR       //Rx buffer Over run status bit clear
            ),
            (
            __BAUDUART2_ //Baud rate
            ));
    ConfigIntUART2(
                UART_RX_INT_EN &        //Receive interrupt enabled
                UART_RX_INT_PR2 &       //Priority RX interrupt 1
                UART_TX_INT_DIS &       //transmit interrupt disabled
                UART_TX_INT_PR1         //Priority TX interrupt 1
            );



#ifdef InvertU2RxTxBits
    U2STAbits.UTXINV = 0;
    U2MODEbits.URXINV = 0;
#endif

    //Set the tristate and map pins for Uart
    TRIS_U2TX;
    TRIS_U2RX;
    MAP_U2TX;
    MAP_U2RX;
}
예제 #6
0
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
unsigned short usBRG;

	/* Create the queues used by the com test task. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

	/* Configure the UART and interrupts. */
	usBRG = (unsigned short)(( (float)configPERIPHERAL_CLOCK_HZ / ( (float)16 * (float)ulWantedBaud ) ) - (float)0.5);
	OpenUART2( UART_EN, UART_RX_ENABLE | UART_TX_ENABLE | UART_INT_TX | UART_INT_RX_CHAR, usBRG );
	ConfigIntUART2( ( configKERNEL_INTERRUPT_PRIORITY + 1 ) | UART_INT_SUB_PR0 | UART_TX_INT_EN | UART_RX_INT_EN );

	xTxHasEnded = pdTRUE;

	/* Only a single port is implemented so we don't need to return anything. */
	return NULL;
}
예제 #7
0
// set the baud rate divider
// The baud is Floor[80000000/(4*(divider+1)].
void SetUARTClockDivider(uint16_t divider)
{

	// define setup Configuration 1 for OpenUARTx
		// Module Enable
		// Work in IDLE mode
		// Communication through usual pins
		// Disable wake-up
		// Loop back disabled
		// Input to Capture module from ICx pin
		// no parity 8 bit
		// 1 stop bit
		// IRDA encoder and decoder disabled
		// CTS and RTS pins are disabled
		// UxRX idle state is '1'
		// 4x baud clock - high speed
	#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_FOUR

    // define setup Configuration 2 for OpenUARTx
		// IrDA encoded UxTX idle state is '0'
		// Enable UxRX pin
		// Enable UxTX pin
		// No interrupt on transfer of every character to TSR
		// Interrupt on every char received
		// Disable 9-bit address detect
		// Rx Buffer Over run status bit clear
	#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


#ifdef HC_UART1
    // Open UART1 with config1 and config2
    OpenUART1( config1, config2, divider);

    // Configure UART RX Interrupt
    //ConfigIntUART1(UART_INT_PR2 | UART_RX_INT_EN /* | UART_TX_INT_EN */ );
#else
    // Open UART2 with config1 and config2
    OpenUART2( config1, config2, divider);

    // Configure UART RX Interrupt
    //ConfigIntUART2(UART_INT_PR2 | UART_RX_INT_EN /* | UART_TX_INT_EN */ );
#endif
    clockDivider = divider;
}
예제 #8
0
파일: serio.c 프로젝트: ncabalos/unicon
void serio_init(uckernel_task handler)
{
	serio_set_rx_handler(handler);

	new_queue(&tx_queue, tx_queue_data, QUEUE_SIZE, sizeof(uint8_t));
	new_queue(&rx_queue, rx_queue_data, QUEUE_SIZE, sizeof(uint8_t));

	iPPSInput(IN_FN_PPS_U2RX, IN_PIN_PPS_RP10);
	iPPSInput(IN_FN_PPS_U2CTS, IN_PIN_PPS_RPI32);
	iPPSOutput(OUT_PIN_PPS_RP17, OUT_FN_PPS_U2TX);
	iPPSOutput(OUT_PIN_PPS_RP31, OUT_FN_PPS_U2RTS);
	CloseUART2();

	/*Enable UART intruupts*/
	ConfigIntUART2(UART_RX_INT_EN | UART_RX_INT_PR6 | UART_TX_INT_EN | UART_TX_INT_PR6 | UART_INT_TX_BUF_EMPTY);
	/*UART initialized to 9600 baudrate @BRGH=0, 8bit,no parity and 1 stopbit*/
	OpenUART2(UART_EN | UART_BRGH_FOUR, UART_TX_ENABLE, 34);
	serio_initialized = true;
}
예제 #9
0
void uartInit() {
    /// UART2 for RS-232 w/PC @ 230400, 8bit, No parity, 1 stop bit
    unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
    U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                  UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                  UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                  UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_2STOPBITS;
    U2STAvalue  = UART_INT_RX_CHAR & UART_SYNC_BREAK_DISABLED &
                  UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                  UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
    U2BRGvalue  = 10; // Approximately 830kBaud

    OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

    in_pkt_ = &(pkt_buf_0_);
    last_bldc_packet = &(pkt_buf_1_);
    last_bldc_packet_is_new = 0;

    ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR6);
}
예제 #10
0
파일: bsp.c 프로젝트: Vanganesha/oufffteam
void  LS2_UART_Init (void)
{
    CPU_INT08U  config;
    CPU_INT32U  config1;
    CPU_INT32U  config2;
       
    config1 = UART_EN                                                   // UART module enabled                              
            | UART_IDLE_CON                                             // UART works in IDLE mode                          
            | UART_RX_TX                                                // Communication is done through the normal pins    
            | UART_DIS_WAKE                                             // Disable Wake-up on START bit detect during SLEEP
            | UART_DIS_LOOPBACK                                         // Disable loop back                               
            | UART_DIS_ABAUD                                            // Input to capture module from ICx pin           
            | UART_NO_PAR_8BIT                                          // 8 bits no parity                               
            | UART_1STOPBIT                                             // 1 stop bit                                      
            | UART_IRDA_DIS                                             // IrDA disabled                                    
            | UART_MODE_FLOWCTRL                                        // UART pins in flow control mode                   
            | UART_DIS_BCLK_CTS_RTS                                     // Disable BCLK, CTS, and RTS pins                  
            | UART_NORMAL_RX                                            // UxRX idle stat is '1'                            
            | UART_BRGH_SIXTEEN;                                        // 16x baud clock                                   
//            
    config2 = UART_TX_PIN_LOW                                           // IrDA encoded UxTx idle stat is '0'               
 //           | UART_RX_ENABLE                                            // Enable UxRx pin                                  
            | UART_TX_ENABLE                                            // Enable UxTx pin                                  
 //           | UART_INT_TX                                               // Interrupt on trasnfer of each character to TSR   
 //           | UART_INT_RX_CHAR                                          // Interrupt on every char received                 
            | UART_ADR_DETECT_DIS                                       // Disable 9-bit address detect                     
            | UART_RX_OVERRUN_CLEAR;                                    // Rx buffer overrun status bit clear               
            
//    config1 = UART_EN;                                                   // UART module enabled                              
                                   
//    config2 = UART_TX_ENABLE;                                            // Enable UxTx pin 
                                 
    OpenUART2(config1, config2, BSP_CLK_FREQ / (16 * UART2_BAUDRATE) - 1);  // Configure the settings                           

//    config = UART_INT_PR3
//           | UART_INT_SUB_PR0
//           | UART_RX_INT;
           
//	ConfigIntUART2(config);
 
}
예제 #11
0
//Initialize UART module and query skinproc tactile grid size
void tactileInit() {
    //unsigned char data[2] = {0};
    //radioSendData(0x3001, 0, CMD_TACTILE, 2, data, 0);
    if (TACTILEUART){
        /// UART2 for SkinProc, 1e5 Baud, 8bit, No parity, 1 stop bit
        unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
        U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                      UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                      UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                      UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT;
        U2STAvalue  = UART_INT_TX & UART_INT_RX_CHAR &UART_SYNC_BREAK_DISABLED &
                      UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                      UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
        U2BRGvalue  = 86;//21; //9; // = (40e6 / (4 * 1e5)) - 1 so the baud rate = 100000
        //this value matches SkinProc

        // =3 for 2.5M Baud
        //U2BRGvalue  = 43; // =43 for 230500Baud (Fcy / ({16|4} * baudrate)) - 1
        //U2BRGvalue  = 86; // =86 for 115200 Baud
        //U2BRGvalue  = 1041; // =1041 for 9600 Baud

        OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

        ConfigIntUART2(UART_TX_INT_EN & UART_TX_INT_PR4 & UART_RX_INT_EN & UART_RX_INT_PR4);
        //EnableIntU2TX;
        DisableIntU2TX;
        EnableIntU2RX;
    }

    tx_idx = TACTILE_TX_IDLE;
    rx_idx = TACTILE_RX_IDLE;

    rx_count = 0;
    TACTILE_ROWS = 0xFF;
    TACTILE_COLS = 0xFF;
    clearRXFlag();
    //checkFrameSize();
    max_buffer_length = LARGE_BUFFER;

}
예제 #12
0
/**************************************************************************************************
  Title: 
    Delay Test
    
  Version: 
    0.1
    
  Filename: 
    delaytest-0.1.c
    
  Author(s): 
    mkobit
    
  Purpose of Program: 
    Test delay protocol for each of the DelayS, DelayMs, and DelayUs
    
  How to build: 
    delay.c
    
  Update History: 
    4/30/12: Having problems testing with the peripheral bus on the PCB, need to figure out what is going on
            * Found out that core timer does not use peripheral bus, it uses system clock
    
**************************************************/
int main(void)
{
  int nc;
  unsigned int pbFreq;
  long int delayed = 0;
  char buffer[50] = "0";

  pbFreq = SYSTEMConfigPerformance(SYSTEM_FREQUENCY);
  //pbFreq = SYSTEM_FREQUENCY;
  OpenUART2(UART_EN | UART_NO_PAR_8BIT | UART_1STOPBIT, UART_RX_ENABLE | UART_TX_ENABLE,
          (pbFreq/16/BAUDRATE) - 1);
  DelayInit(SYSTEM_FREQUENCY);
  putsUART2(CLEAR_VT);
  DelayMs(1500);
  putsUART2("Beginning in 3...\r\n");
  //printf("Hi\n");
  DelayS(1);
  putsUART2("Beginning in 2...\r\n");
  DelayUs(50000);
  DelayMs(995);
  putsUART2("Beginning in 1...\n\r");
  DelayS(1);
  putsUART2("Start!\n\r");
  while(1) {
    DelayMs(770);
    DelayS(2);
    DelayUs(230000);
    DelayMs(2000);
    delayed += 5;
    itoa(buffer, delayed, 10);
    putsUART2(buffer);
    putsUART2(" s\r\n");
  }

  //putsUART2(myHelloStr);

  return nc;
}
예제 #13
0
/**
 * Initialization function for the UART2 peripheral. Should be called in initialization code for the
 * model. This function configures the UART for whatever baud rate is specified. It also configures
 * two circular buffers for transmission and reception.
 *
 * This function can be called again to re-initialize the UART. This clears all relevant registers
 * and reinitializes values to 0.
 */
void Uart2Init(uint16_t brgRegister)
{
	// First initialize the necessary circular buffers.
	CB_Init(&uart2RxBuffer, u2RxBuf, sizeof(u2RxBuf));
	CB_Init(&uart2TxBuffer, u2TxBuf, sizeof(u2TxBuf));

	// If the UART was already opened, close it first. This should also clear the transmit/receive
	// buffers so we won't have left-over data around when we re-initialize, if we are.
	CloseUART2();

	// Configure and open the port.
	OpenUART2(UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_FLOW & UART_UEN_00 &
		UART_EN_WAKE & UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_UXRX_IDLE_ONE &
		UART_BRGH_SIXTEEN & UART_1STOPBIT,
		UART_INT_TX_LAST_CH & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE &
		UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR,
		brgRegister
		);

	// Setup interrupts for proper UART communication. Enable both TX and RX interrupts at
	// priority level 6 (arbitrary).
	ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR6 & UART_TX_INT_EN & UART_TX_INT_PR6);
}
예제 #14
0
파일: main.c 프로젝트: stantheman286/beagl
void gpsSetup(void)
{
    /* Configure Port Direction */
    TRISBbits.TRISB8 = 0;   //  Turn RB8 into output for GPS EN
    TRISBbits.TRISB9 = 1;   //  Turn RB9 into input for GPS FIX
    TRISBbits.TRISB14 = 1;  //  Turn RB14 into input for GPS RX
    TRISBbits.TRISB15 = 0;  //  Turn RB15 into output for GPS TX
    TRISFbits.TRISF4 = 1;   //  Turn RF4 into input for GPS PPS

    /* Configure PPS pins for GPS */
    iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP14);      // Assign U2RX to pin RP14
    iPPSOutput(OUT_PIN_PPS_RP29,OUT_FN_PPS_U2TX);   // Assign U2TX to pin RP29

    /* Enable the GPS module */
    PORTB |= 0x0100;

    /* Close UART in case it's already open */
    CloseUART2();

    /*Enable UART Interface */

    ConfigIntUART2(UART_RX_INT_DIS | UART_RX_INT_PR6 | UART_TX_INT_DIS | UART_TX_INT_PR6);
    // Receive interrupt disabled
    // Priority RX interrupt 6
    // Transmit interrupt disabled
    // Priority TX interrupt 6

    OpenUART2(UART_EN, UART_TX_ENABLE, 25);
    // Module enable
    // Transmit enable
    // 9600 baud rate (@ 4 MHz internal clock)

    /* Initalize the Adafruit GPS libraries */
    common_init();

}
예제 #15
0
void uartInit(packet_callback rx_cb) {
    /// UART2 for RS-232 w/PC @ 230400, 8bit, No parity, 1 stop bit
    unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
    U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                  UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                  UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                  UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT;
    U2STAvalue  = UART_INT_TX & UART_INT_RX_CHAR &UART_SYNC_BREAK_DISABLED &
                  UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                  UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
    U2BRGvalue  = 9; // =3 for 2.5M Baud
    //U2BRGvalue  = 43; // =43 for 230500Baud (Fcy / ({16|4} * baudrate)) - 1
    //U2BRGvalue  = 86; // =86 for 115200 Baud
    //U2BRGvalue  = 1041; // =1041 for 9600 Baud
    

    OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

    tx_idx = UART_TX_IDLE;
    rx_idx = UART_RX_IDLE;
    rx_callback = rx_cb;

    ConfigIntUART2(UART_TX_INT_EN & UART_TX_INT_PR5 & UART_RX_INT_EN & UART_RX_INT_PR6);
}
예제 #16
0
int main()
{

    // Configure UART2 for no interrupts at 9600 baud. Include a reset of
    // the RX flag as required.
    OpenUART2(UART_EN, UART_TX_ENABLE, BRGVAL);
    IFS1bits.U2RXIF = 0;

    // This variable is defined as 2 to specify that UART2 will be used for
    // stdin/stdout.
    __C30_UART = 2;

    /******************************************************************************
     * Your code goes in between this comment and the following one with asterisks.
     *****************************************************************************/
    LcdInit();		//initialize our lcd
    InitButtons();	//initialize our buttons
    InitMorseDecoder();	//initialize morse tree

    printf("Type Morse With Buttons Above\n");
    SetTopLine(greet);
    while(1) {
        if(ReceivedInput(temp)) {				//check for user input
            printf("Your input: %c\n", temp);	//echo input
            EncodeCharacter(temp, out);		//encode the character then display
            printf("In Morse: %c%c%c%c%c%c\n", out[0], out[1], out[2], out[3], out[4], out[5]);
        }
        char x = CheckButtonEvents();					//check for button event
        if (x == 0x00) {								// check if no Buttons were pressed
            if(flag0 != 1) {
                SetTopLine(greet);
            }
            flag0 = 1;

        } else if (x & Button6DownEvent) {			// check if Button 6 was pressed
            if(flag1 != 1) {
                toDecode[position] = dash;	//save input to current slot
                toDecode[position+1] = space;
                position++;					//increment to next slot
                SetBottomLine(toDecode);	//display total line array
            }
            flag1 = 1;		//flag is on
        } else if (x & Button6UpEvent) {				// check if Button 6 was released
            flag1 = 0;		//clear flag
        } else if (x & Button5DownEvent) {			// check if Button 5 was pressed
            if(flag2 != 1) {
                toDecode = (char *)GetBottomLine();	//decode what ever is in bottom line
            }
            flag2 = 1;
        } else if (x & Button5UpEvent) {				// check if Button 5 was released
            decodeChar[0] = DecodeCharacter(toDecode);	// decode our input
            topline[Pos] = decodeChar[0];			// add next decoded char
            Pos++;
            SetTopLine(topline);
            SetBottomLine(empty);						// clear bottom line on LCD
            int i;
            for(i = 0; i < 16; i++) {
                toDecode[i] = ' ';						// clear bottom line
            }
            position = 0;								// start at new line of input
            flag2 = 0;
        } else if (x & Button4DownEvent) {			// check if Button 4 was pressed
            flag3 = 1;		//flag is on
        } else if (x & Button4UpEvent) {				// check if Button 3 was released
            topline[Pos] = ' ';						// add space for next decodedc char
            Pos++;
            SetTopLine(topline);
            SetBottomLine(empty);
            int i;
            for(i = 0; i < 16; i++) {
                toDecode[i] = ' ';						// clear bottom line
            }
            position = 0;								// start at new line of input
            flag3 = 0;
        } else if (x & Button3DownEvent) {			// check if Button 3 was pressed
            if(flag4 != 1) {
                toDecode[position] = dot;
                toDecode[position + 1] = space;
                position++;
                SetBottomLine(toDecode);
            }
            flag4 = 1;		//flag is on
        } else if (x & Button3UpEvent) {				// check if Button 3 was released
            flag4 = 0;		//clear flag
        }
    }


    /******************************************************************************
     * Your code goes in between this comment and the preceeding one with asterisks
     *****************************************************************************/

    while (1);
}
예제 #17
0
파일: main.c 프로젝트: eelcor/Wireless_PIC
int32_t main(void)
{

#ifndef PIC32_STARTER_KIT
    /*The JTAG is on by default on POR.  A PIC32 Starter Kit uses the JTAG, but
    for other debug tool use, like ICD 3 and Real ICE, the JTAG should be off
    to free up the JTAG I/O */
    DDPCONbits.JTAGEN = 0;
#endif

    /*Refer to the C32 peripheral library documentation for more
    information on the SYTEMConfig function.
    
    This function sets the PB divider, the Flash Wait States, and the DRM
    /wait states to the optimum value.  It also enables the cacheability for
    the K0 segment.  It could has side effects of possibly alter the pre-fetch
    buffer and cache.  It sets the RAM wait states to 0.  Other than
    the SYS_FREQ, this takes these parameters.  The top 3 may be '|'ed
    together:
    
    SYS_CFG_WAIT_STATES (configures flash wait states from system clock)
    SYS_CFG_PB_BUS (configures the PB bus from the system clock)
    SYS_CFG_PCACHE (configures the pCache if used)
    SYS_CFG_ALL (configures the flash wait states, PB bus, and pCache)*/

    /* TODO Add user clock/system configuration code if appropriate.  */
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL); 

    /* Initialize I/O and Peripherals for application */
    InitApp();

    /*Configure Multivector Interrupt Mode.  Using Single Vector Mode
    is expensive from a timing perspective, so most applications
    should probably not use a Single Vector Mode*/
    // Configure UART2 RX Interrupt
    INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);

    // configure for multi-vectored mode
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    // enable interrupts
    INTEnableInterrupts();


    /* TODO <INSERT USER APPLICATION CODE HERE> */
    //Open UART2
    OpenUART2(UART_EN, UART_BRGH_FOUR|UART_RX_ENABLE | UART_TX_ENABLE, 21);

    //Open SPI 1 channel
    PORTBbits.RB11 = 1;
    OpenSPI1( SPI_MODE8_ON | MASTER_ENABLE_ON | SEC_PRESCAL_1_1 | PRI_PRESCAL_1_1 | FRAME_ENABLE_OFF | CLK_POL_ACTIVE_HIGH | ENABLE_SDO_PIN , SPI_ENABLE );
    SPI1BRG=39;
    initRadio();
    setTXAddress("UNIT2");
    setRXAddress(0,"UNIT1");
    char temp;
    char text[6];
    text[0]='H';
    text[1]='e';
    text[2]='l';
    text[3]='l';
    text[4]='o';
    text[5]='!';
    while(1)
    {
        setTransmitter();
        PORTBbits.RB11 = 0;
        DelayMs(20);
        transmitData(&text[0],6);
        printf("Hello world! \r\n");
        PORTBbits.RB11 = 1;
        DelayMs(20);
    }
}
예제 #18
0
void InitApp()
{
    _TRISA0 = 0; //led en sortie
    _TRISA1 = 0;
    led = 0;
    led2 = 0;

    //Sortie enable
    _TRISB9 = 0;
    _TRISB11 = 0;
    _ODCB9 = 1; //Open drain RB9 (dir 1)
    _ODCB11 = 1; //Open drain RB11 (dir 2)
    _ODCB10 = 1; //open drain RB10 PWM1H3

    //Le microswicth sur la pin RC5 (par exemple), on la met en entrée
    _TRISC5 = 1; //bumper bas de pince
    //Et on active la pullup qui va bien (registres CNPU1 et CNPU2)
    _CN26PUE = 1;

    _ODCC9 = 1; // Open drain sur la pin RC9 (pour les AX12)

    _TRISA4 = 1;
    _TRISA8 = 1;
    _TRISA9 = 1;
    _TRISB2 = 1; //RTS ?
    _TRISB3 = 1; //FLush ?
    _TRISA2 = 1; //CLK12 ?

    _TRISB4 = 1; // Arret d'urgence
    _CN1PUE = 1; // avec pullup
    _TRISB12 = 1; // switch 1
    _CN14PUE = 1; // avec pullup
    _TRISB13 = 1; // switch 2
    _CN13PUE = 1; // avec pullup
    _TRISB14 = 1; // switch 3
    _CN12PUE = 1; // avec pullup
    _TRISB15 = 1; // Laisse
    _CN11PUE = 1; // avec pullup

    OpenUART2(UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_FLOW
              & UART_UEN_00 & UART_DIS_WAKE & UART_DIS_LOOPBACK
              & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE & UART_BRGH_SIXTEEN
              & UART_NO_PAR_8BIT & UART_1STOPBIT,
              UART_INT_TX_BUF_EMPTY & UART_IrDA_POL_INV_ZERO
              & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE & UART_TX_BUF_NOT_FUL & UART_INT_RX_CHAR
              & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR,
              BRGVALAX12);

    ConfigIntUART2(UART_RX_INT_PR4 & UART_RX_INT_EN
                   & UART_TX_INT_PR4 & UART_TX_INT_DIS);

    OpenTimer2(T2_ON & T2_GATE_OFF & T2_PS_1_256 & T2_32BIT_MODE_OFF & T2_SOURCE_INT, 1500);
    ConfigIntTimer2(T2_INT_PRIOR_3 & T2_INT_ON); //Interruption ON et priorite 3

    OpenTimer5(T5_OFF & T5_GATE_OFF & T5_PS_1_1 & T5_SOURCE_INT, 40000);
    ConfigIntTimer5(T5_INT_PRIOR_2 & T5_INT_ON);

    OpenQEI1(QEI_DIR_SEL_QEB & QEI_INT_CLK & QEI_INDEX_RESET_DISABLE & QEI_CLK_PRESCALE_1
             & QEI_NORMAL_IO & QEI_MODE_x4_MATCH & QEI_UP_COUNT,0);
//    ConfigIntQEI1(QEI_INT_DISABLE);
//    WriteQEI1(65535);        //Valeur pour declencher l'interruption du module QEI

    _QEA1R = 5;     //Module QEI 1 phase A sur RB5
    _QEB1R = 6;     //Module QEI 1 phase B sur RB6
    POS1CNT = 0; //valeur QEI

    IFS2bits.SPI2IF = 0; // Flag SPI2 Event Interrupt Priority
    IPC8bits.SPI2IP = 2; // Priority SPI2 Event Interrupt Priority
    IEC2bits.SPI2IE = 1; //Enable SPI2 Event Interrupt Priority

    // activation de la priorité des interruptions
    _NSTDIS = 0;
}