pls help me !!

Discussion in 'Programmer's Corner' started by cheerzmiki, Aug 9, 2006.

  1. cheerzmiki

    Thread Starter New Member

    Aug 9, 2006
    2
    0
    hi guys ,i am a newbie in asm language. I recently wrote a asm coding to run my 2 small dc motors through using PWM connected to my motor driver h bridge . But i had encountered some bugs when i run the program. The motor started to run before i press any button to start the motor and the buttons do not seems to respond well as at times they will only stop after a few presses , if not will keep running until i press the button again.I am trying it out on MPLAB ICD2. if some one know about this please let me know the reason. A million thanks .

    coding :


    list p=18f452
    #include p18f452.inc

    ;STARTUP CODE
    ;************************************************************
    ; declare variables here


    sec equ 0x0000
    sec2 equ 0x0001
    Count2 equ 0x000
    Count1 equ 0x001

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

    STARTUP CODE
    org 00000h ; Reset Vector
    goto start

    PROG1 CODE

    ;************************************************************
    ;program code starts here

    start

    ;***********initialisation*****************

    clrf PORTC ;initialise PORTC as output port and clear the port.
    movlw b'00000000'
    movwf TRISC

    setf TRISA ;init PORTA as input

    clrf PORTB ;initialise PORTB as input port.
    movlw b'11111111' ;initialise PORTB as input port.
    movwf TRISB ;initialise PORTB as input port.

    ;***********main body*************

    clrf T2CON
    bcf T2CON,TMR2ON
    setf PR2 ;PR2=oxFF
    movlw 0x7F
    movwf CCPR1L

    clrf CCP1CON
    bsf CCP1CON,CCP1M3
    bsf CCP1CON,CCP1M2
    bsf CCP1CON,CCP1M0 ;set CCP1 PWM mode

    movlw 0x7F
    movwf CCPR2L

    clrf CCP2CON
    bsf CCP2CON,CCP2M3
    bsf CCP2CON,CCP2M2
    bsf CCP2CON,CCP2M1
    bsf CCP2CON,CCP2M0 ;set CCP2 PWM mode

    checkSW
    btfsc PORTB,0 ;check for sw.it's normally low , high when pressed
    goto checkSW ;check for sw2 if sw is not pressed.
    bsf T2CON,TMR2ON
    movlw 0x7F
    movwf CCPR1L
    bsf PORTA,0 ;set forward direction
    movlw 0x7F
    movwf CCPR2L
    bsf PORTA,1 ;set forward direction

    call Delay

    wait4SW_release
    btfss PORTB,0 ;check if sw is still being pressed.
    goto wait4SW_release ;if sw is being pressed, check again

    bcf T2CON,TMR2ON

    call Delay

    goto checkSW



    ;*******************delay*******************

    Delay
    movlw 0xFF
    movwf Count1
    movwf Count2
    Repeat
    decfsz Count1,F
    goto Repeat
    movlw 0x01
    movwf Count1
    decfsz Count2,F
    goto Repeat
    return



    end
     
  2. BladeSabre

    Senior Member

    Aug 11, 2005
    105
    0
    If I understand right, your code acts on button-down, then continues on the next button-up. The unresponsive button would probably be improved by debouncing. I recently came across a good explanation and examples while working through the Pickit 2 User Guide and Lessons, found on Microchip's web site ( http://microchip.com/pickit2 ). That code would need to be converted to the 18F452 of course.

    EDIT: Sorry, I meant the Low Pin Count Demo Board's user guide (same page)...
     
Loading...