Esempio n. 1
0
void ckps_init_state_variables(void)
{
 _BEGIN_ATOMIC_BLOCK();

 hall.stroke_period = 0xFFFF;
 hall.advance_angle = HALL_ADVANCE; //=0

 CLEARBIT(flags, F_STROKE);
 CLEARBIT(flags, F_VHTPER);
 CLEARBIT(flags, F_HALLEV);
 CLEARBIT(flags, F_SPSIGN);
 SETBIT(flags2, F_SHUTTER);
 SETBIT(flags2, F_SHUTTER_S);
 SETBIT(flags, F_IGNIEN);

 TCCR0 = 0; //timer is stopped (останавливаем таймер0)

 MCUCR|=_BV(ISC11); //falling edge for INT1
 MCUCR|=_BV(ISC10);

 TIMSK|=_BV(TOIE1);                   //enable Timer 1 overflow interrupt. Used for correct calculation of very low RPM
 hall.t1oc = 0;                       //reset overflow counter
 hall.t1oc_s = 255;                   //RPM is very low

#ifdef STROBOSCOPE
 hall.strobe = 0;
#endif

 hall.knkwnd_mode = 0;
 _END_ATOMIC_BLOCK();
}
Esempio n. 2
0
void Button_SingleInit(sButtonPinPort buttonPinPort)
{
#ifdef __AVR__
#if defined (__AVR_ATmega16__)
	if(buttonPinPort.port == &PINA)
	{
		CLEARBIT(DDRA, buttonPinPort.pin);
		SETBIT(PORTA, buttonPinPort.pin);
	}
#else
   if(0)
   {
   }
#endif
	else if(buttonPinPort.port == &PINB)
	{
		CLEARBIT(DDRB, buttonPinPort.pin);
		SETBIT(PORTB, buttonPinPort.pin);
	}
	else if(buttonPinPort.port == &PINC)
	{
		CLEARBIT(DDRC, buttonPinPort.pin);
		SETBIT(PORTC, buttonPinPort.pin);
	}
	else if(buttonPinPort.port == &PIND)
	{
		CLEARBIT(DDRD, buttonPinPort.pin);
		SETBIT(PORTD, buttonPinPort.pin);
	}
#endif	
}
Esempio n. 3
0
void ckps_init_state(void)
{
 _BEGIN_ATOMIC_BLOCK();

 if ((IOCFG_CB(IOP_CKPS) == (fnptr_t)iocfg_g_ckps) || (IOCFG_CB(IOP_CKPS) == (fnptr_t)iocfg_g_ckpsi))
 {
  CLEARBIT(flags2, F_SELEDGE); //falling edge
  hall.ckps_inpalt = 1; //not remapped
 }
 else
  hall.ckps_inpalt = 0; //CKPS mapped on other input

 ckps_init_state_variables();
 CLEARBIT(flags, F_ERROR);

 //Compare channels do not connected to lines of ports (normal port mode)
 //(Каналы Compare не подключены к линиям портов (нормальный режим портов))
 TCCR1A = 0;

 TCCR1B = _BV(CS11)|_BV(CS10);  //Tune timer 1 (clock = 312.5 kHz)
 TCCR0B = _BV(CS01)|_BV(CS00);  //Tune timer 0 (clock = 312.5 kHz)

 if (hall.ckps_inpalt)
  TIMSK1|=_BV(ICIE1);    //enable input capture interrupt only if CKPS is not remapped
 _END_ATOMIC_BLOCK();
}
Esempio n. 4
0
void ckps_init_state_variables(void)
{
 _BEGIN_ATOMIC_BLOCK();

 hall.stroke_period = 0xFFFF;
 hall.advance_angle = hall.shutter_wnd_width; //=0

 CLEARBIT(flags, F_STROKE);
 CLEARBIT(flags, F_VHTPER);
 CLEARBIT(flags, F_HALLEV);
 CLEARBIT(flags, F_SPSIGN);
 SETBIT(flags, F_IGNIEN);
 SETBIT(flags2, F_SHUTTER);
 SETBIT(flags2, F_SHUTTER_S);

 TIMSK1|=_BV(TOIE1);                  //enable Timer 1 overflow interrupt. Used for correct calculation of very low RPM

 hall.t1oc = 0;                       //reset overflow counter
 hall.t1oc_s = 255;                   //RPM is very low

#ifdef STROBOSCOPE
 hall.strobe = 0;
#endif

 hall.knkwnd_mode = 0;
#ifdef DWELL_CONTROL
 hall.cr_acc_time = 0;
#endif

#ifdef FUEL_INJECT
 hall.cur_chan = 0;
#endif
 _END_ATOMIC_BLOCK();
}
void touch_init(){//uint8_t chan){
    //set up the I/O pins E1, E2, E3 to be output pins
    CLEARBIT(TRISEbits.TRISE1); //I/O pin set to output
    CLEARBIT(TRISEbits.TRISE2); //I/O pin set to output
    CLEARBIT(TRISEbits.TRISE3); //I/O pin set to output

    // ADC init
    //disable ADC
    CLEARBIT(AD1CON1bits.ADON);
    //initialize PIN
    SETBIT(TRISBbits.TRISB15); //set TRISE RB15 to input
    SETBIT(TRISBbits.TRISB9); //set TRISE RB9 to input
    SETBIT(AD1PCFGLbits.PCFG15); // RB15 analog ADC1CH15
    SETBIT(AD1PCFGLbits.PCFG9); // RB9 analog ADC1CH9
    //Configure ADxCON1
    SETBIT(AD1CON1bits.AD12B); //set 12b Operation Mode
    AD1CON1bits.FORM = 0; //set integer output
    AD1CON1bits.SSRC = 0x7; //set automatic conversion
    //Configure ADxCON2
    AD1CON2 = 0; //not using scanning sampling
    //Configure ADxCON3
    CLEARBIT(AD1CON3bits.ADRC); //internal clock source
    AD1CON3bits.SAMC = 0x1F; //sample-to-conversion clock = 31Tad
    AD1CON3bits.ADCS = 0x2; //Tad = 3Tcy (Time cycles)
    //Leave ADxCON4 at its default value
    //enable ADC
    SETBIT(AD1CON1bits.ADON);
}
Esempio n. 6
0
/**
 * set a single port to Output or Input - function requrired for wiringPi interface
 * @param pin - port relative to pinBase
 * @param newMode - 0 - Output; 1 - Input
 * @return new value of complete port
 */
