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

📄 prog38.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG38 - Using a Polaroid Ranging Module with an AT89C2051
;
;  This Application outputs a Pulse to the Poloroid 6500 Ranging
;   Module.  The Current Distance is Displayed on an LCD Connected
;   to P1.
;
;  Myke Predko
;  98.03.29
;
;  Hardware Notes:
;  AT89C2051 is used as the Microcontroller
;   - Oscillator Speed is 4 MHz
;  "Init" Pulse is from P3.7
;  "Echo" is Received on Pin P3.5
;  P1.2 is the "E" Clock
;  P1.3 is the "RS" Line
;  R1.4-P1.7 is the High Four Bits of the LCD

;  Constant Declarations

;  Variable Declarations
Count      EQU 020h             ;  "Dlay" Count Values
Counthi    EQU 021h


;  Macros


;  Mainline
 org 0                          ;  Execution Starts Here

  clr     P3.7                  ;  Keep the Init Pulse Low 

  acall   Dlay                  ;  Wait 100 msec before Initializing the LCD

  mov     A,#030h               ;  Output $30 as the Command
  acall   LCDNybble             
  acall   Dlay                  ;  Wait for the Command to Take

  acall   LCDNybble             ;  Output the Nybble
  acall   Dlay150

  acall   LCDNybble
  acall   Dlay150

  mov     A,#020h               ;  Set the Interface to 4 Bits
  acall   LCDNybble
  acall   Dlay150

  mov     A,#028h               ;  Send 4 Bit, 2 Line Instruction
  acall   LCDINS

  mov     A,#00Ch               ;  Turn the Display On
  acall   LCDINS
  mov     A,#001h               ;  Clear the Display RAM
  acall   LCDINS
  mov     A,#006h               ;  Set the Entry Mode
  acall   LCDINS

  mov     R1,#(DispTable-DispGetTable)	;  Point to Control Store Source String

DispLoop:			;  Loop Around Here until '0' is Loaded
  mov	 A,R1
  movc   A,@A+PC		;  Get the Table Value
DispGetTable:			;  Table Offset to Display
  jz     Loop                   ;  If Zero, then the End of the String
  acall  LCDCHAR                ;  Display the Character
  inc	 R1			;   Strings
  ajmp	 DispLoop		;  If the Value Saved wasn't Zero, Loop

DispTable:	 		;  The Control Store Table for
  db     '  Distance xxx"',0	;   Initializing 'Distance: xxx "'


Loop:                           ;  Loop Around Here, Measuring the Distance

  mov     A,#08Bh               ;  Move the LCD's Cursor to Start of "xxx"
  acall   LCDINS

  clr     P3.7                  ;  Keep the Init Pulse Low 

  acall   Dlay                  ;  Delay 200 msecs before Measuring again
  acall   Dlay

  setb    P3.7                  ;  Turn On the Init Pulse

  clr     A                     ;  Use A to Count the Inches to Echo

EchoLoop:                       ;  Wait for the Echo to Return

  acall   Dlay150               ;  Delay 148 usecs/loop

  inc     A                     ;  Increment the Count
  jz      NoEcho                ;  No Echo if Equal to Zero (256)

  jnb     P3.5,EchoLoop         ;  Anything Come Back Yet?

  mov     B,#100                ;  Figure Out the Distance
  div AB

  add     A,#'0'                ;  Print Out the 100s
  acall   LCDCHAR

  mov     A,B                   ;  Now, Figure Out the 10s
  mov     B,#10

  div AB

  add     A,#'0'                ;  Print out the 10s
  acall   LCDCHAR

  mov     A,B                   ;  Print out the 1s
  add     A,#'0'
  acall   LCDCHAR

  clr     P3.7                  ;  Turn Off the Pulse

  ajmp    Loop

NoEcho:                         ;  No Echo Found, Print "XXX"

  mov     A,#'X'
  acall   LCDCHAR
  mov     A,#'X'
  acall   LCDCHAR
  mov     A,#'X'
  acall   LCDCHAR

  clr     P3.7                  ;  Turn Off the Pulse

  ajmp    Loop


Dlay:                           ;  Delay 100 msecs

  mov     Count,#0              ;  Load the 100 msec Delay
  mov     Counthi,#$40

DlayLoop:                       ;  Loop Here for 100 msec
  djnz    Count,DlayLoop
  djnz    Counthi,DlayLoop

  ret

Dlay150:                        ;  150 usec Dlay

  mov     Count,#19             ;  Delay 116 usecs

Dlay150Loop:

  djnz    Count,Dlay150Loop

  ret


LCDNybble:                      ;  Display the Nybble

  mov     P1,A                  ;  Output the Value

  setb    P1.2                  ;  Toggle the "E" Clock
  clr     P1.2

  ret

LCDINS:                         ;  Output the LCD Command

  push    ACC                   ;  Save the ACC Command

  anl     A,#0F0h               ;  Clear the Bottom 4 Bits

  acall   LCDNybble             ;  Output the Value

  pop     ACC                   ;  Retrieve Character for Outputting
  push    ACC                   ;  Save Again for the Delay

  swap    A                     ;  Reverse the Bit Direction

  anl     A,#0F0h

  acall   LCDNybble

  acall   Dlay150

  pop     ACC                   ;  Now, Check for a Long Character

  anl     A,#0FCh               ;  Clear the Bottom Two Bits
  jnz     LCDINS_End            ;  If Not Zero, Then Not a Long Delay

  acall   Dlay

LCDINS_End:                     ;  Return to Caller

  ret

LCDCHAR:                        ;  Output the LCD Command

  push    ACC                   ;  Save the ACC Command

  anl     A,#0F0h               ;  Clear the Bottom 4 Bits
  orl     A,#008h               ;  Set the R/S Bit

  acall   LCDNybble             ;  Output the Value

  pop     ACC                   ;  Retrieve Character for Outputting

  swap    A                     ;  Reverse the Bit Direction

  anl     A,#0F0h
  orl     A,#008h

  acall   LCDNybble

  acall   Dlay150

  ret

⌨️ 快捷键说明

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