What type of memory?why we use memory in microcontroller?
I do not understand.mainly there are two type of memory firs is rom that is used to write code and second is ram that is used to save the address but can anyone tell me the reason why we used memory in controller
ok I explain I want to run motor with two switches ok I can do with Ic so I used And gate ICs.I do not understand.
You said "ram that is used to save the address" I think you are talking about "stack" which is where address and data is stored. This is a special part of RAM.
, that is, you have "stored" (in ROM) some instructions for the proessor to perform. These instructions not only contain the rules for the processor to follow in performing the task you have assigned, but ALSO what name has been assigned to the DATA that is being collected (and stored in RAM)....write some code on ram...
ok I want to understand with little exampleALU reads commands from program bus, fetches data from the data bus using address bus and writes the results of its operation to the data bus using the address bus.
ROM (or RAM) supplies information to the program bus so that ALU could get its commands.
RAM uses data bus for communications if the address requested by ALU matches any real memory address
I/O uses data bus when the address requested by ALU matches any of I/O addresses. Or I/O may have its own bus.
look at post #12 I am asking about that queryHey, if you did not have RAM, nested subroutine calls would not work. Usually two things have to placed on the stack. The Processor Status Word (Condition codes, etc) and the return address. You would not have stack either.
Its very detail Information and help me lot but I am little confusedswitch bit is at address [1], LED bit is at address [2] - these are I/O addresses.
We also use RAM at addrsss [3]. It'll store state of the switch and LED respectively.
Every time switch goes from high to low we toggle LED.
The program might look like this:
0: mov [1],[3]
1: cmp [3],[1]
2: jmpe 1
3: mov [1],[3]
4: test [3]
5: jmpne 1
6: not [2],[2]
7: jmp 1
For this we'll use 4-bit program address bus, 8-bit command size, 2-bit data address bus and 1-bit data bus.
ALU maintains command pointer - 4 bit and has an internal flag, which could be set to 0 or 1.
We can have command format as follow - 4-bit - opcode; 2-bit - first operand; 2-bit second operand.
Say, mov will have code 1, so the first line becomes:
o: mov[1],[3] - 0001 0111 - this moves something from data address [1] to data address [3] - we remember switch state
At the beginnig command pointer is set to 0000, so ALU fetches the 0001 (mov) command from this address and parses it.
It then issueas a read request on data bus for address [1] - first argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Then ALU posts the state it have just read back to data bus and issues write request for address [3] - second argument.
RAM module recognizes [3] as its address and stores the data from the data bus.
ALU increments its program pointer, so it now 0001.
As a result, the switch state is stored in RAM at address [3]
1: cmp [3],[1] - 0011 1101 - I used ooo2 as a code for compare (cmp command).
ALU fetches the 0011 (cmp) command from the 0001 (current pointer).
It then issueas a read request on data bus for address [3] - first argument.
RAM module recognizes [3] as its address and posts data from this address to the data bus.
ALU reads data from the data bus and stores it in its register
ALU issueas a read request on data bus for address [1] - second argument.
The switch I/O module recognizes the address and posts the switch state to data bus
ALU reads the switch state from data bus.
Now ALU performs the compare operation. It compares the data from the bus with the value stored in the internal register (earlier this command). If they're equal, it sets internal register to 0, if different - to 1. It noe can be analized by the next command.
ALU increments its program pointer to 2.
2: jmpe 1 - 0011 0001 - Another opcode I made up - 0011 - Jump if equal. If internal register is 0 then load the last 4 bits of the code into command pointer
ALU fetches the 0011 (jmpe) command from the 0002 (current pointer).
If it is 0 in the internal register (meaning [1] was equal to [3]), it loads 0001 into the program pointer so the program loops back.
The program will continue to loop back until a difference between [1] and [3] will force internal register to 1 during the execution of previous command.
3: mov [1],[3] - 0001 0111 - same the command at address 0
And it does the same. Switch state changed, it it saves it into RAM
4: test [3] - 0100 1100 - Another opcode - 01oo - comapres first argument to the last bit of command (0 here)
Similar to cmp command, but the second argument is not fetched from the bus but is stored inside the command. This is called immediate addressing
5: jmpne 1 - 0101 0001 - Opcode 0101 - does the same as ooo3, but jumps when internal register is 1
This command will jump back to 1 if the value tested by the test command is not zero. This means that the switch is now high. We don't do anything and continue looping.
And if it is low then we want to switch LED, so we go to the next command
6: not [2],[2] - 0110 1010 - NOT opcode - 0110 - toggles. Note it both read and writes from the same address.
ALU fetches the 0110 (not) command from this address and parses it.
It then issueas a read request on data bus for address [2] - first argument.
The LED I/O module recognizes the address and posts the LED state to data bus
ALU reads the LED state from data bus, and inverts it.
Then ALU posts the new state to data bus and issues write request for address [2] - second argument.
LED I/O module recognizes [2] as its address and accepts the state from the data bus.
ALU increments its program pointer, so it now 7.
As a result, the LED is toggled.
7: jmp 1 - 0111 0001 - Unconditional jump to the address from the last 4 bits of the command.
We continue looping. monitoring switch changes and switching the LED accordingly.
Hope I didn't make too many typos in such a long text.
Its very detail Information and help me lot but I am little confused
controller take input from switch and store address in RAM memory
1) what will happen first processor will take information ROM or RAM memory ?
lets think I have micro controller 89c51 ,LED,switch,compiler(keil),programmer (flesh magic)As I described. Take command code from ROM, decode it, then act according to what is decoded: take info from the switch (which is I/O port, not memory), store info in the RAM.
ORG OH
ON:
SETB P1.1 ; LED IS ON
OFF:
CLRB P1.1 ; LED IS OFF
LOOP:
JB P0.1 ; SWITCH ON
JNB P0.1 ; SWITCH OFF
SJMP LOOP
END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?