/******************************************************************************************************
* Funcao:		ConfiguraTransmissor									  						  	  *
* Entrada:		Nenhuma											  			   						  *
* Saída:		Nenhuma														  						  *
* Descrição:	Configuração do transmissor								    						  *
******************************************************************************************************/
void ConfiguraUSART(void)
{	   

	/*// serial communicatin configuration 

	SPBRG= 18; //Fill SPBRG register to set the baud rate
	RCSTAbits.SPEN=1;     // To activate Serial port (TX and RX pins)
	TXSTAbits.TXEN=1;      // To enable transmission
	RCSTAbits.CREN=1;  // To enable continuous reception
	PIR1bits.RCIF =0; // clear rcif interrupt flag
	PIE1bits.RCIE=1;
	INTCONbits.PEIE =1; // enable peripheral interrupt
	INTCONbits.GIE =1; // enable global interrupt
*/
	OpenUSART(USART_TX_INT_OFF & 
			  USART_RX_INT_ON & 
			  USART_ASYNCH_MODE &
			  USART_EIGHT_BIT &
			  USART_BRGH_LOW,31);
			  
	baudUSART(BAUD_8_BIT_RATE &
			  BAUD_AUTO_OFF &
			  BAUD_WAKEUP_OFF);

}//fim ConfiguraTransmissor
int main(int argc, char** argv) {
    OSCCON = 0xF7; //0b11110111;
    //TRISD = 0x00; //LED output
    TRISC = 0x80; //RX: input, TX: output
    TRISB = 0x10; //Columns and rows = inputs, except column 1 = output
    LATB = 0x00;
    CloseUSART();
    OpenUSART(RS232_CONFIG, RS232_SPBRG);
    baudUSART(RS232_BAUD);
    INTCON = 0xA0; //GIE = 1, TMR0IE = 1, TMR0IF = 0
    while (1) {

    }
    return (EXIT_SUCCESS);
}
Exemple #3
0
void InitApp(void)
{
    unsigned char config, baudconfig;
    unsigned spbrg;
    /* TODO Initialize User Ports/Peripherals/Project here */

    /* Setup analog functionality and port direction */
    SRAM_Setup_Pins();

    /* Initialize peripherals */
    CloseUSART();
    config = USART_TX_INT_OFF & USART_RX_INT_ON & USART_BRGH_HIGH & USART_CONT_RX &
            USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF;
    /* SPBRG based on 8MHz clk */
    //spbrg = 16;   //115200
    //spbrg = 34;   // 57600
    spbrg = 103;  // 19200 known working w/ 8MHz clock
    //spbrg = 207;  //  9600
    //spbrg = 832;  //  2400
    //spbrg = 1665;   //  1200
    /* SPBRG based on 48MHz clk */
    //spbrg = 103; //115200 48MHz
    OpenUSART(config, spbrg);
    baudconfig = BAUD_IDLE_CLK_LOW & BAUD_16_BIT_RATE & BAUD_WAKEUP_OFF & BAUD_AUTO_OFF;
    baudconfig &= ~0x20; // RX Not inverted
    baudUSART(baudconfig);

    PIR1bits.RCIF = 0; // Clear RX interrput flag
    PIE1bits.RCIE = 1; // Enable UART receive interrupts
    IPR1bits.RCIP = 0; // Set UART receive as low priority interrupt
    
    PIR1bits.TXIF = 0; // Clear TX interrupt flag
    PIE1bits.TXIE = 0; // Disable UART transmit interrupts
    IPR1bits.TXIP = 0; // Set UART transmit as low priority interrupt

    /* Configure the IPEN bit (1=on) in RCON to turn on/off int priorities */
    RCONbits.IPEN = 1;

    /* Enable interrupts */
    PIR1 = 0; // Clear peripheral interrupts
    INTCONbits.GIEH = 1; // Enable high priority interrupts
    INTCONbits.GIEL = 1; // Enable low priority interrupts
}
Exemple #4
0
void InitApp(void)
{

    /* Setup analog functionality and port direction */
    //LEDs
    LED1_DIR = OUT;
    LED2_DIR = OUT;
    LED3_DIR = OUT;
    
    //Control panel
    CTRLPOT_DIR = IN;
    CTRLBUTTON1_DIR = IN;
    CTRLSWITCH1_DIR = IN;
    CTRLLED1_DIR = OUT;
    CTRLLED2_DIR = OUT;
    CTRLLED3_DIR = OUT;


    //UART
    RX_DIR = IN;
    TX_DIR = IN; //Module will dynamically change as needed

    /* Initialize peripherals */
    
    //ADC
    OpenADC( ADC_FOSC_RC &
            ADC_RIGHT_JUST  &
            ADC_4_TAD,
            ADC_CH3 &
            ADC_REF_VDD_VSS  &
            ADC_INT_OFF,
            ADC_4ANA);
    
    
    //Timer
    OpenTimer0(TIMER_INT_ON & T0_16BIT &
            T0_SOURCE_INT &
            T0_PS_1_2);
    WriteTimer0(0x0000);
    OpenTimer1(TIMER_INT_ON &
            T1_SOURCE_INT &
            T1_16BIT_RW &
            T1_PS_1_1 &
            T1_OSC1EN_OFF &
            T1_SYNC_EXT_OFF);
    WriteTimer1(SERVO_MIN);
    
    
    //UART
    //BusPirate: m 3 6 ENTER ENTER ENTER 1 e 3 W (2)) P
    OpenUSART( USART_TX_INT_OFF &
            USART_RX_INT_OFF &
            USART_BRGH_HIGH &
            USART_NINE_BIT &
            USART_ASYNCH_MODE &
            USART_ADDEN_OFF, UART_BAUDRATE);

    baudUSART(BAUD_IDLE_CLK_LOW &
            BAUD_16_BIT_RATE &
            BAUD_WAKEUP_OFF &
            BAUD_AUTO_OFF);
    

    /* Configure the IPEN bit (1=on) in RCON to turn on/off int priorities */

    INTCONbits.TMR0IF = 1; //reset Interrupt Flag
    PIR1bits.TMR1IF = 1;
    RCONbits.IPEN = 1;
    RCSTAbits.SPEN=1;
    
    
    /* Enable interrupts */
    ei();
}
Exemple #5
0
void init_sumo ( void )
{
    OSCCONbits.IRCF = 7;                // Set internal clock to 16 Mhz

    ANSELHbits.ANS11 = 0;               // Make RX digital

    // 115200,8,n,1: 138 - 64MHz
    // 19200,8,n,1: 832 - 64MHz; 207 - 16MHz
    // 9600,8,n,1: 129 - 20 MHz; 1249 - 48MHz; 1666 - 64MHz
    usart_open(USART_TX_INT_OFF &       // disable TX interrupt
               USART_RX_INT_ON &        // enable RX interrupt
               USART_BRGH_HIGH &        // Use High BRGH
               USART_CONT_RX &          // Receive continuous data
               USART_EIGHT_BIT &        // Use 8 bit
               USART_ASYNCH_MODE,       // Use Asynchronous mode
               207);                    // 19200 for 16 Mhz
    #if defined (__SDCC)
    stdout = STREAM_USART;              // Set stdout to serial stream
    #else
    baudUSART(BAUD_16_BIT_RATE &
              BAUD_IDLE_CLK_LOW &
              BAUD_WAKEUP_OFF &
              BAUD_AUTO_OFF & 0x48); // 16 bit BRG
    #endif

    #if defined (__SDCC)
    adc_open(ADC_CHN_0,                 // Set channel 0
             ADC_FOSC_16 | ADC_ACQT_8,  // Configure Acquisition frequency
             ADC_CFG_7A,                // Set the number of channels to use
             ADC_FRM_RJUST |            // Adjust result to the right
             ADC_INT_OFF |              // Disable interrupts
             ADC_VCFG_VDD_VSS |         // Configure reference voltages
             ADC_NVCFG_VSS |            // Negative reference to VSS
             ADC_PVCFG_VDD);            // Positive reference to VDD
    #else
    OpenADC(ADC_RIGHT_JUST & ADC_FOSC_16 & ADC_8_TAD,
            ADC_CH0 & ADC_INT_OFF,
            ADC_REF_VDD_VDD & ADC_REF_VDD_VSS,
            0b0000111111110000);
    #endif

    T0CONbits.T08BIT = 0;               // 16 bit mode
    T0CONbits.T0CS = 0;                 // Source is internal
    T0CONbits.PSA = 1;                  // Disable prescaler
    T0CONbits.T0PS = 7;                 // Prescaler to 1:256
    TMR0H = 0; TMR0L = 0;               // Reset Timer0 to 0x0000
    INTCONbits.TMR0IF = 0;              // Clear interrupt flag
    INTCONbits.TMR0IE = 1;              // Enable Interruption from timer0
    T0CONbits.TMR0ON = 1;               // Start timer0

    write_timer_0(Ticks4NextInterrupt);

    Servo.FL = 1;
    Servo.FR = 1;
    Servo.BL = 1;
    Servo.BR = 1;

    FL_SERVO_TRIS = 0;
    FR_SERVO_TRIS = 0;
    BL_SERVO_TRIS = 0;
    BR_SERVO_TRIS = 0;

    RCONbits.IPEN = 0;                  // Interruption Priority Disabled
    INTCONbits.PEIE = 1;                // Peripheral Interrupt Enabled
    INTCONbits.GIE = 1;                 // Global Interrupt Enable
}