How to convert this 6502 to PIC?

A

Allen Bong

Guest
Hi,

I have written a small 6502 program to buzz the piezo with morse code
message. I wish to make it onto a small PCB with a 12F629 mounted.
It will finally be fitted onto the back of my bicycle. While
translating the 6502 to PIC asm, I was stuck on the beginning
of the program. I know it's a piece of cake to the PIC expert here.
The code is as follows:

ORG $800

;using LISA 2.5 by Randy Hyde

JMP main
MESSAGE STR 'APPLE 2 FOREVER'

;str will generate the message in normal ASC with the number of
;characters as the first byte

MAIN LDX #1 ;POINT TO FIRST ASC
MESSLOOP:
LDA MESSAGE,X
CMP $32
BNE CONV
SPACE JSR INT_WORD_DLY ;DELAY 6 DOT ELEMENTS ~500MS
CLC
BCC SPACE_OK
CONV JSR CONVERT ;CONVERT ALPHA-NUMERIC TO INDEX
SPACE_OK:
INX
CPX #MESSAGE+1 ;END OF MESSAGE?
BCC MESSLOOP
RTS


How does the PIC get the address of the Message ? Do I need to use
FSR and INDF ? Can the message be stored in the program area or
should I bring it up the the eeprom area?


TIA,

Allen
 
On Wed, 24 Nov 2010 14:30:07 -0800, Allen Bong wrote:

How does the PIC get the address of the Message ? Do I need to use FSR
and INDF ?
Those are the only means of performing indirect addressing of RAM.

Can the message be stored in the program area
Yes. You need to store each byte as a RETLW instruction, and read the data
using a subroutine which ends with an indirect jump (MOVWF PCL) to the
appropriate instruction.
 
On Wed, 24 Nov 2010, Allen Bong wrote:

Hi,

I have written a small 6502 program to buzz the piezo with morse code
message. I wish to make it onto a small PCB with a 12F629 mounted.
It will finally be fitted onto the back of my bicycle. While
translating the 6502 to PIC asm, I was stuck on the beginning
of the program. I know it's a piece of cake to the PIC expert here.
The code is as follows:

ORG $800

;using LISA 2.5 by Randy Hyde

JMP main
MESSAGE STR 'APPLE 2 FOREVER'

;str will generate the message in normal ASC with the number of
;characters as the first byte

MAIN LDX #1 ;POINT TO FIRST ASC
MESSLOOP:
LDA MESSAGE,X
CMP $32
BNE CONV
SPACE JSR INT_WORD_DLY ;DELAY 6 DOT ELEMENTS ~500MS
CLC
BCC SPACE_OK
CONV JSR CONVERT ;CONVERT ALPHA-NUMERIC TO INDEX
SPACE_OK:
INX
CPX #MESSAGE+1 ;END OF MESSAGE?
BCC MESSLOOP
RTS


How does the PIC get the address of the Message ? Do I need to use
FSR and INDF ? Can the message be stored in the program area or
should I bring it up the the eeprom area?

I think you may be misinterpreting the 6502 code.

MESSAGE STR 'APPLE 2 FOREVER'

"MESSAGE" becomes a value that is the location of the text string

MAIN LDX #1 ;POINT TO FIRST ASC
no, it's a counter into the string
the 6502 only has two 8-bit counters, no 16-bit
So the X register becomes a pointer into the text
string. Since the first byte of the text string
is the length of the string, the X register is set
to "1", the actual offset from "MESSAGE" where the
first character is.

MESSLOOP:
LDA MESSAGE,X
"MESSAGE" points to the location of the string. Hence
the absolute value of the location of the string is the
value that follows the opcode. But the address mode
used (and the opcode will reflect that) uses that absolute
value and adds the value in the X register

So on the first iteration, LDA MESSAGE,X points to MESSAGE+1
(since the X register started with "1" in it) and thus the
first actual character in the string is loaded into the accumulator

Then it's processed and the loop comes back with the value in the
X register incremented by one, and thus ready to retrieve the next
character in the text string, and so on.

It's very simple, how to convert it depends on what's available on
the PIC. Where to put the text message may be a reflection of PIC
standards, or maybe just habit. Some other coder would have put
the text message in the above code after the code, or lumped it
altogether in some segment later on, it's coder's habit than
rigid rules.

Likewise, it's the coder's preference to have
the number of characters in the text message first and then
the text string. There may be advantages, or maybe not, but
there are other ways of doing it, some of which may depend
on what the CPU offers. For instance, another coder (or maybe
on a different CPU) the string's end would be determined by
the last character having the high bit set, and the code
would check for that. Somewhere else, the text message might
be in memory in reverse order, the looping made easier. A
general purpose routine would need to pick up the length of
the string, or the end of the string, while someone else
might code something specific to that string, so they could
hardcode the length of the string. A CPU with more registers,
or different combination of registers, could do the coding
a different way.

Michael
 
On Nov 25, 12:07 pm, Nobody <nob...@nowhere.com> wrote:
On Wed, 24 Nov 2010 14:30:07 -0800, Allen Bong wrote:
How does the PIC get the address of the Message ?  Do I need to use FSR
and INDF ?

Those are the only means of performing indirect addressing of RAM.

