Ir ao conteúdo
  • Cadastre-se

Interrupções


AlcenorFilho

Posts recomendados

Olá galera. Meu professor passou me um trabalho que consiste em refazer o código que segue abaixo só que desta vez usando interrupções, o programa tem que ler teclas de um teclado telefonico simples.

Este é o codigo original:

#include <16f628a.h>

#use delay(clock=4000000)

#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOMCLR,NOLVP

#byte PORTA = 5

#byte PORTB = 6

//Dimensões do teclado em questão

#define NUMCOLS 3

#define NUMLINS 4

//Pinos do teclado

#define linha0 PIN_A4

#define linha1 PIN_A5

#define linha2 PIN_A6

#define linha3 PIN_A7

#define coluna0 PIN_A0

#define coluna1 PIN_A1

#define coluna2 PIN_A2

//Saídas

#define Mostrador PORTB

//Funções

int8 varre_teclado(void);

int8 decodifica_teclado(int8 tecla);

void main()

{

int8 tecla = 0xFF; // Valor para nenhuma tecla pressionada

int8 Number = 0xFF; // O valor inicial de Number acende um hífen no mostrador

// Os bits 4-7 da porta A tornam-se entradas, os bits 0-3 são saídas.

set_tris_a(0xF0);

set_tris_b(0); // Faz todos os pinos da porta B serem saídas.

while(TRUE)

{

tecla = varre_teclado();

// Se tecla for diferente de FF, ou seja, se alguma tecla foi pressionada,

// decodifica essa tecla e põe o resultado em Number

if (tecla != 0xFF)

Number = decodifica_teclado(tecla);

// Este switch/case exibe o algarismo no mostrador.

switch(Number)

{

case 0: Mostrador = 0x3F;

break;

case 1: Mostrador = 0x06;

break;

case 2: Mostrador = 0x5B;

break;

case 3: Mostrador = 0x4F;

break;

case 4: Mostrador = 0x66;

break;

case 5: Mostrador = 0x6D;

break;

case 6: Mostrador = 0x7D;

break;

case 7: Mostrador = 0x07;

break;

case 8: Mostrador = 0x7F;

break;

case 9: Mostrador = 0x6F;

break;

default: Mostrador = 0x40;

}

//Para eliminar a trepidação

delay_ms(20);

}

}

// Função para varrer um teclado de 4 linhas e 3 colunas uma única vez.

// Retorna o valor absoluto da tecla pressionada.

int8 varre_teclado()

{

output_low(coluna0);

output_low(coluna1);

output_low(coluna2);

output_high(coluna0);

// If a 1 is detected, quit the routine with the current address of key.

if (input(linha0)==1)

return 0;

if (input(linha1)==1)

return 1;

if (input(linha2)==1)

return 2;

if (input(linha3)==1)

return 3;

output_low(coluna0);

output_high(coluna1);

// If a 1 is detected, quit the routine with the current value of key.

if (input(linha0)==1)

return 4;

if (input(linha1)==1)

return 5;

if (input(linha2)==1)

return 6;

if (input(linha3)==1)

return 7;

output_low(coluna1);

output_high(coluna2);

// If a 1 is detected, quit the routine with the current value of key.

if (input(linha0)==1)

return 8;

if (input(linha1)==1)

return 9;

if (input(linha2)==1)

return 10;

if (input(linha3)==1)

return 11;

output_low(coluna2);

// If no key is pressed, the value will be FFh. The program should interpret this out-of-range value as ‘no press.’

return 0xFF;

}

int8 decodifica_teclado(tecla)

{

// Este switch/case decodifica a tecla pressionada, retornando o algarismo

// correspondente no teclado. é dependente de cada teclado.

switch(tecla)

{

case 0: return 1;

case 1: return 4;

case 2: return 7;

case 3: return 0xFF;

case 4: return 2;

case 5: return 5;

case 6: return 8;

case 7: return 0;

case 8: return 3;

case 9: return 6;

case 10: return 9;

default: return 0xFF;

}

}

tenho q refazer ele usando interrupções,, :confused: se alguem poder me ajudar eu agradeço muito..... valeu

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!