Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 11336

Problema com interrupção em PORTB no pino 7 do PIC 16f887, compilador MikroC.

$
0
0
Bom dia a todos.
Tenho um problema com interrupção em PORTB no pino 7 do PIC 16f887, compilador MikroC.
Fiz um programa para treinar que mostra os dados no LCD recorrendo uma interrupção, quando carrega-se um botão.
Reparei que no proteus 8.1 não funcionou.

Queria mistrar o código do programa para ver se esá tudo bem.
Obrigado.

Código :
float txt[10];
double valor;
int cont = 0;


sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

void escrever_LCD()
{
         Lcd_out(0,1, "Leitura:"); // Write text in first row
         FloatToStr(valor,txt);
         Lcd_Out(2,1,txt);
}

void interrupt(){
  if (INTCON.RBIF)
  {
         cont = 1;
         INTCON.RBIF = 0;
  }
}

void main()
{
  ANSEL  = 0x04;                          // Configure AN pins as digital I/O
  ANSELH = 0;

  C1ON_bit = 0;                    // Disable comparators
  C2ON_bit = 0;

  TRISA  = 0xFF;                          // PORTA is input
  TRISC  = 0;                            // PORTC is output
  //TRISB  = 0;                          // PORTB is output



  TRISB.RB7 = 1;                          // RB7 is input
  IOCB.IOCB7 = 1;                        // IOCB<7:0>: Interrupt-on-Change PORTB Control bit pg.51(pdf)

  INTCON.GIE = 1;                        // Activar as interrupções
  INTCON.RBIE = 1;
  INTCON.INTE = 1;                      // External Interrupt Enable bit
  INTCON.INTF = 0;                      // INT External Interrupt Flag bit
  INTCON.RBIF = 0;                      // PORTB Change Interrupt Flag bit

  OPTION_REG.b7 = 0;              // PORTB Pull-up Enable bit (enable=0)
  OPTION_REG.INTEDG = 1;          // Interrupt Edge Select bit
                                                          // 1 = Interrupt on rising edge of INT pin
                                                          // 0 = Interrupt on falling edge of INT pin


  ADC_Init();                            // Iniializar ADC
  Lcd_Init();                            // Inicializar LCD
  Lcd_Cmd(_LCD_CLEAR);          // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);   // Cursor off


  while(1)
  {  
         if(cont == 1)
         {
          valor = ADC_Read(2)*0.00488;
          escrever_LCD();
          Delay_ms(1000);
          cont=0;
         }

         else
         {
           //não faz nada
         }

  }
}

Viewing all articles
Browse latest Browse all 11336

Trending Articles