Ejemplo n.º 1
0
Archivo: lcd.c Proyecto: Micha500/gt3b
// send cnt bits to LCD controller, only low bits of "bits" are used
// use timer4 to get 600kHz clock for driving WR/ signal
// timer is used in one-pulse mode and is started after each WR/ change,
//   so there will always be minimal required length of pulse also
//   when interrupted by some interrupt
static void lcd_send_bits(u8 cnt, u16 bits) {
    // shift bits to high-bits
    bits <<= (u8)(16 - cnt);
    WR0;
    BSET(TIM4_CR1, 0);			// start timer
    WR0;				// optimize hack
    do {
	if (bits & 0x8000) {
	    DATA1;
	}
	else {
	    DATA0;
	}
	bits <<= 1;			// to next bit
	while (!BCHK(TIM4_SR, 0));	// wait for timer
	WR1;
	BRES(TIM4_SR, 0);		// clear intr flag
	BSET(TIM4_CR1, 0);		// start timer
	if (!--cnt)  break;
	while (!BCHK(TIM4_SR, 0));	// wait for timer
	WR0;
	BRES(TIM4_SR, 0);		// clear intr flag
	BSET(TIM4_CR1, 0);		// start timer
    } while (1);
    while (!BCHK(TIM4_SR, 0));		// wait for timer
    BRES(TIM4_SR, 0);			// clear intr flag
}
Ejemplo n.º 2
0
Archivo: input.c Proyecto: eknl/gt3b
static void input_loop(void) {

    // read initial ADC values
    BSET(ADC_CR1, 0);			// start conversion
    while (!BCHK(ADC_CSR, 7))  pause();	// wait for end of conversion
    read_ADC();

    // put initial values to all buffers
    ADC_BUFINIT(0);
    ADC_BUFINIT(1);
    ADC_BUFINIT(2);
    adc_battery = adc_battery_last;
    adc_battery_filt = (u32)adc_battery * ADC_BAT_FILT;

    // task CALC must be awaked to compute values before PPM will take on
    awake(CALC);
    input_initialized = 1;

    while (1) {
	// read ADC only when EOC flag (only for first it will not be ready)
	if (BCHK(ADC_CSR, 7))
	    read_ADC();
	read_keys();
	stop();
    }
}