Example #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);
}

}
Example #2
0
void initpwm()
{
  PWM1_Init(5000);
  PWM2_Init(5000);
  Pwm1_Start();          //RIGHT MOTOR
  Pwm2_Start();          //LEFT MOTOR
}
Example #3
0
/*
** ===================================================================
**     Method     :  PWMTpm1_Construct 
**    Description : Metodo Construir el PWMTpm1
** ===================================================================
*/
void PWMTpm1_Construct(struct PWMTpm1* self,TConfPWM * conf){
  PWM_Construct(self,conf);
  
  /* Listo*/
  
   PWM1_Init();
   pwm1_setperiodo (conf->period);
 
  
}
Example #4
0
void InitMain() {
  PORTA = 255;
  TRISA = 255;                        // configure PORTA pins as input
  PORTB = 0;                          // set PORTB to 0
  TRISB = 0;                          // designate PORTB pins as output
  PORTC = 0;                          // set PORTC to 0
  TRISC = 0;                          // designate PORTC pins as output
  PWM1_Init(10000);                    // Initialize PWM1 module at 5KHz
  PWM2_Init(10000);                    // Initialize PWM2 module at 5KHz}
  }
Example #5
0
  void initRobot()
{
  //--PWM------------
  TRISC = 0b00000000;
  PORTC = 0b00000000;
  PWM1_Init(5000);
  PWM2_Init(5000);
  Pwm1_Start();
  Pwm2_Start();

  //--ADC-----------_
  ADCON1 = 0x80;  // Configure analog inputs and Vref
  TRISA  = 0xFF;  // PORTA is input

  //--Usart---------
  Usart_Init(9600);

}
Example #6
0
void main() {
    OPTION_REG = 0x83;             // Set timer TMR0
    TMR0 = 131;
    INTCON = 0xA0;                 // Disable interrupt PEIE,INTE,RBIE,T0IE
    PORTA = 0;                     // Turn off both displays
    TRISA = 0;                     // All port A pins are configured as outputs
    PORTC = 0;                     // Turn off all display segments
    TRISC = 0;                     // All port D pins are configured as outputs
    C1ON_bit = 0;                       // Disable comparators
    C2ON_bit = 0;
    PWM1_Init(500);
    counter = 0;
    segundos = 0;
    minutos = 0;
    horas = 0;
    
    
    while (1) {
    
    }
}
Example #7
0
void main()
{  ADCON0 = 0;         //adc =0
   ADCON1 = 0xF0;     // Set all A/D pins as digital I/O pins.
   TRISA = 0X00;
   TRISC = 0x00;
   PORTC = 0X00;
   PORTA = 0b01010000;
   PWM1_Init(5000);
   PWM2_Init(5000);
   Pwm1_Start();
   Pwm2_Start();
   while(1)
   {
   PWM1_Set_Duty(210);
   PWM2_Set_Duty(135);
   Delay_ms(10000);
   PWM1_Set_Duty(255);
   PWM2_Set_Duty(255);
   Delay_ms(10000);
   PWM1_STOP();
   PWM2_STOP();
}
}
Example #8
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);
            }
    }
}
void main() {
  current_duty=125;
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  
  //LCD_show();
  DDRB = 0xFF;               // Set PORTB as output
  //DDRC = 0xFF;               // Set PORTC as output
  Lcd_Cmd(_LCD_CLEAR);
  Flag=3;
  PWM1_Init(_PWM1_FAST_MODE, _PWM1_PRESCALER_8, _PWM1_NON_INVERTED, current_duty);

  while (1) {


    LDR_1 = ADC_Read(0);    // get ADC value from 2nd channel
    LDR_2 = ADC_Read(1);
    LDR_3 = ADC_Read(2);
    LDR_4 = ADC_Read(3);
    LDR_5 = ADC_Read(4);
    prev_pos=Flag;
    if (LDR_1<LDR_2 && LDR_1<LDR_3 && LDR_1<LDR_4)
    {
    Flag=1;
    }
    else if (LDR_2<LDR_1 && LDR_2<LDR_3 && LDR_2<LDR_4)
    {
    Flag=2;
    }
    else if (LDR_3<LDR_1 && LDR_3<LDR_2 && LDR_3<LDR_4)
    {
    Flag=3;
    }
    else if (LDR_4<LDR_1 && LDR_4<LDR_2 && LDR_4<LDR_3)
    {
    Flag=4;
    }
    goal=Flag;
    Lcd_Cmd(_LCD_CLEAR);
    IntToStr(goal,adc_show1);
    IntToStr(prev_pos,adc_show2);
    IntToStr(LDR_3,adc_show3);
    IntToStr(LDR_4,adc_show4);
    IntToStr(LDR_5,adc_show5);
    Lcd_Out(1,1,adc_show1);
    Lcd_Out(1,8,adc_show2);
    //Lcd_Out(2,1,adc_show3);
    //Lcd_Out(2,6,adc_show4);
    //Delay_ms(5000);
    //Lcd_Out(2,10,adc_show5);
    //
    /*Lcd_Out(1,1,txt5);
    IntToStr(LDR_1,adc_show);
    Lcd_Out(2,1,adc_show);
    Delay_ms(5000);
    Lcd_Cmd(_LCD_CLEAR);
    Delay_ms(1000);
    //
    Lcd_Out(1,1,txt6);
    IntToStr(LDR_2,adc_show);
    Lcd_Out(2,1,adc_show);
    Delay_ms(5000);
    Lcd_Cmd(_LCD_CLEAR);
    Delay_ms(1000);
    //
    Lcd_Out(1,1,txt7);
    IntToStr(LDR_3,adc_show);
    Lcd_Out(2,1,adc_show);
    Delay_ms(5000);
    Lcd_Cmd(_LCD_CLEAR);
    Delay_ms(1000);
    //
    Lcd_Out(1,1,txt8);
    IntToStr(LDR_4,adc_show);
    Lcd_Out(2,1,adc_show);
    Delay_ms(5000);
    Lcd_Cmd(_LCD_CLEAR);
    Delay_ms(1000); */
    //Lcd_Cmd(_LCD_CLEAR);
    //Delay_ms(1000);
    //IntToStr(goal,gool);
    //IntToStr(prev_pos,prv);
    //Lcd_Out(1,1,gool);
    //Lcd_Out(1,6,prv);
    // motor rotation Start
    if (goal==prev_pos)
    {
      Lcd_Out(2,1,txt2);
      Delay_ms(1000);
    }
       else
   {

     Lcd_Out(2,1,txt1);

      if (goal>prev_pos)
      {
         for (i=prev_pos;i<=goal;i++)
         {
          PORTB.B0=0;
          PORTB.B1=1;
          Delay_ms(one_rot);
         }
      }
      else
      {
          for (i=prev_pos;i<=(4+goal);i++)
         {
          PORTB.B0=0;
          PORTB.B1=1;
          Delay_ms(one_rot);
         }
      }

   }
      PORTB.B0=1;
      PORTB.B1=1;// Motor stop
      Delay_ms(1000);
    //motor rotation End
  }

}