Led traffic light Simulation

Source: Internet
Author: User

 

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:
  1. Org 0100 h; reserved space
  2. Main:
  3. Loop: mov P0, # 0xf3h;
  4. Acall dtime
  5. MoV r0, #5; What are the functions of these statements? Make things yellow, North and South Red
  6. Loop1:
  7. MoV P0, # 0f5h
  8. Acall dtime1
  9. MoV P0, # 0f7h
  10. Acall dtime1
  11. Djnz r0, loop1
  12. MoV P0, # 0deh; North-South green light, East-West red light
  13. Acall dtime
  14. MoV r0, #5
  15. Loop2: mov P0, # 0eeh; flashing yellow light in north and south, east/west red light
  16. Acall dtime1
  17. MoV P0, # 0feh
  18. Acall dtime1
  19. Djnz r0, loop2
  20. JMP Loop
  21. Dtime:; latency
  22. MoV R5, #60
  23. X: mov R7, #200.
  24. Del1: mov R6, #248.
  25. NOP
  26. Del2: djnz R6, del2
  27. Djnz R7, del1
  28. Djnz R5, X
  29. RET;
  30. Dtime1: mov R5, #5
  31. X1: mov R7, #200; latency
  32. Del3: mov R6, #248.
  33. NOP
  34. Del4: djnz R6, del4
  35. Djnz R7, del3
  36. Djnz R5, X1
  37. RET;
  38. End

Two types: interruption implementation delay Compilation

Code:
  1. Org 0100 h; reserved space
  2. Start:
  3. 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
  4. Acall dtime
  5. MoV r0, #5; What are the functions of these statements? Make things yellow, North and South Red
  6. Loop1:
  7. MoV P0, # 0f5h
  8. Acall dtime1
  9. MoV P0, # 0f7h
  10. Acall dtime1
  11. Djnz r0, loop1
  12. MoV P0, # 0deh; North-South green light, East-West red light
  13. Acall dtime
  14. MoV r0, #5
  15. Loop2: mov P0, # 0eeh; flashing yellow light in north and south, east/west red light
  16. Acall dtime1
  17. MoV P0, # 0feh
  18. Acall dtime1
  19. Djnz r0, loop2
  20. JMP Loop
  21. Dtime1:; latency
  22. MoV tmod, #01 H
  23. MoV th0, # 3ch
  24. MoV tl0, # 0b0h
  25. MoV R6, #50
  26. SETB tr0
  27. WM: JBC tf0, next1
  28. Ajmp Wm
  29. Next1: djnz R6, next2
  30. RET
  31. Next2: mov th0, # 3ch
  32. MoV tl0, # 0b0h
  33. Ajmp Wm
  34. RET;
  35. Dtime: mov tmod, #01 H
  36. MoV th0, # 3ch
  37. MoV tl0, # 0b0h
  38. MoV R6, #100.
  39. MoV R7, #6
  40. SETB tr0
  41. LM: JBC tf0, next
  42. Ajmp LM
  43. Next: djnz R6, next4
  44. Djnz R7, next3
  45. Ajmp JS
  46. Next3: mov R6, #100.
  47. Next4: mov th0, # 3ch
  48. MoV tl0, # 0b0h
  49. Ajmp LM
  50. JS: Ret
  51. End

 

Three types: Keil C loop delay

Code:
  1. # Include <at89x51. h>
  2. Char C, X;
  3. Bit F;
  4. Char sum = 0;
  5. Xhd ();
  6. Dtime (unsigned int I)
  7. {Unsigned char J;
  8. While (I --)
  9. {For (j = 120; j> 0; j --);}
  10. }
  11. Main ()
  12. {Tmod = 0x01;
  13. Th0 = (65536-50000)/256;
  14. Tl0 = (65536-50000) % 256;
  15. Ea = 1;
  16. Et0 = 1;
  17. Tr0 = 1;
  18. P0 = 0xff;
  19. Xhd ();
  20. }
  21. Xhd ()
  22. {While (1)
  23. {
  24. P0 = 0xf3;
  25. Dtime (600 );
  26. For (x = 0; x <3; X ++)
  27. {
  28. P0 = 0xf5;
  29. Dtime (150 );
  30. P0 = 0xf7;
  31. Dtime (150 );
  32. }
  33. P0 = 0xde;
  34. Dtime (600 );
  35. For (x = 0; x <3; X ++)
  36. {
  37. P0 = 0xEE;
  38. Dtime (150 );
  39. P0 = 0xfe;
  40. Dtime (150 );
  41. }
  42. }
  43. }

4: delay of Keil C interrupt

Code:
  1. # Include <at89x51. h>
  2. Char C, X, R;
  3. Bit F;
  4. Char sum = 0;
  5. Xhd ();
  6. Main ()
  7. {Tmod = 0x01;
  8. Th0 = (65536-50000)/256;
  9. Tl0 = (65536-50000) % 256;
  10. Ea = 1;
  11. Et0 = 1;
  12. Tr0 = 1;
  13. P0 = 0xff;
  14. Xhd ();
  15. }
  16. Void T () interrupt 1 using 1
  17. {Th0 = (65536-50000)/256;
  18. Tl0 = (65536-50000) % 256;
  19. C ++;
  20. If (C = r)
  21. {C = 0;
  22. F = 1;
  23. }
  24. }
  25. Xhd ()
  26. {While (1)
  27. {
  28. R = 20; p0 = 0xf3;
  29. While (sum <10)
  30. {While (! F );
  31. F = 0;
  32. Sum ++;
  33. }
  34. Sum = 0;
  35. For (x = 0; x <3; X ++)
  36. {
  37. R = 8; p0 = 0xf5;
  38. While (sum <1)
  39. {While (! F );
  40. F = 0;
  41. Sum ++;
  42. }
  43. Sum = 0;
  44. P0 = 0xf7;
  45. R = 8;
  46. While (sum <1)
  47. {While (! F );
  48. F = 0;
  49. Sum ++;
  50. }
  51. Sum = 0;
  52. }
  53. R = 20; p0 = 0xde;
  54. While (sum <10)
  55. {While (! F );
  56. F = 0;
  57. Sum ++;
  58. }
  59. Sum = 0;
  60. For (x = 0; x <3; X ++)
  61. {
  62. R = 8; p0 = 0xEE;
  63. While (sum <1)
  64. {While (! F );
  65. F = 0;
  66. Sum ++;
  67. }
  68. Sum = 0;
  69. R = 8; p0 = 0xf3;
  70. While (sum <1)
  71. {While (! F );
  72. F = 0;
  73. Sum ++;
  74. }
  75. Sum = 0;
  76. }
  77. }
  78. }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.