Autor Tema: Ayuda a declar Entradas en PIC16F877A  (Leído 1907 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado jorlijajr

  • PIC10
  • *
  • Mensajes: 4
Ayuda a declar Entradas en PIC16F877A
« en: 22 de Octubre de 2014, 11:54:29 »
Hola a todos! Tengo la idea de controlar 5 servo motores por medio de push Button y para ello declaro los puertos B y C para entrada y  el puerto D para salida, el problema es que cuando configuro el puerto C como salida, TRISC=0x00; no funciona, si alguien tiene alguna idea de que hacer por favor me pueda ayudar, adjunto el código fuente
Código: [Seleccionar]
sbit SUBIR_0 at RB0_bit;
sbit BAJAR_0 at RB1_bit;
sbit SUBIR_1 at RB2_bit;
sbit BAJAR_1 at RB3_bit;
sbit SUBIR_2 at RB4_bit;
sbit BAJAR_2 at RB5_bit;
sbit SUBIR_3 at RB6_bit;
sbit BAJAR_3 at RB7_bit;
sbit SUBIR_4 at RC0_bit;
sbit BAJAR_4 at RC1_bit;

sbit servo_0 at RD0_bit;
sbit servo_1 at RD1_bit;
sbit servo_2 at RD2_bit;
sbit servo_3 at RD3_bit;
sbit servo_4 at RD4_bit;

float pwm_0=9.49,pwm_1=9.49,pwm_2=9.49,pwm_3=9.49,pwm_4=9.49;
float delay_0, delay_1, delay_2, delay_3, delay_4;

void interrupt() {
  delay_0 = pwm_0*10;
  Servo_0 = 1;
  Delay_Cyc(delay_0);  // un retraso de 10 veces el retraso pwm
  Servo_0 = 0;
  TMR0 = 210;        // TMR0 a su valor inicial del conteo
  INTCON.T0IF = 0;   // Bit T0IF se Borra
 
  delay_1 = pwm_1*10;
  Servo_1 = 1;
  Delay_Cyc(delay_1);
  Servo_1 = 0;
  TMR0 = 210;
  INTCON.T0IF = 0;
 
  delay_2 = pwm_2*10;
  Servo_2 = 1;
  Delay_Cyc(delay_2);  // un retraso de 10 veces el retraso pwm
  Servo_2 = 0;
  TMR0 = 210;        // TMR0 a su valor inicial del conteo
  INTCON.T0IF = 0;   // Bit T0IF se Borra
 
  delay_3 = pwm_3*10;
  Servo_3 = 1;
  Delay_Cyc(delay_3);
  Servo_3 = 0;
  TMR0 = 210;
  INTCON.T0IF = 0;
 
  delay_4 = pwm_4*10;
  Servo_4 = 1;
  Delay_Cyc(delay_4);
  Servo_4 = 0;
  TMR0 = 210;
  INTCON.T0IF = 0;
}

void main() {
 CMCON = 0x00;    // desabilita los comparadores
 TRISB = 0xff;
 PORTB = 0;
 TRISC = 0x0f;
 PORTC = 0;
 TRISD = 0x00;
 PORTD = 0;

OPTION_REG = 0x07; // pre-escala(1:256) asignada a  TMR0
TMR0 = 210;        // El timer T0 cuenta desde 180 a 255 creando 20 ms period
INTCON = 0xA0;     //habilita las interrupciones TMR0 y globales
 do{
  if(!Bajar_0){   
    Delay_ms(50);
    pwm_0= pwm_0-0.5;
    if(pwm_0<9.49) pwm_0=9.49;}
  if(!SUBIR_0){
     Delay_ms(50);
     pwm_0 = pwm_0+0.5;
     if(pwm_0>20) pwm_0=20;}
     
     
  if(!Bajar_1){
    Delay_ms(50);
    pwm_1= pwm_1-0.5;
    if(pwm_1<9.49) pwm_1=9.49;}
  if(!SUBIR_1){
     Delay_ms(50);
     pwm_1 = pwm_1+0.5;
     if(pwm_1>20) pwm_1=20;}

  if(!Bajar_2){
    Delay_ms(50);
    pwm_2= pwm_2-0.5;
    if(pwm_2<9.49) pwm_2=9.49;}
  if(!SUBIR_2){
     Delay_ms(50);
     pwm_2 = pwm_2+0.5;
     if(pwm_2>20) pwm_2=20;}

 if(!Bajar_3){
    Delay_ms(50);
    pwm_3= pwm_3-0.5;
    if(pwm_3<9.49) pwm_3=9.49;}
  if(!SUBIR_3){
     Delay_ms(50);
     pwm_3 = pwm_3+0.5;
     if(pwm_3>20) pwm_3=20;}

  if(!Bajar_4){
    Delay_ms(50);
    pwm_4= pwm_4-0.5;
    if(pwm_4<9.49) pwm_4=9.49;}
  if(!SUBIR_4){
     Delay_ms(50);
     pwm_4 = pwm_4+0.5;
     if(pwm_4>20) pwm_4=20;}
 }while(1);
}


Y una imagen del diagrama de conexiones


 

anything