Sei sulla pagina 1di 3

UNIVERSIDADE FEDERAL RURAL DO SEMI-RIDO

DEPARTAMENTO DE ENGENHARIA ELTRICA


CURSO: ENGENHARIA ELTRICA
DISCIPLINA: LABORATRIO DE UP E UC
Aula 1 - Entrada e Sada
PROFESSOR:_______________________________ TURMA:__________ DATA: ____________

1. Objetivos:

Verificar a utilizao das instrues de I/O atravs de teclas e leds.

2. Materiais e equipamentos necessrios:

Kit de Desenvolvimento XM111;


Gravador/Depurador ICD2;
Computador.

3. Instrues utilizadas

set_tris_X( valor ) = { Configura os pinos de uma porta como entrada ou sada}.


output_X (valor) = {Escreve um byte na porta}.
input (pino) = {L o estado do pino do microcontrolador}.

Outras funes de I/O: input_state( ), port_x_pullups( ), input_x( ), output_bit( ), output_high( ), output_low(


), output_toggle( ).

4. Procedimentos:

4.1. Configurar o kit de desenvolvimento de acordo com o circuito abaixo.


4.2. Compilar o cdigo abaixo e validar junto ao kit.
//****************************************************************************************//
// UNIVERSIDADE FEDERAL RURAL DO SEMI-RIDO (UFERSA) //
// *****TECLAS-LED***** //
// AUTOR: Ailton Jr. //
// DISCIPLINA: LABORATRIO DE uC. //
// DATA: 15/05/2014 //
// //
// OBJETIVOS: * Cada tecla lida dever acender seu respectivo led; //
// ATENO: * Jumper JP1 dever estar conectado!!! //
// _______________ //
// -| |- //
// -| |- //
// -| PIC18F4520 |- //
// -| |- //
// -| D0|-0 (LED 0) //
// -| |-1 (LED 1) //
// -| |-2 (LED 2) //
// -| |-3 (LED 3) //
// (CH0) -| B0 |-4 (LED 4) //
// (CH1) -| B1 |-5 (LED 5) //
// (CH2) -| B2 |-6 (LED 6) //
// -| D7|-7 (LED 7) //
// -|_______________|- //
// //
//****************************************************************************************//
#include <18F4520.h> //Definio do Dispositivo.
#use delay(clock=8000000) //Frequncia do Oscilador Principal.

#FUSES HS //High speed Osc (> 4mhz)


#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOMCLR //Master Clear pin used for I/O

int ch0 = 0; //INT0-> Chave no Pino RB0


int ch1 = 0; //INT1-> Chave no Pino RB1
int ch2 = 0; //INT2-> Chave no Pino RB2

void main() //Programa Principal.


{
set_tris_b(0b11111111); //Configurando pinos como entrada para as chaves.
output_d(0xff); //Os leds do kit so ativos BAIXOS.

while(TRUE) //Loop Infinito.


{
ch0 = input_state(pin_b0); //Leitura da tecla ch0.
ch1 = input_state(pin_b1); //Leitura da tecla ch1.
ch2 = input_state(pin_b2); //Leitura da tecla ch2.

if(ch0 == 0) //Verifica se a tecla ch0 foi pressionada.


{
output_d(0b11111110); //Acende o Led 0.
while(!input(pin_b0)); //Espera a tecla ser solta.
output_d(0b11111111); //Apaga o Led 0.
}

if(ch1 == 0) //Verifica se a tecla ch1 foi pressionada.


{
output_d(0b11111101); //Acende o Led 1.
while(!input(pin_b1)); //Espera a tecla ser solta.
output_d(0b11111111); //Apaga o Led 1.
}

if(ch2 == 0) //Verifica se a tecla ch2 foi pressionada.


{
output_d(0b11111011); //Acende o Led 2.
while(!input(pin_b2)); //Espera a tecla ser solta.
output_d(0b11111111); //Apaga o Led 2.
}
}
}

Potrebbero piacerti anche