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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Jonah
  • 11
  • 1
  • 4
  • possible duplicate of [How can I move mototrs connected to PIC16F628A, using PIC BASIC language and MPLAB ?](http://stackoverflow.com/questions/14181961/how-can-i-move-mototrs-connected-to-pic16f628a-using-pic-basic-language-and-mpl) – Oliver Charlesworth Jan 06 '13 at 12:52
  • Please don't post the same question multiple times. – Oliver Charlesworth Jan 06 '13 at 12:52
  • I really need help kavat – Jonah Jan 06 '13 at 13:00
  • It's not possible to tell where your problem is with the information we have. Can you test the voltage on the pins on the port to see if it changes when the PIC is powered on? You might have to disable the comparators (by writing the correct value to `CMCON` - see the [datasheet](http://ww1.microchip.com/downloads/en/devicedoc/40044f.pdf)). – Mathew Hall Jan 09 '13 at 15:52

1 Answers1

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
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51