Está en la página 1de 33

UNIVERSIDAD TECNOLÓGICA DE AGUASCALIENTES

Mecatrónica
SISTEMAS DIGITALES
Prof.Ing. Victor Mora Romo

Prácticas con microcontrolador

Elaborado por:

Carlos Iván Romero Zavala

11225
22 de Junio de 2013
Contenido
PRACTICA 1 UN LED ............................................................................................................................. 3
PRACTICA 2 DOS LED ........................................................................................................................... 4
PRACTICA 3 SEMAFORO ...................................................................................................................... 5
PRACTICA 4 CRUCERO SEMAFORO ..................................................................................................... 7
PRACTICA 5 SECUENCIA DE LUCES 1 ................................................................................................... 9
PRACTICA 6 SECUENCIA DE LUCES 2 ................................................................................................. 10
PRACTICA 7 SECUENCIA DE LUCES 3 ................................................................................................. 11
PRACTICA 8 UN BOTON ..................................................................................................................... 13
PRACTICA 9 BOTON VARIOS LEDS ..................................................................................................... 14
PRACTICA 10 DIP SWITCH ................................................................................................................. 15
Práctica 11 Boton con Simbologia..................................................................................................... 17
Practica 12 Compuerta not ............................................................................................................... 18
Practica 13 Compuerta AND.............................................................................................................. 19
Practica 14 Nand ............................................................................................................................... 19
Practica 15 Compuerta or ................................................................................................................. 21
Practica 16 Compuerta Nor ............................................................................................................... 21
Practica 17 Compuerta Xor ............................................................................................................... 23
Practica 18 Compuerta Xnor ............................................................................................................. 24
Practica 20 Decodificador con secuencia a bits ................................................................................ 25
Practica 21 Decodificador con salida a display 7 segmentos ............................................................ 27
Practica 23 Demultiplexor a leds....................................................................................................... 29
Practica 24 uso del LCD ..................................................................................................................... 30
PRACTICA 1 UN LED
program Un_led

' Declarations section

main:

PORTD=0

TRISD=0

PORTD.0=1

DELAY_MS(1000)

PORTD.0=0

goto main

' Main program

end.
PRACTICA 2 DOS LED
program Dos

' Declarations section

main:

PORTD=0

TRISD=0

PORTD.0=1

DELAY_MS(1000)

PORTD.0=0

PORTD.1=1

DELAY_MS(1000)

PORTD.1=0

GOTO MAIN

' Main program

end.
PRACTICA 3 SEMAFORO
program SEMAFORO

' Declarations section

main:

PORTD=0

TRISD=0

PORTD.0=1

DELAY_MS(1000)

PORTD.0=0

PORTD.1=1

DELAY_MS(2000)

PORTD.1=0

PORTD.2=1

DELAY_MS(200)

PORTD.2=0

DELAY_MS(200)

PORTD.2=1

DELAY_MS(200)

PORTD.2=0

DELAY_MS(200)

PORTD.2=1

DELAY_MS(200)

PORTD.2=0

GOTO MAIN

end.
PRACTICA 4 CRUCERO SEMAFORO
program Crucero PORTD.2=0 PORTC.0=0

PORTD.1=1 PORTC.2=1

' Declarations section DELAY_MS(4000)


DELAY_MS(1000)
PORTC.2=0
PORTD.1=0
main: DELAY_MS(400)

PORTD=0 PORTD.0=1 PORTC.2=1

PORTC=0 PORTD.3=0 DELAY_MS(400)

TRISD=0 PORTD.5=1 PORTC.2=0

TRISC=0 DELAY_MS(4000) DELAY_MS(400)

PORTD.2=1 PORTD.5=0 PORTC.2=1

PORTD.3=1 DELAY_MS(400) DELAY_MS(400)

PORTC.0=1 PORTD.5=1 PORTC.2=0

PORTC.3=1 DELAY_MS(400) DELAY_MS(400)

DELAY_MS(4000) PORTD.5=0 PORTC.2=1

PORTD.2=0 DELAY_MS(400) DELAY_MS(400)

DELAY_MS(400) PORTD.5=1 PORTC.2=0

PORTD.2=1 DELAY_MS(400) PORTC.1=1

DELAY_MS(400) PORTD.5=0 DELAY_MS(1000)

PORTD.2=0 DELAY_MS(400) PORTC.1=0

DELAY_MS(400) PORTD.5=1 PORTC.0=1

PORTD.2=1 DELAY_MS(400) PORTC.3=0

DELAY_MS(400) PORTD.5=0 PORTC.5=1

PORTD.2=0 PORTD.4=1 DELAY_MS(4000)

DELAY_MS(400) DELAY_MS(1000) PORTC.5=0

