Blogia

microcontroladores1

Nuestro 2do Proyecto (Motor p_p)

   list p = 16f84
  radix hex
estado   equ 03
portA    equ 05
portB   equ 06
tmr0_op  equ 01
reg0    equ 0c
reg1    equ 0d
reg2    equ 0e
reg3   equ 0f

    org 00
    bsf estado,5
    movlw 10
   movwf portA
   movlw 0ff
    movwf portB
    movlw 07
   movwf tmr0_op
    bcf estado,5

inicio:  movlw 01
    movwf portA
jul1:   movf portB,0
    movwf reg0
    andlw 03
    movwf reg1
    incf reg1,1
    movf reg0,0
    andlw 0f0
    movwf reg2
    swapf reg2,1
    incf reg2,1
    btfss portA,4
    goto jul1
    btfss reg0,4
    goto jul2           ;es no del RB3
    btfss reg0,3
    goto jul3         ;es no del RB2 paso
ken1   call left
    decfsz reg2,0
  goto jul1
    goto ken1
jul3:   call right
    decfsz reg2,0
    goto jul3
    goto jul1 
jul2:   btfss reg0,3
    goto jul4            ;no de RB2 giro
ken3:   call left
    btfss portA,5
    goto jul1
    goto ken3
jul4:   call right
   btfss portA,5
    goto jul1
    goto jul4

right:   movf reg1,0
    sublw 01
    btfsc estado,2
    call rotar1
    sublw 02
    btfsc estado,2
    call rotar2
    sublw 03
    btfsc estado,2
    call rotar3
    sublw 04
    btfsc estado,2
    call rotar4
    return
 

left:    movf reg1,0
    sublw 01
    btfsc estado,2
    call rotar01
    sublw 02
   btfsc estado,2
    call rotar02
    sublw 03
    btfsc estado,2
    call rotar03
    sublw 04
    btfsc estado,2
    call rotar04
    return

rotar1:  movlw 08
    movwf portA
  rrf portA,1
  call delay1
  btfss portA,4
  goto jul1
    goto rotar1
    return

rotar2: movlw 08
    movwf portA
  rrf portA,1
  call delay2
  btfss portA,4
  goto jul1
    goto rotar2
    return

rotar3:  movlw 08
    movwf portA
  rrf portA,1
  call delay3
  btfss portA,4
  goto jul1
    goto rotar3
    return

rotar4:  movlw 08
    movwf portA
  rrf portA,1
  call delay4
  btfss portA,5
  goto jul1
    goto rotar4
    return

 

rotar01  movlw 08
    movwf portA
  rrf portA,1
  call delay1
  btfss portA,5
  goto jul1
    goto rotar01
    return

rotar02  movlw 08
    movwf portA
  rrf portA,1
  call delay2
  btfss portA,5
  goto jul1
    goto rotar02
    return
rotar03  movlw 08
    movwf portA
  rrf portA,1
  call delay3
  btfss portA,5
  goto jul1
    goto rotar03
    return
rotar04  movlw 08
    movwf portA
  rrf portA,1
  call delay4
  btfss portA,5
  goto jul1
    goto rotar04
    return

delay1:  movlw 08
    movlw d'8'
     movwf reg3
jon:     btfss 0b,2
      goto jon
      bcf 0b,2
      decfsz reg3,1
      goto jon
      return

delay2:  movlw d'60'
     movwf tmr0_op
jon1:    btfss 0b,2
         goto jon1
         bcf 0b,2
         return

delay3:  movlw d'251'
       movwf tmr0_op
jon2:    btfss 0b,2
         goto jon2
         bcf 0b,2
         return 

delay4:  movlw d'253'
       movwf tmr0_op
jon3:    btfss 0b,2
         goto jon3
         bcf 0b,2
         return
     end

Programa de 20% Lab. de Mc

 list p = 16f84
 radix hex
estado equ 03
portA equ 05
portB equ 06
tmr0_op equ 01
reg1 equ 0c
reg2 equ 0d
reg3 equ 0e
reg4 equ 0f
reg5 equ 10
reg6 equ 11
reg7 equ 12
reg8 equ 13
delay1 equ 14
delay2 equ 15

  org 00
  bsf estado,5
  movlw 0ff
  movwf portA
  clrf portB
  movlw 07
  movwf tmr0_op
  bcf estado,5
inicio: movlw 00
  movwf reg1
  movlw 01
  movwf reg2
  movlw 02
  movwf reg3
  movlw 03
  movwf reg4
  movlw 04
  movwf reg5
  movlw 05
  movwf reg6
  movlw 06
  movwf reg7
  movlw 07
  movwf reg8
ave: movf portA,0
  andlw 07
  subwf reg1,0
  btfsc estado,2
  goto jon1
  movf portA,0
  andlw 07
  subwf reg2,0
  btfsc estado,2
  goto jon2
  movf portA,0
  andlw 07
  subwf reg3,0
  btfsc estado,2
  goto jon3
  movf portA,0
  andlw 07
  subwf reg4,0
  btfsc estado,2
  goto jon4
  movf portA,0
  andlw 07
  subwf reg5,0
  btfsc estado,2
  goto jon5
  movf portA,0
  andlw 07
  subwf reg6,0
  btfsc estado,2
  goto jon6
  movf portA,0
  andlw 07
  subwf reg7,0
  btfsc estado,2
  goto jon7
  movf portA,0
  andlw 07
  subwf reg8,0
  btfsc estado,2
  goto jon8
jon1: bsf portB,0
  call retar1
  bcf portB,0
  call retar1
  btfsc portA,3
  goto ave
  goto jon1
jon2: bsf portB,0
  call retar2
  bcf portB,0
  call retar2
  btfsc portA,3
  goto ave
  goto jon2
jon3: bsf portB,0
  call retar3
  bcf portB,0
  call retar3
  btfsc portA,3
  goto ave
  goto jon3
jon4: bsf portB,0
  call retar4
  bcf portB,0
  call retar4
     btfsc portA,3
  goto ave
  goto jon4
jon5: bsf portB,0
  call retar5
  bcf portB,0
  call retar5
  btfsc portA,3
  goto ave
  goto jon5
jon6: bsf portB,0
  call retar6
  bcf portB,0
  call retar6
  btfsc portA,3
  goto ave
  goto jon6
jon7: bsf portB,0
  call retar7
  bcf portB,0
  call retar7
  btfsc portA,3
  goto ave
  goto jon7
jon8: bsf portB,0
  call retar8
  bcf portB,0
  call retar8
  btfsc portA,3
  goto ave
  goto jon8
retar1: movlw d'16'
  movwf delay1
ken1: btfss 0b,2
  goto  ken1
  bcf 0b,2
  decfsz delay1,1
  goto ken1
  return
retar2: movlw d'8'
  movwf delay1
ken2: btfss 0b,2
  goto ken2
  bcf 0b,2
  decfsz delay1,1
  goto ken2
  return
retar3:   movlw d'60'
  movwf tmr0_op
ken3: btfss 0b,2
  goto ken3
  bcf 0b,2
  return
retar4: movlw d'223'
  movwf tmr0_op
ken4: btfss 0b,2
  goto ken4
  bcf 0b,2
  return
retar5: movlw d'251'
  movwf tmr0_op
ken5: btfss 0b,2
  goto ken5
  bcf 0b,2
  return  
retar6: movlw d'253'
  movwf tmr0_op
ken6: btfss 0b,2
  goto ken6
  bcf 0b,2
  return 
retar7: movlw d'16'
  movwf delay2
ken7: decfsz delay2,1
  goto ken7
  return
retar8: nop
  return
  end

Diagrama de flujo

[url=http://www.subir-imagenes.com][img]http://www.subir-imagenes.com/subir_imagenes_y_fotos/cdf708cab7.bmp[/img]