Shop OBEX P1 Docs P2 Docs Learn Events
Basic assembly question — Parallax Forums

Basic assembly question

Basic JimBasic Jim Posts: 106
edited 2006-08-23 17:59 in General Discussion
Hi,


I am finally trying to tackle the strange world of assembly language. What I find odd is that it doesn't seem to behave the same in the regular run mode vs. the debug mode. For example, if you run the following program in debug mode three of the LED’s will light as they should (I think) But, if you assemble it in regular run mode it never turns any lights on. I can't see why it doesn't. I have also run into several tutorial examples that behave this way as well. I'm sure I’m missing something obvious here. But I don't know what it is.· smhair.gif

Thanks,
Jim W.

; Traffic Lights
;
LIST Q = 37
DEVICE· SX28L, TURBO, STACKX, OSCHS2
IRC_CAL IRC_FAST
FREQ··· 4_000_000
RESET·· 0
· Mov·· !rb, #%00000000··; Setup RB as outputs
· Mov ·!RA, #%1111 ··; Setup ra as input from switches
; Make a variable that is tied to the Configuration switches
;
; Setup Initial conditions
clrb·· rb.0 ·; 1 Red
clrb·· rb.1·; 1 Yellow
clrb·· rb.2·; 1 Green
setb·· rb.3·; 2 red
setb·· rb.4·; 2 Yellow
setb·· rb.5·; 2 Green
sleep

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2006-08-23 15:27
    You do not have a pause coded in between when you turn the LED on and off, so it occurs so fast that you can not see it happen. In the debug session, as you single step through the program you can see the LED being turned on and off. If you have Guenthers book, he has some examples as to providing a pause so you can see the LED being turned on and off.

    Ray
  • BeanBean Posts: 8,129
    edited 2006-08-23 15:29
    Jim,
    It seems to work for me from within the IDE.

    What do you mean by "if you assemble it in regular run mode it never turns any lights on"
    What exactly are you doing, that it doesn't work ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • Basic JimBasic Jim Posts: 106
    edited 2006-08-23 15:40
    Bean,
    If I push the program button it programs the chip but the lights never come on. but when I single step using debug the lights turn on as they should and they stay on as they should.

    Ray,
    All I'm trying to do here is to light the LED's by using clrb or setb if the program is exectuted once then I should have three lights on and three lights off. There shouldn't be any need for for delay loops. The light is set or reset and thats all.
  • BeanBean Posts: 8,129
    edited 2006-08-23 16:22
    Jim,
    You need to hit the RUN button (red circle w/arrow).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • Basic JimBasic Jim Posts: 106
    edited 2006-08-23 16:35
    OK that works! When I write in SX/B I don't recall having to do that. But, Doing that seems to only run with the SX key pluged in. If I hit run shut the board down, remove the sx key it doesn't start on power up or reset. How do I run it as a stand alone. I take it there is some code to do that?

    Thanks again,
    Jim W.
  • RsadeikaRsadeika Posts: 3,837
    edited 2006-08-23 16:41
    In order to have it run in stand alone, you have to program the chip. So, hit the Program selection in the menu, and that should do it.

    Ray
  • Basic JimBasic Jim Posts: 106
    edited 2006-08-23 17:00
    Hi Ray,

    I might have something different going on here. Isn't hitting the program chip button along the top of the screen the same thing as hitting the program selection in the nemu. They both have cntrl/p as a short cut. I tried it the way you said but it still isn't working. If I hit the run button it works but using the program button and powering down, then removing the SX-Key all the lights stay off. I think there is something funny about my code or I'm missing something. I know it seems to work ok with SX/b code.

    Thanks,
    Jim W.
  • RsadeikaRsadeika Posts: 3,837
    edited 2006-08-23 17:05
    Could you post your SX/B code, that way we will be able to see what you got going.

    Ray
  • Basic JimBasic Jim Posts: 106
    edited 2006-08-23 17:23
    Here is the assembly version that won't work stand alone as expected. I'm just baffled why it only works in debug and when I hit run with the SX-Key but when downloaded to the SX and the key removed it refuses to light the led's.


    ; Traffic Lights
    ;
    LIST Q = 37
    DEVICE SX28L, TURBO, STACKX, OSCHS2
    IRC_CAL IRC_FAST
    FREQ 4_000_000
    RESET 0

    Mov !rb, #%00000000 ; Setup RB as outputs
    Mov !RA, #%1111 ; Setup ra as input from switches

    ; Make a variable that is tied to the Configuration switches
    ; Blinker sub routine
    ; regular lights
    ; Setup Initial conditions
    clrb rb.0 ; 1 Red
    clrb rb.1 ; 1 Yellow
    clrb rb.2 ; 1 Green
    setb rb.3 ; 2 red
    setb rb.4 ; 2 Yellow
    setb rb.5 ; 2 Green
    sleep


    *** This SX b version downloads and works as expected. ***
    ' =========================================================================
    ' File...... Traffic Lights
    ' Purpose... SX/B Programming Template
    ' Author....
    ' E-mail....
    ' Started...
    ' Updated...
    ' =========================================================================
    ' Program Description
    'This program will emulate a traffic light and be able to do what the
    'flagmen do at roadwork sites.
    '
    ' Device Settings
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
    '
    ' IO Pins
    Tim1 VAR RA.0
    Tim2 VAR RA.1
    'Tim45 VAR RA.2
    'Tim60 VAR RA.3
    Red1 VAR RB.0 '; 1 Red
    Yel1 VAR rb.1 '; 1 Yellow
    Grn1 VAR rb.2 '; 1 Green
    Red2 VAR rb.3 '; 2 red
    Yel2 VAR rb.4 '; 2 Yellow
    Grn2 VAR rb.5 '; 2 Green
    '
    ' Constants
    '
    ' Variables
    INTERRUPT
    ISR_Start:
    ISR_Exit:
    RETURNINT ' {cycles}
    ' =========================================================================
    PROGRAM Start
    Pgm_ID:
    DATA "SX/B Template", 0
    '
    ' Subroutines / Jump Table
    SW00 Sub
    SW01 Sub
    SW10 Sub
    SW11 Sub
    Trans Sub

    '
    ' Program Code
    Start:
    TRIS_B = %00000000 ' make RB pins output
    TRIS_a = %1111 ' make Ra pins input
    low red1
    high yel1
    high grn1
    high red2
    high yel2
    low grn2

    Main:
    If tim1 = 0 then
    gosub SW00
    If tim1 = 1 then
    gosub SW01
    If tim2 = 0 then
    gosub SW10
    If tim2 = 1 then
    gosub SW11
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    low red1
    high yel1
    high grn1
    high red2
    Low yel2
    High grn2
    gosub Trans 'transistion from grenn to yellow
    low red1
    high yel1
    high grn1
    high red2
    Low yel2
    High grn2
    ' main code here
    GOTO Main

    SW00:
    pause 1000
    return
    SW01:
    Pause 1000
    Return
    SW10:
    Pause 1000
    Return
    SW11:
    Pause 1000
    Return
    Trans:
    pause 500
    return

    '
    ' Page 1 Code
    Page_1:
    ADDRESS $200
    P1_Start:
    GOTO P1_Start ' error if Pg0 overruns Pg1
    '
    ' Page 2 Code
    Page_2:
    ADDRESS $400
    P2_Start:
    GOTO P2_Start ' error if Pg1 overruns Pg2
    '
    ' Page 3 Code
    Page_3:
    ADDRESS $600
    P3_Start:
    GOTO P3_Start ' error if Pg3 overruns Pg4

    Best,
    Jim W.
  • BeanBean Posts: 8,129
    edited 2006-08-23 17:36
    Jim,
    · In the SX/B version you are using the internal 4MHz oscillator. Is that what you want the assembly version to do also ? If so you need to change your DEVICE line in your assembly program.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • Basic JimBasic Jim Posts: 106
    edited 2006-08-23 17:59
    Thank you, I will try this asap. I'm sure it will work. I can see clearly now!

    Best,
    Jim W.
Sign In or Register to comment.