• AVR Freaks

Hot!Is PAGESEL the same as movlp HIGH?

Page: < 12 Showing page 2 of 2
Author
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 16:07:52 (permalink)
0
Nice tips, ric!
 
ric
Small instruction saver. Change the last CALL to a GOTO and drop the RETURN
uart_crlf
  movlw 13
  pagesel uart_char
  call uart_char
  movlw 10
  pagesel uart_char
  call uart_char
  return

To save another instruction, make sure "uart_char" follows this function in memory (which in your code, it does),
and just fall into the uart_char code, losing the PAGESEL and the GOTO.

 
Is this because it then relies on the RETURN instruction in uart_char?
#21
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 16:13:45 (permalink)
0
Actually, all the PAGESEL in "uart_crlf" can be removed, because the only way you get there is the page (PCLATH) is already correctly selected. That is, this
  org 0x1E00
uart_crlf
  movlw 13
  pagesel uart_char
  call uart_char
  movlw 10
  pagesel uart_char
  call uart_char
  return
 
uart_char
  movlb 0
  btfss PIR1, 4
  goto $-1
  movlb 3
  movwf TXREG
  return
 

can be replaced with this
        org     0x1E00
uart_crlf
        movlw   '\r'
        call    uart_char
        movlw   '\n'
uart_char
        banksel PIR1
        btfss   PIR1,TXIF
        goto    $-1
        banksel TXREG
        movwf   TXREG
        return

 
#22
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 16:14:49 (permalink)
0
upand_at_them
Is this because it then relies on the RETURN instruction in uart_char?

Yes.
#23
ric
Super Member
  • Total Posts : 28004
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 16:15:05 (permalink)
5 (1)
upand_at_them
Is this because it then relies on the RETURN instruction in uart_char?

Yes.
We used to do the same thing in Z80 code over 35 years ago, and it's still just as applicable now.
(And as I recall, it was often to put a "print_crlf" function immediately before a "character_ouput" function back then too. ;)
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#24
NorthGuy
Super Member
  • Total Posts : 6228
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/04/26 07:13:05 (permalink)
5 (1)
ric
We used to do the same thing in Z80 code over 35 years ago, and it's still just as applicable now.



Now they gave a scientific name to this - tail call optimization.
#25
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/21 19:07:41 (permalink)
0
ric 
For the string handling, use one of the FSR#/INDF# pairs as a string pointer.
This has several immediate benefits.
  • The string doesn't have to be in the same page as the output function, it can be anywhere in memory.
  • The hardware manages incrementing the 16 bit pointer for you.
  • Fetching each character is a single instruction.
  • The zero flag is set appropriately straight after fetching each character.



I was thinking about this again.  I like the idea of using FSR for iterating the string.  But doesn't that turn every "print string" function call into five instructions?
 
movlw LOW(string1)
movwf FSR0L
movlw HIGH(string1)
movwf FSR0H
call print_string

#26
ric
Super Member
  • Total Posts : 28004
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/21 19:20:59 (permalink)
0
upand_at_them
I was thinking about this again.  I like the idea of using FSR for iterating the string.  But doesn't that turn every "print string" function call into five instructions?

Yes, if you want to be able to place them anywhere.
If you put them all inside a single 256 word page, you could embed the
movwf FSR0L
movlw HIGH(string1)
movwf FSR0H

part inside the print_string function, and just pass the offset in W.
 
Alternatively you could pass a string # in W, and interate through the strings like your old code until you get to the nth one.


Or, you could have a lookup table with the offset of each string, and just fetch the string address first from the table, then fall into a "print from this address" function.
There's lots of ways to skin this cat! ;)
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#27
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 04:53:17 (permalink)
0
ric
upand_at_themI like the idea of using FSR for iterating the string.

If you put them all inside a single 256 word page, you could embed the
movwf FSR0L
movlw HIGH(string1)
movwf FSR0H

part inside the print_string function, and just pass the offset in W.
 



This worked.  After I realized I was already using that FSR for something else.  There really needs to be four FSRs!
#28
NorthGuy
Super Member
  • Total Posts : 6228
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 05:41:33 (permalink)
0
upand_at_them
This worked.  After I realized I was already using that FSR for something else.  There really needs to be four FSRs!



I think so too. There are 3 in PIC18s, 16 in PIC24s, and 31 in PIC32s.
#29
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 05:54:17 (permalink)
0
NorthGuy
upand_at_them
This worked.  After I realized I was already using that FSR for something else.  There really needs to be four FSRs!



I think so too. There are 3 in PIC18s, 16 in PIC24s, and 31 in PIC32s.




Wow!
#30
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 06:50:46 (permalink)
0
Something I just realized, in the string routine.  The "getstringaddress" jump isn't even necessary, I can just put that value into W instead of looking it up.
 
 
#define Typestr string0-string0
#define MMCstr string7-string0
#define SD1str string8-string0
#define SD2str string9-string0
#define SDHCstr string10-string0


print_card_info
 movlw Typestr
 call SSD1306_String
 btfsc cardTypeMMC
 movlw MMCstr
 btfsc cardTypeSD1
 movlw SD1str
 btfsc cardTypeSD2
 movlw SD2str
 btfsc cardTypeSDHC
 movlw SDHCstr
 call SSD1306_String


SSD1306_String
 movwf stringIndex
ssd1306string1
 movf stringIndex, w
 call getstringchar
 addlw 0
 btfsc STATUS, Z
 return
 call SSD1306_Char ; defined elsewhere
 incf stringIndex, F
 goto ssd1306string1
         
getstringchar
 brw
string0: dt "Type \0"
string1: dt "Boot \0"
string2: dt "FAT \0"
string3: dt "FAT2 \0"
string4: dt "R\\D \0"
string5: dt "Data \0"
string6: dt "Sectors\\Cluster \0"
string7: dt "MMC\0"
string8: dt "SD1\0"
string9: dt "SD2\0"
string10: dt "SDHC\0"

#31
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 08:57:26 (permalink)
0
upand_at_them
After I realized I was already using that FSR for something else.  There really needs to be four FSRs!

Years ago, a member in this forum debated with me that there's/he's no need for more than one FSR. Haha! 
 
#32
upand_at_them
Super Member
  • Total Posts : 584
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 13:11:11 (permalink)
5 (1)
1and0Years ago, a member in this forum debated with me that there's/he's no need for more than one FSR. Haha!

 
That wasn't Bill Gates, was it? :)
 
#33
1and0
Access is Denied
  • Total Posts : 10999
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Is PAGESEL the same as movlp HIGH? 2020/05/22 16:16:14 (permalink)
5 (1)
upand_at_them
1and0Years ago, a member in this forum debated with me that there's/he's no need for more than one FSR. Haha!

That wasn't Bill Gates, was it? :)

No, it was a fiddle, relative of cello. :)  Too bad I cannot find that thread now. ;)
 
#34
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5