PORTD.2=1 PORTD.4=0 DELAY_MS(400)

DELAY_MS(400) PORTD.3=1 PORTC.5=1


DELAY_MS(400) DELAY_MS(400) PORTC.4=0

PORTC.5=0 PORTC.5=1 GOTO MAIN

DELAY_MS(400) DELAY_MS(400)

PORTC.5=1 PORTC.5=0 ' Main program

DELAY_MS(400) PORTC.4=1 end.

PORTC.5=0 DELAY_MS(1000)
PRACTICA 5 SECUENCIA DE LUCES 1
program Secuencia_de_Luces_1

' Declarations section

main:

ADCON0.ADON=0

ADCON1=0X07

TRISC=0

TRISD=0

PORTC=%11111111

PORTD=%00000000

DELAY_MS(500)

PORTC=%00000000

PORTD=%11111111

DELAY_MS(500)

GOTO MAIN

' Main program

end.
PRACTICA 6 SECUENCIA DE LUCES 2
program Secuencia_de_Luces_2

' Declarations section

main:

ADCON0.ADON=0

ADCON1=0X07

TRISC=0

TRISD=0

PORTC=%01010101

PORTD=%10101010

DELAY_MS(500)

PORTC=%10101010

PORTD=%01010101

DELAY_MS(500)

GOTO MAIN

' Main program

end.
PRACTICA 7 SECUENCIA DE LUCES 3
program Secuencia_de_Luces_3 PORTD=%00000000

DELAY_MS(100)

' Declarations section PORTC=%00000000

dim k as byte PORTD=%11111111

DELAY_MS(100)

main: next k

ADCON0.ADON=0

ADCON1=0X07

TRISC=0 for k=0 to 10

TRISD=0 PORTC=%01010101

for k=0 to 10 PORTD=%10101010

PORTC=%01010101 DELAY_MS(100)

PORTD=%10101010 PORTC=%10101010

DELAY_MS(500) PORTD=%01010101

PORTC=%10101010 DELAY_MS(100)

PORTD=%01010101 next k

DELAY_MS(500)

next k GOTO MAIN

' Main program

for k=0 to 10 end.

PORTC=%11111111
PRACTICA 8 UN BOTON
program Boton

' Declarations section

main:

ADCON0.ADON=0

ADCON1=0X07

TRISA=1

TRISB=0

IF PORTA.0=1 THEN

PORTB.0=1 ELSE

PORTB.0=0

DELAY_MS(70)

END IF

GOTO MAIN

' Main program

end.
PRACTICA 9 BOTON VARIOS LEDS
program Boton_varios_led

' Declarations section

main:

ADCON1=0X07

TRISA=1

TRISB=0

IF PORTA.0=1 THEN

PORTB=%11111111 ELSE

PORTB=%00000000

DELAY_MS(70)

END IF

GOTO MAIN

' Main program

end.
PRACTICA 10 DIP SWITCH
program Dip switch END IF PORTB.5=0

IF PORTD.2=1 THEN DELAY_MS(100)

' Declarations section PORTB.2=1 ELSE END IF

PORTB.2=0 IF PORTD.6=1 THEN

main: DELAY_MS(100) PORTB.6=1 ELSE

ADCON1=0X07 END IF PORTB.6=0

TRISD=1 IF PORTD.3=1 THEN DELAY_MS(100)

TRISB=0 PORTB.3=1 ELSE END IF

PORTB.3=0 IF PORTD.7=1 THEN

IF PORTD.0=1 THEN DELAY_MS(100) PORTB.7=1 ELSE

PORTB.0=1 ELSE END IF PORTB.7=0

PORTB.0=0 IF PORTD.4=1 THEN DELAY_MS(100)

DELAY_MS(100) PORTB.4=1 ELSE END IF

END IF PORTB.4=0

IF PORTD.1=1 THEN DELAY_MS(100) GOTO MAIN

PORTB.1=1 ELSE END IF ' Main program

PORTB.1=0 IF PORTD.5=1 THEN end.

DELAY_MS(100) PORTB.5=1 ELSE


Práctica 11 Boton con Simbologia
program _botonsymbol porta=0

portb=0

' Declarations section if A = 1 then

symbol B = portb.0 B=1

symbol A = porta.0 delay_ms(500)

end if

main: goto main

ADCON0.ADON=0

ADCON1=0X07 ' Main program

trisa=1 end.

trisb=0
Practica 12 Compuerta not
program _not ADCON1=0X07

PORTD=0

' Declarations section PORTB=0

symbol B = portB.0 trisB=0

symbol D = portD.0 trisD=1

B = not D

goto main

main: end.

