コード例 #1
0
ファイル: flgmain.c プロジェクト: EmbeddedLinuxGuy/flg
int main(void)
{
	cli();

	flg_hw_setup();
#if (FOSC == 18432000UL)
	/*
	 * Fosc = 18432000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 180;
	 */
	set_timer2(_BV(CS22) | _BV(CS20), 180);
#elif (FOSC == 7372800UL)
	/*
	 * Fosc = 7372800
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 72;
	 */
	set_timer2(_BV(CS22) | _BV(CS20), 72);
#else
#error "FLGMAIN: unsupported FOSC freq"
#endif
	config_init();
	uart_init(uart_baud(FOSC, 115200));

	flg_proto.handlers->set_addr = &flg_set_addr;
	flg_proto.handlers->send = &flg_queue_pkt;
	proto_init(&flg_proto, config.addr);

	sei();

	wdt_enable(WDTO_1S);

	while (1) {
		flg_work();
	}
}
コード例 #2
0
ファイル: main.C プロジェクト: eunwho/lcdConverter
void PowerOnSetProc()
{		 	
	port_b_pullups(TRUE);	output_b(0xff); output_c(0xff);		
	
	set_tris_A(0b00000011);	set_tris_B(0b01111111);

	set_tris_D(0b00000000);	set_tris_E(0b00000000);
	
	set_tris_C(0b10010000);
	
	setup_adc_ports(NO_ANALOGS);
	setup_adc(ADC_OFF);

	setup_comparator(NC_NC_NC_NC);
	setup_vref(FALSE);
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

	setup_timer_2(T2_DIV_BY_4,250,2);		 // 8,000,000 / (4 * 8 * (249 +1)) = 1,000 = 1/1000 sec
	set_timer2(0);
	enable_interrupts(INT_TIMER2);
	
	// LCD 초기화 하기 전에 대기 없으면 이상한 현상이 생김  
	delay_ms(100); 

	LCD_Initialization();				

	setup_psp(PSP_DISABLED);	
	delay_ms(250);
	SerialPortSetup();	

	LCD_Clear();
	enable_interrupts(INT_RDA);	
	enable_interrupts(GLOBAL);	

             //"01234567890123456789"
	strcpy(st, "DIGITAL OPERAT      "); PrintLCD(0,0,st);
	strcpy(st, "[EwDo-21] v2.60     "); PrintLCD(1,0,st);
	strcpy(st, "EunWho Power Electic"); PrintLCD(2,0,st);
	strcpy(st, "TEL 82-51-262-7532  "); PrintLCD(3,0,st);
	delay_ms(3250);
	delay_ms(3250);
}
コード例 #3
0
ファイル: main.c プロジェクト: claudioasfilho/Original
void  EXT_isr(void) 
{
	// This interrupt should fire when a keep alive pulse is received from the 3219. We will then set this port to an output, write some bits, set it back to an input and restart timer2.  If the 
	//	3219 does not pull it low before timer2 expires then we will reset the board
	extintcounter += 1;
	
	clear_interrupt(INT_EXT);																//clear external interrupt flag
	clear_interrupt(INT_TIMER2);															//clear timer2 interrupt flag

	if (timer2counter == 0) {																//Then this the first time EXT interrupt has fired
		printf("\r\n3219 Watchdog start detected\n");
		Timeout3219 = 0;																	//Clear the status bit that indicates the 3219 communicated in time
		enable_interrupts(INT_TIMER2);														//start timer2 interrupt for 3219 watchdog
		timer2counter = 1;																	//reset timer overlap counter
	}
	
	set_timer2(0);																			//reset timer2
	timer2counter = 1;																		//reset timer overlap counter
	
	//Write something back out this pin
}
コード例 #4
0
ファイル: servo4.c プロジェクト: omnister/velo
void init() {
   unsigned int16 i;

   blink();

   init_queue(&rxque0);
   init_queue(&txque0);

   set_step(1);		// 0=full, 1=1/2, 5=1/4, 4=1/8, 7=1/16
   enable(1);

   //setup_counters(T0_INTERNAL, T0_DIV_1 | T0_8_BIT);
   setup_counters(T0_INTERNAL, T0_DIV_2 | T0_8_BIT);

   set_timer0(0);

   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   output_bit(CTS,0);		// ready to receive from usb
   output_bit(STROBE,1);	// parallel port strobe

   // input(PIN_C3);		// ESTOP
   input(PIN_C4);		// ALIM
   input(PIN_C0);		// XLIM
   input(PIN_C1);		// YLIM
   
   // input(PIN_C2);		// ZLIM
   output_bit(PIN_C2,0);	// changed from ZLIM to PWM OUTPUT

   setup_ccp1(CCP_PWM);
   setup_timer_2(T2_DIV_BY_16, 255, 1); // mode, period, postscale
   set_timer2(0);
   set_pwm1_duty(0);		// duty cycle is val/(4*(255+1))
}
コード例 #5
0
ファイル: main.c プロジェクト: jmesmon/reefdemon
int main(void)
{
	uint8_t last_min = 0;
	cli();

	DDRC = _BV(C_SCL);

	DDRD = _BV(D_LCD_BL) | _BV(D_LCD_SEL) | _BV(D_LCD_SCK) |
		_BV(D_LCD_MOSI) | _BV(D_LCD_RESET) | _BV(D_ALERT);

#if (FOSC == 18432000UL)
	/*
	 * Fosc = 18432000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 180;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 180);
#elif (FOSC == 7372800UL)
	/*
	 * Fosc = 7372800
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 72;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 72);
#elif (FOSC == 16000000UL)
	/*
	 * Fosc = 16000000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 156;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 156);
#else
#error "unsupported FOSC freq"
#endif

	twi_master_init();
	twi_add_device(rtc_begin, rtc_end);
	twi_add_device(relay_begin, relay_end);
	sei();

	lcd_init();
	lcd_fill(0, 0, 131, 131, 0x000);

	ow_init();
	ds18b20_init();
	adc_sample();

	set_point = 25 << 8;

	while (1) {
		ds18b20_ping();

		if (last_min != time[1]) {
			temp_history[temp_history_idx] = ds18b20_temps[1];
			temp_history_idx++;
			if (temp_history_idx == ARRAY_SIZE(temp_history))
				temp_history_idx = 0;
			last_min = time[1];
		}

		if (ph == 0) {
			ph = (uint32_t)adc_data[2] << PH_IIR_SHIFT;
		} else {
			ph -= ph >> PH_IIR_SHIFT;
			ph += adc_data[2];
		}

		ui();

		if (alert)
			PORTD |= _BV(D_ALERT);
		else
			PORTD &= ~_BV(D_ALERT);

		cli();
		if (ds18b20_temps[1] < set_point)
			relays &= ~0x1;
		else if(ds18b20_temps[1] > (set_point + (1 << 4)))
			relays |= 0x1;
		sei();
	}

}