Ejemplo 1
#include <16F877A.h>
#use delay(clock=4M)
#define MAX_DUTY 255
void main()
{
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,254,8);
set_tris_b(0xff);
set_tris_c(0x00);
while (true){
if(input(pin_b0)){
set_pwm1_duty(255);
}
if(input(pin_b1)){
set_pwm1_duty(100);
}
if(!input(pin_b0) && !input(pin_b1)){
set_pwm1_duty(0);
}
}
}
Ejemplo 2
#include <16F877A.h>
#use delay(clock=40M)
#fuses HS,NOWDT,NOLVP
#define MAX_DUTY 255
void main(){
int i;
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,254,8);
set_tris_b(0xff);
set_tris_c(0x00);
while(true){
for(i=0;i<=255;i++){
set_pwm1_duty(i);
delay_ms(50);
}
}
}
No hay comentarios:
Publicar un comentario