int Max7312::configPort(int pin, bool newMode){
   if (isLowerPort(pin)) {
      if(newMode)
      {
         SETBIT(_port1_mode, (GET_LOWER_PIN_ID(pin)));
      }
      else
      {
         CLEARBIT(_port1_mode, (GET_LOWER_PIN_ID(pin)));
      }
      configPort1(_port1_mode);
      return _port1_mode;
   } else {
      if(newMode)
      {
         SETBIT(_port2_mode, (GET_HIGHER_PIN_ID(pin)));
      }
      else
      {
         CLEARBIT(_port2_mode, (GET_HIGHER_PIN_ID(pin)));
      }
      configPort2(_port2_mode);
      return _port2_mode;
   }
}
void touch_select_dim(uint8_t dim){
    /*
    if (dim == 1){ // x
        //set up the I/O pins E1, E2, E3 so that the touchscreen X-coordinate pin
        //connects to the ADC
        CLEARBIT(PORTEbits.RE1);
        SETBIT(PORTEbits.RE2);
        SETBIT(PORTEbits.RE3);
    }else if (dim == 2){ // y
        SETBIT(PORTEbits.RE1);
        CLEARBIT(PORTEbits.RE2);
        CLEARBIT(PORTEbits.RE3);
    } else{
        SETBIT(PORTEbits.RE1);
        SETBIT(PORTEbits.RE2);
        CLEARBIT(PORTEbits.RE3);
    }
    */
    if (dim == 1){ // x
        //set up the I/O pins E1, E2, E3 so that the touchscreen X-coordinate pin
        //connects to the ADC
        CLEARBIT(LATEbits.LATE1);
        SETBIT(LATEbits.LATE2);
        SETBIT(LATEbits.LATE3);
    }else if (dim == 2){ // y
        SETBIT(LATEbits.LATE1);
        CLEARBIT(LATEbits.LATE2);
        CLEARBIT(LATEbits.LATE3);
    } else{
        SETBIT(LATEbits.LATE1);
        SETBIT(LATEbits.LATE2);
        CLEARBIT(LATEbits.LATE3);
    }
}
Esempio n. 8
0
static void key(byte mode) 
/*! 
 @brief     Keys the transmitter and produces a sidetone
 
 .. but only if the corresponding functions (TXKEY and SIDETONE) have been set in
 the feature register. This function also handles a request to invert the keyer line
 if necessary (TXINV bit).
 
 This is a private function.

 @param mode    UP or DOWN
 
 */
{
	
    if (mode == DOWN) 
    {
        if (volflags & SIDETONE) // Are we generating a Sidetone?
        {
            OCR0A = ctcvalue;		// Then switch on the Sidetone generator
            OCR0B = ctcvalue;
            
            // Activate CTC mode
            TCCR0A |= (1<<COM0B0 | 1<<WGM01);
            
            // Configure prescaler
            TCCR0B = 1<<CS01;
        }
        
        if (volflags & TXKEY) // Are we keying the TX?
        {
            if (yackflags & TXINV) // Do we need to invert keying?
                CLEARBIT(OUTPORT,OUTPIN);
            else
                SETBIT(OUTPORT,OUTPIN);
        }

    }
    
    if (mode == UP) 
    {

        if (volflags & SIDETONE) // Sidetone active?
        {
            TCCR0A = 0;
            TCCR0B = 0;
        }
        
        if (volflags & TXKEY) // Are we keying the TX?
        {
            if (yackflags & TXINV) // Do we need to invert keying?
                SETBIT(OUTPORT,OUTPIN);
            else
                CLEARBIT(OUTPORT,OUTPIN);
        }

    }
    
}
Esempio n. 9
0
File: main.c Progetto: jaseg/avr-uip
void timedAlarmCheck(void)
{
	for (uint8_t alarm=1; alarm<=4; alarm++)
	{
		uint16_t pos = 400 + ((alarm-1)*15); //400 415 430 445

		if (eepromReadByte(pos+0) == 1)
		{
				uint8_t sensorpos = findSensor(
				eepromReadByte(pos+1),
				eepromReadByte(pos+2),
				eepromReadByte(pos+3),
				eepromReadByte(pos+4),
				eepromReadByte(pos+5),
				eepromReadByte(pos+6),
				eepromReadByte(pos+7),
				eepromReadByte(pos+8));

				int8_t value = (int8_t)sensorValues[(sensorpos*SENSORSIZE)+VALUE1];
				char sign = sensorValues[(sensorpos*SENSORSIZE)+SIGN];
				if (sign == '-') value *= -1;

				int8_t target = eepromReadByteSigned(pos+10);

				if (
					(eepromReadByte(pos+9) == 1 && value < target)
					||
					(eepromReadByte(pos+9) == 2 && value == target)
					||
					(eepromReadByte(pos+9) == 3 && value > target)
				)
				{
					//ALARM
					//DDR=in/out PIN=value/pullup PORT=state
					uint8_t pin = eepromReadByte(pos+11);

					if (pin >= 1 && pin <= 4)
					{
						if (eepromReadByte(pos+12) == 1)
						{
							SETBIT(PORTC, (1+pin));
						}
						else
							CLEARBIT(PORTC, (1+pin));
					}
 				} else if (eepromReadByte(pos+13) == 1) {
 					//REVERSE
					uint8_t pin = eepromReadByte(pos+11);
					if (pin >= 1 && pin <= 4)
					{
						if (eepromReadByte(pos+12) == 1)
							CLEARBIT(PORTC, (1+pin));
						else
							SETBIT(PORTC, (1+pin));
					}
 				}
		}
	}
}
Esempio n. 10
0
void main(){
	//Init LCD
	__C30_UART=1;	
	lcd_initialize();
	lcd_clear();
        touch_init();

        CLEARBIT(T1CONbits.TON); // Disable Timer
        CLEARBIT(T1CONbits.TCS); // Select internal instruction cycle clock
        CLEARBIT(T1CONbits.TGATE); // Disable Gated Timer mode
        TMR1 = 0x00; // Clear timer register
        T1CONbits.TCKPS = 0b10; // Select 1:64 Prescaler
        PR1 = 2000; // Load the period value
        IPC0bits.T1IP = 0x01; // Set Timer1 Interrupt Priority Level
        CLEARBIT(IFS0bits.T1IF); // Clear Timer1 Interrupt Flag
        SETBIT(IEC0bits.T1IE); // Enable Timer1 interrupt



        while(1) {
            int i = 0;

            
            
            touch_select_dim(0);
            lock = 1;
            TMR1 = 0x00;
            SETBIT(T1CONbits.TON); // Start Timer
            while(lock);
            
            for (i = 0; i < 5; i++) {
                xs[i] = touch_adc();
            }

            // read y
            touch_select_dim(1);
            lock = 1;
            TMR1 = 0x00;
            SETBIT(T1CONbits.TON); // Start Timer
            while(lock);
            for (i = 0; i < 5; i++) {
                ys[i] = touch_adc();
            }

            

            qsort(xs, 5, sizeof(uint16_t), cmpfunc);
            qsort(ys, 5, sizeof(uint16_t), cmpfunc);

            lcd_locate(0,0);
            lcd_printf("x position:             ");
            lcd_locate(0,0);
            lcd_printf("x position: %d", xs[2]);
            lcd_locate(0,1);
            lcd_printf("y position:             ");
            lcd_locate(0,1);
            lcd_printf("y position: %d", ys[2]);
        }
}
void lcd_spi_transmit_CMD(unsigned char temp){
   CLEARBIT(PORTB,RS);
   CLEARBIT(PORTB,SS_bar);
   SPDR = temp;
   while(!TESTBIT(SPSR,SPIF));
   SPSR &= 0x7F;
   SETBIT(PORTB, SS_bar);
 }