ADCON0.ADON=0
Practica 13 Compuerta AND
program _and PORTD=0

PORTB=0

' Declarations section trisB=0

symbol B = portB.0 trisD=1

symbol D = portD.0 IF D AND D1 THEN

SYMBOL D1= PORTD.1 B=1 ELSE

B=0

main: end IF

ADCON0.ADON=0 goto main

ADCON1=0X07 END.

Practica 14 Nand
program _nand PORTB=0

trisB=0

' Declarations section trisD=1

symbol B = portB.0 IF NOT(D AND D1) THEN

symbol D = portD.0 B=1 ELSE

SYMBOL D1= PORTD.1 B=0

DELAY_MS(100)

main: end IF

ADCON0.ADON=0 goto main

ADCON1=0X07

PORTD=0 end.
Practica 15 Compuerta or
program _or trisB=0

trisD=1

' Declarations section IF D OR D1 THEN

symbol B = portB.0 B=1 ELSE

symbol D = portD.0 B=0

SYMBOL D1= PORTD.1 DELAY_MS(100)

end IF

main: goto main

ADCON0.ADON=0

ADCON1=0X07 ' Main program

PORTD=0 end.

PORTB=0

Practica 16 Compuerta Nor


program _nor PORTB=0

trisB=0

' Declarations section trisD=1

symbol B = portB.0 IF NOT(D OR D1) THEN

symbol D = portD.0 B=1 ELSE

SYMBOL D1= PORTD.1 B=0

DELAY_MS(100)

main: end IF

ADCON0.ADON=0 goto main

ADCON1=0X07 ' Main program

PORTD=0 end.
Practica 17 Compuerta Xor
program _xor trisB=0

trisD=1

' Declarations section IF (NOT D AND D1)OR (NOT D1 AND D) THEN

symbol B = portB.0 B=1 ELSE

symbol D = portD.0 B=0

SYMBOL D1= PORTD.1 DELAY_MS(100)

end IF

main: goto main

ADCON0.ADON=0

ADCON1=0X07 ' Main program

PORTD=0 end.

PORTB=0
Practica 18 Compuerta Xnor
program _xnor trisB=0

trisD=1

' Declarations section IF (NOT D AND NOT D1)OR (D1 AND D) THEN

symbol B = portB.0 B=1 ELSE

symbol D = portD.0 B=0

SYMBOL D1= PORTD.1 DELAY_MS(100)

end IF

main: goto main

ADCON0.ADON=0

ADCON1=0X07 ' Main program

PORTD=0 end.

PORTB=0
Practica 20 Decodificador con secuencia a bits
program ADCON1=0X07 DELAY_MS(500)
DECODIFICADOR_A_BITS
trisb=1 PORTC=%00001000
symbol B = portb.0
trisc=0 DELAY_MS(500)
symbol B1 = portb.1
portb=0 PORTC=%00001001
symbol B2 = portb.2
portc=0 DELAY_MS(500)
symbol B3 = portb.3
PORTC=%00001010
symbol B4 = portb.4
PORTC=%00000000 DELAY_MS(500)
symbol B5 = portb.5
DELAY_MS(500) PORTC=%00001011
symbol B6 = portb.6
PORTC=%00000001 DELAY_MS(500)
symbol B7 = portb.7
DELAY_MS(500) PORTC=%00001100
symbol C = portc.0
PORTC=%00000010 DELAY_MS(500)
symbol C1 = portc.1
DELAY_MS(500) PORTC=%00001101
symbol C2 = portc.2
PORTC=%00000011 DELAY_MS(500)
symbol C3 = portc.3
DELAY_MS(500) PORTC=%00001110
' Declarations section
PORTC=%00000100 DELAY_MS(500)

DELAY_MS(500) PORTC=%00001111

PORTC=%00000101 DELAY_MS(500)

DELAY_MS(500)

PORTC=%00000110 GOTO MAIN


main:
DELAY_MS(500) ' Main program
ADCON0.ADON=0
PORTC=%00000111 end.
Practica 21 Decodificador con salida a display 7 segmentos
program ADCON0.ADON=0 PORTC=%00000111
DECODIFICADOR_A_7SEG
MENTOS ADCON1=0X07 DELAY_MS(500)

trisb=1 PORTC=%00001000

symbol B = portb.0 trisc=0 DELAY_MS(500)

symbol B1 = portb.1 portb=0 PORTC=%00001001

symbol B2 = portb.2 portc=0 DELAY_MS(500)

symbol B3 = portb.3 PORTC=%00001010

symbol B4 = portb.4 PORTC=%00000000 DELAY_MS(500)

symbol B5 = portb.5 DELAY_MS(500) PORTC=%00001011

