CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Translating ASM code to CCS code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MarkJ
Guest







Translating ASM code to CCS code
PostPosted: Fri Mar 14, 2008 11:27 am     Reply with quote

Hi.

I am using the the asm code and hardware found on this site:

*www.hobby-elec.org/e_step.htm

The hardware is the same ( homemade ) but when i compile the ASM code i get bunch of errors. I have no programming experience with ASM so if someone could be so kind and translate this code into CCS C.


Code:

;********************************************************
;
;               Stepper Motor controller
;
;                                 Author : Seiichi Inoue
;********************************************************

        list            p=pic16f84a
        include         p16f84a.inc
        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
        errorlevel      -302    ;Eliminate bank warning

;****************  Label Definition  ********************
        cblock  h'0c'
mode                            ;Operation mode
                                ;0=stop 1=right 2=left
count1                          ;Wait counter
count2                          ;Wait counter(for 1msec)
        endc

rb0     equ     0               ;RB0 of PORTB
rb1     equ     1               ;RB1 of PORTB
rb2     equ     2               ;RB2 of PORTB
rb5     equ     5               ;RB5 of PORTB
rb7     equ     7               ;RB7 of PORTB

;****************  Program Start  ***********************
        org     0               ;Reset Vector
        goto    init
        org     4               ;Interrupt Vector
        clrf    intcon          ;Clear Interruption reg

;****************  Initial Process  *********************
init
        bsf     status,rp0      ;Change to Bank1
        clrf    trisa           ;Set PORTA all OUT
        movlw   b'00100111'     ;RB0,1,2.5=IN RB7=OUT
        movwf   trisb           ;Set PORTB
        movlw   b'10000000'     ;RBPU=1 Pull up not use
        movwf   option_reg      ;Set OPTION_REG
        bcf     status,rp0      ;Change to Bank0
        clrf    mode            ;Set mode = stop
        clrf    count1          ;Clear counter
        clrf    count2          ;Clear counter
        movlw   b'00000101'     ;Set PORTA initial value
        movwf   porta           ;Write PORTA
        bsf     portb,rb7       ;Set RB7 = 1
        btfsc   portb,rb5       ;RB5 = 0 ?
        goto    $-1             ;No. Wait

start
;*************  Check switch condition  *****************
        btfsc   portb,rb1       ;RB1(stop key) = ON ?
        goto    check1          ;No. Next
        clrf    mode            ;Yes. Set stop mode
        goto    drive           ;No. Jump to motor drive
check1
        btfsc   portb,rb2       ;RB2(right key) = ON ?
        goto    check2          ;No. Next
        movlw   d'1'            ;Yes. Set right mode
        movwf   mode            ;Save mode
        goto    drive           ;No. Jump to motor drive
check2
        btfsc   portb,rb0       ;RB0(left key) = ON ?
        goto    drive           ;No. Jump to motor drive
        movlw   d'2'            ;Yes. Set left mode
        movwf   mode            ;Save mode

;********************  Motor drive  *********************
drive
        movf    mode,w          ;Read mode
        bz      start           ;mode = stop
        bsf     portb,rb7       ;Set RB7 = 1
        btfsc   portb,rb5       ;RB5 = 0 ?
        goto    $-1             ;No. Wait
        movlw   d'5'            ;Set loop count(5msec)
        movwf   count1          ;Save loop count
loop    call    timer           ;Wait 1msec
        decfsz  count1,f        ;count - 1 = 0 ?
        goto    loop            ;No. Continue
        bcf     portb,rb7       ;Set RB7 = 0
        btfss   portb,rb5       ;RB5 = 1 ?
        goto    $-1             ;No. Wait
        movf    porta,w         ;Read PORTA
        sublw   b'000000101'    ;Check motor position
        bnz     drive2          ;Unmatch
        movf    mode,w          ;Read mode
        sublw   d'1'            ;Right ?
        bz      drive1          ;Yes. Right
        movlw   b'00001001'     ;No. Set Left data
        goto    drive_end       ;Jump to PORTA write
drive1
        movlw   b'00000110'     ;Set Right data
        goto    drive_end       ;Jump to PORTA write
;-------
drive2
        movf    porta,w         ;Read PORTA
        sublw   b'000000110'    ;Check motor position
        bnz     drive4          ;Unmatch
        movf    mode,w          ;Read mode
        sublw   d'1'            ;Right ?
        bz      drive3          ;Yes. Right
        movlw   b'00000101'     ;No. Set Left data
        goto    drive_end       ;Jump to PORTA write