Can the message be stored in the program area

Yes. You need to store each byte as a RETLW instruction, and read the data
using a subroutine which ends with an indirect jump (MOVWF PCL) to the
appropriate instruction.
Thanks Nobody,

I shall follow your hints and try my best shot to translate it to
PIC. Only if I fail, you would see me again here :)

Allen
 
On Nov 25, 1:33 pm, Michael Black <et...@ncf.ca> wrote:
On Wed, 24 Nov 2010, Allen Bong wrote:
Hi,

I have written a small 6502 program to buzz the piezo with morse code
message.  I wish to make it onto a small PCB with a 12F629 mounted.
It will finally be fitted onto the back of my bicycle.  While
translating the 6502 to PIC asm,  I was stuck on the beginning
of the program.  I know it's a piece of cake to the PIC expert here.
The code is as follows:

  ORG $800

;using LISA 2.5 by Randy Hyde

  JMP main
MESSAGE STR 'APPLE 2 FOREVER'

;str will generate the message in normal ASC with the number of
;characters as the first byte

MAIN  LDX #1     ;POINT TO FIRST ASC
MESSLOOP:
     LDA MESSAGE,X
     CMP $32
     BNE CONV
SPACE JSR INT_WORD_DLY   ;DELAY 6 DOT ELEMENTS ~500MS
     CLC
     BCC SPACE_OK
CONV  JSR CONVERT        ;CONVERT ALPHA-NUMERIC TO INDEX
SPACE_OK:
     INX
     CPX #MESSAGE+1     ;END OF MESSAGE?
     BCC MESSLOOP
     RTS

How does the PIC get the address of the Message ?  Do I need to use
FSR and INDF ?  Can the message be stored in the program area or
should I bring it up the the eeprom area?

I think you may be misinterpreting the 6502 code.

MESSAGE STR 'APPLE 2 FOREVER'

"MESSAGE" becomes a value that is the location of the text string

MAIN  LDX #1     ;POINT TO FIRST ASC

     no, it's a counter into the string
     the 6502 only has two 8-bit counters, no 16-bit
     So the X register becomes a pointer into the text
     string.  Since the first byte of the text string
     is the length of the string, the X register is set
     to "1", the actual offset from "MESSAGE" where the
     first character is.

MESSLOOP:
     LDA MESSAGE,X

   "MESSAGE" points to the location of the string.  Hence
    the absolute value of the location of the string is the
    value that follows the opcode.  But the address mode
    used (and the opcode will reflect that) uses that absolute
    value and adds the value in the X register

So on the first iteration, LDA MESSAGE,X points to MESSAGE+1
(since the X register started with "1" in it) and thus the
first actual character in the string is loaded into the accumulator

Then it's processed and the loop comes back with the value in the
X register incremented by one, and thus ready to retrieve the next
character in the text string, and so on.

It's very simple, how to convert it depends on what's available on
the PIC.  Where to put the text message may be a reflection of PIC
standards, or maybe just habit.  Some other coder would have put
the text message in the above code after the code, or lumped it
altogether in some segment later on, it's coder's habit than
rigid rules.

Likewise, it's the coder's preference to have
the number of characters in the text message first and then
the text string. There may be advantages, or maybe not, but
there are other ways of doing it, some of which may depend
on what the CPU offers.  For instance, another coder (or maybe
on a different CPU) the string's end would be determined by
the last character having the high bit set, and the code
would check for that.  Somewhere else, the text message might
be in memory in reverse order, the looping made easier.  A
general purpose routine would need to pick up the length of
the string, or the end of the string, while  someone else
might code something specific to that string, so they could
hardcode the length of the string.  A CPU with more registers,
or different combination of registers, could do the coding
a different way.

    Michael- Hide quoted text -

- Show quoted text -
Yes your're right Micheal about the logic of my 6502 program, I have
corrected my 6502 program as the first time I was using "ASC" instead
of "STR" and it worked fine. The corrected one is as follows:


ORG $800
;using LISA 2.5 by Randy Hyde
JMP main
MESSAGE STR 'APPLE 2 FOREVER'

;str will generate the message in normal ASC with the lengthr of
message as the first byte

MAIN LDX #0
MESSLOOP:
LDA MESSAGE+1,X ;Get First Character
CMP #32 ;Is it SPACE?
BNE CONV
SPACE JSR INT_WORD_DLY ;DELAY 6 DOT ELEMENTS ~500MS
CLC
BCC SPACE_OK
CONV JSR CONVERT ;CONVERT ALPHA-NUMERIC TO INDEX
SPACE_OK:
INX
CPX MESSAGE ;END OF MESSAGE?
BCC MESSLOOP
RTS

I have actually completed the 6502 program running on an apple 2
emulator. It did work and gererating Morse Code on the PC speaker at
10 WPM. I am just stuck on how to translate the instruction:

"LDA MESSAGE,X" with "MESSAGE" stored at the end of program to PIC
Codes. I have no problem with the rest of the PIC program. I have
hard coded the message "SOS" with ...---... using the PIC and it
worked. It was when I wanted to make the program more flexible when I
got stuck.

Allen
PIC Newbie
 

Welcome to EDABoard.com

Sponsor

Back
Top