Вы находитесь на странице: 1из 127

Manual de Practicas

Microcontroladores para Instrumentacin y Control


Universidad Tecnolgica de Chihuahua
T.S.U. Mecatrnica

Elaborado por:
Arzabala Contreras Ernesto Alonso
Salazar Lopez Luis Ricardo
Vallejo Gonzlez Mario Alberto

Contenido
Unidad I Arquitectura interna de los Microcontroladores.................................................................. 8
Practica 1.1 Conexiones basicas y encendido de leds ..................................................................... 8
Descripcin P1.1: ......................................................................................................................... 8
Cdigo P1.1: ................................................................................................................................ 8
Circuito P1.1: ............................................................................................................................... 9
Practica 1.2 Oscilador interno y ciclos de repeticin ...................................................................... 9
Descripcin P1.2: ......................................................................................................................... 9
Cdigo P1.2: .............................................................................................................................. 10
Circuito P1.2: ............................................................................................................................. 12
Practica 1.3 Ciclos anidados .......................................................................................................... 13
Descripcin P1.3: ....................................................................................................................... 13
Cdigo P1.3: .............................................................................................................................. 13
Circuito P1.3: ............................................................................................................................. 15
Practica 1.4 Temporizador TMR0 e interrupciones ...................................................................... 15
Descripcin P1.4: ....................................................................................................................... 15
Cdigo P1.4: .............................................................................................................................. 16
Circuito P1.4: ............................................................................................................................. 19
Practica 1.5 Uso de botones y subrutinas ..................................................................................... 19
Descripcin P1.5: ....................................................................................................................... 19
Cdigo P1.5: .............................................................................................................................. 20
Circuito P1.5: ............................................................................................................................. 22
Practica 1.6 Temporizador TMR0 como contador, variables y relevadores ................................. 22
Descripcin P1.6: ....................................................................................................................... 22
Cdigo P1.6: .............................................................................................................................. 23
Circuito P1.6: ............................................................................................................................. 25
Practica 1.7 Macros y rutinas para evitar el rebote de botones ................................................... 25
Descripcin P1.7: ....................................................................................................................... 25
Cdigo P1.7: .............................................................................................................................. 25
Circuito P1.7: ............................................................................................................................. 31
Practica 1.8 Temporizador TMR1 e interrupciones ...................................................................... 31
Descripcin P1.8: ....................................................................................................................... 31

Cdigo P1.8: .............................................................................................................................. 31


Circuito P1.8: ............................................................................................................................. 34
Practica 1.9 Temporizador TMR2 y configuracin del oscilador ................................................... 34
Descripcin P1.9: ....................................................................................................................... 34
Cdigo P1.9: .............................................................................................................................. 34
Circuito P1.9: ............................................................................................................................. 38
Practica 1.10 Modulo CCP 1 como generador de seales tipo PWM ........................................... 38
Descripcin P1.10: ..................................................................................................................... 38
Cdigo P1.10: ............................................................................................................................ 38
Circuito P1.10: ........................................................................................................................... 42
Practica 1.11 Utilizacin del convertidor analgico-digital (ADC)................................................ 42
Descripcin P1.11: ..................................................................................................................... 42
Cdigo P1.11: ............................................................................................................................ 43
Circuito P1.11: ........................................................................................................................... 44
Practica 1.12 Uso de la memoria EEPROM ................................................................................... 45
Descripcin P1.12: ..................................................................................................................... 45
Cdigo P1.12: ............................................................................................................................ 45
Circuito P1.12: ........................................................................................................................... 49
Practica 1.13 Contador de dos dgitos multiplexado .................................................................... 49
Descripcin P1.13: ..................................................................................................................... 49
Cdigo P1.13: ............................................................................................................................ 49
Circuito P1.13: ........................................................................................................................... 57
Practica 1.14 Generacin de sonidos usando macros .................................................................. 57
Descripcin P1.14: ..................................................................................................................... 57
Cdigo P1.14: ............................................................................................................................ 57
Circuito P1.14: ........................................................................................................................... 62
Practica 1.15 Utilizacin del display de cristal lquido (LCD) ......................................................... 62
Descripcin P1.15: ..................................................................................................................... 62
Cdigo P1.15: ............................................................................................................................ 62
Circuito P1.15: ........................................................................................................................... 73
Practica 1.16 Comunicacin serial RS232...................................................................................... 73
Descripcin P1.16: ..................................................................................................................... 73

Cdigo P1.16: ............................................................................................................................ 73


Circuito P1.16: ........................................................................................................................... 80
Unidad II Compilador C para Microcontroladores ......................................................................... 81
Practica 2.1 Encendido de leds y configuraciones basicas. ........................................................... 81
Descripcin P2.1: ....................................................................................................................... 81
Circuito P2.1: ............................................................................................................................. 81
Cdigo P2.1: .............................................................................................................................. 82
Practica 2.2 Oscilador interno y mezcla de lenguaje ensamblador y C........................................ 84
Descripcin P2.2: ....................................................................................................................... 84
Circuito P2.2: ............................................................................................................................. 84
Cdigo P2.2: .............................................................................................................................. 85
Practica 2.3 Temporizador TMR0 como contador, variables y relevadores ................................. 87
Descripcin P2.3: ....................................................................................................................... 87
Circuito P2.3: ............................................................................................................................. 87
Cdigo P2.3: .............................................................................................................................. 87
Practica 2.4 Temporizadores TMR0,TMR1 y TMR2 e interrupciones ........................................... 89
Descripcin P2.4: ....................................................................................................................... 89
Circuito P2.4: ............................................................................................................................. 89
Cdigo P2.4: .............................................................................................................................. 89
Practica 2.5 Uso de del watchdog timer .................................................................................... 94
Descripcin P2.5: ....................................................................................................................... 94
Circuito P2.5: ............................................................................................................................. 94
Cdigo P2.5: .............................................................................................................................. 94
Practica 2.6 Modulo CCP 1 como generador de seales tipo PWM ............................................. 95
Descripcin P2.6: ....................................................................................................................... 95
Circuito P2.6: ............................................................................................................................. 95
Cdigo P2.6: .............................................................................................................................. 96
Practica 2.7 Utilizacin del convertidor analgico-digital (ADC).................................................. 98
Descripcin P2.7: ....................................................................................................................... 98
Circuito P2.7: ............................................................................................................................. 98
Cdigo P2.7: .............................................................................................................................. 98
Practica 2.8 Uso de la memoria EEPROM ................................................................................... 100

Descripcin P2.8: ..................................................................................................................... 100


Circuito P2.8: ........................................................................................................................... 100
Cdigo P2.8: ............................................................................................................................ 101
Practica 2.9 Contador de dos dgitos multiplexado .................................................................... 102
Descripcin P2.9: ..................................................................................................................... 102
Circuito P2.9: ........................................................................................................................... 102
Cdigo P2.9: ............................................................................................................................ 103
Practica 2.10 Utilizacin del display de cristal lquido (LCD) ....................................................... 106
Descripcin P2.10: ................................................................................................................... 106
Circuito P2.10: ......................................................................................................................... 106
Cdigo P2.10: .......................................................................................................................... 106
Practica 2.11 Comunicacin serial RS232.................................................................................... 109
Descripcin P2.11: ................................................................................................................... 109
Circuito P2.11: ......................................................................................................................... 109
Cdigo P2.11: .......................................................................................................................... 110
Practica 2.12 Generacin de sonidos utilizando una librera ...................................................... 111
Descripcin P2.12: ................................................................................................................... 111
Circuito P2.12: ......................................................................................................................... 111
Cdigo P2.12: .......................................................................................................................... 112
Unidad III Aplicaciones para el control de procesos y comunicacin ............................................. 115
Practica 3.1 Control de un motor de DC mediante un puente H ................................................ 115
Descripcion P3.1: ..................................................................................................................... 115
Circuito P3.1: ........................................................................................................................... 115
Cdigo P3.1: ............................................................................................................................ 116
Practica 3.2 Control de un motor de pasos ................................................................................. 117
Descripcion P3.2: ..................................................................................................................... 117
Circuito P3.2: ........................................................................................................................... 118
Cdigo P3.2: ............................................................................................................................ 119
Practicas 3.3 Control de un servo motor..................................................................................... 120
Desripcion P3.3: ...................................................................................................................... 120
Circuito P3.3: ........................................................................................................................... 121
Cdigo P3.3: ............................................................................................................................ 121

Practica 3.4 Medicin de temperatura con un sensor tipo IC y calibracin de un termistor. .... 122
Descripcion P3.4: ..................................................................................................................... 122
Circuito P3.4: ........................................................................................................................... 122
Cdigo P3.4: ............................................................................................................................ 122
Practica 3.5 Control de temperatura tipo ON/OFF ..................................................................... 123
Descripcion P3.5: ..................................................................................................................... 123
Circuito P3.5: ........................................................................................................................... 123
Cdigo P3.5: ............................................................................................................................ 123
Practica 3.6 Modulo remoto de medicin y control. 3 sensores, 2 actuadores, comunicacin
mediante RS232, modo de control remoto mediante PC, modo de control local mediante
botones. ...................................................................................................................................... 123
Descripcion P3.6: ..................................................................................................................... 123
Circuito P3.6: ........................................................................................................................... 124
Cdigo P3.6: ............................................................................................................................ 124
Proyecto final .............................................................................................................................. 124
Descripcion PF: ........................................................................................................................ 124
Circuito PF: .............................................................................................................................. 124
Cdigo PF:................................................................................................................................ 124
Formato de reportes ................................................................................................................... 125
Criterios y ponderaciones de evaluacin .................................................................................... 126
Unidad I ................................................................................................................................... 126
Unidad II .................................................................................................................................. 126
Unidad III ................................................................................................................................. 126
Links de ayuda ............................................................................................................................. 127

Unidad I Arquitectura interna de los Microcontroladores


Practica 1.1 Conexiones basicas y encendido de leds
Descripcin P1.1:
El nico propsito de esta prctica es mostrar el circuito bsico, tambin llamado sistema mnimo,
y el proceso de programacin de un microcontrolador (uC) PIC16F887. El PIC16F887 es el uC que
se utilizara en todas las prcticas de este manual a menos que se indique lo contrario. Cabe
resaltar que los Microcontroladores PIC16F877, PIC16F877A, PIC16F887 y PIC16F917 son
compatibles. El PIC16F887 puede ser considerado como una nueva y mejor versin del PIC16F887,
as mismo el PIC16F917 es similar al PIC16F877A pero adems incorpora un mdulo manejador de
LCD.
El circuito y el programa nicamente realizan la funcin de encender algunos led conectados al
puerto B del microcontrolador (uC) PIC16F887.
Cdigo P1.1:
;************************************************
;

Nombre

P1_1.asm

Fecha

Enero 10,2013

Alumno

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Prueba del microcontrolador

;************************************************

list p=16f887
#include <p16f887.inc>

errorlevel -302

__CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON &
_FCMEN_ON & _LVP_OFF

__CONFIG _CONFIG2, _BOR40V & _WRT_OFF

ORG

0x0000

Banksel

TRISB

clrf

TRISB

banksel

PORTB

movlw

B'01010101'

movwf

PORTB

end

Circuito P1.1:

Practica 1.2 Oscilador interno y ciclos de repeticin


Descripcin P1.2:
Esta prctica es una continuacin de P1.1. En esta prctica se pretende hacer que los leds
conectados al puerto B parpadeen (blink).
El efecto de que los leds parecen parpadear es conseguido de la siguiente manera:

1.
2.
3.
4.
5.

En el puerto B se carga la combinacin binaria 01010101


Permanecer en el ciclo1 durante un tiempo determinado
Reemplazar la combinacin binaria existente en el puerto B con la combinacin 10101010
Permanecer en el ciclo1 durante un tiempo determinado
Regresar al paso 1 y repetir todo el proceso de nuevo.

