Shop OBEX P1 Docs P2 Docs Learn Events
Assembly question — Parallax Forums

Assembly question

MazziniMazzini Posts: 58
edited 2011-08-20 16:40 in Propeller 1
Good Day ,

Do you know why this code works ( blink Led P23 on Quickstart Board)
CON 
  _clkmode = xtal1 + pll16x 
  _xinfreq = 5_000_000 
 
 
PUB Main 
{Launch cog to toggle P16 endlessly} 
 
  cognew(@Toggle, 0)                       'Launch new cog 
 
   
DAT 
{Toggle P16} 
                   org     0               'Begin at Cog RAM addr 0 
Toggle             mov     dira, port      'Set Pin to output 
                   mov     Time, cnt       'Calculate delay time 
                   add     Time, #9        'Set minimum delay here 
:loop              waitcnt Time, Delay     'Wait 
                   xor     outa, Pin23       'Toggle Pin 
                   jmp     #:loop          'Loop endlessly 
 
Pin16     long       |< 16                   'Pin number
Pin23     long       |< 23                   'Pin number

Port    long       $FFFFFFFF
Delay   long       6_000_000               'Clock cycles to delay 
Time               res  1 

and this doesnt ( blink the Led P19(!) on Quickstart Board)
CON 
  _clkmode = xtal1 + pll16x 
  _xinfreq = 5_000_000 
 
 
PUB Main 
{Launch cog to toggle P16 endlessly} 
 
  cognew(@Toggle, 0)                       'Launch new cog 
 

DAT

Toggle                        org     0

 
                        mov dira,port         

                       rdlong  delay, #0
                        mov     t1, cnt    ' setup
                        add     t1, delay  ' first add

:loop                   waitcnt t1, delay  'all subsequent adds use the waitcnt                 
                        xor outa,Pin23            
                                                
                        jmp #:loop
  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'delay @80MHz
delay                   long    80_000_000 
delay18ms               long    1_440_000
delay200us              long    16_000  

t1                      res 1
cmd                     byte
data                    byte

RS                      long    |< 16
RW                      long    |< 17
EN                      long    |< 18

DB4                      long    |< 19
DB5                      long    |< 20
DB6                      long    |< 21
DB7                      long    |< 22
Pin23                    long    |< 23
port                     long    $FFFFFFFF

Thanks

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2011-08-19 15:31
    Did you wait long enough? You read a long from HUB-RAM address $0 and store the result in delay (with the rdlong instruction). In $0 you find a pretty high number.

    Make the rdlong a comment and your program should toggle with 0,5Hz.

    By the way ... with your
    mov dira,port

    you switch all pins to output-mode. That's a bad idea! You should only switch the pins which are really used as output. Otherwise you can accidently produce shortcuts. For example the PropPlug of course uses one PIN for transmitting data to the propeller. You are lucky that the propeller plug has a protecting resistor which limits the currency.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-08-19 15:41
    One important thing might be that reserves (RES) must be at the end of all declarations for it to always work as you may expect. You have it before byte and long declarations at the end.

    Another note is that you get the entire set of pins (all 32) as an output with the "mov dira,port" instruction (with port having all bits set to 1 -- as you have it).
    EDIT: I see MagIO2 added this on to his post.
  • MazziniMazzini Posts: 58
    edited 2011-08-19 16:08
    yes move dira,port like all out is a bad idea and I changed "res"'s position and it works Thank :)
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-08-19 16:27
    Probably what you should be doing for the DIRA register control is something like this:
    [FONT=monospace]port                     long    RS | RW | EN | DB4 | DB5 | DB6 | DB7 | Pin23[/FONT]
    
  • MazziniMazzini Posts: 58
    edited 2011-08-20 16:40
    Good to know , Thanks
Sign In or Register to comment.