drive3
        movlw   b'00001010'     ;Set Right data
        goto    drive_end       ;Jump to PORTA write
;-------
drive4
        movf    porta,w         ;Read PORTA
        sublw   b'000001010'    ;Check motor position
        bnz     drive6          ;Unmatch
        movf    mode,w          ;Read mode
        sublw   d'1'            ;Right ?
        bz      drive5          ;Yes. Right
        movlw   b'00000110'     ;No. Set Left data
        goto    drive_end       ;Jump to PORTA write
drive5
        movlw   b'00001001'     ;Set Right data
        goto    drive_end       ;Jump to PORTA write
;-------
drive6
        movf    porta,w         ;Read PORTA
        sublw   b'000001001'    ;Check motor position
        bnz     drive8          ;Unmatch
        movf    mode,w          ;Read mode
        sublw   d'1'            ;Right ?
        bz      drive7          ;Yes. Right
        movlw   b'00001010'     ;No. Set Left data
        goto    drive_end       ;Jump to PORTA write
drive7
        movlw   b'00000101'     ;Set Right data
        goto    drive_end       ;Jump to PORTA write
;-------
drive8
        movlw   b'00000101'     ;Compulsion setting

drive_end
        movwf   porta           ;Write PORTA
        goto    start           ;Jump to start

;*************  1msec Timer Subroutine  *****************
timer
        movlw   d'200'          ;Set loop count
        movwf   count2          ;Save loop count
tmlp    nop                     ;Time adjust
        nop                     ;Time adjust
        decfsz  count2,f        ;count - 1 = 0 ?
        goto    tmlp            ;No. Continue
        return                  ;Yes. Count end

;********************************************************
;             END of Stepper Motor controller
;********************************************************

        end



ASM ERRORS:
Symbol not previously defined (_hs_osc)
Symbol not previously defined (_wdt_off)
Symbol not previously defined (_pwrte_on)
Symbol not previously defined (_cp_off)
Symbol not previously defined (intcon)
Symbol not previously defined (status)
Symbol not previously defined (rp0)
Symbol not previously defined (trisa)
Symbol not previously defined (trisb)
Symbol not previously defined (option_reg)
Symbol not previously defined (status)
Symbol not previously defined (rp0)
Symbol not previously defined (porta)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (portb)
Symbol not previously defined (porta)
Symbol not previously defined (porta)
Symbol not previously defined (porta)
Symbol not previously defined (porta)
Symbol not previously defined (porta)
Halting build on first failure as requested.
Trent___



Joined: 20 Jun 2007
Posts: 11
Location: London, UK

View user's profile Send private message MSN Messenger

PostPosted: Fri Mar 14, 2008 12:00 pm     Reply with quote

I would love to but.........

Its not a five min job.

Might be best to stay with the ASM.

The errors you are getting are due to missing definitions.

What compiler are you using, and what file came from the site?

My guess is your missing the header file for the processor you are using.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 12:05 pm     Reply with quote

If you need help with assembling an ASM file, please ask your questions
on the Microchip forum. That's the best forum for ASM programming:
http://forum.microchip.com/tt.aspx?forumid=11

If you want to program in C, it's better if you look at the CCS example
program for a stepper motor. It's in this directory:
Quote:
c:\program files\picc\examples\ex_step.c


Last edited by PCM programmer on Fri Mar 14, 2008 12:19 pm; edited 1 time in total
Guest2
Guest







PostPosted: Fri Mar 14, 2008 12:18 pm     Reply with quote

Am using MPASM and the source with list and hex file can be found at:

*www.hobby-elec.org/e_step7.htm

By the way, how to use the hex file in MPLAB ?

I will try to find the missing file, if that's the main problem but i dont want to send this to microchip cuz they will give me solution based on microchip C17,18 or 30 toolsuite. Then i would be again on the beginning Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 12:20 pm     Reply with quote

While you were making your last post, I was editing my post to show you
the CCS example file, Ex_Step.c. Please look at my post again.
MarkJ
Guest







PostPosted: Fri Mar 14, 2008 12:34 pm     Reply with quote

OK. I will take a look.

Do you know how to use the HEX file in MPLAB.
Am asking this so i can try the original code.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 12:54 pm     Reply with quote

Quote:
Do you know how to use the HEX file in MPLAB.

See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=34037&start=1
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group