Board logo

标题: 24C02计数器实战 [打印本页]

作者: fghser    时间: 2010-10-12 09:16     标题: 24C02计数器实战

  1. ;24c02的开机计数器,系统复位或停送电一次数码管加1
  2. ;***************************************************************************
  3. ;* (程序转载请著明出处 ,www.wenqi89s51.com) *

  4. SDA24 EQU P3.6
  5. SCLK24 EQU P3.7

  6. ORG 0000H
  7. AJMP MAIN
  8. ORG 0030H
  9. MAIN:

  10. MOV SP,#70H;设置堆栈栈顶
  11. MOV DPTR,#TAB
  12. MOV A,#00H ;读地址
  13. LCALL RD24
  14. CJNE A,#10,TT
  15. TT: JNC TT1
  16. AJMP TT2
  17. TT1: MOV A,#00
  18. TT2: MOV 30H,A
  19. MOVC A,@A+DPTR
  20. CLR P2.0 ;开数码管
  21. MOV P0,A ;送显示

  22. MOV A,30H
  23. INC A
  24. MOV B,A
  25. MOV A,#00H
  26. LCALL WT24
  27. AJMP $
  28. TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H;七段数码管0-9字形编码


  29. RD24: PUSH ACC ;读24C02子程序。
  30. SETB SDA24
  31. CLR SCLK24
  32. CALL START24
  33. MOV A,#0A0H
  34. CALL SHIFT8
  35. CALL ACK
  36. POP ACC
  37. CALL SHIFT8
  38. CALL ACK
  39. CALL START24
  40. MOV A,#0A1H
  41. CALL SHIFT8
  42. CALL ACK
  43. SETB SDA24
  44. MOV R7,#8
  45. CLR A
  46. SETB SDA24
  47. RD000: RL A
  48. SETB SCLK24
  49. MOV C,SDA24
  50. MOV ACC.0,C
  51. CLR SCLK24
  52. DJNZ R7,RD000
  53. RET
  54. ;-------------------------------
  55. ;写入24C02程序:
  56. WT24: PUSH ACC
  57. SETB SDA24
  58. CLR SCLK24
  59. CALL START24
  60. MOV A,#0A0H
  61. CALL SHIFT8
  62. CALL ACK
  63. POP ACC
  64. CALL SHIFT8
  65. CALL ACK
  66. MOV A,B
  67. CALL SHIFT8
  68. CALL ACK
  69. CALL STOP
  70. CALL DELAY2
  71. RET
  72. ; -------------------------------
  73. ;开始条件
  74. START24:CLR SDA24
  75. SETB SDA24
  76. SETB SCLK24
  77. CLR SDA24
  78. CLR SCLK24
  79. RET

  80. ;停止条件
  81. STOP: CLR SDA24
  82. SETB SCLK24
  83. SETB SDA24
  84. RET

  85. ;应答信号
  86. ACK: SETB SCLK24
  87. CLR SCLK24
  88. RET

  89. ;读、写数据
  90. SHIFT8: MOV R7,#8
  91. SH01: RLC A
  92. MOV SDA24,C
  93. SETB SCLK24
  94. CLR SCLK24
  95. DJNZ R7,SH01
  96. RET

  97. DELAY2:
  98. NOP
  99. NOP
  100. NOP
  101. NOP
  102. RET
  103. END
复制代码





欢迎光临 珩源工控论坛 (http://bbs.hymcu.com/) Powered by Discuz! 7.2