Esempio n. 12
0
/*!
 * \brief   sends a chunk of data and does not block
 * \param   thisport = which port to use
 * \param	data = pointer to data to send
 * \param	length = number of bytes to send
 * \return	SSP_TX_BUFOVERRUN = tried to send too much data
 * \return	SSP_TX_WAITING = data sent and waiting for an ack to arrive
 * \return	SSP_TX_BUSY = a packet has already been sent, but not yet acked
 *
 * \note
 *
 */
int16_t qssp::ssp_SendData(const uint8_t *data, const uint16_t length )
{

    int16_t value = SSP_TX_WAITING;

    if( (length + 2) > thisport->txBufSize ) {
        // TRYING to send too much data.
        value = SSP_TX_BUFOVERRUN;
    } else if( thisport->SendState == SSP_IDLE ) {
#ifdef ACTIVE_SYNCH
        if( thisport->sendSynch == TRUE )  {
            sf_SendSynchPacket();
        }
#endif

#ifdef SYNCH_SEND
        if( length == 0 ) {
            // TODO this method could allow a task/user to start a synchronisation step if a zero is mistakenly passed to this function.
            //      could add a check for a NULL data pointer, or use some sort of static flag that can only be accessed by a static function
            //      that must be called before calling this function.
            // we are attempting to send a synch packet
            thisport->txSeqNo = 0;                        // make this zero to cause the other end to re-synch with us
            SETBIT(thisport->flags, SENT_SYNCH);
        } else {
            // we are sending a data packet
            CLEARBIT( thisport->txSeqNo, ACK_BIT );     // make sure we are not sending a ACK packet
            thisport->txSeqNo++;                        // update the sequence number.
            if( thisport->txSeqNo > 0x7F) {             // check for sequence number rollover
                thisport->txSeqNo = 1;                  // if we do have rollover then reset to 1 not zero,
                // zero is reserviced for synchronization requests
            }
        }

#else
        CLEARBIT( thisport->txSeqNo, ACK_BIT );     // make sure we are not sending a ACK packet
        thisport->txSeqNo++;                        // update the sequence number.
        if( thisport->txSeqNo > 0x7F) {             // check for sequence number rollover
            thisport->txSeqNo = 1;                  // if we do have rollover then reset to 1 not zero,
            // zero is reserved for synchronization requests
        }
#endif
        CLEARBIT( thisport->flags, ACK_RECEIVED);
        thisport->SendState = SSP_AWAITING_ACK;
        value = SSP_TX_WAITING;
        thisport->retryCount = 0;				// zero out the retry counter for this transmission
        sf_MakePacket( thisport->txBuf, data, length, thisport->txSeqNo );
        sf_SendPacket( );				// punch out the packet to the serial port
        sf_SetSendTimeout(  );	// do the timeout values
         if (debug)
             qDebug()<<"Sent DATA PACKET:"<<thisport->txSeqNo;
    } else {
        // error we are already sending a packet. Need to wait for the current packet to be acked or timeout.
        value = SSP_TX_BUSY;
         if (debug)
             qDebug()<<"Error sending TX was busy";
    }
    return value;
}
Esempio n. 13
0
void led_init(void)
{
  LEDDIR |= _BV(LEDBIT);

  CLEARBIT(PINSEL1, 28);
  CLEARBIT(PINSEL1, 29);

  led_off();
}
/*
;*********************************
 NAME:       lcd_spi_transmit_DATA
 ASSUMES:    temp = byte to transmit to LCD.
             SPI port is configured.
 RETURNS:    nothing
 MODIFIES:   temp, SPCR
 CALLED BY:  init_dsp, update
 DESCRITION: outputs a byte passed in r16 via SPI port. Waits for
             data to be written by spi port before continuing.
 *****************************************************************
 */
  void lcd_spi_transmit_DATA(unsigned char data){
    PORTB = (1 << RS);
    CLEARBIT(PORTB, SS_bar);
    CLEARBIT(SPSR, SPIF);
    SPDR = data;
    while(!TESTBIT(SPSR,SPIF));
    SPSR &= 0x7F;
    SETBIT(PORTB, SS_bar);
  }