Para poder observar los cambios de combinacin binaria en el puerto B, apreciar el efecto del
parpadeo, el proceso mencionado anteriormente se necesita llevar a cabo de una manera lenta.
Para lograr esto se utiliza el oscilador interno LFINTOSC del microcontrolador el cual tiene una
frecuencia de 31 kHz mucho ms lenta que la del oscilador externo el cual tiene conectado el
cristal de 8 MHz.
La fuente de la seal de reloj es cambiada durante la ejecucin del programa, on the fly. Para
verificar que esto realmente est sucediendo, antes de energizar el uC desconecta el cristal. Qu
paso? El uC no debe de hacer nada ya que la configuracin de este requiere el uso del cristal al
momento de iniciar a ejecutar el programa. Si el cristal se desconecta despus de que el uC ya
inicio la ejecucin del programa esto no debe de afectar el funcionamiento del uC de ninguna
manera.
Cdigo P1.2:
;************************************************
;

Nombre :

P1_2.asm

Fecha

Enero 10,2013

Alumno :

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Parpadear leds Puerto B

;************************************************
list p=16f887
#include <p16f887.inc>
errorlevel -302
__CONFIG
_CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF &
_BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG

_CONFIG2, _BOR40V & _WRT_OFF

;************************************************************************
;************* DEFINING VARIABLES ***************************************

cblock 0x20

; Bloque de variables inicia en dir. 20h

counter1

; La variable "counter1" en la dir. 20h

endc
;************************************************************************
org

0x0000

; Direccion de la primera instruccion

banksel OSCCON

; Selecciona el banco de memoria que

; contiene el registro OSCCON


bcf

OSCCON,6

; Selecciona el oscilador interno LFINTOSC

bcf

OSCCON,5

; con la frequency de 31KHz

bcf

OSCCON,4

bsf

OSCCON,0

; uC usa el oscilador interno

banksel TRISB

; Selecciona el banco que contiene a TRISB

clrf TRISB

; Todos los pines del PORTB configurados


; como salidas

banksel PORTB

loop

; Selecciona el banco que contiene a PORTB

; etiqueta con el nombre de "loop"

movlw B'01010101'
movwf PORTB
movlw h'FF'

; Numero binario 01010101 se carga en W


; Numero binario se mueve al PORTB

; Numero hFF se carga en W

movwf counter1
loop1

; Numero se mueve a la variable "counter1"


; etiqueta con el nombre de "loop1"

decfsz counter1
goto loop1

; Variable "counter1" se decrementa en 1


; Si "counter1" es 0, continuar.

; de lo contrario volver a "loop1"

movlw B'10101010'
movwf PORTB
movlw h'FF'

; Numero BIN 10101010 se carga en W


; Numero se mueve a PORTB

; Numero hFF se carga en W

movwf counter1
loop2

; Number se mueve a la variable "counter1"


; etiqueta con el nombre de "loop2"

decfsz counter1
goto loop2

; Variable "counter1" se decrementa en 1


; Si "counter1" es 0, continuar.

; de lo contrario volver a "loop2"


goto loop
end

Circuito P1.2:

; Volver a la etiqueta "loop"


; Fin del Programa

Practica 1.3 Ciclos anidados


Descripcin P1.3:
En la prctica anterior se pudo observar que el microcontrolador ejecuta las instrucciones muy
rpido y en ocasiones es necesario hacerlo que vaya ms lento. El uso del oscilador interno LF,
como se hace en la prctica P1.2, debe de ser la ltima opcin. Una mejor manera de realizarlo es
utilizar ciclos anidados en el programa. En esta prctica, la variable counter1 se decrementa una
unidad 255 veces, es decir el programa contara de 255 a 0 antes de salir del ciclo interior loop1.
El programa contara 255 veces de 255 a 0 en cada ciclo exterior loop. Lo anterior quiere decir
que entre dos parpadeos consecutivos de leds hay 255 x 255 pulsos del cristal oscilador.
De manera ms precisa el nmero de pulsos entre dos parpadeos consecutivos es de
aproximadamente de 196000, esto es debido a que la ejecucin de las instrucciones de brinco
(goto) y de decremento requieren de un cierto nmero de pulsos para ser ejecutadas.
La instruccin de decremento DECFSZ se realiza en 1 o 2 ciclos. La instruccin de brinco GOTO se
realiza en 2 ciclos tambin. Si suponemos que la instruccin DEC FSZ se realiza en un ciclo y la
instruccin GOTO en 2 ciclos, eso son tres ciclos. Si estas dos instrucciones, que se realizan en 3
ciclos, se realizan 255*255 veces eso equivale : 255 * 255 * 3 = 195075, aproximadamente 196000
instrucciones como se haba comentado antes.
Cdigo P1.3:
;************************************************
;

Nombre :

P1_3.asm

Fecha

Enero 10,2013

Alumno :

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Parpadear leds Puerto B , Ciclos anidados

;************************************************
list p=16f887
#include <p16f887.inc>
errorlevel -302
__CONFIG
_CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF &
_BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG

_CONFIG2, _BOR40V & _WRT_OFF

;************* DEFINING VARIABLES *****************************************


cblock

0x20

; Block of variables starts at address 20h

counter1

; Variable "counter1" at address 20h

counter2

; Variable "counter2" at address 21h

endc
;**************************************************************************
org

banksel
clrf

banksel

0x0000

; Address of the first program instruction

TRISB

; Selects bank containing register TRISB

TRISB

; Clears TRISB

PORTB

; Selects bank containing register PORTB

loop
movlw

B'11110000' ; Binary number 11110000 is moved to W

movwf

PORTB

movlw

h'FF'

movwf

counter2

; Number is moved to PORTB


; Number hFF is moved to W
; Number is moved to variable "counter2"

loop2
movlw

h'FF'

; Number hFF is moved to W

movwf

counter1

; Number is moved to "counter1"

loop1
decfsz

counter1

goto

loop1

decfsz

counter2

goto

loop2

movlw

; Decrements "counter1" by 1. If result is 0


; skip next instruction

; Decrements "counter2" by 1. If result is 0


; skip next instruction

B'00001111' ; Binary number 00001111 is moved to W

movwf

PORTB

; Number is moved to PORTB

movlw

h'FF'

movwf

counter2

; Number hFF is moved to W


; Number is moved to variable "counter2"

loop4
movlw

h'FF'

; Number hFF is moved to W

movwf

counter1

; Number is moved to variable "counter1"

loop3
decfsz

counter1

; Decrements "counter1" by 1. If result is 0

; skip next instruction


goto

loop3

decfsz

counter2

goto

loop4

; skip next instruction

goto

loop

; Jump to label loop

end

; Decrements "counter2" by 1. If result is 0

; End of program

Circuito P1.3:
Igual al de la prctica P1.2

Practica 1.4 Temporizador TMR0 e interrupciones


Descripcin P1.4:
En la prctica anterior se puede apreciar la desventaja de realizar retardos de tiempo (delays)
utilizando ciclos. En casos como el de la practica anterior, el microcontrolador est captivo y no
hace nada ms que esperar a que pase el tiempo. Esa prdida de tiempo es inaceptable y es
necesario encontrar otro mtodo para realizar retardos de tiempo.
En este ejemplo se hace uso de los temporizadores (timers) y de interrupciones (interrupts) y
se hace un vnculo entre ambos de manera prctica. Para este ejemplo es necesario realizar un
retardo de tiempo lo suficientemente largo para apreciar el cambio en los leds del PORTB. En esta
ocasin el temporizador TMR0, con un pre-escalador (prescaler), es utilizado para ese propsito.
La interrupcin ocurre cada vez que ocurre un sobre-flujo (overflow) el registro del
temporizador. La interrupcin incrementa el valor mostrado en el PORTB en uno. Todo el proceso
es realizado detrs de cmaras (behind the scenes) , esto permite que el microcontrolador haga
otras cosas mientras espera a que en el registro del temporizador se genere una interrupcin por
sobre-flujo y se interrumpa momentneamente la ejecucin del programa principal.
En este ejemplo hay poner atencin a ciertos detalles:

Aun y cuando no es necesario en este caso, los contenidos de los registros ms


importantes (W, STATUS and PCLATH) deben de guardarse al inicio de cada rutina de
interrupcin.
La interrupcin causa que la bandera apropiada se active (set), en este ejemplo la
bandera que se activa es TMR0IF, y que el bit GIE se desactive (clear). Al finalizar la
rutina de interrupcin no hay que olvidar regresar el bit GIE y la bandera a los valores que
tenan anteriormente.
Finalmente es crucial que los registros importantes sean devueltos a los valores que tenan
antes de entrar a la rutina de interrupcin.

Cdigo P1.4:
;************************************************
;

Nombre :

P1_4.asm

Fecha

Enero 10,2013

Alumno :

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Temporizador TMR0 e interrupciones

;************************************************

list p=16f887
#include <p16f887.inc>

errorlevel -302

__CONFIG
_CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF &
_BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG

_CONFIG2, _BOR40V & _WRT_OFF

;**************** DEFINING VARIABLES ****************************************

cblock

0x20

; Block of variables starts at address 20h

w_temp

; Variable at address 20h

pclath_temp

; Variable at address 21h

status_temp

; Variable at address 22h

endc

;************************ START OF PROGRAM **********************************


org

0x0000

; Address of the first program instruction

goto

main

; Go to label "main"

;************************ INTERRUPT ROUTINE *********************************


org
movwf
movf
movwf
movf

0x0004

; Interrupt vector

w_temp
STATUS

; Saves value in register W


; Saves value in register STATUS

status_temp
PCLATH

; Saves value in register PCLATH

movwf

pclath_temp

banksel

PORTB

incf

banksel
bcf

movf
movwf
movf

PORTB

INTCON

; Increments register PORTB by 1

; Selects bank containing INTCON

INTCON,TMR0IF ; Clears interrupt flag TMR0IF

pclath_temp,w ; PCLATH is given its original content


PCLATH
status_temp,w ; STATUS is given its original content

movwf

STATUS

swapf

w_temp,f

swapf

w_temp,w

bsf

; Selects bank containing PORTB

INTCON,GIE

; W is given its original content

; Global interrupt enabled

retfie

; Return from interrupt routine

;************************ MAIN PROGRAM **************************************


main

banksel

; Start of the main program

ANSEL

clrf

ANSEL

clrf

ANSELH

banksel
clrf

banksel

; Bank containing register ANSEL


; Clears registers ANSEL and ANSELH
; All pins are digital

TRISB

; Selects bank containing register TRISB

TRISB

; All port B pins are configured as outputs

OPTION_REG

; Bank containing register OPTION_REG

bcf

OPTION_REG,T0CS ; TMR0 counts pulses from oscillator

bcf

OPTION_REG,PSA ; Prescaler is assign to timer TMR0

bsf

OPTION_REG,PS0 ; Prescaler rate is 1:256

bsf

OPTION_REG,PS1

bsf

OPTION_REG,PS2

banksel

INTCON

; Bank containing register INTCON

bsf

INTCON,TMR0IE ; TMR0 interrupt overflow enabled

bsf

INTCON,GIE

banksel
clrf

PORTB

; Global interrupt enabled

; Bank containing register PORTB

PORTB

; Clears port B

loop

; Remain here

loop
goto
end

; End of program

Circuito P1.4:

Practica 1.5 Uso de botones y subrutinas


Descripcin P1.5:
En los ejemplos anteriores el microcontrolador simplemente ejecuta el programa sin la posibilidad
de poder interactuar de alguna manera con este. En la realidad dispositivos trabajando de esta
manera son poco comunes. Para agregarle ms funcionalidad al programa que ejecuta un
microcontrolador es necesario utilizar las entradas con las que este cuenta.
Este ejemplo es bastante sencillo en realidad. Al inicio del programa, justo despus de definir las
variables, los pines del microcontrolador son configurados utilizando los registros TRISA y TRISB.
Los pines del PORTA son configurados como entrada utilizando el registro TRISA, aun y cuando
esto no es necesario ya que la configuracin inicial de los pines del PORTA es de ser entradas.
El programa inicia activando un bit del PORTB y luego el contenido de este registro es
constantemente desplazados un lugar hacia la izquierda (utilizando la instruccin RLF, Rotate Left
f through Carry). Esto produce la impresin de que el diodo led encendido se mueve.
Presionando el botn STOP detiene el movimiento y el programa se mantiene en el loop3. El
retardo de tiempo en esta ocasin es realizado en una subrutina llamada DELAY.

Cdigo P1.5:
;************************************************
;

