Está en la página 1de 7

“Proyecto Final”

Nombre de la Carrera
Ingeniería en Mecatrónica
Nombre de la materia
Microcontroladores
Presenta
Alfonso Joaquín Medina Morales 219341798
Braulio de la Torre Martin del Campo
Profesor
Roger Chiu Zarate

24/05/2023
Introducción
En este proyecto se llevará a cabo la programación en un robot operado de manera
autónoma, el cuál deberá resolver un laberinto, con ayuda de un sensor ultrasónico
podrá llevar a cabo dicha tarea. Se utilizará un microcontrolador MSP---, que es el
elemento al que se le cargará el código y lo ejecutará. Asimismo, el código estará en
lenguaje C y también se utilizará un robot móvil con ruedas para este proyecto.

Desarrollo
Se utilizó un robot móvil como base (modelo del robot), un sensor ultrasónico, un
microcontrolador MSP--, y una tabla protoboard. Primero se analizó el sensor que se
iba a utilizar, al final se decantó por el ultrasónico, así empezó entonces el proceso de
programación, se ideó el como tenía que funcionar para que el robot avanzara de una
manera más fluida y con ayuda del sensor poder resolver el laberinto de manera algo
rápida.

Código
;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file

;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.

;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer

;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------
bis.b #BIT7,&P4DIR
bic.b #BIT7,&P4OUT
bis.b #BIT0,&P1DIR
bis.b #BIT0,&P1OUT
bis.b #BIT1,&P4DIR
bis.b #BIT1,&P4OUT
bis.b #BIT2,&P4DIR
bis.b #BIT2,&P4OUT
; SALIDAS LED
bic.b #BIT1,&P1DIR
bis.b #BIT1,&P1REN
bis.b #BIT1,&P1OUT
bis.b #BIT1,&P1IE
bis.b #BIT1,&P1IES
bic.b #BIT1,&P1IFG
; ENTRADA DE BOTONES / SENSORES
bic.b #BIT1,&P2DIR
bis.b #BIT1,&P2REN
bis.b #BIT1,&P2OUT
bis.b #BIT1,&P2IE
bis.b #BIT1,&P2IES
bic.b #BIT1,&P2IFG
; INTERRUPCION #2

bis.b #BIT0,&P2DIR
bis.b #BIT0,&P2SEL
bis.b #BIT4,&P2DIR
bis.b #BIT4,&P2SEL
; PWM

bic.w #MC0|MC1, &TA0CTL


bis.w #TACLR, &TA0CTL
bis.w #TASSEL__ACLK, &TA0CTL
bic.w #ID0|ID1, &TA0CTL
bis.w #MC0,&TA0CTL
bis.w #TAIE, &TA0CTL
bic.w #TAIFG, &TA0CTL
mov.w #0x1f40, &TA0CCR0

; CONFIGURACION DE INTERRPCIONES Y BOTONES

bic.w #MC0|MC1, &TA1CTL


bis.w #TACLR, &TA1CTL
bis.w #TASSEL__ACLK, &TA1CTL
bic.w #ID1, &TA1CTL
bis.w #ID0, &TA1CTL
bis.w #MC0|MC1, &TA1CTL
bic.w #CAP, &TA1CCTL1
bis.w #OUTMOD_6, &TA1CCTL1
mov.w #250, &TA1CCR0
mov.w #50, &TA1CCR1
bis.w #MC0|MC1, &TA1CTL
; PWM 1
bic.w #MC0|MC1, &TA2CTL
bis.w #TACLR, &TA2CTL
bis.w #TASSEL__ACLK, &TA2CTL
bic.w #ID1, &TA2CTL
bis.w #ID0, &TA2CTL
bis.w #MC0|MC1, &TA2CTL
bic.w #CAP, &TA2CCTL1
bis.w #OUTMOD_6, &TA2CCTL1
mov.w #250, &TA2CCR0
mov.w #50, &TA2CCR1
bis.w #MC0|MC1, &TA2CTL
; PWM 2
mov.w #0, r5

nop
bis.w #LPM3|GIE, SR
nop

; INTERRUPCIONES
BT1_ISR:
cmp.w#250, &TA1CCR1
jeq end_bt1
add.w #5, &TA2CCR1
add.w #5, &TA1CCR1
jmp end_bt1
nop
end_bt1:
bic.b #BIT1,&P1IFG
reti
nop

BT2_ISR:
cmp.w#50, &TA1CCR1
jeq end_bt2
sub.w #5, &TA2CCR1
sub.w #5, &TA1CCR1
jmp end_bt2
nop
end_bt2:
bic.b #BIT1,&P2IFG
reti
nop

TA0_ISR:

add.w #1, r5
xor.b #BIT7,&P4OUT
xor.b #BIT0, &P1OUT
cmp.w#5, r5
jlo run_1
cmp.w#10, r5
jlo run_2
cmp.w#12, r5
jlo turn_1
cmp.w#13, r5
jeq rst_1
jmp end_t
nop
run_2:
bic.b #BIT2,&P4OUT
bic.b #BIT1,&P4OUT
jmp end_t
nop
turn_1:
bis.b #BIT2,&P4OUT
bis.b #BIT1,&P4OUT
mov.w #50, &TA2CCR1
mov.w #250, &TA1CCR1
jmp end_t
nop
rst_1:
mov.w #50, &TA2CCR1
mov.w #50, &TA1CCR1
mov.w #0, r5
jmp end_t
nop
run_1:
bis.b #BIT2,&P4OUT
bis.b #BIT1,&P4OUT
jmp end_t
nop
end_t:
bic.w #TAIFG, &TA0CTL
reti
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
.sect ".int52"
.shortTA0_ISR
.sect ".int47"
.shortBT1_ISR
.sect ".int42"
.shortBT2_ISR

Conclusiones
Se pudo observar como por medio de interrupciones un robot puede detectar y hacer
una acción u otra, haciendo las funciones de un If, pero que sucederán dependiendo su
jerarquía y el orden en el que están. De igual manera se puso en práctica la
programación de servomotores y sensores vistos en clase, para unirlos en un solo
programa.

También podría gustarte