Beispiel #1
0
void sysInit(void){
	
	PMOD_DDR |= _BV(PMOD0) | _BV(PMOD1) | _BV(PMOD2) | _BV(PORTD4);		//Set PMOD as outputs
	WIZ_DDR &= ~(_BV(INT_W5500));							//Int is an input
	WIZ_PORT |= _BV(INT_W5500);								//Enable pull up
	WIZ_DDR |= _BV(SS_W5500);								//Set SS as output 
	AUX_DDR &= ~(_BV(BTN0) | _BV(ISENSE) | _BV(VSENSE));	//Button set as input Isense and Vsense inputs(will be used for ADC)
	AUX_DDR |= _BV(WP_EEP);									//WP pin for eeprom as output
	LED_DDR |= _BV(LED_R) | _BV(LED_G) | _BV(LED_B);
	AUX_PORT |= _BV(BTN0);									//Enable pull up on btn
	
	PMOD_PORT |= _BV(PMOD0) | _BV(PMOD1) | _BV(PMOD2);		//Full auto
	
	
	uartInit();
	i2c_init();
	sei();
	
	DDRB |= _BV(PORTB2) | _BV(PORTB1) | _BV(PORTB0);
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);  // SPI enable, Master, f/16
	
	uartPutsP("\n\n[Base Station]\n");
	uartPutsP(">Pins init\n");
	timer0Init();
	uartPutsP(">Timer 0 init\n");
	timer1Init();
	uartPutsP(">Timer 1 init\n");

}
STATUS initServo(void) {
	INT_LOCK();
	// Servo1 pin config
	DDRB  = DDRB | 0x20;  //making PORTB 5 pin output
	PORTB = PORTB | 0x20; //setting PORTB 5 pin to logic 1
	
	// Servo2 pin config
	DDRB  = DDRB | 0x40;  //making PORTB 6 pin output
	PORTB = PORTB | 0x40; //setting PORTB 6 pin to logic 1
	
	// Servo3 pin config
	DDRB  = DDRB | 0x80;  //making PORTB 7 pin output
	PORTB = PORTB | 0x80; //setting PORTB 7 pin to logic 1
	
	// Initialize timers
	timer1Init();
	
	/* Set initial motor positions */
	OCR1AL = (SERVO1_MIN + SERVO1_MAX)/2;
	OCR1AH = 0x00;
	OCR1BL = (SERVO2_MIN + SERVO2_MAX)/2;
	OCR1BH = 0x00;
	OCR1CL = (SERVO3_MIN + SERVO3_MAX)/2;
	OCR1CH = 0x00;
	
	INT_UNLOCK();
	
	return STATUS_OK;
 }