Nombre :

P1_5.asm

Fecha

Enero 10,2013

Alumno :

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Uso de botones y subrutinas

;************************************************

list p=16f887
#include <p16f887.inc>

errorlevel -302

__CONFIG
_CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF &
_BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG

_CONFIG2, _BOR40V & _WRT_OFF

;************* DEFINING VARIABLES *******************************************

cblock

0x20

; Block of variables starts at address 20h

counter1

; Variable "counter1" at address 20h

counter2

; Variable "counter2" at address 21h

endc

; Block of variables ends

;************************ MAIN PROGRAM **************************************

org
banksel

0x0000
ANSEL

clrf

ANSEL

clrf

ANSELH

; Address of the first program instruction


; Selects bank containing register ANSEL
; Clears registers ANSEL and ANSELH to
; configure all inputs as digital

banksel
clrf

TRISB

; Selects bank containing register TRISB

TRISB

; All port B pins are configured as outputs

movlw

B'00000010'

movwf

TRISA

; Pin RA1 is input

banksel

PORTB

; Selects bank containing register TRISB

movlw

B'00000001'

movwf

PORTB

; Writes 1 to register W
; Number is moved to PORTB

loop
rlf

PORTB

; Port B bits rotates by one place left

call

DELAY

; Calls subroutine "DELAY"

loop3
btfss

PORTA,1

; Tests the first port A bit

goto

loop3

; "0" is applied to pin.Go to label "loop3"

goto

loop

; "1" is applied to pin.Go to label "loop"

;************************ SUBROUTINES ***************************************


DELAY
clrf

counter2

; Clears variable "counter2"

counter1

; Clears variable "counter1"

loop1
clrf
loop2
decfsz

counter1

goto

loop2

decfsz

counter2

goto

loop1

return

end

; Decrements variable "counter1" by 1


; Result is not 0. Go to label loop2
; Decrements variable "counter2" by 1
; Result is not 0. Go to lab loop1

; Return from subroutine "DELAY"

; End of program

Circuito P1.5:

Practica 1.6 Temporizador TMR0 como contador, variables y relevadores


Descripcin P1.6:
En este ejemplo el temporizador TMR0 es usado como contador. La idea es conectar la entrada del
contador a un botn de tal manera que se cuente un pulso cada vez que se presione el botn.
Cuando el nmero de pulsos contados es igual al nmero en el registro TEST, un nivel lgico de 1
(5 V DC) aparece en el pin 3 del PORTD. Dado que este voltaje activa un relevador electromecnico,
este bit es llamado Relay.
En este ejemplo, el registro TEST contiene el nmero 5. En realidad, puede ser cualquier nmero.
En lugar del relevador, el microcontrolador puede activar algn otro dispositivo y en lugar de
botones se pueden usar sensores.

Cdigo P1.6:
;************************************************
;

Nombre :

P1_6.asm

Fecha

Enero 10,2013

Alumno :

Arzabala Contreras Ernesto

Grupo

MT00X

;************************************************
;

Descripcion

Temporizador TMR0 como contador, variables y relevadores

;************************************************

list p=16f887
#include <p16f887.inc>

errorlevel -302

__CONFIG
_CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF &
_BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG

_CONFIG2, _BOR40V & _WRT_OFF

;************* DEFINING VARIABLES *******************************************

TEST
#define

equ B'00000101' ; Binary number 00000101 = TEST


RELAY PORTD,3 ; Pin PORTD,3 = RELAY

;************************ MAIN PROGRAM **************************************


org

banksel

0x0000

; Address of the first program instruction

TRISB

; Selects bank containing register TRISB

clrf

TRISB

; All port B pins are configured as outputs

clrf

TRISD

; All port D pins are configured as outputs

movlw

B'00010000'

movwf

TRISA

; This number is written to W register

; Only the forth pin of port A is input

banksel

OPTION_REG

; Bank containing OPTION_REG register

bsf

OPTION_REG,T0CS ; Pin RA4 is supplied with pulses

bsf

OPTION_REG,PSA ; Prescaler rate is 1:1

banksel

PORTB

clrf

TMR0

bcf

PORTD,3

; Selects bank containing PORTB register

; Clears timer register


; Pin PORTD,3 = 0

loop
movfw

TMR0

; Timer register is moved to W register

movwf

PORTB

; W register is moved to PORTB

xorlw

TEST

; Operation exclusive OR between


; W register and number TEST (00000101)

btfsc
bsf
goto

end

STATUS,Z
PORTD,3
loop

; If numbers are equal, result is 0 and


; bit STATUS,Z = 1. Bit PORTD,3 is set
; and jump to label loop is executed

; End of program

Circuito P1.6:

Practica 1.7 Macros y rutinas para evitar el rebote de botones


Descripcin P1.7:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.7:
;********************** Header **********************
;************* DEFINING VARIABLES *************************

cblock

HIcnt

0x20

; Block of variables starts at address 20hex

LOcnt
LOOPcnt
cnt
endc

; End of block of variables

;**********************************************************************
ORG

0x000

; Reset vector

nop
goto

main

; Go to program start (label "main")

;**********************************************************************

include "pause.inc"
include "button.inc"

;**********************************************************************
main
banksel

ANSEL

clrf

ANSEL

clrf

ANSELH

banksel

TRISB

bsf

TRISA, 0

bsf

TRISA, 1

clrf

TRISB

banksel
clrf

PORTB
cnt

; Selects bank containing ANSEL


; All pins are digital

Loop
button

PORT,0,0,Increment

button

PORT,1,0,Decrement

goto

Loop

Increment
incf
movf
movwf
goto

cnt, f
cnt, w
PORTB
Loop

Decrement
decf
movf
movwf
goto

cnt, f
cnt, w
PORTB
Loop

end

; End of program

Macro pausems

ARCHIVO: pause.inc

; Todo este cdigo va en un archivo llamado pause.inc


;**********************************************************************
pausems MACRO arg1
local

Loop1

local

dechi

local

Delay1ms

local

Loop2

local

End

movlw

High(arg1)

; Higher byte of argument is moved

; to HIcnt
movwf

HIcnt

movlw

Low(arg1)

; Lower byte of argument is moved

; to LOcnt
movwf

LOcnt

Loop1
movf

LOcnt, f

btfsc

STATUS, Z

goto

dechi

call

Delay1ms

decf

LOcnt, f

goto

Loop1

; Decrements HIcnt and LOcnt while


; needed and calls subroutine Delay1ms

dechi
movf

HIcnt, f

btfsc

STATUS, Z

goto

End

call

Delay1ms

decf

HIcnt, f

decf

LOcnt, f

goto

Loop1

Delay1ms:

; Delay1ms provides delay of

movlw

.100

movwf

LOOPcnt

; 100*10us=1ms
; LOOPcnt<-100

Loop2:
nop
nop
nop
nop
nop
nop
nop
decfsz

LOOPcnt, f

goto

Loop2

return

; Execution time of Loop2


; is 10 us

End
ENDM
;**********************************************************************

Macro button

ARCHIVO: button.inc

; Todo este cdigo va en un archivo llamado button.inc


;****************************************************
button MACRO port,pin,hilo,label
local

Pressed1

local

Pressed2

local

Exit1

local

Exit2

IFNDEF

; All labels are local

debouncedelay ; Enables debounce time to be defined

; in main program
#define

debouncedelay .10

ENDIF

IF (hilo == 0)
btfsc

port, pin

goto

Exit1

pausems

; If pull-up used
; If "1", push-button is pressed

debouncedelay ; Wait for 10ms debounce

Pressed1
btfss

port, pin

goto

Pressed1

pausems
goto

debouncedelay ; Wait until released and


label

; jump to specified address

Exit1
ELSE

; If pull-down used

btfss

port, pin

goto

Exit2

pausems

; If "0", push-button is released

debouncedelay ; Wait for 10ms debounce

Pressed2
btfsc

port, pin

goto

Pressed2

pausems
goto
Exit2
ENDIF

debouncedelay ; Wait until released and


label

; jump to specified address

ENDM
;**********************************************************************
Circuito P1.7:

Practica 1.8 Temporizador TMR1 e interrupciones


Descripcin P1.8:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.8:
;*************************** Header *****************************************
;************* DEFINING VARIABLES *******************************************

cblock

0x20

w_temp

; Block of variables starts at address 20h


; Variable at address 20h

pclath_temp

; Variable at address 21h

status_temp

; Variable at address 22h

endc

;************************ PROGRAM START ************************


org

0x0000

; Address of the first program instruction

goto

main

; Jump to label "main"

;************************ INTERRUPT ROUTINE **********************************

org
movwf

movf
movwf

movf

0x0004

; Interrupt vector

w_temp

STATUS

; Save register W

; Save register STATUS

status_temp

PCLATH

; Save register PCLATH

movwf

pclath_temp

banksel

PORTB

incf

movf
movwf
movf

PORTB

; Selects bank containing PORTB


; Register PORTB is incremented by 1

pclath_temp,w ; PCLATH is given its original content


PCLATH
status_temp,w ; STATUS is given its original content

movwf

STATUS

swapf

w_temp,f

swapf

w_temp,w

; W is given its original content

banksel

PIR1

; Selects bank containing PIR1

bcf

PIR1,TMR1IF

; Clears interrupt flag TMR1IF

bsf

INTCON,GIE

; Global interrupt enabled

retfie

; Return from interrupt routine

;************************ MAIN PROGRAM ***************************************

main
banksel

; Start of main program


ANSEL

clrf

ANSEL

clrf

ANSELH

banksel
clrf

banksel

; Selects bank containing register ANSEL


; Clears registers ANSEL and ANSELH
; All pins are digital

TRISB
TRISB

; Selects bank containing register TRISB


; All port B pins are configured as outputs

T1CON

; Selects bank containing register T1CON

bcf

T1CON,TMR1CS ; TMR1 counts pulses generated by oscillator

bsf

T1CON,T1CKPS0 ; Prescaler rate is 1:8

bsf

T1CON,T1CKPS1

bsf

T1CON,TMR1ON ; Turns on timer TMR1

banksel

PIE1

; Selects bank containing register PIE1

bsf

PIE1,TMR1IE

; TMR1 interrupt overflow enabled

bsf

INTCON,PEIE

; Peripheral modules interrupt enabled

; Timer TMR1 belongs to peripheral modules


bsf

banksel
clrf

INTCON,GIE

PORTB

; Global interrupt enabled

; Selects bank containing register PORTB

PORTB

; Clears port B

loop

; Remain here

loop
goto
end

; End of program

Circuito P1.8:

Practica 1.9 Temporizador TMR2 y configuracin del oscilador


Descripcin P1.9:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.9:
;********************** Header ***************************************************

;************* DEFINING VARIABLES ************************************************

cblock

0x20

w_temp

; Block of variables starts at address 20h


; Variable at address 20h

pclath_temp

; Variable at address 21h

status_temp

; Variable at address 22h

endc

;************************ PROGRAM START


******************************************
org

0x0000

; Address of the first program instruction

goto

main

; Jump to label "main"

;************************ INTERRUPT ROUTINE **************************************

org
movwf

movf
movwf

movf

0x0004

; Interrupt vector

w_temp

STATUS

; Save register W

; Save register STATUS

status_temp

PCLATH

; Save register PCLATH

movwf

pclath_temp

banksel

PORTB

incf

PORTB

; Selects bank containing PORTB


; Increments PORTB register by 1

banksel
decf
movf
movwf
movf

PR2

; Selects bank containing PR2

PR2

; PR2 is decremented by 1

pclath_temp,w ; PCLATH is given its original state


PCLATH
status_temp,w ; STATUS is given its original state

movwf

STATUS

swapf

w_temp,f

swapf

w_temp,w

banksel

PIR1

; W is given its original state

; Selects bank containing PIR1

bcf

PIR1,TMR2IF

; Clears interrupt flag TMR2IF

bsf

INTCON,GIE

; Global interrupt enabled

retfie

; Return from interrupt routine

;************************ MAIN PROGRAM


*******************************************
main
banksel

; Start of the main program


OSCCON

; Selects bank containing register OSCCON

bcf

OSCCON,6

; Selects internal oscillator HFINTOSC with

bsf

OSCCON,5