symbol B6 = portb.6 PORTC=%00000001 DELAY_MS(500)

symbol B7 = portb.7 DELAY_MS(500) PORTC=%00001100

symbol C = portc.0 PORTC=%00000010 DELAY_MS(500)

symbol C1 = portc.1 DELAY_MS(500) PORTC=%00001101

symbol C2 = portc.2 PORTC=%00000011 DELAY_MS(500)

symbol C3 = portc.3 DELAY_MS(500) PORTC=%00001110

' Declarations section PORTC=%00000100 DELAY_MS(500)

DELAY_MS(500) PORTC=%00001111

PORTC=%00000101 DELAY_MS(500)

DELAY_MS(500)

PORTC=%00000110 GOTO MAIN

main: DELAY_MS(500) end.


Practica 23 Demultiplexor a leds
program Demultiplexor main: ELSE

ADCON0.ADON=0 IF (B=1) AND (B1=0)


THEN
symbol B = portb.0 ADCON1=0X07
C2=1
symbol B1 = portb.1 trisb=1
DELAY_MS(500)
symbol B2 = portb.2 trisc=0
ELSE
symbol B3 = portb.3 portb=0
IF (B=1) AND (B=1)
symbol B4 = portb.4 portc=0 THEN
symbol B5 = portb.5 C3=1
symbol B6 = portb.6 if (B=0) AND (B1=0) THEN DELAY_MS(500)
symbol B7 = portb.7 C=1 END IF
symbol C = portc.0 DELAY_MS(500) END IF
symbol C1 = portc.1 ELSE END IF
symbol C2 = portc.2 IF (B=0) AND (B1=1) END IF
THEN
symbol C3 = portc.3 GOTO MAIN
C1=1
end.
DELAY_MS(500)
Practica 24 uso del LCD
program LCD

dim LCD_RS as sbit at RA1_bit ' You can define and connect the LCD

LCD_EN as sbit at RA3_bit

LCD_D4 as sbit at RD4_bit

LCD_D5 as sbit at RD5_bit

LCD_D6 as sbit at RD6_bit

LCD_D7 as sbit at RD7_bit

dim LCD_RS_Direction as sbit at TRISA1_bit

LCD_EN_Direction as sbit at TRISA3_bit

LCD_D4_Direction as sbit at TRISD4_bit

LCD_D5_Direction as sbit at TRISD5_bit

LCD_D6_Direction as sbit at TRISD6_bit

LCD_D7_Direction as sbit at TRISD7_bit

' End Lcd module connections

dim txt1 as char [11] ' Define char and length for every phrase

txt2 as char [13]

txt3 as char [11]

txt4 as char [8]

txt5 as char [11]

txt6 as char [11]

txt7 as char [11]

txt8 as char [7]

txt9 as char [8]


txt10 as char [9]

txt11 as char [6]

txt12 as char [6]

main:

ADCON0.ADON = 0 'Modulo ADC a Off

ADCON1 = 0x07 'todos los pin como I/O

' Main program

TRISB = 0 ' Define PORTB as output

PORTB = 0

TRISA = 0 ' Define PORTB as output

PORTA = 0

txt1 = "Carlos Ivan" ' Here you can change the text

txt2 = "Romero Zavala" ' Remeber to change also char length n

txt3 = "La Hacienda" ' of every phrase in dim txt as char [n]

txt4 = "#123 JM"

txt5 = "Mecatronica"

txt6 = "UTA 9636664"

txt7 = "Mecatronica"

txt8 = "Materia"

txt9 = "Sistemas"

txt10 = "Digitales"

txt11 = ":):):)"

txt12 = ":):):)"
Lcd_Init() ' Initialize Lcd

Delay_ms (100) ' Wait 100ms

Lcd_Cmd(_LCD_CLEAR) ' Clear display

Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off

while TRUE ' Endless loop

Lcd_Out(1, 1, txt1) ' Write text in first row

Lcd_Out(2, 1, txt2) ' Write text in second row

Delay_ms (800) ' Wait 800ms

Lcd_Cmd(_LCD_CLEAR) ' Clear display

Lcd_Out(1, 1, txt3) ' Write text in first row

Lcd_Out(2, 1, txt4) ' Write text in second row FILA,COLUMNA

Delay_ms (800) ' Wait 800ms

Lcd_Cmd(_LCD_CLEAR) ' Clear display

Lcd_Out(1, 1, txt5) ' Write text in first row

Lcd_Out(2, 1, txt6) ' Write text in second row FILA,COLUMNA

Delay_ms (800) ' Wait 800ms

Lcd_Cmd(_LCD_CLEAR) ' Clear display

Wend

End.

También podría gustarte