Is my circuit diagram
Below are four programs I write with two different languages and two different latencies, but I don't know what time to ask during simulation (I haven't solved it yet)
A loop assembly delay
Code:
- Org 0100 h; reserved space
- Main:
- Loop: mov P0, # 0xf3h;
- Acall dtime
- MoV r0, #5; What are the functions of these statements? Make things yellow, North and South Red
- Loop1:
- MoV P0, # 0f5h
- Acall dtime1
- MoV P0, # 0f7h
- Acall dtime1
- Djnz r0, loop1
- MoV P0, # 0deh; North-South green light, East-West red light
- Acall dtime
- MoV r0, #5
- Loop2: mov P0, # 0eeh; flashing yellow light in north and south, east/west red light
- Acall dtime1
- MoV P0, # 0feh
- Acall dtime1
- Djnz r0, loop2
- JMP Loop
- Dtime:; latency
- MoV R5, #60
- X: mov R7, #200.
- Del1: mov R6, #248.
- NOP
- Del2: djnz R6, del2
- Djnz R7, del1
- Djnz R5, X
- RET;
- Dtime1: mov R5, #5
- X1: mov R7, #200; latency
- Del3: mov R6, #248.
- NOP
- Del4: djnz R6, del4
- Djnz R7, del3
- Djnz R5, X1
- RET;
- End
Two types: interruption implementation delay Compilation
Code:
- Org 0100 h; reserved space
- Start:
- Loop: mov P0, # 11110011b; what is the role of the two statements? Let the lights of the east place shine on the north and south
- Acall dtime
- MoV r0, #5; What are the functions of these statements? Make things yellow, North and South Red
- Loop1:
- MoV P0, # 0f5h
- Acall dtime1
- MoV P0, # 0f7h
- Acall dtime1
- Djnz r0, loop1
- MoV P0, # 0deh; North-South green light, East-West red light
- Acall dtime
- MoV r0, #5
- Loop2: mov P0, # 0eeh; flashing yellow light in north and south, east/west red light
- Acall dtime1
- MoV P0, # 0feh
- Acall dtime1
- Djnz r0, loop2
- JMP Loop
- Dtime1:; latency
- MoV tmod, #01 H
- MoV th0, # 3ch
- MoV tl0, # 0b0h
- MoV R6, #50
- SETB tr0
- WM: JBC tf0, next1
- Ajmp Wm
- Next1: djnz R6, next2
- RET
- Next2: mov th0, # 3ch
- MoV tl0, # 0b0h
- Ajmp Wm
- RET;
- Dtime: mov tmod, #01 H
- MoV th0, # 3ch
- MoV tl0, # 0b0h
- MoV R6, #100.
- MoV R7, #6
- SETB tr0
- LM: JBC tf0, next
- Ajmp LM
- Next: djnz R6, next4
- Djnz R7, next3
- Ajmp JS
- Next3: mov R6, #100.
- Next4: mov th0, # 3ch
- MoV tl0, # 0b0h
- Ajmp LM
- JS: Ret
- End
Three types: Keil C loop delay
Code:
- # Include <at89x51. h>
- Char C, X;
- Bit F;
- Char sum = 0;
- Xhd ();
- Dtime (unsigned int I)
- {Unsigned char J;
- While (I --)
- {For (j = 120; j> 0; j --);}
- }
- Main ()
- {Tmod = 0x01;
- Th0 = (65536-50000)/256;
- Tl0 = (65536-50000) % 256;
- Ea = 1;
- Et0 = 1;
- Tr0 = 1;
- P0 = 0xff;
- Xhd ();
- }
- Xhd ()
- {While (1)
- {
- P0 = 0xf3;
- Dtime (600 );
- For (x = 0; x <3; X ++)
- {
- P0 = 0xf5;
- Dtime (150 );
- P0 = 0xf7;
- Dtime (150 );
- }
- P0 = 0xde;
- Dtime (600 );
- For (x = 0; x <3; X ++)
- {
- P0 = 0xEE;
- Dtime (150 );
- P0 = 0xfe;
- Dtime (150 );
- }
- }
- }
4: delay of Keil C interrupt
Code:
- # Include <at89x51. h>
- Char C, X, R;
- Bit F;
- Char sum = 0;
- Xhd ();
- Main ()
- {Tmod = 0x01;
- Th0 = (65536-50000)/256;
- Tl0 = (65536-50000) % 256;
- Ea = 1;
- Et0 = 1;
- Tr0 = 1;
- P0 = 0xff;
- Xhd ();
- }
- Void T () interrupt 1 using 1
- {Th0 = (65536-50000)/256;
- Tl0 = (65536-50000) % 256;
- C ++;
- If (C = r)
- {C = 0;
- F = 1;
- }
- }
- Xhd ()
- {While (1)
- {
- R = 20; p0 = 0xf3;
- While (sum <10)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- For (x = 0; x <3; X ++)
- {
- R = 8; p0 = 0xf5;
- While (sum <1)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- P0 = 0xf7;
- R = 8;
- While (sum <1)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- }
- R = 20; p0 = 0xde;
- While (sum <10)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- For (x = 0; x <3; X ++)
- {
- R = 8; p0 = 0xEE;
- While (sum <1)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- R = 8; p0 = 0xf3;
- While (sum <1)
- {While (! F );
- F = 0;
- Sum ++;
- }
- Sum = 0;
- }
- }
- }