Esempio n. 1
0
void Writeeeprom(void)
{    //switch write ZCurVal,SCurVal,CCurVal,MCurVal,PCurVal,ICurVal,DCurVal;
    int8u retval;
    switch(Command)
    {
        case 'Z': retval = WriteEEP(ZCurVal,ZADDR);   break;
        case 'S': retval = WriteEEP(SCurVal,SADDR);   break;
        case 'T': retval = WriteEEP(NoTeeth,TADDR);   break;
        //case 'M': retval = WriteEEP(MCurVal,MADDR);   break;
        case 'P': retval = WriteEEP(PCurVal,PADDR);   break;
        case 'I': retval = WriteEEP(ICurVal,IADDR);   break;
        case 'D': retval = WriteEEP(DCurVal,DADDR);   break;
        case 'Q': break;
        case 'B': retval = WriteEEP(BCurVal,BADDR);   break;
        case 'R': retval = WriteEEP(CLKVIZ,DIADDR);   break;
        case 'F': retval = WriteEEP(BoardFreq,FADDR);   break;
        case 'A': retval = WriteEEP(ACurVal,AADDR);   break;
    }
    if(retval)
    {
        USARTWriteChar('G');USARTWriteString(strnw);
        //USARTWriteString("Success");USARTWriteString(strnw);
    }
    else
    {
        USARTWriteChar('H');USARTWriteString(strnw);
        //USARTWriteString("Fail");USARTWriteString(strnw);
    }
}
Esempio n. 2
0
int main(void)
{
	
	//Initial Serial, ADC & LCD Display:
	USARTInit(52);
	lcd_init();
	ADCinit();
	pwm_init();
	
	char adc_output[6][4];	
	int adc_value[6]; // Variable to hold ADC result
	
    while(1)
   {	
	   for(int i=0;i<6;i++){
		   adc_value[i] = ADCread(i);
		   itoa(adc_value[i],adc_output[i],10);
		   USARTWriteString(adc_output[i]);
		   if(i!=5){USARTWriteChar(';');}
	   }
	   
		//Sending a new line:
	   	USARTWriteChar('\r');
	   	USARTWriteChar('\n');
		
		//Set PWM:
		pwm(adc_value[5]);
		
		//Show data on the lcd display   
		show(adc_output);
		
		//Delay:
		_delay_ms(500);
   }
}
int main( void )
{   
	sei();
 	Timer1_Init();
	I2C_init(0x52);	 
    USARTInit(9600);
//	SERVO_Init();
	
		
//	SERVO_UpdateServo(0,1500);
//	SERVO_UpdateServo(1,1800);
//	SERVO_UpdateServo(2,2600);
//	SERVO_UpdateServo(3,2800);
	

	//Timer1_print_time(Timer1_get_time());
	
	USARTWriteString("\r\nReset\r\n");
	SERVO_Run();

	
	
	while(1)
	{
		//handleI2C();
		//I2C_isdataready();
		
	}
	
	return 0;
}
Esempio n. 4
0
void msg(uint8_t err, const char* fmt, ...)
{
	va_list vl;
	va_start(vl,fmt);

#if DEBUG_OS_ENABLED
	vfprintf((err? stderr:stdout),fmt,vl);

#elif EMBED_AVR
	char str[DEBUG_MAXMSGLEN];
	vsnprintf(str,sizeof(str),fmt,vl);
	if (err) USARTWriteString("ERR: ");
	USARTWriteString(str);

#endif

	va_end(vl);
}
Esempio n. 5
0
void main(void)
{
    OSCCON = 0b01100001;  //4 MHz
    OSCTUNE= 0;
    //INTCON = 0;
    //Count1micros = 0;
    Count4ms = 0;
    //Delay(2);
    initports();
    USARTinit();
//USARTWriteString("Serial init\n\rchecking for config enable...\n\r");
    while(SERIALDETECT == 1)
    {
        //USARTWriteString("\n\rEnter Config\n\r");USARTWriteString(strnw);
        //USARTWriteString("\n\rEnter ");
        getData();
    }
    ENB = 0;
    nSLEEP = 1;
    DECAY = 1;
    initall();
    int i;
    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 270; CurStepDir = ANTICLKVIZ; CurStepMode = MIC32STEP ;

        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }

    while(Crankflg == 0)
    {
        get_Actrpm();
        Calc_SetPoint();
        USARTWriteChar('N');USARTWriteString(strnw);
    }

    for( i = 0 ; i < 4 ; i++)
    {
        CurTotNoStep = 225; CurStepDir = CLKVIZ; //CurStepMode = MIC32STEP ;
        Make_Table( CurTotNoStep );
        while(!MotionComplete);
    }
        //MoveMotor();
    while(1)
    {
        if(MS100Flag)
        {
            MS100Flag = 0;
            Calc_Err(PIDCycleNo);
            
            if((PIDCycleNo >= 2) /*&& Crankflg*/ )
            {
                Calc_PID_op();
            }//USARTWriteString("100 ms done \n\r");
            /*else
            {
                USARTWriteChar('N');USARTWriteString(strnw);
                //USARTWriteString("no crank\n\r");
            }*/
        }
    }
}
Esempio n. 6
0
void CheckState()
{
	/*
	// main track
	if (MAIN_IS_SHORT && !shortMain)
	{
		shortMain = true;
		MAIN_TRACK_OFF;
		LED_SHORT_MAIN_ON;
		USARTWriteString("MTS1*");
	}
	// program track
	if (PROG_IS_SHORT && !shortProg)
	{
		shortProg = true;
		PROG_TRACK_OFF;
		LED_SHORT_PROG_ON;
		USARTWriteString("PTS1*");
	}
	// ack detect
	if (ACK_IS_DETECTED && !ackDetect)
	{
		ackDetect = true;
		USARTWriteString("ACK1*");
	}

	if (!MAIN_IS_SHORT && shortMain)
	{
		_delay_ms(6000);
		shortMain = false;
		MAIN_TRACK_ON;
		LED_SHORT_MAIN_OFF;
		USARTWriteString("MTS0*");
	}
	if (!PROG_IS_SHORT && shortProg)
	{
		_delay_ms(6000);
		shortProg = false;
		PROG_TRACK_ON;
		LED_SHORT_PROG_OFF;
		USARTWriteString("PTS0*");
	}
	if (!ACK_IS_DETECTED && ackDetect)
	{
		ackDetect = false;
		USARTWriteString("ACK0*");
	}
	*/




	// main track
	if (MAIN_IS_SHORT)
	{
		MAIN_TRACK_OFF;
		LED_SHORT_MAIN_ON;
		USARTWriteString("MTS1*");
		_delay_ms(6000);
		LED_SHORT_MAIN_OFF;
		USARTWriteString("MTS0*");
	}
	// program track
	if (PROG_IS_SHORT)
	{
		PROG_TRACK_OFF;
		LED_SHORT_PROG_ON;
		USARTWriteString("PTS1*");
		_delay_ms(6000);
		LED_SHORT_PROG_OFF;
		USARTWriteString("PTS0*");
	}

	// ack detect
	if (ACK_IS_DETECTED && !ackDetect)
	{
		ackDetect = true;
		USARTWriteString("ACK1*");
	}
	if (!ACK_IS_DETECTED && ackDetect)
	{
		ackDetect = false;
		USARTWriteString("ACK0*");
	}
}
Esempio n. 7
0
File: main.c Progetto: sdeodhar/PIC
void main(void)
{
    UINT8 i=0,j=0,k,t;//togflg = 1;

    OSCCON = 0b01111000;
    OSCTUNE = 0b00000000;
    SWDTEN = 0b01;
    UINT8 tholdcount;
    ANSELA = 0;
    ANSELB = 0;
    TRISA = 0;
    TRISB = 0;
    TRISC = 0;
    WDTCONbits.WDTPS = 0b01010;

    for ( j = 0 ; j < 8 ; j++ )
    {
        debounc[j] = 0;
        threshold[j] = 0;
        cur_read[j] = 0;
        average[j] = 0;
        keystat[j]= 0;keycnt[j]= 0;
    }
    TRISCbits.TRISC5 = 0; // RC6 = TX out
    KEYSTATPIN = 1;
    capsensinit(); //Delay(5);
    setscanchannel();
    channelno = 0;avgflag = 0;
    count = 0;
    usartinit();
    I2Cinit();
    if(STATUSbits.nTO == 0){ USARTWriteString(" reset ");}
    //else {tholdflg = 0;}
    //tholdflg = 0;
    tholdcount=0;
    max = 500; pos = 9;
  //  TRISAbits.TRISA2 = 0;
  //  LATAbits.LATA2 = 1;
/*       while(1)
        {
          USARTWriteChar('U');
        }
*/
        while(1)
        {
            CLRWDT();
    /*        if(togflg)
            {
                LATAbits.LATA2 = 0;//togflg;
                togflg = 0;
            }
            else {
                LATAbits.LATA2 = 1;//togflg;
                togflg = 1;
            }
*/
		if(avgflag)
		{
			for( i = 0 ; i < 8 ; i++ )
			{
				average[i] /= capsense_avg_cnt;
				/*USARTWriteInt(average[i],5);
                    		USARTWriteChar('\t');
				if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');}*/

                                if(tholdflg == 0)
                                {
                                    if(tholdcount == 8) threshold[i] = 0;
                                    threshold[i] += average[i];
                                    if ( i == 7 ) tholdcount++ ;
                                    if( tholdcount == 16 )
                                    {
                                        for ( j = 0 ; j < 8 ; j++ )
                                            threshold[ j ] >>= 3 ;
                                        tholdflg = 1;
                                    }
                                }
                                else
                                {
                                    olddiff[i] = curdiff[i];
                                    curdiff[i] = threshold[i] - average[i];
                                    if ( curdiff[i] > olddiff[i] )
                                        diff[i]= curdiff[i] - olddiff[i];
                                    else
                                        diff[i]= olddiff[i]- curdiff[i];
                                    if( diff[i] > max ) { max = diff[i]; pos = i; }
                                    //if( curdiff[i] > max ){ max = curdiff[i]; pos = i;}

                                    //USARTWriteInt(diff[i],5);
                    		    //USARTWriteChar('\t');
				    if(i == 7) 
                                    {
                                        //USARTWriteInt(pos,2);
                                        //USARTWriteChar(' ');
                                        //USARTWriteInt(diff[pos],5);
                                        //USARTWriteChar('\n');USARTWriteChar('\r');

                                        for(t = 0; t < 8 ; t++)
                                        {
                                            if(t != pos) {if(keycnt[t])keycnt[t]--;keystat[t] =0;}
                                            else if( max > 600 )
                                            {
                                                keycnt[t]++;
                                                if( keycnt[t] > 7 )
                                                {
                                                    for(k = 0 ; k < 8 ; k++) keycnt[k] = 0;
                                                    keystat[t] = 1;
                                                }
                                            }
                                            else{ if(keycnt[t])keycnt[t]-- ; keystat[t] = 0;}
                                            USARTWriteInt(keycnt[t],1);
                                        }
                                        
                                        if( pos != 9 && debounc[pos] == 0 )
                                        {
                                            debounc[pos] = 400;
                                            USARTWriteChar('\n');
                                            USARTWriteString("Key Detected = ");
                                            i2c_tx_buff[ 0 ] = pos;
                                            KEYSTATPIN = 0;
                                        }
                                            USARTWriteInt(pos,2);
                                            //i2c_tx_buff[ 0 ] = pos;
                                            USARTWriteChar('\n');USARTWriteChar('\r');
                                            
                                            max = 500; pos = 9;

                                    }
                                    //USARTWriteInt(keycnt[i],1);
                                    //USARTWriteChar('\t');
                                    //if(i == 7){USARTWriteChar('\n');USARTWriteChar('\r');}
                                    //pos = i;
                                    /*USARTWriteInt(curdiff[i],5);
                    		    USARTWriteChar('\t');
				    if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');}
                                    if(curdiff[i] > 800){keycnt[i]++;}
                                    else if(curdiff[i] < 800){ keycnt[i]=0; keystat[i] = 0;}
                                    if(keycnt[i] == 8) keystat[i] = 1;*/
                                    /*USARTWriteInt(keystat[i],1);
                    		    USARTWriteChar('\t');
				    if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');}*/
                                                                      
                                }

			}

		        avgflag = 0 ;
		}


	}
void USARTWriteLine(const char *ln)
{
	USARTWriteString(ln);
	USARTWriteString("\r\n");
}