; frequency of 500KHz

bsf

OSCCON,4

bsf

OSCCON,0

; Microcontroller uses internal oscillator

ANSEL

; Selects bank containing register ANSEL

banksel
clrf

ANSEL

; Clears registers ANSEL and ANSELH

clrf

banksel

ANSELH

; All pins are digital

TRISB

clrf

TRISB

clrf

PR2

; Selects bank containing register TRISB


; All port B pins are configured as outputs

banksel

T2CON

movlw

H'FF'

movwf

T2CON

clrf

banksel

; Selects bank containing register T2CON


; Sets all control register bits
; prescaler=1:16, postscaler=1:16 TMR2=ON

PORTB

PIE1

; Selects bank containing register PIE1

bsf

PIE1,TMR2IE

; TMR2 interrupt enabled

bsf

NTCON,PEIE

; Peripheral modules interrupt enabled

; Timer TMR2 belongs to peripheral modules


bsf

INTCON,GIE

; Global interrupt enabled

loop
goto
end

loop

; Remain here
; End of program

Circuito P1.9:

Practica 1.10 Modulo CCP 1 como generador de seales tipo PWM


Descripcin P1.10:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.10:
;********************** Header **********************************************
;************* DEFINING VARIABLES *******************************************
cblock

0x20

w_temp

; Block of variables starts at address 20h


; Variable at address 20h

pclath_temp

; Variable at address 21h

status_temp

; Variable at address 22h

endc

#define

DARK PORTB,0 ; Push-button "DARK" is connected

; to PORTB,0 pin
#define

BRIGHT PORTB,1 ; Push-button "BRIGHT" is connected


; to PORTB,1 pin

;************************ PROGRAM START *************************************

org

0x0000

; First program instruction address

goto

main

; Jump to label "main"

;************************ INTERRUPT ROUTINE *********************************

org

movwf

movf
movwf

movf

0x0004

; Interrupt vector

w_temp

STATUS

; Save register W

; Save register STATUS

status_temp

PCLATH

; Save register PCLATH

movwf

pclath_temp

banksel

CCPR1L

btfss

DARK

; Tests push-button "DARK"

decf

CCPR1L

; Push-button is pressed - decrement CCP1L by 1

btfss

BRIGHT

; Testing push-button "BRIGHT"

incf

CCPR1L

; Push-button is pressed - increment CCP1L by 1

movf
movwf
movf

pclath_temp,w ; PCLATH is given its original content


PCLATH
status_temp,w ; STATUS is given its original content

movwf

STATUS

swapf

w_temp,f

swapf

w_temp,w

banksel

PIR1

; W is given its original content

; Selects bank containing PIR1

bcf

PIR1,TMR1IF

bsf

TMR1H,7

; Accelerates timer TMR0 counting

bsf

TMR1H,6

bsf

INTCON,GIE

retfie

; Clears interrupt flag TMR1IF

; Global interrupt enabled

; Return from interrupt routine

;************************ MAIN PROGRAM **************************************

main
banksel

; Start of the main program


ANSEL

clrf

ANSEL

clrf

ANSELH

banksel

; Selects bank containing register ANSEL


; Clears registers ANSEL and ANSELH
; All pins are digital

OPTION_REG

; Selects bank containing register ANSEL

bcf

OPTION_REG,7 ; Pull-up resistors enabled

bsf

WPUB,0

; Pull-up resistors enabled

bsf

WPUB,1

; on port B pins 0 and 1

banksel
clrf

banksel

TRISC
TRISC

; Selects bank containing register TRISC


; All port C pins are configured as outputs

T1CON

; Selects bank containing register T1CON

bcf

T1CON,TMR1CS ; TMR1 operates as a timer

bcf

T1CON,T1CKPS0 ; Prescaler rate is 1:8

bcf

T1CON,T1CKPS1

bsf

T1CON,TMR1ON ; Activates timer TMR1

banksel

PIE1

; Selects bank containing register PIE1

bsf

PIE1,TMR1IE ; Interrupt TMR1 is enabled

bsf

INTCON,PEIE ; Peripheral modules interrupts are


; enabled

bsf

INTCON,GIE

; Global interrupt enabled

movlw

B'11111101' ; Prescaler TMR2 = 1:4

banksel

T2CON

movwf

T2CON

movlw

B'11111111' ; Number in register PR2

banksel

PR2

movwf

PR2

banksel

CCP1CON

movlw

B'00001100' ; Bits to configure CCP1 module

movwf

CCP1CON

loop
goto

loop

end

; Remain here
; End of program

Circuito P1.10:

Practica 1.11 Utilizacin del convertidor analgico-digital (ADC)


Descripcin P1.11:
[Escriba aqu una descripcin del funcionamiento]

Cdigo P1.11:
;*********************** Header *********************************************
;************************ PROGRAM START *************************************

org

banksel
clrf

0x0000

; Address of the first program instruction

TRISB

; Selects bank containing register TRISB

TRISB

; All port B pins are configured as outputs

movlw

B'00001100'

movwf

TRISA

; Pins RA2 and RA3 are configured as inputs

banksel

ANSEL

; Selects bank containing register ANSEL

movlw

B'00001100'

movwf

ANSEL

clrf

banksel

; Inputs AN2 and AN3 are analog while


; all other pins are digital

ANSELH

ADCON1

; Selects bank including register ADCON1

bsf

ADCON1,ADFM

; Right justification of result

bcf

ADCON1,VCFG1 ; Voltage Vss is used as Vref

bsf

ADCON1,VCFG0 ; RA3 pin voltage is used as Vref+

banksel

ADCON0

; Selects bank containing register ADCON0

movlw

B'00001001'

; AD converter uses clock Fosc/2, AD channel

movwf

ADCON0

; on RA2 pin is used for conversion and

; AD converter is enabled
loop
banksel

ADCON0

btfsc

ADCON0,1

goto

loop

; Tests bit GO/DONE


; Conversion in progress, remain in

; loop
banksel
movf

ADRESL
ADRESL,w

; Lower byte of conversion result is

; copied to W
banksel

PORTB

movwf

PORTB

bsf
goto

; Byte is copied to PORTB

ADCON0,1
loop

end
Circuito P1.11:

; Starts new conversion


; Jump to label "loop"

; End of program

Practica 1.12 Uso de la memoria EEPROM


Descripcin P1.12:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.12:
;********************** Header **********************************************
;*********** Defining variables in program **********************************
cblock

0x20

; Block of variables starts at address 20h

HIcnt
LOcnt
LOOPcnt
cnt
endc

; End of block

;****************************************************************************
ORG

0x000

; Reset vector

nop
goto

main

; Go to start of the program (label "main")

;****************************************************************************
include

"pause.inc"

include

"button.inc"

;****************************************************************************
main
banksel

ANSEL

clrf

ANSEL

clrf

ANSELH

; Selects bank containing ANSEL

; All pins are digital

banksel

TRISB

bsf

TRISA, 0

; Input pin

bsf

TRISA, 1

; Input pin

bsf

TRISA, 2

; Input pin

clrf

TRISB

; All port B pins are outputs

clrf

TRISD

; All port D pins are outputs

banksel

PORTB

clrf

PORTB

; PORTB=0

clrf

PORTD

; PORTD=0

clrf

cnt

; cnt=0

Loop
banksel

PORTA

button

PORTA,0,0,Increment

button

PORTA,1,0,Decrement

button

PORTA,2,0,Save

banksel

EEADR

movlw

.5

movwf

EEADR

banksel

EECON1

; Reads EEPROM memory location


; at address 5

bcf

EECON1,EEPGD

bsf

EECON1,RD

banksel

EEDATA

movfw

EEDATA

banksel

PORTD

; Reads data from EEPROM memory

; Moves data to W

movwf
goto

PORTD

; Data is moved from W to PORTD

Loop

Increment
incf
movf
movwf
goto

; Increments number on port B


cnt, f
cnt, w
PORTB
Loop

Decrement
decf
movf
movwf
goto

; Decrements number on port B


cnt, f
cnt, w
PORTB
Loop

Save

; Copies data from port B to EEPROM

banksel

EEADR

movlw

.5

movwf

EEADR

banksel

PORTB

movfw

PORTB

banksel

EEDAT

movwf

EEDAT

banksel

EECON1

; memory location at address 5

; Writes address

; Copies port B to register W

; Writes data to temporary register

bcf

EECON1,EEPGD

bsf

EECON1,WREN

bcf

INTCON,GIE

btfsc

INTCON,GIE

; Write enabled

; All interrupts disabled

goto

$-2

movlw

55h

movwf

EECON2

movlw

H'AA'

movwf

EECON2

bsf

EECON1,WR

btfsc

EECON1,WR

goto

$-1

bsf

INTCON,GIE

bcf

EECON1,WREN

goto
end

Loop

; Wait for write to complete

; Interrupt enabled

; Tests push-buttons again


; End of program

Circuito P1.12:

Practica 1.13 Contador de dos dgitos multiplexado


Descripcin P1.13:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.13:
;************************* Header *******************************************
;****************************************************************************

DEFINING VARIABLES IN PROGRAM


w_temp

EQU 0x7D

; Variable for saving W register

status_temp EQU 0x7E

; Variable for saving STATUS register

pclath_temp EQU 0x7F

; Variable for saving PCLATH register

CBLOCK

0x20

; Block of variables starts at address 20h

Digtemp
Dig0

; Variables for displaying digits - LSB

Dig1
Dig2
Dig3

; Variables for displaying digits - MSB

Dval

; Counter value

One

; Auxiliary variable which determines which


; display is to be switched on

ENDC

; End of block of variables

poc_vr

EQU .99

; Initial counter value is 99

include

"Digbyte.inc"

;****************************************************************************
ORG

0x0000

; First instruction address

goto

main

; Jump to label "main"

;****************************************************************************
ORG

0x0004

movwf

movf
movwf

; Interrupt vector address

w_temp

; Move w register to w_temp register

STATUS,w

; Move STATUS register to status_temp

status_temp

movf

PCLATH,w

movwf

pclath_temp

; register

; Move PCLATH register to pclath_temp


; register

; Start of interrupt routine...

BANKSEL

TMR0

movlw

.100

movwf

TMR0

bcf

INTCON, T0IF

bcf

PORTA, 0

bcf

PORTA, 1

btfsc

One, 0

goto

Lsdon

goto

Msdon

Lsdon
incf

One, f

movlw

HIGH (Bcdto7seg)

movwf

PCLATH

digbyte

Dval

movf

Dig1, w

call
movwf
bsf
goto

Bcdto7seg

; Place L1 mask on the PORTD

PORTD
PORTA, 1
ISR_end

Msdon
incf

One, f

movlw

HIGH (Bcdto7seg)

movwf

PCLATH

digbyte

Dval

movf

Dig0, w

call
movwf
bsf
goto

Bcdto7seg

; Place LO mask on the PORTD

PORTD
PORTA, 0
ISR_end

; End of interrupt routine...

ISR_end
movf

pclath_temp,w ; PCLATH register is given its original

movwf

PCLATH

movf

; state

status_temp,w ; STATUS register is given its original

movwf

STATUS

swapf

w_temp,f

; state

; W register is given its original

; state
swapf

w_temp,w

retfie

; Return from interrupt routine

main
banksel

ANSEL

clrf

ANSEL

clrf

ANSELH

BANKSEL
movlw

; Selects bank containing ANSEL


; All pins are digital

TRISA
b'11111100'

; RA0 and RA1 are configured as outputs and

; used for 7-segment display multiplexing


; RA2 is input push-button for initializa
; tion

movwf
clrf

TRISA
TRISD

BANKSEL

OPTION_REG

movlw

b'10000110'

movwf

OPTION_REG

; TMR0 is incremented each 32us (Fclk=8MHz)

BANKSEL

PORTA

movlw

poc_vr

movwf

Dval

movlw

b'00000001'

movwf

One

movwf

PORTA

movlw

.100

movwf

TMR0

; Dval contains counter value


; Initializes variable specifying display

; to switch on

; TMR0 interrupt appr.every 10ms

bsf

INTCON, GIE

; Global interrupt enabled

bsf

INTCON, T0IE ; Timer TMR0 interrupt enabled

bcf

INTCON, T0IF

Loop
btfss

One, 3

goto Dec

; Falling edge encountered?


; Yes! Go to Dec

btfss

PORTA, 2

goto

Reset

goto

Loop

; Counter reset button pressed?


; Yes! Go to Reset

; Decrement Dval counter by 1


Dec
btfss

One, 3

goto

Dec

movf

Dval, f

btfsc

STATUS, Z

; Is Dval equal to 0?

goto

Loop

; If it is, go to loop and wait for T2

decf

Dval, f

; If Dval not equal to 0, decrement it by 1

goto

Loop

Reset
btfss

PORTA, 2

goto

Reset

movlw

poc_vr

movwf

Dval

goto

; Wait for rising edge

; Write initial value to counter

Loop

;****************************************************************************
ORG

0x0300

; Lookup table is at the top of third page, but

; can be placed at some other place, it is impor


; tant to have it all on one page
Bcdto7seg
addwf
DT

PCL, f
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f

;****************************************************************************
END

; End of program

Macro digbyte

Archivo: Digbyte.inc

; Todo este cdigo va en un archivo llamado Digbyte.inc


;****************************************************

digbyte MACRO arg0

LOCAL

Exit0

LOCAL

Exit1

LOCAL

Exit2

clrf

Dig0

clrf

Dig1

clrf

Dig2

clrf

Dig3

movf

arg0, w

movwf

Digtemp

movlw

.100

Exit2
incf
subwf

Dig2, f
Digtemp, f

btfsc

STATUS, C

goto

Exit2

decf

Dig2, f

addwf

Digtemp, f

Exit1
movlw
incf
subwf

.10
Dig1, f
Digtemp, f

btfsc

STATUS, C

goto

Exit1

decf

Dig1, f

addwf

Digtemp, f

Exit0
movf
movwf

Digtemp, w
Dig0

ENDM
Circuito P1.13:

Practica 1.14 Generacin de sonidos usando macros


Descripcin P1.14:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.14:
*********************** Header ***************************************
;******************* Defining variables in program ********************
cblock
HIcnt

0x20
; Auxiliary variables for macro pausems

LOcnt
LOOPcnt
PRESCwait
Beep_TEMP1

; Belongs to macro "BEEP"

Beep_TEMP2
Beep_TEMP3
endc

#define BEEPport PORTD, 2

; Speaker pin

#define BEEPtris TRISD, 2

expand

;**********************************************************************
ORG

0x0000

goto

main

; RESET vector address


; Jump to program start (label - main)

;**********************************************************************
; remaining code goes here

include

"pause.inc"

include

"button.inc"

include

"beep.inc"

main
banksel

ANSEL

clrf

ANSEL

clrf

ANSELH

; Selects bank containing ANSEL


; All outputs are digital

banksel

TRISD

movlw

b'11111011'

movwf

TRISD

banksel

PORTD

BEEPinit

; PORTA D initialization

; Macro "Beep"

Loop
button

PORTD,0,0,Play1 ; Push-button 1

button

PORTD,1,0,Play2 ; Push-button 2

goto

Loop

Play1

; First tone

BEEP

0xFF, 0x02

BEEP

0x90, 0x05

BEEP

0xC0, 0x03

BEEP

0xFF, 0x03

goto

Loop

Play2

; Second tone

BEEP

0xBB, 0x02

BEEP

0x87, 0x05

BEEP

0xA2, 0x03

BEEP

0x98, 0x03

goto

Loop

;**********************************************************************
END

; End of program

Macro beep
BEEPinit MACRO
bcf

STATUS, RP0

bcf

STATUS, RP1

bcf

BEEPport

bsf

STATUS, RP0

bcf

STATUS, RP1

bcf

BEEPtris

movlw

b'00000111'

movwf

OPTION_REG

bcf

STATUS, RP0

bcf

STATUS, RP1

; TMR0 prescaler rate 1:256


; OPTION <- W

ENDM
BEEP MACRO

freq, duration

bcf

STATUS, RP0

bcf

STATUS, RP1

movlw

freq

movwf

Beep_TEMP1

movlw

duration

movwf

Beep_TEMP2

call

BEEPsub

ENDM
;**********************************************************************

; Subroutines

BEEPsub
clrf

TMR0

; Counter initialization

bcf

INTCON, T0IF

bcf

BEEPport

BEEPa
bcf

INTCON, T0IF ; Clears TMR0 Overflow Flag

BEEPb
bsf

BEEPport

call

B_Wait

bcf

BEEPport

call

B_Wait

; Logic one "1" duration

; Logic zero "0" duration

btfss

INTCON, T0IF ; Check TMR0 Overflow Flag,

goto

BEEPb

decfsz

Beep_TEMP2, f ; Is Beep_TEMP2 = 0 ?

goto BEEPa

; skip next if set

; Go to BEEPa again

return
B_Wait
movf Beep_TEMP1, w
movwf Beep_TEMP3
B_Waita
decfsz Beep_TEMP3, f
goto B_Waita
return

Circuito P1.14:

Practica 1.15 Utilizacin del display de cristal lquido (LCD)


Descripcin P1.15:
Cdigo P1.15:
;*********************** Header ***********************************
; DEFINING VARIABLES IN PROGRAM

CBLOCK

HIcnt
LOcnt

0x20

; Block of variables starts at address 20h

; Belongs to macro "pausems"

LOOPcnt

LCDbuf

; Belongs to functions "LCDxxx"

LCDtemp
LCDportBuf

; LCD Port Buffer

Digtemp

; Belongs to macro "digbyte"

Dig0
Dig1
Dig2
Dig3

temp
ENDC

; End of block

LCDport EQU PORTB ; LCD is on PORTB (4 data lines on RB0-RB3)


RS

EQU 4

; RS line connected to RB4

EN

EQU 5

; EN line connected to RB5

;**********************************************************************
ORG

0x0000

; Reset vector address

nop
goto

main

; Go to beginning of the program (label "main")

;**********************************************************************
include "LCD.inc"
include "digbyte.inc"

include "pause.inc"
;**********************************************************************
main
banksel

ANSEL

; Selects bank containing ANSEL

clrf

ANSEL

; All pins are digital

clrf

ANSELH

bcf

STATUS,RP0

bcf

STATUS,RP1

movlw

.23

movwf

temp

; Bank0 active only

; Move arbitrary value to variable

; is to be displayed on LCD
lcdinit

; LCD initialization

Loop
lcdcmd
lcdtext

0x01

; Instruction to clear LCD

1, "mikroelektronika" ; Write text from the begin


; ning of the first line

lcdtext

2, "Beograd" ; Write text from the beginning of


; the second line

pausems
lcdcmd

.2000
0x01

; 2 sec. delay
; Instruction to clear LCD

lcdtext 1, "Temperatura1" ; Write text from the begin


; ning of the first line
lcdtext 2, "temp=" ; Write text from the beginning of
; the second line
lcdbyte

temp

; Write variable (dec.)

lcdtext 0, " C"


pausems
goto

; Write text after cursor

.2000

; 2 sec. delay

Loop

;**********************************************************************
end

; End of program

Archivo LCD.inc
; Esto va en un archivo que lleva el nombre de LCD.inc

;**********************************************************************
; Initialization must be done by using macro lcdinit before access
; ing LCD
;**********************************************************************
lcdinit MACRO
bcf

STATUS, RP0

bcf

STATUS, RP1

clrf

LCDportBuf

movf
movwf

; Bank0

LCDportBuf, w
LCDport

bsf

STATUS, RP0

bcf

STATUS, RP1

clrf

TRISB

bcf

STATUS, RP0

bcf

STATUS, RP1

; Bank1

; LCDport with output LCD


; Bank0

; Function set (4-bit mode change)


movlw

b'00100000'

movwf

LCDbuf

swapf

LCDbuf, w

movwf
bcf
movf
movwf
bsf
movf
movwf
bcf
movf
movwf
call

LCDportBuf
LCDportBuf, RS
LCDportBuf, w
LCDport
LCDportBuf, EN
LCDportBuf, w
LCDport
LCDportBuf, EN
LCDportBuf, w
LCDport
Delay1ms

; 1 ms delay

; Function set (display mode set)


lcdcmd
call

b'00101100'
Delay1ms

; 1 ms delay

; Display ON/OFF Control


lcdcmd
call

b'00001100'
Delay1ms

; 1 ms delay

; Entry Mode Set


lcdcmd
call

b'00000110'
Delay1ms

; 1 ms delay

; Display Clear
lcdcmd

b'00000001'

pausems

.40

; 40 ms delay

; Function set (4-bit mode change)


movlw

b'00100000'

movwf

LCDbuf

swapf

LCDbuf, w

movwf
bcf
movf
movwf
bsf
movf
movwf
bcf
movf
movwf
call

LCDportBuf
LCDportBuf, RS
LCDportBuf, w
LCDport
LCDportBuf, EN
LCDportBuf, w
LCDport
LCDportBuf, EN
LCDportBuf, w
LCDport
Delay1ms

; 1 ms delay

; Function set (display mode set)


lcdcmd
call

b'00101100'
Delay1ms

; 1 ms delay

; Display ON/OFF Control


lcdcmd

b'00001100'

call

Delay1ms

; 1 ms delay

; Entry Mode Set


lcdcmd
call

b'00000110'
Delay1ms

; 1 ms delay

; Display Clear
lcdcmd

b'00000001'

pausems

.40

; 40 ms delay

ENDM

;**********************************************************************
; lcdcmd sends command to LCD (see the table on the previous page)
; lcdclr is the same as lcdcmd 0x01
;**********************************************************************
lcdcmd MACRO LCDcommand
movlw
call

LCDcommand
LCDcomd

ENDM

LCDcomd
movwf
bcf
movf
movwf

LCDbuf
LCDportBuf, RS
LCDportBuf, w
LCDport

; Send command to LCD

goto

LCDwr

LCDdata
movwf
bsf
movf
movwf
goto

LCDbuf
LCDportBuf, RS
LCDportBuf, w
LCDport
LCDwr

LCDwr
swapf
call
movf
call

LCDbuf, w
SendW
LCDbuf, w
SendW

return
SendW
andlw

0x0F

movwf

LCDtemp

movlw

0xF0

andwf

LCDportBuf, f

movf

LCDtemp, w

iorwf

LCDportBuf, f

movf

LCDportBuf, w

movwf

LCDport

call

Delay1ms

bsf

LCDportBuf, EN

movf

LCDportBuf, w

movwf
bcf

LCDport
LCDportBuf, EN

movf

LCDportBuf, w

movwf
call

LCDport
Delay1ms

return

;**********************************************************************
; lcdtext writes text containing 16 characters which represents a
; macro argument. The first argument select selects the line in which
; text writing is to start. If select is 0, text writing starts from
; cursor current position.
;**********************************************************************
lcdtext MACRO select, text

; This macro writes text from cursor

; current position. Text is specified


; in argument consisting of 16 charac
; ters
local

Message

local

Start

local

Exit

local

i=0

goto

Start

Message
DT

DT text

Start
IF (select == 1)

; Create lookup table from arguments

lcdcmd b'10000000'
ELSE
IF (select == 2)
lcdcmd b'11000000'
ENDIF
ENDIF

WHILE (i<16)

; Repeat conditional program compiling 16 times

call Message+i

; Read lookup table and place value in W

addlw 0
bz Exit

; until 0 is read

call LCDdata

; Call routine displaying W on LCD

i=i+1
ENDW
Exit
ENDM

;**********************************************************************
; This macro writes value in size of 1 byte on LCD
; excluding leading zeros
;**********************************************************************
lcdbyte MACRO arg0
digbyte

arg0

; A hundred is in Dig2,
; A ten is in Dig1 and one in Dig0

movf

Dig2, w

addlw

0x30

call

LCDdata

movf

Dig1, w

addlw

0x30

call

LCDdata

movf

Dig0, w

addlw

0x30

call

; If digit is 0 move cursor

; If digit is 0 move cursor

LCDdata

ENDM
;**********************************************************************
; 1ms Delay
Delay1ms:
movlw

.200

movwf

LOOPcnt

Delay10us:
nop

;1us

nop

;1us

nop

;1us

nop

;1us

nop

;1us

nop

;1us

nop

;1us

decfsz

LOOPcnt, f

;1us

goto

Delay10us

;2us

return

Circuito P1.15:

Practica 1.16 Comunicacin serial RS232


Descripcin P1.16:
[Escriba aqu una descripcin del funcionamiento]
Cdigo P1.16:
;*********************** Header ***************************************
;

DEFINING VARIABLES IN PROGRAM

w_temp

EQU 0x7D

; Variable for saving W register

status_temp EQU 0x7E

; Variable for saving STATUS register

pclath_temp EQU 0x7F

; Variable for saving PCLATH w register

cblock

0x20

; Block of variables starts at address 20 h

Port_A

; Variable at address 20 h

Port_B

; Variable at address 21 h

RS232temp

; Variable at address 22 h

RXchr

; Variable at address 23 h

endc

; End of block of variables

;**********************************************************************
ORG

0x0000

; Reset vector

nop
goto

main

; Go to beginning of program (label "main")

;**********************************************************************
ORG

movwf
movf
movwf
movf
movwf

0x0004

; Interrupt vector address

w_temp
STATUS,w

; Save value of W register


; Save value of STATUS register

status_temp
PCLATH,w

; Save value of PCLATH register

pclath_temp

;**********************************************************************
; This part of the program is executed in interrupt routine
banksel

PIE1

btfss

PIE1, RCIE

goto

ISR_Not_RX232int

banksel
btfsc
call

PIE1
PIR1, RCIF
RX232_int_proc

ISR_Not_RX232int
movf

pclath_temp,w

movwf

movf

PCLATH

; PCLATH is given its original value

status_temp,w

movwf

STATUS

swapf

w_temp,f

swapf

w_temp,w

retfie

; STATUS is given its original value

; W is given its original value

; Return from interrupt routine

;**********************************************************************
RX232_int_proc
banksel
movf
movwf

; Check if error has occurred

RCSTA
RCSTA, w
RS232temp

btfsc

RS232temp, FERR

goto

RX232_int_proc_FERR

btfsc

RS232temp, OERR

goto

RX232_int_proc_OERR

goto

RX232_int_proc_Cont

RX232_int_proc_FERR
bcf

RCSTA, CREN

; To clear FERR bit, receiver is first

; switched off and on afterwards


nop

; Delay ...

nop
bsf
movf

RCSTA, CREN
RCREG, w

; Reads receive register and clears FERR bit

bsf
movf
movwf
goto

Port_A, 0

; Switches LED on ( UART error indicator)

Port_A, w
PORTA
RS232_exit

RX232_int_proc_OERR
bcf

RCSTA, CREN

nop

; Clears OERR bit

; Delay ...

nop
bsf
movf
bsf
movf
movwf
goto

RCSTA, CREN
RCREG, w
Port_A, 1

; Reads receive register and clears FERR bit


; Switches LED on ( UART error indicator)

Port_A, w
PORTA
RS232_exit

RX232_int_proc_Cont
movf

RCREG, W

movwf

RXchr

movwf

PORTB

movwf

TXREG

; Reads received data

; Sends data back to PC

RS232_exit
return

; Return from interrupt routine

;**********************************************************************
; Main program

main
banksel

ANSEL

clrf

ANSEL

clrf

ANSELH

; Selects bank containing ANSEL


; All inputs are digital

;--------------------------------------; Port configuration


;--------------------------------------banksel

TRISA

movlw

b'11111100'

movwf

TRISA

movlw

b'00000000'

movwf

TRISB

;--------------------------------------; Setting initial values


;--------------------------------------banksel

PORTA

movlw

b'11111100'

movwf

PORTA

movwf

Port_A

movlw

b'00000000'

movwf

PORTB

movwf

Port_B

;--------------------------------------; USART - setting for 38400 bps

;--------------------------------------banksel

TRISC

bcf

TRISC, 6

; RC6/TX/CK = output

bsf

TRISC, 7

; RC7/RX/DT = input

banksel
bsf

BAUDCTL
BAUDCTL, BRG16

banksel

SPBRG

movlw

.51

; baud rate = 38400


; ( Fosc/(4*(SPBRG+1)) ) Error +0.16%

movwf
clrf

banksel

SPBRG
SPBRGH

TXSTA

bcf

TXSTA, TX9

bsf

TXSTA, TXEN

; Data transmission enabled

bcf

TXSTA, SYNC

; Asynchronous mode

bsf

TXSTA, BRGH

; High-speed Baud rate

banksel

; Data is 8-bit wide

RCSTA

bsf

RCSTA, SPEN

; RX/DT and TX/CK outputs configuration

bcf

RCSTA, RX9

; Select mode for 8-bit data receive

bsf

RCSTA, CREN

bcf

RCSTA, ADDEN ; No address detection, ninth bit may be

; Receive data enabled

; used as parity bit


movf

RCSTA, W

movf

RCREG, W

;--------------------------------------; Interrupts enabled


;--------------------------------------banksel

PIE1

bsf

PIE1, RCIE

; USART Rx interrupt enabled

bsf

INTCON, PEIE ; All peripheral interrupts enabled

bsf

INTCON, GIE

; Global interrupt enabled

;--------------------------------------; Remain here


;--------------------------------------goto $

end

; End of program

Circuito P1.16:

Unidad II Compilador C para Microcontroladores


Practica 2.1 Encendido de leds y configuraciones basicas.
Descripcin P2.1:
Circuito P2.1:

Cdigo P2.1:
/*
*************************************************************
* Este es el Header
* Nombre del programa : p2_1.c
* Descripcion: Programa simple para demostrar el funcionamiento de un uC
* encendiendo y apagando leds conectados al puerto B.
* Configuracion:
*

Microcontroladores: PIC16F887

Kit de desarrollo: sistema mnimo

Oscilador: HS, 8.0 MHz

Compilador: mikroC PRO

* Notas: Construir el sistema mnimo en un protoboard


*/
/*
*
*/
int k;

void main() {

ANSEL = 0;

ANSELH = 0;
PORTB = 0XFF;
TRISB 0 0;

Delay_ms(1000);

PORTB = 0;

for(k=1; k<20; k++)


{

switch(PORTB) {

case 0x00:
PORTB = 0xFF;
Delay_ms(100);
break;
case 0XFF:
PORTB = 0x00;
Delay_ms(500);
}
}

PORTB = 0b01010101;

while(1) {

PORTB = ~PORTB;
Delay_ms(200);
}
}

Practica 2.2 Oscilador interno y mezcla de lenguaje ensamblador y C


Descripcin P2.2:
Circuito P2.2:

Cdigo P2.2:
/* Header *********************************************/

int k = 0;
char saveBank;

void main() {
ANSEL = 0;

// All I/O pins are configured as digital

ANSELH = 0;
PORTB = 0;

// All port B pins are set to 0

TRISB = 0;

// Port B pins are configured as outputs

do {
PORTB = ~PORTB;
Delay_ms(100);
k++;

// Invert port B logic state


// 100mS delay

// Increment k by 1

}
while(k<20);

k=0;

// Remain in loop while k<20

// Reset variable k

saveBank = STATUS & 0b01100000; // Save the state of bits RP0 and RP1
// (bits 5 and 6 of the STATUS register)

asm {

// Start of assembly sequence

bsf STATUS,RP0

// Select memory bank containing the OSCCON

bcf STATUS,RP1

// register

bcf OSCCON,6

// Select internal oscillator LFINTOSC

bcf OSCCON,5

// of 31KHz frequency

bcf OSCCON,4
bsf OSCCON,0
}

// Microcontroller uses internal oscillator


// End of assembly sequence

STATUS &= 0b10011111;

// Bits RP0 and RP1 return their original state

STATUS |= saveBank;

do {
PORTB = ~PORTB;
Delay_ms(10);
k++;

// Invert port B logic state


// 10 mS delay

// Increment k by 1

}
while(k<20);
}

// Remain in loop while k<20

Practica 2.3 Temporizador TMR0 como contador, variables y relevadores


Descripcin P2.3:
Circuito P2.3:

Cdigo P2.3:
/*Header******************************************************/

void main() {
char TEST = 5;

// Constant TEST = 5

enum outputs {RELAY = 3}; // Constant RELAY = 3

ANSEL = 0;
ANSELH = 0;

// All I/O pins are configured as digital

PORTA = 0;

// Reset port A

TRISA = 0xFF;

// All portA pins are configured as inputs

PORTD = 0;

// Reset port D

TRISD = 0b11110111;

// Pin RD3 is configured as an output, while the rest are

// configured as inputs

OPTION_REG.F5 = 1;

// Counter TMR0 receives pulses through the RA4 pin

OPTION_REG.F3 = 1;

// Prescaler rate is 1:1

TMR0 = 0;

// Reset timer/counter TMR0

do {
if (TMR0 == TEST)

// Does the number in timer match constant TEST?

(PORTD.RELAY = 1); // Numbers match. Set the RD3 bit (output RELAY)
}
while (1);
}

// Remain in endless loop

Practica 2.4 Temporizadores TMR0,TMR1 y TMR2 e interrupciones


Descripcin P2.4:
Circuito P2.4:

Cdigo P2.4:

/*Header*****************************************************
Interrupt occurs on every timer register TMR0 overflow.

*/
unsigned cnt;

// Define variable cnt

