⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog18.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG18 - State Machines
;
;  This Application Demonstrates how a set of traffic lights could
;   be controlled in the 8051 using a State Machine and Table Jumps.  
;
;  This program will run in the UMPS simulator for a DS80C320.
;
;  Myke Predko
;  98.02.18
;
;  Hardware Notes:
;   This program is only meant to run on the Simulator
;    It could be modified to run in hardware by making "Dlay" more than
;    a dummy routine
;
;  North/South Lights
;   NSGreen  - P1.0
;   NSYellow - P1.1
;   NSRed    - P1.2
;
;  East/West Lights
;   EWGreen  - P1.4
;   EWYellow - P1.5
;   EWRed    - P1.6

;  Variable Declarations
State EQU 020h			;  The Current State Variable
StateDir EQU 004h               ;  The Direction Bit - Bit 4 of 020h
;  Bit States
;   Bit 4: _EW/NS - This Bit is Set for NS, Reset for East/West
;   Low Nybble: Current Light State


;  R0 is used as an Index Pointer to Array
;  R1 is used as the Source Location for the Control Store Table

Array EQU 0B0h			;  Define Array in Scratchpad RAM

;  Mainline
 org 0                          ;  Execution Starts Here

  mov	 State,#0		;  Start with E/W "Red"

  mov	 P1,#0BBh               ;  Turn on the Red Lights

  mov	 DPTR,#LightTable	;  Have the DPTR Point to the 

Loop:				;  Loop Back Here for Each Light State

  acall	 NextLight

  sjmp	 Loop


NextLight:			;  Now, Turn Off the Current Light and Turn
				;   The Next One
  mov	 A,State		;  Get the State x2
  rl	 A
  anl	 A,#0DFh		;  Clear the _EW/NS Flag

  jmp	 @A+DPTR		;  Jump to the Appropriate Response

LightTable:

  sjmp	 GreenLight		;  Currently Have a Red Light, Go to Green
  sjmp	 YellowLight		;  Currently Have a Green Light, Go to Yellow
  sjmp	 RedLight		;  Currently Have a Yellow Light, Go to Red

GreenLight:			;  Turn the Light to Green

  mov	 A,#0EBh		;  Are We turning on the E/W Light
  jnb	 StateDir,GL_EW
  mov	 A,#0BEh		;   No - Do the North South
GL_EW:
  mov	 P1,A			;  Now, Turn on the Light

  mov	 R0,#0			;  Delay for a Green Light Period
  acall	 Dlay

  inc	 State			;  Increment to the Next State

  ret

YellowLight:			;  Turn the Light to Yellow

  mov	 A,#0DBh		;  Are We turning on the E/W Light
  jnb	 StateDir,YL_EW
  mov	 A,#0BDh  		;   No - Do the North South
YL_EW:
  mov	 P1,A			;  Now, Turn on the Light

  mov	 R0,#1			;  Delay for a Yellow Light Period
  acall	 Dlay

  inc	 State			;  Increment to the Next State

  ret

RedLight:			;  Turn the Light to Red

  mov	 P1,#0BBh		;  Turn Everything to Red

  mov	 R0,#2			;  Delay for a Red Light Period
  acall	 Dlay

  mov	 A,#0F0h		;  Reset back to Green for the Next Light
  anl	 State,A

  cpl	 StateDir		;  Change Which Light is Active

  ret


Dlay:				;  Delay a Set amount of Time for Each Light

;  #### - Put Delay Code Here

  ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -