Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

"mcs-51 switch" example dosen't work.

3 posters

Go down  Message [Page 1 of 1]

1"mcs-51 switch" example dosen't work. Empty "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 10:30 am

royqh1979



I've tried to run the examples in examples/Micro/mcs-51/mcs-51_switch.

I loaded the circuit and started simulation.

but the LED just won't light, no matter the switch "Switch" is on or off.

Is there anything wrong with my operation?

2"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 10:45 am

arcachofo

arcachofo

It is working for me.
Note that 8051 Reset is active High, so to get it working it must be Low.

3"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 10:58 am

royqh1979



arcachofo wrote:It is working for me.
Note that 8051 Reset is active High, so to get it working it must be Low.
"mcs-51 switch" example dosen't work. Switch10
"mcs-51 switch" example dosen't work. Switch11

4"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 11:00 am

arcachofo

arcachofo

I see, you are using development branch.
I will have a look.

5"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 11:09 am

royqh1979



arcachofo wrote:I see, you are using development branch.
I will have a look.

Thanks a lot!

And all registers exerpt PC is empty in the MCU monitor.

"mcs-51 switch" example dosen't work. Snap510

6"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 11:14 am

arcachofo

arcachofo

And all registers exerpt PC is empty in the MCU monitor.
Have a look to this video (from 04:29) to see how to use MCU Monitor:
https://www.youtube.com/watch?v=XcCq9B0rIDA&ab_channel=SimulIDE

7"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 11:18 am

KerimF

KerimF

If I remember well, the output pins of C51 MCU family are open collector.

8"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Mon Aug 28, 2023 11:20 am

arcachofo

arcachofo

If I remember well, the output pins of C51 MCU family are open collector.
Yes, but I think it has internal pullups.

And all registers exerpt PC is empty in the MCU monitor.
This video is specific for MCU Monitor in 1.0.0
https://www.youtube.com/watch?v=uVwMEadtIEM

arcachofo

arcachofo

examples/Micro/mcs-51/mcs-51_switch should be working after trunk Rev 1824.

Anyway 8051 still nedds some work and a lot of testing.
This one has been completely re-written, it has nothing in common with 8051 in 1.0.0.

10"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 2:19 pm

royqh1979



Here seems wrong.
Why PC+3 is pushed to the stack?

"mcs-51 switch" example dosen't work. Snap410

According to the manual, PC should be pushed.

"mcs-51 switch" example dosen't work. Snap511

11"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 2:37 pm

arcachofo

arcachofo

Why PC+3 is pushed to the stack?
Instruction LCALL does that:
LCALL calls a subroutine located at the indicated address. The instruction adds
three to the program counter to generate the address of the next instruction and
then pushes the 16-bit result onto the stack (low byte first)

The part of the manual you show seems an interrupt jump to reset vector, which is managed here:
src/microsim/cores/cpubase.h:
Code:
virtual void INTERRUPT( uint32_t vector ) { CALL_ADDR( vector ); }

Which calls:
Code:
void McuCpu::CALL_ADDR( uint32_t addr ) // Used by MCU Interrupts:: All MCUs should use or override this
{
    PUSH_STACK( m_PC );
    setPC( addr );
    m_mcu->cyclesDone = m_retCycles;
}

12"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 2:44 pm

royqh1979



But before LCALL() (which is called by Exec()) called, m_PC has already been updated  ( m_tmpPC has been increased by 3 while decoding) and pointing to the instruction next to LCALL.

"mcs-51 switch" example dosen't work. Snap611


arcachofo wrote:
Why PC+3 is pushed to the stack?
Instruction LCALL does that:
LCALL calls a subroutine located at the indicated address. The instruction adds
three to the program counter to generate the address of the next instruction and
then pushes the 16-bit result onto the stack (low byte first)

13"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 2:53 pm

royqh1979



royqh1979 wrote:But before LCALL() (which is called by Exec()) called, m_PC has already been updated  ( m_tmpPC has been increased by 3 while decoding) and pointing to the instruction next to LCALL.

And PC do messed up after RET in R1821.

Attachment is a simple demo sdcc program. PC will soon go beyond 4096 after silumation started.
Attachments
"mcs-51 switch" example dosen't work. Attachmentled_timer.zip
You don't have permission to download attachments.
(37 Kb) Downloaded 2 times

14"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 2:59 pm

arcachofo

arcachofo

But before LCALL() (which is called by Exec()) called, m_PC has already been updated ( m_tmpPC has been increased by 3 while decoding) and pointing to the instruction next to LCALL.
Yes, you are right.

15"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 3:21 pm

arcachofo

arcachofo

I also had a look at ACALL and it pushes PC to stack, not PC+2, so it is obvious that LCALL is wrong.

Solved at trunk Rev 1926.

16"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 4:24 pm

royqh1979



And the decode of mov reg, Rx seems not right. It should mov the content of Rx, not address of Rx.

Hex generated by sdcc use Rx to handle function parameters, and it failed to run correctly.

"mcs-51 switch" example dosen't work. Snap711
"mcs-51 switch" example dosen't work. Snap810

17"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 4:56 pm

arcachofo

arcachofo

And the decode of mov reg, Rx seems not right. It should mov the content of Rx, not address of Rx.
I see...
Maybe you can try the commented part:
Code:
void I51Core::operRgx() { m_op0 = m_RxAddr; }//{ m_op0 = m_dataMem[m_RxAddr]; }
// Change to:
void I51Core::operRgx() { m_op0 = m_dataMem[m_RxAddr]; } //{ m_op0 = m_RxAddr; }
Maybe I changed it for some reason and forgot to return to the original.

18"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 5:21 pm

royqh1979



arcachofo wrote:
And the decode of mov reg, Rx seems not right. It should mov the content of Rx, not address of Rx.
I see...
Maybe you can try the commented part:
Code:
void I51Core::operRgx() { m_op0 = m_RxAddr; }//{ m_op0 = m_dataMem[m_RxAddr]; }
// Change to:
void I51Core::operRgx() { m_op0 = m_dataMem[m_RxAddr]; } //{ m_op0 = m_RxAddr; }
Maybe I changed it for some reason and forgot to return to the original.

operRgx() is also used in other places. So maybe it should be kept and create a new method for instructions 0x8x only.

19"mcs-51 switch" example dosen't work. Empty Re: "mcs-51 switch" example dosen't work. Tue Aug 29, 2023 6:00 pm

arcachofo

arcachofo

operRgx() is also used in other places. So maybe it should be kept and create a new method for instructions 0x8x only.
Not sure...
For what I see all instructions using operRgx() take the value.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum