pls help me !!

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

  1. cheerzmiki

    Thread Starter New Member

    Aug 9, 2006
    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

    ; declare variables here

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


    org 00000h ; Reset Vector
    goto start


    ;program code starts here



    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

    btfsc PORTB,0 ;check for'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

    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


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

  2. BladeSabre

    Senior Member

    Aug 11, 2005
    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 ( ). 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)...