Beispiel #1
0
void delay(unsigned int delay){
    int i;
    switches sw,oldsw;
    sw.all = read_sw();
    oldsw = sw;
    for(i=0; i<delay; i++){
        sw.all = read_sw();
        if(sw.all != oldsw.all)
            break; /* break the loop if someone touched the switches */
        else
            oldsw = sw;
    }

}
Beispiel #2
0
// Initializes UFO, determines pipe size K factor & Units
void uf_init(void)
{
	byte 		i,size,fs,sregl,sregh;
	double	smarktime;
	uint16	sregs;	
	asm("clrwdt");	
	size = read_sw();						//Get switch setting
	Size_ind = size >> 5;				//3 bit pipe dia index
#ifdef _TEN
	Size_ind = 8;
#endif	
	K = load_eeprom_data(K_ADD);
	if(K <.5)								// First time?
		{
		K 	= K_init[Size_ind];			//K for this pipe size,Gal/min
		if(size & 0x01)					
			K *= 3.785;						//Asking for liters/gal
		write_eeprom_data(K_ADD, K);
	}
	fs = (size & 0x08) ? HI :LO;		//FS selection
	if(size & 0x01)
		FS = Fs_L[Size_ind][fs];		//Set FS Gal value to use.
	else
		FS = Fs_G[Size_ind][fs];
#ifdef _lowFS
	if(!fs)
		FS = _lowFS;
	else
		FS = _highFS;
#endif
	//Set response time and bad measurement limit to use.				
	Resp = (size & 0x10) ? FAST : SLOW;
	Bad_limit = (size & 0x10) ? BAD_LIMIT_FAST : BAD_LIMIT_SLOW;	
	Pt = Ptrig[Size_ind];		
	TRISC = TRISC_OUT;					//Enable data lines for output
	PWRDWN = OFF;							//Allow UFO to power up
	delay(5);
	uset_reg(REG0,RESET_UFO);			//Reset all
	uset_reg(REG0,UNSET_UFO);
	for(i = 0;i < MAXADD; i++)			//Non size dependent registers only
		uset_reg(Uf_init[i][0], Uf_init[i][1]);	//Traverse array of addresses and data
	TCur = Tt[Size_ind];						//Start with nominal Tt
	smarktime = .75*Tt[Size_ind];	
	Enable_delay = (byte)(smarktime/8); //6 us/timing loop
	sregs = (uint16)(smarktime*CLK_FREQ - 2);	//SMARK value
	sregl = (byte)(sregs & 0x00FF);
	sregh = (byte)(sregs >> 8);
	uset_reg(REG7,sregl);				//Set SMARKL
	uset_reg(REG8,sregh);				//Set SMARKH
	sregs = (uint16)(1.25*CLK_FREQ*Tt[Size_ind] - 2);	//SSPACE value
	sregl = (byte)(sregs & 0x00FF);
	sregh = (byte)(sregs >> 8);
	uset_reg(REG9,sregl);				//Set SSPACEL
	uset_reg(REG10,sregh);				//Set SSPACEH
	asm("clrwdt");	
}	
Beispiel #3
0
//******************************************************************
//  EditMemoryInit
//  FILENAME:
//  PARAMETERS:
//  DESCRIPTION: 
//  RETURNS:
//*******************************************************************
void EditMemoryInit(int initstate)
{
	read_sw();
	if(GetKey(MODE_KEY))
	{
		// reset nickname -> nickname discovery
		vscp_setNickname( VSCP_ADDRESS_FREE );
		PrintString( (UINT8 const *)"\n\rRESET NICKNAME" );
	}
}
Beispiel #4
0
int main() {        
    char buzz = 0;
    unsigned char leds = 0;
    unsigned char stage = 0;
    /* array to do the "fan" assignment */
    unsigned char fan[] = { bit(3)|bit(4), bit(2)|bit(5),
                               bit(1)|bit(6), bit(0)|bit(7) };
    switches sw = {0}, prevsw = {0};
    init();

    while (1) {
        prevsw = sw; /* set the previous switches aside */
        sw.all = read_sw(); /* read switches */
        
        /* if function changed - start new function from scratch */
        /*     if( (sw.all & 7) != (prevsw.all & 7))
            stage = 0; */

        /* switch 5 stops all motion*/
        if(sw.s5)
            continue;

        /* switch logic */
        /* switch s2 does the fan thing */
        if (sw.s2){

                stage = stage % 4;
                leds = fan[stage];

        /* switch s1 does the shift bit thing */
        } else if(sw.s1) {

            stage = stage % 8;
            leds = 1 << stage;

        /* switch s0 does the counter */
        } else if(sw.s0) {

            leds = stage;
        }

        /* setup the next stage */
        if(sw.s3)
            stage--;
        else
            stage++;

        
        if (sw.s6) {
            buzz = ~buzz;
            buzzer(buzz);
        } else {
            buzzer(OFF);
        }

        write_leds(leds);

        if (sw.s4)
            delay(LONG_DELAY);
        else
            delay(SHORT_DELAY);

        /* exit the main loop */
        if(sw.s7)
            break;
    }

    /* blink the leds before dying */
    write_leds(0xFF);
    delay(LONG_DELAY);
    write_leds(OFF);

    return 0;
}