Discussion in "8051 Discussion Forum" started by    kikoues    Sep 19, 2010.
Sun Sep 19 2010, 07:18 pm
#1
As i have run out of registers, i am using memory locations to store the values of some variables. i am using the memory bank 30 to 7h. my code simulates as expected however it does not run correctly on the micrcontroller. i am reading a data from a peripheral. i probed with oscilloscope its signal at my micrcontroller port, it is as expected in my program. however my output is badly synchronised and does not work as expected although it simulatedsfine. any tips please because i am not able to fix it. i have found the following , which may be the cause of my problems although i don't understand what the author means by system stack
General Purpose RAM: 30h to 7Fh
These 80 bytes of Internal RAM memory are available for general-purpose data
storage. Access to this area of memory is fast compared to access to the main memory
and special instructions with single byte operands are used. However, these 80 bytes
are used by the system stack and in practice little space is left for general storage. The
general purpose RAM can be accessed using direct or indirect addressing modes.
Examples of direct addressing:


cheers
Sun Sep 19 2010, 11:54 pm
#2
hi kikoues
it is better u upload ur program which u made then anyone can help u better

stack is the temporary memory by default it is bank1
when we call a function then its present address is push to stack the control goes to function after executing the function it pop the address and goes there from where it comes
Mon Sep 20 2010, 08:47 pm
#3
thanks majoka, i fixed the problem by avoiding this bank although i still don't understand what the author means by SYSTEM STACK
Tue Sep 21 2010, 12:19 am
#4
Stack is part of ram memory used for temporary storage data when controller makes a context switch during call to a subroutine or an interrupt routine. Data is stored on stack by pushing important working registers and poping them back.

Register Banks are part of RAM memory from 00H to 1FH. In 8051 the stack pointer is loaded at 7H on power up. so incase you are going to use memory banks in your code you have to setup stack pointer to a safe location that is not used by your program.

Lets say you are not using area above 50H in your RAM memory. so setup SP to 50H e.g.
mov SP, #50H ;load stack pointer at 50H


So you will now have the area from 20H to 50H free to use for your general purpose ram, and 0H to 1FH for memory banks and 51H to 7FH for stack. simple isnt it?

Incase you are using an 8052 based controller which has 256 bytes of ram so stack pointer can be initialized to 80H instead. which means you have 20H to 7FH available for general purpose use and 80H to FFH for stack.

Hope you get the point now

[edit: changed the wrong reference]


[ Edited Wed Sep 22 2010, 01:48 am ]
Tags 8051 stack setupstack initialization 80518051 stack pointer initialization
Tue Sep 21 2010, 12:23 am
#5
SYSTEM STACK is a stack as i mention above that is by default bank 1
Tue Sep 21 2010, 10:22 pm
#6
Many thanks Ajay and Majoka for your replies. I am coding in assembly, so why are you are making ref. to compiler? also in my programs, i am using R0-R7 registers + memory locations to access and store data. my code operates correctly when i define the memory locations in the 08-E range while initialising SP @ 0fH as you showed in your code.
I am using subroutineS but without PUSH and POP. yet my code does not work when i define the memory location iin the bank 30-7f. any explanation?

also i have read in the ref that the band 20-2f is bit addressable. so how can the assembler find out if
clr 20 is setting the bit 20 to zero or instead setting the byte 20 to zero
...sorry but i am confused...
Tue Sep 21 2010, 10:54 pm
#7
ok dear kikoues
it is better u post ur code here so we help u better
ok u confused in compiler term u r doing coding in assembly so assembler is used in assembly. in assembly coding u hav to do check and balance of every thing by urself even memory banks , stack etc
30 to 7f memory is a scrath pad mean general purpose ram may be u defining it in wrong way when u use this memory then mov sp,#07
but it is better u post ur code for this question
20 to 2f is bit addressable memory
clr 20 means move zero to 20 location of bit addressable memory mean clearing a bit not a byte
if u want to move zero to a 20 location byte then syntax is
mov 20h,#00h
hop so nw ur cleared
Wed Sep 22 2010, 01:43 am
#8
and my mistake i should have said controller instead of compiler or assembler as controller is the one doing a context switch. during a context switch push pop is done by controller automatically you have no control over it.

an example, when you make acall to a subroutine, and at end of subroutine you execute ret statement. to make ret run correctly controller should know where to return, so this return addressed is pushed to stack when a call is made and poped from stack when returning from subroutine.

second example, you have written a routine where you're using registers r0 to r7 suddenly an interrupt comes so controller will push the return address to stack. now in ISR you are again going to use r0 and r1 so your application must push those working register to stack before using them in ISR while coming back from ISR you pop those two registers and return back where you've left. thats how stack is used.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am