Esempio n. 15
0
//intialize
void initialize(void){
    size_t i;
    //bit-array set to one
    for (i = 0; i < size; i++ ){
        SETBIT(threadstack, i);
    }
    CLEARBIT(threadstack, 0);
    CLEARBIT(threadstack, 1);
    //http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html
    
}
Esempio n. 16
0
void kbd_scan(void)
{
	uint8_t	kbd_value;
	uint8_t	key_id;

	kbd_value = KBD_PORT;
	for (key_id = 0; key_id < 8; key_id++)
	{
		if (TESTBIT(kbd_value_1, key_id) && 
			TESTBIT(kbd_value_2, key_id) &&
			!TESTBIT(kbd_value, key_id))
			
			CLEARBIT(kbd_value_1, key_id);
			
		else if (!TESTBIT(kbd_value_1, key_id) && //key pressed
			TESTBIT(kbd_value_2, key_id) &&
			!TESTBIT(kbd_value, key_id))
		{
			CLEARBIT(kbd_value_2, key_id);
		}
		else if (!TESTBIT(kbd_value_1, key_id) && 
			TESTBIT(kbd_value_2, key_id) &&
			TESTBIT(kbd_value, key_id))
			 
			SETBIT(kbd_value_1, key_id);
			
		else if (!TESTBIT(kbd_value_1, key_id) && 
			!TESTBIT(kbd_value_2, key_id) &&
			TESTBIT(kbd_value, key_id))
			 
			SETBIT(kbd_value_1, key_id);
			
		else if (TESTBIT(kbd_value_1, key_id) && 
			!TESTBIT(kbd_value_2, key_id) &&
			!TESTBIT(kbd_value, key_id))
			 
			CLEARBIT(kbd_value_1, key_id);

		else if (TESTBIT(kbd_value_1, key_id) && // key released
			!TESTBIT(kbd_value_2, key_id) &&
			TESTBIT(kbd_value, key_id))
		{	 
			SETBIT(kbd_value_2, key_id);
			
			SETBIT(key_pressed, key_id);
		}
		else if (!TESTBIT(kbd_value_1, key_id) && // key still pressed
			!TESTBIT(kbd_value_2, key_id) &&
			!TESTBIT(kbd_value, key_id))
		{	 
		}
	}
}
Esempio n. 17
0
void tlc5940_init(void)
{
	//enable clocks to GPIO block
	LPC_SYSCON->SYSAHBCLKCTRL |= (1UL <<  6);

	INIT_GPIO(SCLK_PORT, SCLK);
	INIT_GPIO(XLAT_PORT, XLAT);
	INIT_GPIO(SIN_PORT, SIN);
	//INIT_GPIO(GSCLK_PORT, GSCLK);
	//INIT_GPIO(DCPRG_PORT, DCPRG);
	//INIT_GPIO(VPRG_PORT, VPRG);
	INIT_GPIO(BLANK_PORT, BLANK);

	CLEARBIT(SCLK_PORT, SCLK);
	CLEARBIT(XLAT_PORT, XLAT);
	CLEARBIT(SIN_PORT, SIN); 
	//CLEARBIT(GSCLK_PORT, GSCLK); 
	//CLEARBIT(DCPRG_PORT, DCPRG);
	//SETBIT(VPRG_PORT, VPRG);
	SETBIT(BLANK_PORT, BLANK);

	/* Init IOCON - Nothing works without this... */
	LPC_SYSCON->SYSAHBCLKCTRL |= (1 <<  16);

	/* TMR16B1 -- GSCLK Generator */	
//	LPC_SYSCON->SYSAHBCLKCTRL |=  (1<<8);             	// Enable Clock for TMR1
//	LPC_IOCON->PIO1_9 |= (1<<0);
//	LPC_TMR16B1->MR0 = 118;					//Fire Interrupt each .02 second (20 ms or 50 Hz)
//	LPC_TMR16B1->PR = 1;							  	
//	LPC_TMR16B1->EMR |= (3<<4);							//Toggle on MR0
//	LPC_TMR16B1->MCR |= (1<<1);							//Reset on MR0	  
//  	LPC_TMR16B1->TCR |= (1<<0);                        	// GO
	

	/* TMR16B0 -- Interrupt timer */	
	LPC_SYSCON->SYSAHBCLKCTRL |=  (1<<7);             	// Enable Clock for TMR0
	//LPC_IOCON->PIO1_9 |= (1<<0);
	LPC_TMR16B0->MR2 = 20000;							//Fire Interrupt each .02 second (20 ms or 50 Hz)
	LPC_TMR16B0->PR = 48;							  	
	LPC_TMR16B0->MCR |= (1<<6);							//Interrupt on MR2
	LPC_TMR16B0->MCR |= (1<<7);							//Reset on MR2
	NVIC_EnableIRQ(TIMER_16_0_IRQn);         			//enable interrupt 	  
  	LPC_TMR16B0->TCR |= (1<<0);                        	// GO	

	/* GS CLK */
	LPC_SYSCON->CLKOUTDIV = 59;
	LPC_SYSCON->CLKOUTCLKSEL = 0;
	LPC_SYSCON->CLKOUTUEN = 0;
	LPC_SYSCON->CLKOUTUEN = 1;

	LPC_IOCON->PIO0_1 |= (1<<0);
}
Esempio n. 18
0
void	shift_init(void)
{
	SETBIT(SHIFT_OUT_DDR, SHIFT_OUT_BIT);
	SETBIT(SHIFT_CLK_DDR, SHIFT_CLK_BIT);
	SETBIT(SHIFT_LATCH_DDR, SHIFT_LATCH_BIT);
	CLEARBIT(SHIFT_OUT_PORT, SHIFT_OUT_BIT);
	CLEARBIT(SHIFT_CLK_PORT, SHIFT_CLK_BIT);
	CLEARBIT(SHIFT_LATCH_PORT, SHIFT_LATCH_BIT);
	controls[0] = 0x00;
	controls[1] = 0x00;
	old_controls[0] = 0xFF;
	old_controls[1] = 0xFF;	
}
Esempio n. 19
0
void TIMER16_0_IRQHandler(void)
{
	//Make sure interrupt flag is set -- not sure if needed
	if(LPC_TMR16B0->IR & (1<<2))
	{
		uint8_t first_cycle = 0;
		uint8_t data_count = 0;
		uint16_t tmp;
							
		LPC_IOCON->PIO0_1 &= ~(1<<0);
		SETBIT(BLANK_PORT, BLANK);

//		if(CHECKBIT(VPRG_PORT, VPRG))
//		{
//			CLEARBIT(VPRG_PORT, VPRG);
//			first_cycle = 1;
//		}

		if(xlat_pulse)
		{
			PULSE(XLAT_PORT, XLAT);
			xlat_pulse = 0;
		}

		if(first_cycle)
			PULSE(SCLK_PORT, SCLK);
	
		CLEARBIT(BLANK_PORT, BLANK);
		LPC_IOCON->PIO0_1 |= (1<<0);
		while(1)
		{
		 	if(data_count < NUM_TLC5940 * NUM_SIN_BITS)
			{
				tmp = pwm[data_count/12];
				tmp &= BV(11 - (data_count%12));
			 	if(tmp)
				//if(gsdata[data_count])
					SETBIT(SIN_PORT, SIN);
				else
					CLEARBIT(SIN_PORT, SIN);

				PULSE(SCLK_PORT, SCLK);
				data_count++;
			}else{
				xlat_pulse = 1;
				break;
			}
		}
		LPC_TMR16B0->IR |= (1<<2);
	}
}
Esempio n. 20
0
short SqAtakd (short sq, short side)
/**************************************************************************
 *
 *  To determine if sq is attacked by any pieces from side.
 *
 **************************************************************************/
{
   register BitBoard *a, b, *c, d, blocker;
   int t;
   
   a = board.b[side];

   /* Knights */
   if (a[knight] & MoveArray[knight][sq])
      return (true);

   /* Kings */
   if (a[king] & MoveArray[king][sq])
      return (true);

   /* Pawns */
   if (a[pawn] & MoveArray[ptype[1^side]][sq])
      return (true);
      
   c = FromToRay[sq];
   blocker = board.blocker;

   /* Bishops & Queen */
   b = (a[bishop] | a[queen]) & MoveArray[bishop][sq];
   d = ~b & blocker; 
   while (b)
   {
      t = leadz (b);
      if (!(c[t] & d))
         return (true);
      CLEARBIT (b, t); 
   }

   /* Rooks & Queen */
   b = (a[rook] | a[queen]) & MoveArray[rook][sq];
   d = ~b & blocker;
   while (b)
   {
      t = leadz (b);
      if (!(c[t] & d))
         return (true);
      CLEARBIT (b, t); 
   }
   return (false);
}
// Configure the real-time task timer and its interrupt.
void timers_initialize() {

  //Set Timer1 to generate an interrupt every 10ms (100Hz) ==> PR1=500
  CLEARBIT(T1CONbits.TON); //Disable Timer
  CLEARBIT(T1CONbits.TCS); //Select internal instruction cycle clock
  CLEARBIT(T1CONbits.TGATE); //Disable Gated Timer mode
  T1CONbits.TCKPS = 0b11; //Select 1:256 Prescaler
  PR1 = 500; //Load the period value ==> running at 100Hz now!
  TMR1 = 0x00; //Clear timer register
  IPC0bits.T1IP = 0x01; // Set Timer1 Interrupt Priority Level
  CLEARBIT(IFS0bits.T1IF); // Clear Timer1 Interrupt Flag
  SETBIT(IEC0bits.T1IE); // Enable Timer1 interrupt
  SETBIT(T1CONbits.TON); // Start Timer
}
Esempio n. 22
0
void touch_select_dim(uint8_t dim) {
    if (dim == 0) {
        // x dim
        CLEARBIT(LATEbits.LATE1);
        SETBIT(LATEbits.LATE2);
        SETBIT(LATEbits.LATE3);
        AD1CHS0bits.CH0SA = 0xF;
    } else {
        // ydim
        SETBIT(LATEbits.LATE1);
        CLEARBIT(LATEbits.LATE2);
        CLEARBIT(LATEbits.LATE3);
        AD1CHS0bits.CH0SA = 0x9;
    }
}
void uart2_init(uint16_t baud){
	// ==== Stop UART port
	CLEARBIT(U2MODEbits.UARTEN); //Disable UART for configuration
	// Disable Interrupts
	IEC1bits.U2RXIE = 0;
	IEC1bits.U2TXIE = 0;
	// Clear Interrupt flag bits
	IFS1bits.U2RXIF = 0;
	IFS1bits.U2TXIF = 0;
	// Set IO pins
	TRISFbits.TRISF4 = 1; //set as input UART2 RX pin
	TRISFbits.TRISF5 = 0; //set as output UART2 TX pin
	// baud rate
	// use the following equation to compute the proper
	// setting for a specific baud rate
	U2MODEbits.BRGH = 0; //Set low speed baud rate
	U2BRG = (uint32_t)800000 / baud -1; //Set the baudrate to be at 9600
	// Operation settings and start port
	U2MODE = 0; // 8-bit, no parity and, 1 stop bit
	U2MODEbits.RTSMD = 0; //select simplex mode
	U2MODEbits.UEN = 0; //select simplex mode
	U2MODE |= 0x00;
	U2MODEbits.UARTEN = 1; //enable UART

        //uint8_t c = 0;
        //while(U2STAbits.URXDA)
        //    c = U2RXREG & 0x00FF;

	U2STA = 0;
	U2STAbits.UTXEN = 1; //enable UART TX
        //U2STAbits.URXEN = 1; //enable UART RX
}
Esempio n. 24
0
uint8_t *WriteToNrf(uint8_t ReadWrite, uint8_t reg, uint8_t *val, uint8_t antVal)
{
	//ReadWrite --> "R" or "W", reg --> 'register', *val --> array with package, antVal --> number of int in array
	if(ReadWrite == W)//If it is in READMODE, then addr is already 0x00
	{
		reg = W_REGISTER + reg;
	}
	static uint8_t ret[32];	//Array to be returned in the end
	
	_delay_us(10);						//Delay for 10us
	CLEARBIT(PORTB,CSNPin);				//Set CSN Low - nRf starts listening for commands 10us after CSN Low
	_delay_us(12);						//Delay for 12us
	WriteReadByteSPI(reg);				//"reg" --> Set nRf to write or read mode
	_delay_us(10);
	
	for(int i = 0; i<antVal; i++)
	{
		if(ReadWrite == R && reg != W_TX_PAYLOAD)
		{
			//READ A REGISTRY
			ret[i] = WriteReadByteSPI(NOP);		//Send dummy Byte to read data
			_delay_us(10);
		}
		else
		{
			//Write to nRF
			WriteReadByteSPI(val[i]);			//Send command one at a time
			_delay_us(10);
		}
	}
	SETBIT(PORTB,CSNPin);		//nRf into IDLE with CSN HIGH
	return ret;					//Return the data read
}
Esempio n. 25
0
/*!
 * \brief   Runs the send process, checks for receipt of ack, timeouts and resends if needed.
 * \param   thisport = which port to use
 * \return  SSP_TX_WAITING - waiting for a valid ACK to arrive
 * \return  SSP_TX_TIMEOUT - failed to receive a valid ACK in the timeout period, after retrying.
 * \return  SSP_TX_IDLE    - not expecting a ACK packet (no current transmissions in progress)
 * \return  SSP_TX_ACKED   - valid ACK received before timeout period.
 *
 * \note
 *
 */