void interrupt() {
cnt++;
TMR0 = 96;

// Interrupt causes cnt to be incremented by 1


// Timer TMR0 is returned its initial value

INTCON = 0x20;

// Bit T0IE is set, bit T0IF is cleared

void main() {
OPTION_REG = 0x84;
ANSEL = 0;

// Prescaler is assigned to timer TMR0

// All I/O pins are configured as digital

ANSELH = 0;
TRISB = 0;

// All port B pins are configured as outputs

PORTB = 0x0;

// Reset port B

TMR0 = 96;

// Timer T0 counts from 96 to 255

INTCON = 0xA0;

// Enable interrupt TMR0

cnt = 0;

do {

// Variable cnt is assigned a 0

// Endless loop

if (cnt == 400) {

// Increment port B after 400 interrupts

PORTB = PORTB++; // Increment number on port B by 1


cnt = 0;

// Reset variable cnt

}
} while(1);
}
/*Header*****************************************************
In this case, an interrupt is enabled after the timer register TMR1 (TMR1H, TMR1L) overflow occurs

*/

unsigned short cnt; // Define variable cnt

void interrupt() {
cnt++ ;

// Interrupt causes cnt to be incremented by 1

PIR1.TMR1IF = 0;

// Reset bit TMR1IF

TMR1H = 0x80;

// TMR1H and TMR1L timer registers are returned

TMR1L = 0x00;

// their initial values

void main() {
ANSEL = 0;

// All I/O pins are configured as digital

ANSELH = 0;
PORTB = 0xF0;
TRISB = 0;
T1CON = 1;

// Initial value of port B bits


// Port B pins are configured as outputs
// Set timer TMR1

PIR1.TMR1IF = 0;

// Reset bit TMR1IF

TMR1H = 0x80;

// Set initial value for timer TMR1

TMR1L = 0x00;
PIE1.TMR1IE = 1;
cnt = 0;

// Enable interrupt on overflow


// Reset variable cnt

INTCON = 0xC0;

do {

// Enable interrupt (bits GIE and PEIE)

// Endless loop

if (cnt == 76) {

// Change port B state after 76 interrupts

PORTB = ~PORTB;
cnt = 0;
}
} while (1);

// Number in port B is inverted

// Reset variable cnt

/*Header*****************************************************
This time, an interrupt occurs after timer register TMR2 overflow occurs.

*/

unsigned short cnt;

// Define variable cnt

void Replace() {
PORTB = ~PORTB;
}

// Define new function Replace

// Function inverts port state

void interrupt() {
if (PIR1.TMR2IF) { // If bit TMR2IF = 1,
cnt++ ;

// Increment variable cnt by 1

PIR1.TMR2IF = 0;// Reset bit and


TMR2 = 0;

// reset register TMR2

}
}

// main
void main() {
cnt = 0;
ANSEL = 0;

// Reset variable cnt


// All I/O pins are configured as digital

ANSELH = 0;
PORTB = 0b10101010; // Logic state on port B pins
TRISB = 0;

// All port B pins are configured as outputs

T2CON = 0xFF;

// Set timer T2

TMR2 = 0;

// Initial value of timer register TMR2

PIE1.TMR2IE = 1; // Enable interrupt


INTCON = 0xC0;

while (1) {

// Set bits GIE and PEIE

// Endless loop

if (cnt > 30) { // Change PORTB after more than 30 interrupts


Replace(); // Function Replace inverts the port B state
cnt = 0; // Reset variable cnt
}
}
}

Practica 2.5 Uso de del watchdog timer


Descripcin P2.5:
Circuito P2.5:

Cdigo P2.5:
/*Header*****************************************************
In order to make this example work properly, it is necessary to enable the watchdog
Timer Watchdog Timer - Enabled option in mE programmer.

*/

void main() {
OPTION_REG = 0x0E; // Prescaler is assigned to timer WDT (1:64)

asm CLRWDT;

// Assembly command to reset WDT timer

PORTB = 0x0F;
TRISB = 0;

// Initial value of the PORTB register


// All port B pins are configured as outputs

Delay_ms(300);

// 30mS delay

PORTB = 0xF0;

// Porta B value different from initial

while (1);

// Endless loop. Program remains here until WDT


// timer resets the microcontroller

Practica 2.6 Modulo CCP 1 como generador de seales tipo PWM


Descripcin P2.6:
Circuito P2.6:

Cdigo P2.6:
/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the following
Libraries in the Library Manager prior to compiling:

PWM
Button

*/

unsigned short current_duty, old_duty; // Define variables


// current_duty and old_duty

void initMain() {
ANSEL = 0;

// All I/O pins are configured as digital

ANSELH = 0;
PORTA = 255;

// Port A initial state

TRISA = 255;

// All port A pins are configured as inputs

PORTB = 0;

// Initial state of port B

TRISB = 0;
PORTC = 0;
TRISC = 0;
PWM1_Init(5000);

// All port B pins are configured as outputs


// Port C initial state
// All port C pins are configured as outputs
// PWM module initialization (5KHz)

void main() {
initMain();
current_duty = 16;

// Initial value of variable current_duty

old_duty = 0;
PWM1_Start();

while (1) {

// Reset variable old_duty


// Start PWM1 module

// Endless loop

if (Button(&PORTA, 0,1,1))
current_duty++ ;

// increment variable current_duty

if (Button(&PORTA, 1,1,1))
current_duty-- ;

// If the button connected to RA0 is pressed

// If the pressed button is connected to RA1

// decrement value current_duty

if (old_duty != current_duty) { // If current_duty and old_duty are not


PWM1_Set_Duty(current_duty); // equal set PWM to a new value,
old_duty = current_duty;
PORTB = old_duty;

// save the new value


// and show it on port B

Delay_ms(200);
}
}

// 200mS delay

Practica 2.7 Utilizacin del convertidor analgico-digital (ADC)


Descripcin P2.7:
Circuito P2.7:

Cdigo P2.7:
/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the ADC library
in the Library Manager prior to compiling:

ADC

*/

unsigned int temp_res;

void main() {

ANSEL = 0x0C;

// Pins AN2 and AN3 are configured as analog

TRISA = 0xFF;

// All port A pins are configured as inputs

ANSELH = 0;

// Rest of pins is configured as digital

TRISB = 0x3F;

// Port B pins RB7 and RB6 are configured as


// outputs

TRISD = 0;

// All port D pins are configured as outputs

ADCON1.F4 = 1 ;

// Voltage reference is brought to the RA3 pin.

do {
temp_res = ADC_Read(2); // Result of A/D conversion is copied to temp_res
PORTD = temp_res;

// 8 LSBs are moved to port D

PORTB = temp_res >> 2; // 2 MSBs are moved to bits RB6 and RB7
} while(1);
}

// Endless loop

Practica 2.8 Uso de la memoria EEPROM


Descripcin P2.8:
Circuito P2.8:

Cdigo P2.8:
/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the EEPROM

library in the Library Manager prior to compiling:

EEPROM

*/

void main() {
ANSEL = 0;

// All I/O pins are configured as digital

ANSELH = 0;

PORTB = 0;
TRISB = 0;
PORTD = 0;
TRISD = 0;
TRISA = 0xFF;

// Port B initial value


// All port B pins are configured as outputs
// Port B initial value
// All port D pins are configured as outputs
// All port A pins are configured as inputs

PORTD = EEPROM_Read(5);

// Read EEPROM memory at address 5

do {
PORTB=PORTB++;
Delay_ms(100);

// Increment port B by 1
// 100mS delay

if (PORTA.F2){
EEPROM_Write(5,PORTB); // If MEMO is pressed, save PORTB
PORTD = EEPROM_Read(5); // Read written data

do;
while (PORTA.F2);

// Remain in this loop as long as the button is

// pressed
}
}
while(1);

// Endless loop

Practica 2.9 Contador de dos dgitos multiplexado


Descripcin P2.9:
Circuito P2.9:

Cdigo P2.9:
/*Header******************************************************/

unsigned short mask(unsigned short num);


unsigned short digit_no, digit10, digit1, digit, i;

void interrupt() {
if (digit_no==0) {
PORTA = 0;
PORTD = digit1;
PORTA = 1;

// Turn off both displays


// Set mask for displaying ones on PORTD
// Turn on display for ones (LSD)

digit_no = 1;
} else {
PORTA = 0;
PORTD = digit10;
PORTA = 2;

// Turn off both displays


// Set mask for displaying tens on PORTD
// Turn on display for tens (MSD)

digit_no = 0;
}
TMR0 = 0;
INTCON = 0x20;

// Reset counter TMRO


// Bit T0IF=0, T0IE=1

void main() {
OPTION_REG = 0x80;
TMR0 = 0;

// Set timer TMR0

INTCON = 0xA0;

// Disable interrupt PEIE,INTE,RBIE,T0IE

PORTA = 0;

// Turn off both displays

TRISA = 0;

// All port A pins are configured as outputs

PORTD = 0;

// Turn off all display segments

TRISD = 0;

// All port D pins are configured as outputs

do {
for (i = 0; i<=99; i++) { // Count from 0 to 99
digit = i % 10u;
digit1 = mask(digit); // Prepare mask for displaying ones
digit = (char)(i / 10u) % 10u;
digit10 = mask(digit); // Prepare mask for displaying tens
Delay_ms(1000);
}
} while (1);

// Endless loop

}
Archivo : mask.c
/*Header*****************************************************
In order to make this example work properly, it is necessary to include document
mask.c into the project prior to compiling:
Sources - Add File To Project

*/
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;

case 2 : return 0x5B;


case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
}
}

Practica 2.10 Utilizacin del display de cristal lquido (LCD)


Descripcin P2.10:
Circuito P2.10:

Cdigo P2.10:
/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the following
libraries in the Library Manager prior to compiling:

ADC
LCD

*/

// LCD module connections


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;
// End LCD module connections

unsigned char ch;

//

unsigned int adc_rd;

// Declare variables

char *text;

//

long tlong;

//

void main() {
INTCON = 0;

// All interrupts disabled

ANSEL = 0x04;

// Pin RA2 is configured as an analog input

TRISA = 0x04;
ANSELH = 0;

Lcd_Init();

// Rest of pins are configured as digital

// LCD display initialization

Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);

text = "mikroElektronika";

// LCD command (cursor off)


// LCD command (clear LCD)

// Define the first message

Lcd_Out(1,1,text);

// Write the first message in the first line

text = "LCD example";

// Define the second message

Lcd_Out(2,1,text);

// Define the first message

ADCON1 = 0x82;

// A/D voltage reference is VCC

TRISA = 0xFF;

// All port A pins are configured as inputs

Delay_ms(2000);

text = "voltage:";

// Define the third message

while (1) {
adc_rd = ADC_Read(2);
Lcd_Out(2,1,text);

// A/D conversion. Pin RA2 is an input.


// Write result in the second line

tlong = (long)adc_rd * 5000; // Convert the result in millivolts


tlong = tlong / 1023;

// 0..1023 -> 0-5000mV

ch = tlong / 1000;

// Extract volts (thousands of millivolts)

// from result
Lcd_Chr(2,9,48+ch);

// Write result in ASCII format

Lcd_Chr_CP('.');
ch = (tlong / 100) % 10;

// Extract hundreds of millivolts

Lcd_Chr_CP(48+ch);

// Write result in ASCII format

ch = (tlong / 10) % 10;


Lcd_Chr_CP(48+ch);
ch = tlong % 10;
Lcd_Chr_CP(48+ch);
Lcd_Chr_CP('V');

// Extract tens of millivolts


// Write result in ASCII format
// Extract digits for millivolts
// Write result in ASCII format

Delay_ms(1);
}
}

Practica 2.11 Comunicacin serial RS232


Descripcin P2.11:
Circuito P2.11:

Cdigo P2.11:
/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the
UART library in the Library Manager prior to compiling:

UART

*/

unsigned short i;

void main() {
UART1_Init(19200);

// Initialize USART module

// (8 bit, 19200 baud rate, no parity bit...)


while (1) {
if (UART1_Data_Ready()) { // If data has been received

}
}
}

i = UART1_Read();

// read it

UART1_Write(i);

// and send it back

Practica 2.12 Generacin de sonidos utilizando una librera


Descripcin P2.12:
Circuito P2.12:

Cdigo P2.12:

/*Header*****************************************************
In order to make this example work properly, it is necessary to tick off the following
libraries in the Library Manager prior to compiling:

Button
Sound

*/

void Tone1() {
Sound_Play(659, 250);

// Frequency = 659Hz, duration = 250ms

void Tone2() {
Sound_Play(698, 250);

// Frequency = 698Hz, duration = 250ms

void Tone3() {
Sound_Play(784, 250);

// Frequency = 784Hz, duration = 250ms

void Melody1() {

// Make funny melody 1

Tone1(); Tone2(); Tone3(); Tone3();


Tone1(); Tone2(); Tone3(); Tone3();
Tone1(); Tone2(); Tone3();
Tone1(); Tone2(); Tone3(); Tone3();

Tone1(); Tone2(); Tone3();


Tone3(); Tone3(); Tone2(); Tone2(); Tone1();
}

void ToneA() {

// Tone A

Sound_Play(880, 50);
}

void ToneC() {

// Tone C

Sound_Play(1046, 50);
}

void ToneE() {

// Tone E

Sound_Play(1318, 50);
}

void Melody2() {

// Make funny melody 2

unsigned short i;
for (i = 9; i > 0; i--) {
ToneA(); ToneC(); ToneE();
}
}

void main() {
ANSEL = 0;
ANSELH = 0;

// All I/O pins are digital

TRISB = 0xF0;

// Pins RB7-RB4 are configured as inputs,


// RB3 is configured as an output

Sound_Init(&PORTB, 3);
Sound_Play(1000, 500);

while (1) {
if (Button(&PORTB,7,1,1)) // RB7 generates Tone1
Tone1();
while (PORTB & 0x80) ; // Wait for push button release

if (Button(&PORTB,6,1,1)) // RB6 generates Tone2


Tone2();
while (PORTB & 0x40) ; // Wait for push button release

if (Button(&PORTB,5,1,1)) // RB5 generates melody 2


Melody2();
while (PORTB & 0x20) ; // Wait for push button release

if (Button(&PORTB,4,1,1)) // RB4 generates melody 1


Melody1();
while (PORTB & 0x10) ; // Wait for push button release
}
}

Unidad III Aplicaciones para el control de procesos y comunicacin


Practica 3.1 Control de un motor de DC mediante un puente H
Descripcion P3.1:
Control de la velocidad y direccin de un motor de DC. El control es por medio de un puente H
construido con transistores tipo MOSFET y sus drivers respectivos.
El control del motor debe de ser remoto y local.
Control local por medio de 7 botones:

Ir en la direccin de las manecillas del reloj (ClockWise, CW)


Ir en la direccin contraria a las manecillas del reloj (Counter ClockWise , CCW)
Aumentar velocidad (limite mximo 100%)
Disminuir velocidad (limite minimo 0%)
Arrancar motor , CW , velocidad 50%
Detener motor de manera inmediata.
Detener motor suavemente.

Control remoto por medio del puerto series (protocolo RS232), por medio de las siguientes
secuencias de bytes:

ATINT, arrancar motor


ATSTx , detener motor, donde si x=0 detener suavemente, x=1 detener inmediata.
ATDCW, direccin del motor CW
ATDCC, direccin del motor CCW
ATSxyz, La velocidad se fija al xyz%, donde xyz es un nmero en el rango del 000 al 100.

Circuito P3.1:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]

Transistor: IRF640 o Transistor MOSFET canal N o equivalente.

Driver: 4011 CMOS Quad NAND Gate IC, alimentado con +12 V DC.
4049 CMOS Hex Inverting Buffer IC.
NOTA: Los transistores MOSFET canal N se activa con un voltaje positivo en la terminal de Gate.
Cdigo P3.1:
[Escriba aqu el cdigo que implemento]

Practica 3.2 Control de un motor de pasos


Descripcion P3.2:
Control del movimiento, la direccin y el nmero de pasos a avanzar de un motor de pasos.
El control del motor debe de ser remoto y local.
Control local por medio de 5 botones:

Ir en la direccin de las manecillas del reloj (ClockWise, CW) continuamente.


Ir en la direccin contraria a las manecillas del reloj (Counter ClockWise , CCW)
continuamente.
Avanzar un paso CW
Avanzar un paso CCW
Detener motor, solo si esta en modo contino.

Control remoto por medio del puerto series (protocolo RS232), por medio de las siguientes
secuencias de bytes:

ATCMx, modo continuo, donde si x=0 avanzar CW, x=1 avanzad CCW.
ATSTP, detener motor.
ATMxyz, El motor se mueve en la direccin (x=0 CW ,x=1 CCW) un numero de pasos yz,
donde yz es un numero en el rango de 0-99.

Circuito P3.2:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]

Step

wire 1

wire 2

low

high

high

high

high

low

low

low

Step

wire
1

wire
2

wire
3

wire
4

High

low

high

low

low

high

high

low

low

high

low

high

high

low

low

high

Cdigo P3.2:
[Escriba aqu el cdigo que implemento]

Practicas 3.3 Control de un servo motor


Desripcion P3.3:
Control del movimiento de un servo motor.
El control del motor debe de ser remoto y local.
Control local por medio de 3 botones:

Movimiento en direccin de las manecillas del reloj (ClockWise, CW), el servo motor debe
de avanzar solo un grado, o la minima resolucin posible.
Movimiento en direccin contraria a las manecillas del reloj (Counter ClockWise , CCW), el
servo motor debe de avanzar solo un grado, o la minima resolucin posible.
Volver a la posicin central o neutral. NOTA: Suponer que el movimiento del servo motor
esta limitado a 180 grados, 90 grados en sentido positivo y 90 grados en sentido negativo.
NOTA: Verificar esto, cada servo es diferente el servo que utilizen puede estar limitado a
solo 120 grados, 60 grados en ambos sentidos.

Control remoto por medio del puerto series (protocolo RS232), por medio de las siguientes
secuencias de bytes:

ATSIP, el servo motor regresa a su posicin central o neutral.


ATMxyz, El motor se mueve en la direccin (x=0 CW, x=1 CCW) un numero de grados yz,
donde yz es un numero en el rango de 0-90.

El siguiente diagrama de tiempos de una seal tipo PWM para el control de un servo motor es solo
ilustrativa. Las seales de control de los servos motores no siguen un estndar verdadero. Lo nico
estandarizado es que el circuito de control del servo motor espera recibir un pulso cada 20 ms
(periodo). La duracin del pulso debe de ser entre 0.7 ms y 2.0 ms. Si la duracin del pulso esta
entre 0.7 y 1.0 ms el servo se mover hacia la derecha (CW). Si la duracin del pulso esta entre 1.7
y 2.0 ms el servo se mover hacia la izquierda (CCW). Si la duracin del pulso esta entre 1.3 y 1.5
ms el servo se mover a su posicin central o neutral.

http://www.ermicro.com/blog/?p=771
Circuito P3.3:

[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]


Cdigo P3.3:

[Escriba aqu el cdigo que implemento]

Practica 3.4 Medicin de temperatura con un sensor tipo IC y calibracin


de un termistor.
Descripcion P3.4:
Utilizar un sensor de temperatura tipo IC (circuito integrado, ejemplo LM35) para realizar la
calibracin de un termistor. La calibracin del termistor se tiene que hacer aplicando la equacion
de Steinhart-Hart, la cual relaciona la resistencia de un termistor y la temperatura a la que este
esta sometido.
El programa del uC debe de funcionar de la siguiente manera:

Debe de tener un boton para iniciar el proceso. Si el proceso se ha iniciado se debe de


indicar por medio de un LED que estar parpadeando mientras el proceso se lleva a
cabo.Este mismo boton permitir reiniciar el proceso.
Un boton que permita realizar la lectura de la temperatura medida por el sensor de
temperatura tipo IC y la resistencia del termistor. El proceso realizara y almacenara tres
mediciones de temperatura y de resistencia nicamente.
Al realizar las tres mediciones se indicara que el proceso finalizo encendiendo un LED que
indica la finalizacin del proceso.
Los datos de temperatura y de resistencia debern de ser mostrados tanto en un display
tipo LCD como transmitidos por el puerto serie (protocolo RS232).

http://web.cecs.pdx.edu/~eas199/B/howto/thermistorCalibration/thermistorResistanceCalibratio
n.pdf
http://web.cecs.pdx.edu/~eas199/B/howto/thermistorCalibration/thermistorResistanceCalibratio
n.m
http://web.cecs.pdx.edu/~eas199/B/howto/thermistorProbe/
http://web.cecs.pdx.edu/~eas199/B/howto/arduino/horner.html
http://www.daycounter.com/Calculators/Steinhart-Hart-Thermistor-Calculator.phtml

Circuito P3.4:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]
Cdigo P3.4:
[Escriba aqu el cdigo que implemento]

Practica 3.5 Control de temperatura tipo ON/OFF


Descripcion P3.5:
Control de temperatura tipo ON/OFF con histresis de una caja.
La temperatura baja (TLow) y la temperatura alta (THigh) podrn ser ajustadas mediante dos
botones cada una. Los botones harn las siguientes funciones:

Boton TLow_Up aumenta el valor de la temperatura baja.


Boton TLow_Down disminuye el valor de la temperatura baja.
Boton THigh_Up aumenta el valor de la temperatura alta.
Boton THigh_Downdisminuye el valor de la temperatura alta.
Boton On/Off el control de temperatura de activa/desactiva

Se debe de usar un sensor de temperatura para realizar las mediciones, un foco incandescente
como fuente de calor y un ventilador que servir para disminuir la temperatura de la caja.
Circuito P3.5:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]

Cdigo P3.5:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]

Practica 3.6 Modulo remoto de medicin y control. 3 sensores, 2


actuadores, comunicacin mediante RS232, modo de control remoto
mediante PC, modo de control local mediante botones.
Descripcion P3.6:
Se debe de realizar un circuito y programa que permita realizar la medicin remota de 3 variables
o sensores (pueden ser cualquier tipo de sensores pero cada uno de diferente variable,
preprense para justificar la seleccin de estos sensores). La medicin de estos tres sensores
permitara realizar el control de algn tipo de proceso (el proceso ustedes lo pueden idear, pero de
igual manera hay que preparar una justificacin de este) mediante dos actuadores. Los actuadores
deben de ser de tipos diferentes, es decir, elctricos, electroneumaticos, electrohidrulicos, o
electromecnicos.
El control de los dos actuadores puede realizarse de manera remota mediante la comunicacin
con una PC utilizando el protocolo RS232, o localmente mediante el uso de botones.
Las mediciones de los sensores de deben de mostrar localmente utilizando un display tipo LCD o
display tipo 7 segmentos.

Circuito P3.6:
[Dibuje aqu el circuito esquemtico. El circuito debe de estar completo]

Cdigo P3.6:
[Escriba aqu el cdigo que implemento]

Proyecto final
Descripcion PF:
Modificar tanto el cdigo como el hardware necesario para realizar este proyecto con un
PIC16F887 .
La construccin del pndulo invertido y del hardware de control debe de ser construido,
modificado o alterado a su conveniencia.
Software PID Control of an Inverted Pendulum Using the PIC16F684
The purpose of this application note is to describe how a PIC16F684 can be used to implement a positional
Proportional-Integral-Derivative (PID) feedback control in an inherently unstable system. An inverted pendulum
is used to demonstrate this type of control.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en
021807

http://ww1.microchip.com/downloads/en/AppNotes/00964A.pdf

Circuito PF:
http://ww1.microchip.com/downloads/en/AppNotes/00964A.pdf

Cdigo PF:
http://ww1.microchip.com/downloads/en/AppNotes/INV_PEN_CODE.zip
http://ww1.microchip.com/downloads/en/AppNotes/AN964.zip

Formato de reportes
Todas las prcticas deben de ir acompaadas de un reporte.El reporte debe de entregarse escrito
a mano (diagramas y cdigo fuente tambin). Cada reporte dede de contener al menos los
siguientes componentes:

La pagina de presentacin. Debe de ser sobria y sencilla. Debe de contener el nombre


completo de los integrantes del grupo, el nombre y nmero de la prctica, el nombre de
la materia y la fecha de realizacin.
Introduccion. Se resume de manera clara y concisa de que se trata la prctica.
Desarrollo y anlisis. Esta es el componente ms importante del reporte. Se debe de
explicar claramente y nicamente con los detalles necesarios todas las actividades que se
realizaron para poder llevar a cabo la practica.
Conclusiones y discusiones. Aqu cada miembro del equipo aporta sus conclusiones
personales acerca de la realizacin de la prctica. Se debe de incluir una discusin por
parte del equipo acerca de la dificultad de realizar la prctica, los conceptos que se
pudieron apreciar y cualquier comentario o sugerencia para mejorar las practicas.
Apendice A. Codigo fuente. Aqu se incluye el cdigo fuente tal y cual se compilo y
programo para la prctica.
Apendice B. Diagrama esquemtico. Aqu se incluye el diagrama esquemtico de todos los
circuitos que se utilizaron para llevar a cabo y revisar la practica.
Apendice C. Todo aquello que no se incluyo en los puntos anteriores va aqu.

El reporte tambin lleva su contraparte electrnica. Esta es una carpeta comprimida, en


formato ZIP, que contenga las siguientes subcarpetas:

SourceCode, aqu va la carpeta del proyecto generado por la IDE y el compilador


utilizados.
Schematics, aqu van los diagramas esquemticos de los circuitos realizados. Deben
de estar en formato PDF.

Este reporte deber de ser subido a la seccin del curso en la plataforma.


http://www.eav.utch.edu.mx/course/view.php?id=921

Criterios y ponderaciones de evaluacin


Unidad I
Calificacion = ((Calif. Examen) * (Practicas_Relizadas /16) * 0.5) + ((Reportes_Revisados/16) * 0.5)
Unidad II
Calificacion = ((Calif. Examen) * (Practicas_Relizadas /12) * 0.5) + ((Reportes_Revisados/12) * 0.5)
Unidad III
Calificacion = ((Calif. Examen) * (Practicas_Relizadas /6) * 0.4) + ( Calif_PF * 0.6)

Links de ayuda
http://ww1.microchip.com/downloads/en/devicedoc/33023a.pdf
http://www.microchip.com/pagehandler/en-us/family/mplabx/#downloads
http://www.mikroe.com/products/view/11/book-pic-microcontrollers/
http://www.mikroe.com/products/view/285/book-pic-microcontrollers-programming-in-c/
http://tutorial.cytron.com.my/2012/07/02/mplab-x-ide-with-mplab-xc8/
http://tutorial.cytron.com.my/category/projects/page/2/
https://forum.sparkfun.com/viewtopic.php?f=32&t=31170
http://tutorial.cytron.com.my/2011/08/08/project-0-%E2%80%93-my-1st-pic-project-load-asimple-led-blink/
http://www.microchipc.com/
http://www.microchipc.com/sourcecode/
http://www.picmicros.org.uk/
http://www.mikroe.com/forum/viewtopic.php?t=19530

Вам также может понравиться