Subroutine problem with PIC18F452

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Re: Subroutine problem with PIC18F452

Postby ric » Sun Jun 29, 2014 2:11 pm

You are answering the general question of what the entire program should do, not the specific question I am asking.
Is this your very first attempt at programming in assembly language?
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby Tom Maier » Sun Jun 29, 2014 3:39 pm

Aside from what Ric is pointing out, the "unpackdata" routine is also a perpetual loop.

You would probably have a more straight-forward implimentation of this if you switched over to the XC8 C compiler. It's free now.

Also, as you write the code, document it with comments about what you are trying to do before you write the code. It is getting tangled. Less time coding, more time planning is needed.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby ric » Sun Jun 29, 2014 10:18 pm

Tom Maier wrote:Aside from what Ric is pointing out, the "unpackdata" routine is also a perpetual loop.
...

Ahhh yes. It is trying to use zero terminated strings, but the strings are using C style escape sequences to include the zero, which I doubt works in MPASM.
So,
Code: Select all
PM                 data       " Program Mode  \r\0";1    $

should be
Code: Select all
PM                 data       " Program Mode  ",0x0D,0x00    ;1    $
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby Dimebag » Mon Jun 30, 2014 8:23 am

Is this your very first attempt at programming in assembly language?
Yes it is.
What is meant to happen when you go to Newpointer?
Newpointer is meant to select the subroutine to goto depending on what character is entered. If the letter "D" is entered it is meant to go to Label 'Program Mode' Execute the code until such time as the key to exit the routine is entered. I did look at program flow being a major problem at the moment as well. Thank you for pointing it out.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Subroutine problem with PIC18F452

Postby ric » Mon Jun 30, 2014 9:09 am

What is meant to happen when you go to Newpointer?
Newpointer is meant to select the subroutine to goto depending on what character is entered

You are still missing the point.
I am not talking about the overall program flow after there, I am talking about the VERY NEXT INSTRUCTION that is executed after you "GOTO Newpointer".
There is nothing there, so the next instruction executed will be the first instruction after the Hyper_Tlink_1 label.
You have called unpackdata as a subroutine, so you need a return instruction to exit from that subroutine, but you don't have one where I would expect, which is after the "Newpointer" label.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby Dimebag » Mon Jun 30, 2014 12:01 pm

Hi Ric,
Thank you very much for putting up with me and my inexperience. I have decided to shelve this idea for later on again. I believe I need more experience with assembly language coding practices. I still plan to make the project, but for now I will try a more simple serial communication program. You are right, the program didn't have flow and some parts of the code are seriously lacking details. In my rush to understand assembly coding I think I tried to bite off more than I can realistically do.

: As you also said the program didn't work the way I intended it to do. To me it looked like it worked, but as I got more into it I soon realized that what you said is true.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Subroutine problem with PIC18F452

Postby ric » Mon Jun 30, 2014 12:51 pm

ok, you're call.
I'm sure we could help you save the program, but you'd have to listen carefully to the advice given. In each case I recommended what you needed to add, but you seemed to just ignore that and focus on other bits of the code that were actually ok.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby Dimebag » Mon Jun 30, 2014 1:24 pm

I am talking about the VERY NEXT INSTRUCTION that is executed after you "GOTO Newpointer".
That is actually the part of the program I couldn't work out what to do with. After the "BZ Newpointer" I just don't know what to do after it goes to 'Newpointer'. I thought the program should have gone back to the routine that next said 'goto'
Code: Select all
   btfss   PIR1,RCIF   ;
   goto   test_receive
   movf   RCREG,w   ;
   call    request   ;

request

       ;Program Mode

   xorlw     "A"   ;
   btfsc     STATUS,Z   ;
   goto      set1   


Code: Select all
 set1

   movlw     upper     (PM)
   movwf     TBLPTRU
   movlw     high      (PM)                 
   movwf     TBLPTRH
   movlw     low       (PM)
   movwf     TBLPTRL
   call      unpackdata
   goto      Hyper_Tlink_1

Now for some reason code runs straight to "set 40" label and prints out ''To Program' on any key pressed. Newpointer was to debug code. I haven't given up Ric. Sorry if I made Code tags hard to read.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Subroutine problem with PIC18F452

Postby ric » Mon Jun 30, 2014 1:57 pm

Dimebag wrote: That is actually the part of the program I couldn't work out what to do with. After the "BZ Newpointer" I just don't know what to do after it goes to 'Newpointer'. I thought the program should have gone back to the routine that next said 'goto'

Yes, I agree, and I already told you how to do that.
You called unpackdata as a subroutine, using the "call" instruction.
Code: Select all
call      unpackdata

Once a subroutine has finished, you have to execute a "return" instruction to tell the PIC to return to the next instruction after the call.
Once you have finished outputting your string, you jump to your "Newpointer" label. THAT is where you should have a return instruction to exit from your subroutine.
I already said a few posts ago, you should have a return instruction straight after the Newpointer label.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Subroutine problem with PIC18F452

Postby Dimebag » Mon Jun 30, 2014 2:38 pm

I am trying Ric. I am not very happy with most of my code at the moment. I am thinking that I need a more simple routine to handle jumping around code. I think that 'TBLPTRU, TBLPTRH, TBLPTRL' it appears to be making the code hard to read. So code lines like.
Code: Select all
   xorlw     "A"
   xorlw     "B"
   btfsc     STATUS,Z
   goto      set2
The code looks messy and not very well written. I need a simple, but effective routine to manage Serial coms. Well back to the drawing board again.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

PreviousNext

Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 7 guests

cron