MICROCONTROLADORES: LED ENCIENDE Y APAGA CON UN PULSADOR.
Explicación del circuito:
Si RA0 se encuentra en estado bajo, el led enciende en un segundo y si RA0 se encuentra en estado alto, el led se apaga en un segundo.
Materiales:
- Un pic16f887.
- Un led rojo.
- Una resistencia de 220Ω.
- Una resistencia de 10kΩ.
- Un pulsador.
Simulación.
Funciones utilizadas en el programa:
#INCLUDE <16F887.h>: La librería a utilizar es la del pic16F887.
#USE DELAY(CLOCK=4000000): Se configura la frecuencia del reloj del sistema a 4MHZ.
#FUSES XT, NOPROTECT,NOWDT: Son los bits de configuración. En donde:
#FUSES XT: Se habilita el oscilador del sistema.
#FUSES NOPROTECT: Se deshabilita la protección contra lectura de la FLASH.
#FUSES NOWDT: Se deshabilita el Watch Dog Timer.
#BYTE PORTA=5 / #BYTE PORTA=0X05: Se define el puerto A, que se sitúa en la dirección 0X05 de la memoria RAM.
#BYTE PORTB=6 / #BYTE PORTB=0X06: Se define puerto B , que se sitúa en la dirección 0X06 de la memoria RAM.
#DEFINE SW1 PORTA, 0: El pulsador se coloca en el pin cero del puerto A.
#DEFINE LED PORTB, 7: El led se coloca en el pin siete del puerto B(RB7).
SET_TRIS_A(255): Para configurar el puerto A como entrada digital. En este caso, se trabaja con decimal; pero también se puede trabajar con binario de la siguiente forma: 0B11111111.
SET_TRIS_B(0B01111111): Se configura el pin siete del puerto B(RB7), como salida digital.
SET_TRIS_C(255): Se configura el puerto C como entradas digitales. Como se está trabajando con decimal, también es posible trabajar con binario de la siguiente manera: 0B11111111.
BIT_CLEAR(LED)/ BIT_CLEAR(PORTB,7): Pone en cero el bit de la variable (el puerto B). Entonces el led se encuentra apagado.
BIT_SET(LED)/BIT_SET(PORTB, 7): Pone en uno el bit de la variable(el puerto B). Entonces el led está encendido.
BIT_TEST(SW1)/BIT_TEST(PORTA,0): Pone en uno el bit de la variable, en este caso, el puerto A. Pero como está negado en el programa !BIT_TEST(SW1)/!BIT_TEST(PORTA,0), devuelve un cero.
Simulación.
codigo fuente.
//Parpadea el led si RA0=bajo y si RA0=alto,el LED=apagado.LED esta en RB7 #INCLUDE <16F887.h> //Es el reloj o frecuencia que se usa para generar retardos #USE DELAY(CLOCK=4000000) //Bit de configuración inicial que se habilitan o desabilitan para que pueda trabjar el microcontrolador #FUSES XT,NOPROTECT,NOWDT //Define los registros //El cinco y el seis son las posiciones de memoria de la memoria RAM #BYTE PORTA=5 #BYTE PORTB=6 //Definición de entrada/salidas #DEFINE SW1 PORTA,0 //Swiche se va a colocar en RA0 #DEFINE LED PORTB,7 //Led se coloca en RB7 main(){ //Con TRIS, esta instrucción indica que se esta trabajando como digitales SET_TRIS_B(0B01111111); //OB inidica que se esta trabajando en binario, RB7 es configurado como salida digital SET_TRIS_A(255); //Aquí se trabaja en decimal y se puede poner en binario como 0B11111111, es configurado entrada digitales SET_TRIS_C(255); //Aquí se trabaja en decimal y se puede poner en binario como 0B11111111, es configurado entrada digitales BIT_CLEAR(LED); //El led inicialmente esta apagado WHILE(1){ IF(!BIT_TEST(SW1)){ //BIT_TEST, evalua que lo haya en parentesis valga uno; pero en este caso esta negado y vale cero BIT_SET(LED); //Prende led DELAY_MS(1000); //Retardo BIT_CLEAR(LED); //Apagar led DELAY_MS(1000); //Retardo } ELSE{ BIT_CLEAR(LED); //Apaga led } } }
CONTENIDOS MÁS RELEVANTES.

LOS MEJORES SITIOS PARA APRENDER ELECTRICIDAD GENERAL
Leer Más

LOS MEJORES SITIOS PARA APRENDER ELECTRONICA
Leer Más

PLC: APRENDER A PROGRAMAR
Leer Más

LOS MEJORES SITIOS PARA APRENDER ROBOTICA COMPLETAMENTE GRATIS.
Leer Más

DESCARGAR GRATIS LIBROS DE ELECTRÓNICA
Leer Más

LOS MEJORES SITIOS PARA APRENDER INSTRUMENTACIÓN Y CONTROL
Leer Más

MICROCONTROLADORES: CURSO COMPLETAMENTE GRATIS.
Leer Más

PLC: CURSO COMPLETAMENTE GRATIS.
Leer Más

APRENDE LABVIEW CON ESTOS SENCILLOS TUTORIALES
Leer Más

IGBT. QUE ES- PARA QUE SIRVE- COMO FUNCIONA
Leer Más

INVERSOR DE GIRO DE MOTOR TRIFÁSICO
Leer Más

CONTROL ELECTRICO-INTRODUCCION
Leer Más
Only wanna input on few general things, The website pattern is perfect, the subject matter is really superb : D. Arlee Merry Culley
I was studying some of your blog posts on this internet site and I conceive this web site is very instructive! Retain posting . Daffie Mitchell Heimer
This excellent website really has all the information I wanted about this subject and didn at know who to ask. Retha Barton Durtschi
I love looking through an article that can make people think. Also, many thanks for allowing me to comment. Ava Jamey Dalston
Dear Satyendra, Kanpur University BSc Time Table 2020 link is available in this article. Debra Wolfy Mihalco
Amazing! Its actually remarkable paragraph, I have got much clear idea concerning from this piece of writing. Emilie Shane Suzanne
Post writing is another fun, in the event you know then it is possible to write if not it is actually complicated to create. Orsa Waylen Bunce
I quite like reading through a post that will make people think. Also, thank you for allowing for me to comment. Jocelin Lew Tuppeny
Lots of bowling spheres have a urethane coverstock. Brittni Gaspar Deb
Very good blog! Do you have any hints for aspiring writers? I am hoping to start my own site soon but I am a little lost on everything. Hollyanne Pascale Mabelle
Wonderful website. Lots of useful information here. Cristine Chucho Dewey