int16_t qssp::ssp_SendProcess( )
{
    int16_t value = SSP_TX_WAITING;

    if (thisport->SendState == SSP_AWAITING_ACK ) {
        if (sf_CheckTimeout() == TRUE) {
            if (thisport->retryCount < thisport->maxRetryCount) {
                // Try again
                sf_SendPacket();
                sf_SetSendTimeout();
                value = SSP_TX_WAITING;
            } else {
                // Give up, # of trys has exceded the limit
                value = SSP_TX_TIMEOUT;
                CLEARBIT( thisport->flags, ACK_RECEIVED);
                thisport->SendState = SSP_IDLE;
                if (debug)
                  qDebug()<<"Send TimeOut!";
            }
        } else {
            value = SSP_TX_WAITING;
        }
    } else if( thisport->SendState == SSP_ACKED ) {
        SETBIT( thisport->flags, ACK_RECEIVED);
        value = SSP_TX_ACKED;
        thisport->SendState = SSP_IDLE;
    } else {
        thisport->SendState = SSP_IDLE;
        value = SSP_TX_IDLE;
    }
    return value;
}
Esempio n. 26
0
char amdEraseSector(char sector){
	// to erase device you must execute the erase command sequence
	// DQ7 is data polling and DQ6 is toggle status bits.
	//refer to the table on page 9 to erase all sectors
	// Erase operation will take approx 8 seconds to run its 1 second per sector
	//65535bits 
	struct AMD_Settings *Point_AMD = &Data;
	uint32_t sector_erase=0; 
	

	AMD_DATA_DDR |= ALL_PORT_MASK;
	SETBIT(AMD_CTRL_PORT_WE, AMD_WE);
	AMD_CTRL_PORT_CEOE |= (1 << AMD_OE) & ~(1 << AMD_CE);
	CLEARBIT(AMD_CTRL_PORT_CEOE, AMD_CE);


	// SEND THE 5 Unlock commands 	
	AMD_Send_Command(AMD_DATA_MASK_AA, AMD_ADDR_MASK_555);
	AMD_Send_Command(AMD_DATA_MASK_55, AMD_ADDR_MASK_2AA);
	AMD_Send_Command(AMD_DATA_MASK_80, AMD_ADDR_MASK_555);
	AMD_Send_Command(AMD_DATA_MASK_AA, AMD_ADDR_MASK_555);
	AMD_Send_Command(AMD_DATA_MASK_55, AMD_ADDR_MASK_2AA);
	
	// Erase specific sectors 
	sector_erase = sector; 
	sector_erase <<= 16; 	
	AMD_Send_Command(AMD_DATA_MASK_30, sector_erase );
	_delay_ms(2);
	
	return;
}
Esempio n. 27
0
void ckps_init_state(void)
{
 _BEGIN_ATOMIC_BLOCK();
 ckps_init_state_variables();
 CLEARBIT(flags, F_ERROR);

 MCUCR|=_BV(ISC11); //falling edge for INT1
 MCUCR|=_BV(ISC10);

 //set flag indicating that Hall sensor input is available
 WRITEBIT(flags, F_HALLSIA, IOCFG_CHECK(IOP_PS));
 GICR|=  CHECKBIT(flags, F_HALLSIA) ? _BV(INT1) : 0; //INT1 enabled only when Hall sensor input is available

 //Compare channels do not connected to lines of ports (normal port mode)
 //(Каналы Compare не подключены к линиям портов (нормальный режим портов))
 TCCR1A = 0;

 //Tune timer 1 (clock = 250kHz)
 TCCR1B = _BV(CS11)|_BV(CS10);

 //enable overflow interrupt of timer 0
 //(разрешаем прерывание по переполнению таймера 0)
 TIMSK|= _BV(TOIE0);
 _END_ATOMIC_BLOCK();
}
Esempio n. 28
0
//seive function this takes only one argument because the create function allows only one parameter.
void *eratosthenes(void *threadnum){
    size_t i;
    size_t min;
    size_t max;
    size_t offset = 0;
    size_t ops = (long int)threadnum;
    long long z;
    
    
    for (i = 0; i < (ops+1); i++){
        max = offset + sieve[i];
        min = offset + 1;
        offset += sieve[i];
        if (sqrt(size) < max){
            max = sqrt(size);
        }
    }
    
    //http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
    for(i = min; i < (max+1); i++){
        if(TESTBIT(threadstack, i)){
            //z = i^2
            // all values that are mulitles of z should be marked
            for (z = i * i; z < size; z += i){
                if(TESTBIT(threadstack, z)){
                    CLEARBIT(threadstack, z);
                }
            }
        }
    }
    return 0;
}
Esempio n. 29
0
int main(void)
{
uint8_t p=0;
uint8_t value;
DDRB |= (1<<DDB0); //led
SETBIT(PORTB,0);

NRF_Init();
NRF_Config();
INT0_init();

NRF_Start_RX();

sei();

while(1)
{

if(p++%2)
{
CLEARBIT(PORTB, 0);
}
else
{ 
SETBIT(PORTB, 0);
}
_delay_ms(1000);


	
value=NRF_Read_Register_Value(STATUS);

}
	return 0;
}
Esempio n. 30
0
int32_t serdes777_rwbits(int32_t rwflag,void *ptr,int32_t len,HUFF *hp)
{
    int32_t i,bit;
    if ( rwflag == 0 )
    {
        for (i=0; i<len; i++)
        {
            if ( (bit= hgetbit(hp)) < 0 )
                return(-1);
            if ( bit != 0 )
                SETBIT(ptr,i);
            else CLEARBIT(ptr,i);
        }
        //printf("rbits.%d (%02x)\n",len,*(uint8_t *)ptr);
    }
    else
    {
        //printf("wbits.%d (%02x)\n",len,*(uint8_t *)ptr);
        for (i=0; i<len; i++)
            if ( hputbit(hp,GETBIT(ptr,i) != 0) < 0 )
                return(-100*i-100);
    }
    //printf("rwbits len.%d (%02x)\n",len,*(uint8_t *)dest);
    //printf("(%d) ",*(uint8_t *)ptr);
    return(len);
}