Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC problem with GPR

Status
Not open for further replies.

demestav

Member
Hello.
I am writting a program where at the beggining i declare which variables are used in the program using
Code:
cblock	h'20'
			timer0
			timer1
			NumL
         huns
			tens
			ones
			BIN
	endc

When i run the simulator i can see that these registers are messed up as variables are declared elsewhere in the GPRs. They are declared at 0A0h instead of 020h.
any help?
the pic i am using is 16f873
Thank you
 
demestav said:
Hello.
I am writting a program where at the beggining i declare which variables are used in the program using
Code:
cblock	h'20'
			timer0
			timer1
			NumL
         huns
			tens
			ones
			BIN
	endc

When i run the simulator i can see that these registers are messed up as variables are declared elsewhere in the GPRs. They are declared at 0A0h instead of 020h.
any help?
the pic i am using is 16f873
Thank you

That works fine here, although personally I use 0x20 rather than h'20', but I've just tried your way and it compiles perfectly.

Have you tried checking the code it produces when you assemble it?, as opposed to looking in the simulator.

Otherwise, try posting the complete code so we can see if there's anything else that could upset it.
 
thank you for your reply. I tried with 0x20 but the same thing happens. which simulator are you using?
the code is **broken link removed**

This is my first actual program so furthre suggestions are welcome :D
Thank you
 
demestav said:
thank you for your reply. I tried with 0x20 but the same thing happens. which simulator are you using?
the code is **broken link removed**

This is my first actual program so furthre suggestions are welcome :D
Thank you

I don't use any simulator :lol:

Your program seems lacking a lot of parts it needs, it gives 104 errors when I try to assemble it!

The problems are probably in the missing parts at the beginning, for a start you don't even specify your processor?. Also, why not use the include files provided, rather than write your own definitions, have a look at my tutorials for examples of how to layout PIC source code.

If this is your first program, I would suggest you start off simpler, jumping straight into interrupts and analogue converters is making life far more complicated for you. I would suggest starting off simply and working up, again my tutorials may be helpful.
 
hello and thank you for your reply.
I think you got me wrong. I know a thing or two for microcontrollers about interrupts and a/d. Yes you are right that my program is not complete. It isnt. i just started it and i came up with this problem. When i compile it i get no errors at all. The program is working fine on the simulator with only problem the GPR's as i explained you before.

That must be something i don't know about GPRs. If i write:

MOVWF 0x20

i can see that the code is actually

0A0

Why this happens?
Thank you.
 
The resulting binary code for MOVWF 0x20 is indeed 0x0A0. You can see it in table 13-2 of the PIC16F87X datasheet.

Remember that for direct addressing, only seven bits are used and therefore 128 locations on a given memory bank are directly addressable at a given time.
 
thnx about your reply motion. can you tell me in which page of the datasheet is that plz because i cannot find it..

Could you plz explain me a bit more plz? Thnx :!:
 
demestav said:
thnx about your reply motion. can you tell me in which page of the datasheet is that plz because i cannot find it..

Could you plz explain me a bit more plz? Thnx :!:

Right, thanks to motion I now see what you are doing, you're looking at the machine code produced by the assembler!. This seems rather a strange thing to be doing? - fair enough, I did it, many years ago - but I was writing a PIC disassembler!.

All the PIC instructions are listed in their data sheets, it's hard to miss, it's a complete listing of all 35 instructions.

They are also listed in Appendix B.1 of the MPASM help file, which is installed along with MPLAB - which is usually easier to find than the datasheet.
 
demestav said:
thnx about your reply motion. can you tell me in which page of the datasheet is that plz because i cannot find it..

Could you plz explain me a bit more plz? Thnx :!:

It's found on page 138 of document 30292c.pdf.
 

Attachments

  • table.jpg
    table.jpg
    81.7 KB · Views: 581
thnx for replies :)

maybe thereis a misunderstanding or something i do not know. The problem at the begginig was:

The timer0 variable EVEN IF it is declared to be at 0x20 address, WHEN i run the simulator i can see that it is saved at 0xA0 address.**broken link removed**

I dont know if the rest of my comments are relevant. Thank you for answering me. The actual problem is shown in the picture

Thank you. :!:
 
Address 0x20 and 0xA0 are on the same position, but in a diffirent bank

0x20 is bank 0 and
0xA0 is bank 1...

If you save something to your timer0 variable at address 0x20, but it is address 0xA0 that changes then this means you are in the wrong bank (bank1 - while you should be in bank0)
 
hmm
thnx EXO.
i though i had already did that and was not working. Seems i was wrong. I tried it again now and it works!!!
Thank you very much for your time and replies, and sorry causing too much trouble for things i should already know by now....
thanx
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top