Ejemplo 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);
    }
}
Ejemplo 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);
   }
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: sdeodhar/PIC
void USARTWriteString(const char *str)
{
  while(*str!='\0')
  {
      USARTWriteChar(*str);
      str++;
  }
}
Ejemplo n.º 4
0
void main()
{
  //Initialize USART with baud rate 9600
  USARTInit(9600);

  //Write intro text
  USARTWriteLine("***********************************************");
  USARTWriteLine("USART Test");
  USARTWriteLine("----------");
  USARTWriteLine("Type a character on keyboard");
  USARTWriteLine("it will reach the PIC MCU via the serial line");
  USARTWriteLine("PIC MCU will return the same character but ");
  USARTWriteLine("enclosed in a <>");
  USARTWriteLine("--");
  USARTWriteLine("For example if you type 'a' you will see <a>");
  USARTWriteLine("appear on serial terminal.");
  USARTWriteLine(" ");
  USARTWriteLine("This checks both way serial transfers.");
  USARTWriteLine("");
  USARTWriteLine("Copyright (C) 2008-2013");
  USARTWriteLine("www.eXtremeElectronics.co.in");
  USARTWriteLine("***********************************************");
  USARTGotoNewLine();
  USARTGotoNewLine();

  while(1)
  {
      //Get the amount of data waiting in USART queue
      uint8_t n= USARTDataAvailable();

      //If we have some data
      if(n!=0)
      {
          //Read it
          char data=USARTReadData();

          //And send back
          USARTWriteChar('<');
          USARTWriteChar(data);
          USARTWriteChar('>');
      }

  }
}
Ejemplo n.º 5
0
int main(){

	DDRC|=(1<<EmissorFrontBig)|(1<<EmissorFrontSmall);
	DDRB&=~((1<<SensorFrontLeft)|(1<<SensorFrontRight));

	PORTC|=(1<<EmissorFrontBig)|(1<<EmissorFrontSmall);

	unsigned volatile short valueL,valueR;
	ADCInit();
	TIMER_init();
	USARTInit(51); //Just for testing
	
	while(1){
		distanceOpponentLeft=DistancePTLeft();
		USARTWriteChar(distanceOpponentLeft); //Just for testing
		distanceOpponentRight=DistanceRight();
		USARTWriteChar(distanceOpponentRight); // Just for testing
	}

	return 0;
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: sdeodhar/PIC
void USARTWriteInt(int val, int field_length)
{
    char str[5]={0,0,0,0,0};
    int i=4,j=0;
    //Handle negative integers
    if(val<0)
    {
        USARTWriteChar('-');   //Write Negative sign
        val=val*-1;     //convert to positive
    }
    else
    {
        USARTWriteChar(' ');
    }

    if(val==0 && field_length<1)
    {
        USARTWriteChar('0');
        return;
    }
    while(val)
    {
        str[i]=val%10;
        val=val/10;
        i--;
    }

    if(field_length==-1)
        while(str[j]==0) j++;
    else
        j=5-field_length;

    for(i=j;i<5;i++)
    {
        USARTWriteChar('0'+str[i]);
    }
}
Ejemplo n.º 7
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");
            }*/
        }
    }
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: 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 ;
		}


	}
Ejemplo n.º 9
0
void USARTWriteString(const char* str)
{
    unsigned int i = 0;
    while (str[i] != '\0')
        USARTWriteChar(str[i++]);
}