예제 #1
0
void main() {
trisb=0b11111011;
uart1_init(2400);
PWM1_Init(30000);
PWM1_Set_Duty(127);
PWM1_Start();
for(;;){
if(portb.f0==0)
{
uart1_write('a');
}while(portb.f0==0);
if(portb.f4==0)
{
uart1_write('a');
}while(portb.f4==0);
if(portb.f5==0)
{
uart1_write('b');
}while(portb.f5==0);
if(portb.f6==0)
{
uart1_write('c');
}while(portb.f6==0);
}

}
예제 #2
0
void main(void)
{
	//initialize portc
	PORTC = 0x00;
	TRISC = 0x00;
	
	//initialize pwm
	PWM_Init(5000); //initialize pwm at 5khz
	PWM1_Duty(0); //set initial duty cycle at 0 on pin RC2
	PWM2_Duty(0); 
	
	//start pwm
	PWM1_Start();
    PWM2_Start();
	
	
	while (1)
	{
	
		for (int i=0; i<1023; i+=4)
		{
			PWM1_duty();
			PWM2_Duty(1023-i);
			__delay_ms(2);
		}
	
	
	}


}
예제 #3
0
void main() {
  InitMain();
  current_duty  = 200;                 // initial value for current_duty
  current_duty1 = 200;                 // initial value for current_duty1
  TRISA  = 0xFF;              // PORTA is input
  TRISB = 0xFF;                             // Set PORTB as input
  //PORTB = 0x00;
  PWM1_Start();                       // start PWM1
  PWM2_Start();                       // start PWM2
  PWM1_Set_Duty(0);        // Set current duty for PWM1
  PWM2_Set_Duty(0);       // Set current duty for PWM2
  adcon1 = 0b1000010;
  while (1) {                         // endless loop

    temp_res = ADC_Read(0);
    temp_res=temp_res*255.0/1024.0;
    newduty=temp_res;
    if(RB0_bit==1 && RB1_bit==0){
         PWM1_Set_Duty(newduty);
         PWM2_Set_Duty(0);
    }else if(RB0_bit==0 && RB1_bit==1){
         PWM1_Set_Duty(0);
         PWM2_Set_Duty(newduty);
    }
    else{
         PWM1_Set_Duty(0);
         PWM2_Set_Duty(0);
    }
    

    Delay_ms(5);                      // slow down change pace a little
  }
}
예제 #4
0
//################################################################################################################################
//--------------------------------------------------------------------------------------------------------------------------------
//函数名称:CLevel21_Sure()
//--------------------------------------------------------------------------------------------------------------------------------
//函数功能:确认键的第二层第3个任务
//--------------------------------------------------------------------------------------------------------------------------------
//输入参数:	tmp为第几个按键的值
//--------------------------------------------------------------------------------------------------------------------------------
//输出参数:	null
//--------------------------------------------------------------------------------------------------------------------------------
//说   明:
//--------------------------------------------------------------------------------------------------------------------------------
//################################################################################################################################
void CLevel23_Sure(uint8 tmp)//
{
	switch(tmp)
	{
        case 1://自检 喇叭响完就关闭了
			ClearScreen(0);
			UartCom(CMD_139W,2);	   //发送心跳命令

			SetZjFlag(1);
		//加声光
			Led_On();
								
            DelayMs(10);
			PWM1_Start();
			PWM1_Set( PWM_CYCLE, 0 );
				
		//delay
            DelayMs(10);
            PWM1_Stop();
            DelayMs(10);

            PWM1_Start();
            PWM1_Set( PWM_CYCLE, 0 );

            TestSelf_Menu();

				
				
				
				
// 		SetSpeaker_Counter(1);
// 		CLevel27_Sure();	
			break;
        case 2://部件信号强度
			ClearScreen(0);
			CompInten_Menu(0,0,0,0);
			CSetIntenFlag(1);
			break;
		default:break;
	}
}
예제 #5
0
파일: inttm0.c 프로젝트: vronikp/PetFeeder
void alimentar(unsigned short tamanio) {
  PWM1_Start();                       // start PWM1
  PWM1_Set_Duty(90);
  Delay_ms(750);
  PWM1_Stop();
  if (tamanio == 'A'){
     Delay_ms(500);
   }
  else if (tamanio == 'B'){
     Delay_ms(1500);
   }
  else if (tamanio == 'C'){
     Delay_ms(2000);
   }
  else if (tamanio == 'D'){
     Delay_ms(2500);
   }
  PWM1_Start();
  PWM1_Set_Duty(30);
  Delay_ms(750);
  PWM1_Stop();
}
예제 #6
0
파일: servir.c 프로젝트: vronikp/PetFeeder
void alimentar(unsigned short tama) {
  PWM1_Set_Duty(70);
  PWM1_Start();                       // start PWM1
  Delay_ms(1000);
  PWM1_Stop();
  if (tama = 65){
     Delay_ms(100);
   }
  else if (tama = 66){
     Delay_ms(150);
   }
  else if (tama = 67){
     Delay_ms(200);
   }
  else if (tama = 68){
     Delay_ms(250);
   }
  PWM1_Set_Duty(50);
  PWM1_Start();
  Delay_ms(1000);
  PWM1_Stop();
}
예제 #7
0
파일: pwm.c 프로젝트: 12019/mtktest
/*level = 1~5, level = 0, close PWM*/
void PWM_level(kal_uint8 level)
{
   if (level > 5)
      ASSERT(0);
   
   PWM1_LEVEL_SAVE = level;
   if (level)
   {
      PWM1_Configure(PWM1_Level_Info[level-1][0],PWM1_Level_Info[level-1][1]);
      PWM1_Start();
   }
   else
   {
      PWM1_Stop();
   }
}
예제 #8
0
void CLevel23_Return(void)
{
	//switch(vCounter[1])
	switch(GetCounter2())
	{
        case 1://自检 返回 检测蜂鸣器标志是否已经打开 ,如果已经打开,则开启
			Led_Off();
				

//             if(GetSpeakerClick())
//             {
//                 SetAlarmFlag(0,1);
//             }
            //delay

            DelayMs(10);
            PWM1_Stop();
            PWM1_Set(0,0);
            DelayMs(10);
            BEEPOn();
            PWM1_Start();
            PWM1_Set( PWM_CYCLE, 0 );
            DelayMs(10);
            PWM1_Stop();
            PWM1_Set(0,0);

      
            SetZjFlag(0);//中断里打开喇叭响检测
				
            ClearScreen(0);
			Test_Menu(1);
//			SetSpeaker_Counter(0);
//			CLevel27_Sure();
			break;
		case 2:
			CSetIntenFlag(0);
			ClearScreen(0);
			Test_Menu(2);
			break;
		default:break;		
	}	
	SetCounter3(1);
 	//vCounter[2] = 1;
}
예제 #9
0
void main() {
    char p1;
    unsigned int Duty;
    char tmp;

    OSCCON = 0b01111100;
    OSCCON2 = 0b10000111;
    OSCTUNE = 0b01000000;
    ADCON0 = 0;
    CCP1CON = 0;
    CCP2CON = 0;
    CCP3CON = 0;
    PWM1_Init( 44000 );
    PWM1_Start();
    x1 = 0;
    xStep = 1;
    TRISB4_bit = 1;
    TRISB5_bit = 1;
    InitTimer1();
    while(1)
    {
            if( PORTB.B4 == 1) // Play Cat Meow
            {
                x1 = 0;
                wavSel = 0;
                T1CON         = 0x01;
                Delay_ms(250);
            }
            if( PORTB.B5 == 1) // Play Dog Bark
            {
                x1 = 0;
                wavSel = 1;
                T1CON         = 0x01;
                Delay_ms(250);
            }
    }
}
예제 #10
0
void Interrupt(){

  if(INTF_bit){    //External Interrupt occurred
  INTCON = 0;      //Disable all interrupts
  PORTB.F2 = 0;
  PORTD = 0;
  PWM1_Stop();
  }

  if (TMR1IF_bit){        //Timer1 Interrupt occurred
    TMR1IF_bit = 0;
    TMR1H         = 0x6D;
    TMR1L         = 0x84;
  dt = ADC_Read(0);   //Read analog value

  if (dt != dt0) {
  dt0 = dt;
  dt0 = dt0 >> 2;
  PWM1_Set_Duty(dt0);
  PWM1_Start(); 

  }

 }
예제 #11
0
void main(void)
{
	// Enable Global Interrupt   
	M8C_EnableGInt;

	// Clear the flags
	FlagsElevator = 0;
	FlagsAileron = 0;// new for motorcontroll2
	FlagUltrasoon = 0;

	// Start timers and enable interrupt
	Timer1_Start();
	Timer1_EnableInt();

	Timer2_Start();// new for motorcontroll2
	Timer2_EnableInt();// new for motorcontroll2

	Timer3_Start();
	Timer3_EnableInt();
   
	TriggerUltrasoon();	

	// Init motors
	PWM1_Start();
	PWM2_Start();

#if (DEBUG_LCD)
	LCD_Start();
#endif  
	
	while (TRUE)
	{
		float aileronNormalized,
			  elevatorNormalized;
		float distance;
		float speed, direction;
		float motorLeft, motorRight;
		BOOL forward;
		
		aileronNormalized = EvaluateAileron(PulseWidthAileron);
		direction  = fabs(aileronNormalized);

		elevatorNormalized = EvaluateElevator(PulseWidthElevator);
		speed  = fabs(elevatorNormalized);
		forward = (elevatorNormalized >= 0);
		
		distance = EvaluateUltrasoonSensor();
		if (distance < MIN_SAFE_DISTANCE)
		{
			if (forward)
				speed = 0;
		}
		
		motorLeft  = speed; // default is straight forward
		motorRight = speed;
		
		if (aileronNormalized < 0) // turning left
		{
			motorRight = speed;
			motorLeft  = speed * (1 - direction);
		}
		else if (aileronNormalized > 0) // turning right
		{
			motorLeft  = speed;
			motorRight = speed * (1 - direction);
		}
				
		if (forward)
		{
			// ccw
			PRT1DR |=  0x08; // AIN1
			PRT1DR &= ~0x02; // AIN2
			
			PRT1DR |=  0x20; // BIN1
			PRT1DR &= ~0x80; // BIN2
		}
		else 
		{
			//cw
			PRT1DR &= ~0x08; // AIN1
			PRT1DR |=  0x02; // AIN2
			
			PRT1DR &= ~0x20; // BIN1
			PRT1DR |=  0x80; // BIN2
		}
	
		// Denormalize to Engine
		motorLeft *= (MAX_POWER - MIN_POWER);
		motorLeft += MIN_POWER;
		motorRight *= (MAX_POWER - MIN_POWER);
		motorRight += MIN_POWER;

		PWM1_WritePulseWidth(motorLeft);
		PWM2_WritePulseWidth(motorRight);

#if (DEBUG_LCD)
		LCD_Position(0,7);
		LCD_PrHexInt(motorLeft);
		LCD_Position(1,7);
		LCD_PrHexInt(motorRight);
		
		LCD_Position(0,12);
		LCD_PrCString(forward ? "F" : "B");
#endif 	

   }
}