0% found this document useful (0 votes)
14 views

#Define Butt1 RB1 - Bit #Define Butt2 RB2 - Bit #Define Butt3 RB3 - Bit #Define Butt4 RB4 - Bit

This code initializes two pulse width modulation (PWM) signals using pins on ports B and C of a PIC microcontroller. It defines macros for the pin assignments and initializes the ports and PWM modules. The main loop continuously checks the states of four buttons to increment or decrement the duty cycles of the two PWM outputs.

Uploaded by

REINALDOSEMP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

#Define Butt1 RB1 - Bit #Define Butt2 RB2 - Bit #Define Butt3 RB3 - Bit #Define Butt4 RB4 - Bit

This code initializes two pulse width modulation (PWM) signals using pins on ports B and C of a PIC microcontroller. It defines macros for the pin assignments and initializes the ports and PWM modules. The main loop continuously checks the states of four buttons to increment or decrement the duty cycles of the two PWM outputs.

Uploaded by

REINALDOSEMP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#define

#define
#define
#define

butt1
butt2
butt3
butt4

RB1_bit
RB2_bit
RB3_bit
RB4_bit

unsigned short duty1, duty2;


void main()
{
CMCON =
TRISB =
TRISC =
PORTB =
PORTC =

0x07;
0xFF;
0x00;
0xFF;
0x00;

//Desabilitar os comparadores do PIC


//Todo PORTB ser entrada
//Todo PORTC como sada
//PORTB inicia em high
//PORTC inicia em low

PWM1_Init(5000);
PWM2_Init(5000);
duty1 = 127;
duty2 = 127;
PWM1_Start();
PWM2_Start();
PWM1_Set_Duty(duty1);
PWM2_Set_Duty(duty2);
while(1)
{
if(!butt1)
{
delay_ms(40);
duty1++;
PWM1_Set_Duty(duty1);
}
if(!butt2)
{
delay_ms(40);
duty1--;
PWM1_Set_Duty(duty1);
}
if(!butt3)
{
delay_ms(40);
duty2++;
PWM2_Set_Duty(duty2);
}
if(!butt4)
{
delay_ms(40);
duty2--;
PWM2_Set_Duty(duty2);

}
} //end while
}

You might also like