Beispiel #1
0
static void InitializeBoard(void)
{
	
#if (defined(MCHP_C18) && (defined(__18F458) || defined(__18F448))) \
		|| (defined(HITECH_C18) && (defined(_18F458) || defined(_18F448)))
	CMCON  = 0x07; /* Comparators off CM2:CM0 = 111 for PIC 18F448 & 18F458 */
#endif


    /////////////////////////////////////////////////
    //Enable 4 x PLL if configuration bits are set to do so
#if ( defined(MCHP_C18) && (defined(__18F6621 ) || defined(__18F6680 )))
    OSCCON = 0x04;              // Enable PLL (PLLEN = 1)
    while (OSCCON_LOCK == 0);   // Wait until PLL is stable (LOCK = 1)
    
    // Seeing that this code does currently not work with Hi-Tech compiler, disable this feature
    OSCCON_SCS1 = 1;
    
    //Switch on software 4 x PLL if flag is set in configuration data
    //if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_PLLON) {
    //    OSCCON_SCS1 = 1;
    //}
#endif

#if defined(_18F6680) || defined(__18F6680)    
	vscp18f_init( FALSE );

	// Enable peripheral interrupt	
	INTCONbits.PEIE = 1;
	
	// EnableCAN Receive Error Interrupt
	PIE3bits.IRXIE = 1;
#endif    
	// Disable external pull-ups
    INTCON2_RBPU = 1;

    // Enable interrupts
    T0CON = 0;
    INTCON_GIEH = 1;
    INTCON_GIEL = 1;
}
Beispiel #2
0
void init(void)
{
unsigned char msgdata[ 8 ];

     vscp18f_init( TRUE );

	// Initialize the uP

	// PortA
	// RA0 -  SENS  - Input
	// RA1 -        - Output
	// RA2 -        - Output
	// RA3 -        - Output
	// RA4 -        - Output
	// RA5 -        - Output
	// RA6 - OSC
	TRISA = 0b00000001;
    PORTA = 0b00000000;

	// PortB
	// RB0 - RFID_RX- Input
	// RB1 -        - Output
	// RB2 - CAN TX - Output
	// RB3 - CAN RX - input
	// RB4 -  		- input
	// RB5 - 		- input
	// RB6 - 		- input
	// RB7 - 		- input 
	TRISB = 0b11111001;
    PORTB = 0b00000000;
	
	// RC0 -           - Output
	// RC1 - Button    - Input
    // RC2 - PWM       - Output
	// RC3 -           - Output
	// RC4 -           - Output
	// RC5 -           - Output
	// RC6 -           - Output
 	// RC7 -           - Output
	TRISC = 0b00000010;
    PORTC = 0b00000000;    

    // TIMERS    
    OpenTimer0(TIMER_INT_OFF  &               
               T0_16BIT       &
               T0_SOURCE_INT  &
               T0_PS_1_1
              );

    OpenTimer1(TIMER_INT_ON   &
               T1_16BIT_RW    &
               T1_SOURCE_INT  &
               T1_PS_1_1      &
               T1_OSC1EN_OFF
              );

    OpenTimer2(TIMER_INT_OFF  & 
               T2_PS_1_1      &
               T2_POST_1_1
              );

    // ADC

    OpenADC(ADC_FOSC_64       &
            ADC_RIGHT_JUST    &
            ADC_20_TAD        ,
            ADC_CH0           &
            ADC_INT_OFF       &
            ADC_REF_VDD_VREFMINUS /*ADC_VREFPLUS_VDD*/  &
            ADC_REF_VREFPLUS_VSS  /*ADC_VREFMINUS_VSS*/ ,
            0x0E);            
     
    // PWM 125 kHz
    PWM_Calibr(&PWM_f,&PWM_adc);
    OpenPWM1(PWM_f);// 79
    SetDCPWM1((PWM_f*2)-6);  // 156  
    PWM_enable = ON;

    RCONbits.IPEN = 1; // enable HI and LOW priorities

    // INT priority
    IPR1bits.TMR1IP = 0;      // Timer1 LOW priority

    OpenRB0INT( PORTB_CHANGE_INT_ON & RISING_EDGE_INT & PORTB_PULLUPS_OFF );

    // Global INT ebable
	INTCONbits.GIEH = 1;		
    INTCONbits.GIEL = 1;    

	return;
}