Beispiel #3
0
void UserInit(void)
{
	mInitAllLEDs();
	mInitAllSwitches();
	InitAdc();
	old_sw2 = sw2;
	Pump1tris = 0;
	Pump2tris = 0;
	
	TRISVPP = 0; //output
	TRISVPP_RST=0; //output
	TRISPGD=0;    
	TRISPGC=0;    
	TRISVDD=0;
	TRISVPP_RUN=0;
	VPP_RUN=0;	//run = off
	PGD_LOW=1;
	TRISPGD_LOW=1; //LV devices disabled, high impedance / input
	PGC_LOW=1;
	TRISPGC_LOW=1; //LV devices disabled, high impedance / input
	VPP = 1; //VPP is low (inverted)
	VPP_RST=0; //No hard reset (inverted
	PGD=0;		
	PGC=0;
	INTCON2bits.RBPU=1; //disable Portb pullup resistors
	timer1Init();
	timer0Init();
}//end UserInit
// Main program: Counting on T1
int main( void )
{
	DDRB = 0xFF;					// set PORTB for compare output 
	DDRA = 0xFF;					// set PORTA for output in main program
	timer1Init();					// it is running now!!

	while (1)
	{
		// do something else
		wait(100);					// every 100 ms (busy waiting)
		PORTA ^= BIT(7);			// toggle bit 7 PORTA
	}
}
Beispiel #5
0
/*----------------------------------------------------------------------------*/
void sys_init(void)
{
#ifdef UART_ENABLE
    uartInit();
    printf("power up \r\n");
 #endif

#if RTC_ENABLE
    if (init_rtc())
    {
        work_mode = SYS_RTC;
    }
#else 
	{
		u8 rtc_reg;
	    rtc_reg=read_rtc_reg();
		//printf("RTC reg:%02bx\n",rtc_reg);	
		if (rtc_reg & BIT(6))   ///<RTC是否完全掉电
	    {
#if (MEMORY_STYLE == USE_RTCRAM)
			reset_rtc_ram();
#endif
			rtc_reg &= ~(BIT(6)); 				 //清零PDGLG
    			write_rtc_reg(rtc_reg);
	    }
	}
#endif

    P0IE_init();
    keyInit();
    timer1Init();
    timer3Init();
#ifdef USE_USB_SD_DECODE_FUNC	    
#ifndef NO_SD_DECODE_FUNC
    sd_speed_init(1,100);
    init_port_sd();
#endif
#endif
#if SDMMC_CMD_MODE
	sd_chk_ctl(SET_SD_H_CHK);
#endif
    DACCON0 |= 0x05;	//打开DSP
    EA = 1;
}
Beispiel #6
0
void initFullLEDState(void) {

    if(ledInited) return;
    ledInited = 1;

    /*
    	timer0 = usb, ps/2 interface
    	timer1 = pwm
    	timer2 = custom macro
    */

    timer1Init();

    timer1PWMInit(8);
    timer1PWMBOn();

//	DEBUG_PRINT(("______________________ init LED State_____________\n"));

    initFullLEDStateAfter();

}
Beispiel #7
0
void init(void)
{
	//Make outputs low
	cbi(PWM_PORT, PWM_BIT);
	cbi(SD_PORT, PWM_BIT);
	
	//Make outputs outputs
	sbi(PWM_DDR, PWM_BIT);

	//Pull-up swithces
	sbi(ESTOP_PORT, ESTOP_BIT);
	sbi(BRAKE_PORT, BRAKE_BIT);
	
	//RGB Outputs
	sbi(RGB_DDR, RED);
	sbi(RGB_DDR, GREEN);
	sbi(RGB_DDR, BLUE);
	
	//RGB Off
	sbi(RGB_PORT, RED);
	sbi(RGB_PORT, GREEN);
	sbi(RGB_PORT, BLUE);
	
	//Initialise the ADC 
	a2dInit();
	
	//Initialise timer 1
	timer1Init();
	timer1SetPrescaler(TIMER_CLK_DIV1);
	timer1PWMInitICR(TOP_COUNT); //Enable PWM with top count
	timer1PWMAOn(); //Turn PWM on
	
	rgb(green);

	sei(); //Enable interupts
}
Beispiel #8
0
int main()
{
    //SYSTEMConfigPerformance(SYS_FREQ);
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    PORTFbits.RF1 = 0;

    //Function that initializes all of the required I/O
    initIO();

    //Initialize all of the LED pins
    ledinit();
    adcConfigureAutoScan();
    timer1Init();
    encodersInit();
    motorinit();
    PWMinit();
    motorRstop();
    motorLstop();
    leftspeed = 310;
    rightspeed = 300;

    while(PORTDbits.RD3 == 0)
            {}

            for(i = 0; i < 5000000; i++)
            {
            }
    setpwmR(rightspeed);
    setpwmL(leftspeed);
    motorRfwd();
    motorLfwd();

    //turnright();
    //turnleft();
	while (1)
	{
                if(readpins(0) > 300)   //left
		{
                    setpwmR(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed < 315)
                        leftspeed++;
                    if(rightspeed > 275)
                        rightspeed--;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 600)
                if(readpins(2) > 600) //right
		{
                    setpwmL(100);
                    for(i=0;i<800;i++);
                    /*
                    if(leftspeed > 265)
                        leftspeed--;
                    if(rightspeed < 325)
                        rightspeed++;
                     */
                    setpwmR(rightspeed);
                    setpwmL(leftspeed);
                    motorRfwd();
                    motorLfwd();
                }
                //for(i = 0; i < 500; i++){};

                //if (channel13 < 900)
                if(readpins(1) > 900) //middle
		{
                    setpwmR(0);
                    setpwmL(0);
                    motorRstop();
                    motorLstop();
                    turnright();

                }
                //for(i = 0; i < 1500; i++){};


	}

    return (EXIT_SUCCESS);
}
Beispiel #9
0
void SBTimersInit(void(*inputTask)(void), uint8_t inputPriority, uint32_t inputPeriod) {
    timer1Task = inputTask;
    timer1Priority = inputPriority;

    timer1Init(inputPeriod/2, timer1Priority);
}
Beispiel #10
0
/*----------------------------------------------------------------------------*/
void sys_init(void)
{
#ifdef UART_ENABLE
    uartInit();
    printf("power up \r\n");
 #endif

#if RTC_ENABLE
    if (init_rtc())
    {
        work_mode = SYS_RTC;
    }
#else 
	{
		u8 rtc_reg;
	    rtc_reg=read_rtc_reg();
		//printf("RTC reg:%02bx\n",rtc_reg);	
		if (rtc_reg & BIT(6))   ///<RTC是否完全掉电
	    {
#if (MEMORY_STYLE == USE_RTCRAM)
			reset_rtc_ram();
#endif
			rtc_reg &= ~(BIT(6)); 				 //清零PDGLG
    			write_rtc_reg(rtc_reg);
	    }
	}
#endif
    set_brightness_all_on();	

    P0IE_init();
    keyInit();
    timer1Init();
    timer3Init();
#ifdef USE_USB_SD_DECODE_FUNC	    
#ifndef NO_SD_DECODE_FUNC
    sd_speed_init(1,100);
    init_port_sd();
#endif
#endif
#if SDMMC_CMD_MODE
	sd_chk_ctl(SET_SD_H_CHK);
#endif
#ifdef USE_POWER_KEY
      sys_power_up();	
#endif	
    DACCON0 |= 0x05;	//打开DSP
    EA = 1;
#ifdef USE_POWER_KEY
      sys_power_up();	
#endif	
    work_mode = read_info(MEM_SYSMODE);

#ifdef CUSTOMED_POWER_ON_AT_RADIO_MODE
	work_mode  = SYS_FMREV;
#endif

    if (work_mode  == SYS_MP3DECODE_USB){

#ifdef REMOVE_USE_MODE
	work_mode  = SYS_FMREV;
	Disp_Con(DISP_TUNER);			
	return;
#endif

	Disp_Con(DISP_SCAN_DISK);

    }
    else if ((work_mode  == SYS_FMREV)
#ifdef AM_RADIO_FUNC		
	||(work_mode == SYS_AMREV)
#endif			
){

#ifdef AM_RADIO_FUNC		
		if(work_mode == SYS_AMREV){
			cur_sw_fm_band = MW_MODE;
		}
		else
#endif		
		{
			cur_sw_fm_band = FM_MODE;
		}
		Disp_Con(DISP_TUNER);			
    }
    else if (work_mode  == SYS_MCU_CD){

    		Disp_Con(DISP_SCAN_TOC);
    }	
    else if (work_mode  == SYS_AUX){
    		Disp_Con(DISP_AUX);
    }	
#if defined(USE_BLUE_TOOTH_FUNC)			
	
    else if (work_mode  == SYS_BLUE_TOOTH){
    		Disp_Con(DISP_BT);
    }	
#endif
	CD_PWR_GPIO_CTRL_INIT();
    	CD_PWR_GPIO_OFF();

	//TUNER_PWR_GPIO_CTRL_INIT();		
    	//TUNER_PWR_GPIO_OFF();

	AUX_GPIO_CTRL_INIT();
	AUX_PWR_GPIO_OFF();		

	BT_GPIO_CTRL_INIT();
	BT_PWR_GPIO_OFF();	
}
// Main program: Counting on T1
int main( void )
{
	DDRB = 0xFF;					// set PORTB for compare output 
	timer1Init();
	wait(100);

	while (1)
	{
		int delta = 1;
		setRed (0);

		// change some colors
		// RED
		for (int red = 0; red<=255; red+=delta)
		{
			setRed( red );
			setBlue(255-red);				// 8-bits PWM on pin OCR1a 
			delta += 2;					// progressive steps up
			wait(100);					// delay of 100 ms (busy waiting)
		}
		for (int red = 255; red>=0; red-=delta)
		{
			setRed( red );				// 8-bits PWM on pin OCR1a 
			setGreen(255-red);
			delta -= 2;					// progressive steps down
			wait(100);					// delay of 100 ms (busy waiting)
		}
		for (int green = 0; green<=255; green+=delta)
		{
			setGreen( 255-green );
			setBlue(green);				// 8-bits PWM on pin OCR1a
			delta += 2;					// progressive steps up
			wait(100);					// delay of 100 ms (busy waiting)
		}
		setRed( 0 );
		delta = 1;
		wait(100);


		// RED
		for (int red = 0; red<=255; red+=delta)
		{
			setRed( red );				// 8-bits PWM on pin OCR1a
p
			wait(100);					// delay of 100 ms (busy waiting)
		}
		for (int red = 255; red>=0; red-=delta)
		{
			setRed( red );				// 8-bits PWM on pin OCR1a
			setGreen(255-red);
			delta -= 2;					// progressive steps down
			wait(100);					// delay of 100 ms (busy waiting)
		}
		// GREEN
		for (int gr = 0; gr<=255; gr+=delta) {
			setGreen(gr);
			wait(100);	 
		}
		for (int gr = 255; gr>=0; gr-=delta) {
			setGreen(gr);
			wait(100);
		}
		// BLUE
		for (int blue = 0; blue<=255; blue+=delta) {
			setBlue(blue);
			wait(100);
		}
		for (int blue = 255; blue>=0; blue-=delta) {
			setBlue(blue);
			wait(100);
		}


		// YELLOW
		// for (int yellow= 0; yellow<=255; yellow += delta)
		// . . .


		// WHITE
		// for (int white = 0; white<=255; white += delta)
		// . . .
	} 
}