Lab Microcontroladores
Enviado por cdcampod • 27 de Mayo de 2013 • 1.364 Palabras (6 Páginas) • 244 Visitas
PRACTICA 9
PWM Y ADC
OBJETIVOS:
• Familiarizarse con el manejo del PWM y del convertidor digital analógico ADC
Proyectos:
MANEJO DEL PWM
/*
* Nombre del Proyecto:
P9a_pwm.c
* Nombre del Autor:
(c) Mikroelektronika, 2009.
* Description:
(Explicación del ejercicio)
* Test configuration:
MCU: PIC16F887
Oscillator: HS, 08.0000 MHz
SW: mikroC PRO for PIC
* NOTES:
*/
unsigned short current_duty, old_duty, current_duty1, old_duty1;
void InitMain() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
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(5000); // Initialize PWM1 module at 5KHz
PWM2_Init(5000); // Initialize PWM2 module at 5KHz
}
void main() {
InitMain();
current_duty = 16; // initial value for current_duty
current_duty1 = 16; // initial value for current_duty1
PWM1_Start(); // start PWM1
PWM2_Start(); // start PWM2
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
PWM2_Set_Duty(current_duty1); // Set current duty for PWM2
while (1) { // endless loop
if (RA0_bit) { // button on RA0 pressed
Delay_ms(40);
current_duty++; // increment current_duty
PWM1_Set_Duty(current_duty);
}
if (RA1_bit) { // button on RA1 pressed
Delay_ms(40);
current_duty--; // decrement current_duty
PWM1_Set_Duty(current_duty);
}
if (RA2_bit) { // button on RA2 pressed
Delay_ms(40);
current_duty1++; // increment current_duty1
PWM2_Set_Duty(current_duty1);
}
if (RA3_bit) {
...