0

I have a PIC16F628A, and I have 2 motors coonnected to pins of that PIC. Pins RB0 and RB1 are connected to right motor. Pins RB2 and RB3 are connected to left motor. I'm using MPLAB as compiler from .pbp to .hex. I want to write a PIC BASIC program (.pbp) that will move one of these motors( for ex: left one) ... I have just written a simple code segment like this.

TRISB= %11110000

PORTB.2=0 
PORTB.3=0

MAINLOOP:

PORTB.2=1 
PAUSE 50 
PORTB.3=1 
PAUSE 50

GOTO MAINLOOP

END

Compiler compiles it correctly, after I burn the hex file successfully, I place the pig, then I start it, I see nothing...! I'm really so amateur in this programming language, I just want to ask that do I need to write any other code segment to run my motors? Or is there anybody who had such kind of project before?

4

1 Answer 1

1
list p=16F628A
    include <P16F628A.INC>

    cblock 0x20
        COUNT1
        COUNT2
    endc

    org 0x00

init    movlw .50
        movwf COUNT1
        movwf COUNT2
        ;;;SET PWM FREQUENCY;;;
        bank1         ;SELECT BANK 01
        movlw D'128'  ;SET PR2 TO 128 DECIMAL SO THE PWM PERIOD = 2064uS => PWM FREQUENCY = 484Hz
        movwf PR2
        bank0         ;SELECT BANK 00
        clrf CCPR1L   ;SET PWM STARTING DUTY CYCLE;;;
        comf CCPR1L
        movlw B'00001100' ;SET PWM MODE, BITS 5 AND 4 ARE THE TWO LSBs OF THE 10BIT DUTY CYCLE REGISTER (CCPR1L:CCP1CON<5:4>)
        movwf CCP1CON     ;SET PWM PIN TO OUTPUT MODE;;;
        bank1             ;SELECT BANK 01
        bcf TRISB, 3      ;SET RB3 AS OUTPUT, TO USE FOR PWM
        bank0             ;SELECT BANK 00
        movlw B'00000010' ;SET TIMER 2 PRESCALE VALUE;;;PRESCALE = 16 SO THE PWM PERIOD = 2064uS => PWM FREQUENCY = 484Hz
        movwf T2CON
        clrf TMR2         ;CLEAR TIMER 2 MODULE;;;
        bsf T2CON, TMR2ON ;ENABLE TIMER 2 MODULE;;;

main    call DELAY
        goto main


DELAY
loop1       decfsz COUNT1,1
            goto loop1
            decfsz COUNT2,1
            goto loop1
            return
            end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.