Loading ...
Sorry, an error occurred while loading the content.
 

Servo motor using PIC16F877A (Assembly Language)

Expand Messages
  • gabby
    Can someone help me? I m trying to debug this code on how to control the priority of a servomotor. It is composed of 2 LDR s which controls the movement of the
    Message 1 of 1 , Nov 15, 2012
      Can someone help me? I'm trying to debug this code on how to control the priority of a servomotor. It is composed of 2 LDR's which controls the movement of the servo motor(either 0 or 180 degrees). My problem is when the two LDR's are enabled, it goes to 90 degrees but our requirement is to have its priority set on one direction only. Can someone teach me how to code for its priority? Thanks


      LIST P=PIC16f877A

      #include "p16f877A.inc"

      __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _LVP_OFF & _CPD_OFF

      ; Define variables used
      CBLOCK 0x20
      Delay
      Delay1
      Delay2
      PRIOR
      ENDC

      ORG 0x00
      init:

      banksel ADCON1
      movlw 0x06 ; all pins digital I/O
      movwf ADCON1

      CLRF PORTA

      Banksel TRISA
      CLRF TRISA ; All pins on porta are output
      movlw b'00000000'
      movwf TRISB
      banksel PORTA




      loop:

      btfsc PORTB,6
      goto alternate1
      btfsc PORTB,7
      goto alternate
      BSF PORTA,1 ;
      MOVLW d'249' ; set delay of approx 1.5ms
      CALL Delay_1x ;
      BCF PORTA,1 ; Turn them off, no more pulse
      MOVLW d'18' ; set delay of approx 18ms
      CALL Delay_10x ;
      GOTO loop ; Start over
      alternate:
      BSF PORTA,1 ;
      MOVLW d'1' ; set delay of approx 1.5ms
      CALL Delay_10x ;
      BCF PORTA,1 ; Turn them off, no more pulse
      MOVLW d'18' ; set delay of approx 18ms
      CALL Delay_10x ;
      btfsc PORTB,7
      goto alternate
      GOTO loop ; Start over
      alternate1:
      BSF PORTA,1 ;
      MOVLW d'2' ; set delay of approx 1.5ms
      CALL Delay_10x ;
      BCF PORTA,1 ; Turn them off, no more pulse
      MOVLW d'18' ; set delay of approx 18ms
      CALL Delay_10x ;
      btfsc PORTB,6
      goto alternate1
      GOTO loop ; Start over



      ;Setup up the delay routines that may be used
      ;delay of 1ms for 4mHz clock
      ;

      Delay_1ms
      Movlw D'166'
      Delay_1x ;call here with W set allows diiferent delays
      Movwf Delay
      delay_loop
      Nop
      Nop
      Nop
      Decfsz Delay,f
      goto delay_loop
      return




      ;delay of 10ms for 4mHz clock
      Delay_10ms
      movlw d'10'
      Delay_10x ;call here with W set allows diiferent delays

      movwf Delay2
      Delay_Loop_10ms
      Call Delay_1ms ; Call 1ms delay
      Decfsz Delay2,f
      goto Delay_Loop_10ms
      return





      end
    Your message has been successfully submitted and would be delivered to recipients shortly.