void PWM_SENAL() {
lcd_putc("\f");
lcd_gotoxy(1, 1);
// ****************
lcd_putc("\fGENERANDO SEÑAL ");
lcd_gotoxy(1, 2);
lcd_putc("PWM DE 0 A 1KHZ ");
lcd_gotoxy(1, 3);
lcd_putc("AJUSTAR ANCHO ");
// Generemos una Señal cuadrada de 1 Khz
Timer2 = 249; //Se carga timer 2 con 249 como lo vimos en la pagina
//Preescaler=4; //Preescaler solo puede tomar valores de: 1 - 4 - 16
//Para el preescaler colocamos "t2_div_by_4"
Poscaler = 1; //Preescaler solo puede tomar valores de: 1
//setup_timer_2(T2_DIV_BY_16, 15, 1);
// setup_timer_2(T2_DIV_BY_4,249,1);
setup_timer_2(t2_div_by_4, Timer2, Poscaler); //Configuracion de Timer 2 para establecer frec. PWM a 1kHz
setup_ccp1(ccp_pwm); //Configurar modulo CCP1 en modo PWM
setup_adc_ports(ALL_ANALOG); //Configurar ADC
setup_adc(ADC_CLOCK_INTERNAL);
while (TRUE) {
// CONFIGURO EL ADC
set_adc_channel(0);
delay_us(100);
duty = read_adc();
set_pwm1_duty(duty);
DELAY_MS(10);
// MUESTRO EN LA PANTALLA LOS RESULTADOS
lcd_gotoxy(1, 4);
printf(lcd_putc
, " PWM: %4Lu ", duty
); // RUTINA PARA SALIR DEL BUCLE usando la tecla salir
// DESACTIVO ENTRADAS ANALOGICAS PARA PODER LEER LAS TECLAS // QUEDAN COMO DIGITALES
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
if (input(SALIR) == 0) {
DELAY_MS(250);
if (input(SALIR) == 1) {
DELAY_MS(10);
men = 6;
break;
}
}
DELAY_MS(10);
// vuelvo a configurar el ADC
setup_adc_ports(ALL_ANALOG); //Configurar ADC
setup_adc(ADC_CLOCK_INTERNAL);
}
}