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

📄 prog47e.asm

📁 主要是8051源代码
💻 ASM
字号:
;  PROG47E - Working through the Electronic Breakout Box  
;
;
;  Working on the RS-232 Interface.  
;
;  PROG47E - Check I/O Capabilities
;
;  PROG47D - Read (and Debounce) the Button
;
;  PROG47C - Output a Table and Save the Blank Positions in R5, R6 and R7 
;
;  Myke Predko
;  98.06.20
;
;  Hardware Notes:
;  DS87C520 is used as the Microcontroller
;   - Oscillator Speed is 11.052 MHz
;  P2.4-7 are the LCD Data Bits (NOTE: Bits Are Reversed)
;  P0.3 is Pulled up with a 4.7L K resistor and used for the LCD "RS" Bit
;  P0.4 is Pulled up with a 4.7K Resistor and used for the LCD "E" Bit
;  P2.0 is Used as the "Select" Button
;  P2.1 is Used as the "Enter" Button
;
;  P2.2 is Used as Left _DTE/DCE Control
;  P2.3 is Used as the Right _DTE/DCE Control

;  Constant Declarations
;define RS=P0.3                  ;  Define the LCD "RS" Bit
;define EStrobe=P0.4             ;  Define the LCD "E" Bit

;define Select=P2.0              ;  Define the "Select" Button
;define Enter=P2.1               ;  Define the "Enter" Button

;define LeftDCE=P2.2             ;  Define the _DTE/DCE Bits
;define RightDCE=P2.3

;  Variable Declarations
;DelayCount   EQU 030h           ;  Button Delay Count
;DelayCounthi EQU 031h


;  Macros


;  Mainline
; org 0                          ;  Execution Starts Here
;MainLine:                       ;  Mainline of the Program

;  acall   LCDInit               ;  Initialize the LCD

;Loop:                           ;  Loop Here for Each One

;  clr     RS                    ;  Clear the LCD
;  mov     A,#1
;  acall   CharSend

;  clr     A                     ;  Put in the "LEFT" Message
;  acall   MsgSend
;  mov     A,#10                 ;  Put in the "Port Type" Message
;  acall   MsgSend

;  clr     RS                    ;  Put in the Lower Line
;  mov     A,#0C0h
;  acall   CharSend
;  mov     A,#11                 ;  Display The Forth Message
;  acall   MsgSend               ;  Output the Message

;  acall   MenuRead              ;  Get the Left _DCE Information

;  cjne    R0,#0,Left_DTE        ;  DCE Requested

;  clr     LeftDCE               ;  DCE Specified

;  ajmp    Check_Right_DTE

;Left_DTE:

;  setb    LeftDCE               ;  DTE Specified
  
;Check_Right_DTE

;  clr     RS                    ;  Clear the LCD
;  mov     A,#1
;  acall   CharSend

;  mov     A,#1                  ;  Put in the "RIGHT" Message
;  acall   MsgSend
;  mov     A,#10                 ;  Put in the "Port Type" Message
;  acall   MsgSend

;  clr     RS                    ;  Put in the Lower Line
;  mov     A,#0C0h
;  acall   CharSend
;  mov     A,#11                 ;  Display The Forth Message
;  acall   MsgSend               ;  Output the Message

;  acall   MenuRead              ;  Get the Left _DCE Information

;  cjne    R0,#0,Right_DTE       ;  DCE Requested

;  clr     RightDCE               ;  DCE Specified

;  ajmp    Finished_DTECheck

;Right_DTE:

;  setb    RightDCE              ;  DTE Specified
  
;Finished_DTECheck:

;  #### - Put the Other Information Here...

;  ajmp    Loop


;  Subroutines
;MsgSend:                        ;  Send the Specified Message to the Display

;  mov     R1,A                  ;  Save the Message Number

;  mov     R0,#0                 ;  Use R0 as the Offset Counter

;MsgSend_Find:                   ;  Look for the Appropriate Message

;  mov     A,R1                  ;  Are we Now At Zero?
;  jz      MsgSend_Output        ;   If Count is Zero

;  mov     A,#LOW(MsgSendTable-MsgSendFindGet)
;  add     A,R0                  ;  Get Current Address

;  movc A,@A+PC                  ;  Get the Character in the Displays
;MsgSendFindGet:

;  inc     R0                    ;  Point to the Next Character

;  jnz     MsgSend_Find          ;  If NOT Equal to Zero,
  
;  dec     R1                    ;  It is, Decrement the Message Counter

;  ajmp    MsgSend_Find

;MsgSend_Output:                 ;  Now, Output the String to '\0'

;  mov     2,R0                  ;  Save the Start of the Message

;  mov     R5,#0FFh              ;  Set the Registers As Invalid
;  mov     R6,#0FFh
;  mov     R7,#0FFh

;  setb    RS                    ;  Make Sure Characters Are going out

;MsgSendOutput_Loop:             ;  Output Each Character in the Table to "\0"

;  mov     A,R0
;  add     A,#LOW(MsgSendTable-MsgSendOutputGet)

;  movc A,@A+PC                  ;  Read the Table
;MsgSendOutputGet:

;  inc     R0                    ;  Point to the Next Character

;  jz      MsgSendOutput_Check   ;  If at Zero, Stop the Reading

;  mov     R1,A                  ;  Save the Character
;  acall   CharSend

;  cjne    R1,#' ',MsgSendOutput_Loop

;  mov     5,R6                  ;  Save the Blank Position
;  mov     6,R7
;  mov     A,R0                  ;  Calculate the Offset
;  setb    C
;  subb    A,R2
;  mov     R7,A

;  ajmp    MsgSendOutput_Loop

;MsgSendOutput_Check:            ;  Now, Shift down the Blanks

;  mov     A,R7                  ;  Do we Have No Blanks?
;  xrl     A,#0FFh
;  jz      MsgSend_End

;MsgSendOutputCheck_Loop:        ;  May Only Have One Blank

;  cjne    R5,#0FFh,MsgSend_End  ;  Everything Shifted Down

;  mov     5,R6                  ;  Shift the Data Down Until All Blanks Saved
;  mov     6,R7
;  mov     R7,#0FFh

;  ajmp    MsgSendOutputCheck_Loop

;MsgSend_End:                    ;  Message Output and Blanks Setup

;  ret

;MsgSendTable:                   ;  Messages to be Displayed
;  db      'Left  ', 0           ;  Message  0
;  db      'Right ', 0           ;  Message  1
;  db      'BREAKOUT BOX',0      ;  Message  2
;  db      ' Run Configure',0    ;  Message  3
;  db      'Speed',0             ;  Message  4
;  db      ' 110 300 Cont',0     ;  Message  5
;  db      'Speed -',0           ;  Message  6
;  db      ' 1200 2400 Cont', 0  ;  Message  7
;  db      'Speed |',0           ;  Message  8
;  db      ' 9600 19200 Cont',0  ;  Message  9
;  db      'Port Type',0         ;  Message 10
;  db      ' DCE DTE',0          ;  Message 11
;  db      'Modem Ctrl',0        ;  Message 12
;  db      ' Enble Loop None',0  ;  Message 13
;  db      'Display',0           ;  Message 14
;  db      ' String Byte/Bit',0  ;  Message 15


;MenuRead:                       ;  Read the Output Menu

;MenuRead_Skip1:
;  mov     DelayCount,#0         ;  Load With a 20 Msec Wait
;  mov     DelayCounthi,#29
;MenuRead_Loop1:                 ;  Wait for the "Enter" Button to be Down 20 msec
;  jnb     Enter,MenuRead_Skip1  ;  If Button is Pressed (Down), Wait Again
;  djnz    DelayCount,MenuRead_Loop1       ;  4
;  djnz    DelayCounthi,MenuRead_Loop1     ;  4  

;  clr     RS                    ;  Only Sending Commands
;  mov     A,#0C0h               ;  Move the Cursor to The Start of the 2nd Line
;  acall   CharSend

;  mov     R0,#0                 ;  Start at the First Blank

;MenuRead_Loop:                  ;  Wait for the Buttons to be Pressed 

;  jb      Select,MenuRead_Skip  ;  Check if Select Pressed

;MenuRead_Skip3:
;  mov     DelayCount,#0         ;  Load With a 20 Msec Wait
;  mov     DelayCounthi,#29
;MenuRead_Loop3:                 ;  Wait for the "Enter" Button to be Down 20 msec
;  jb      Select,MenuRead_Skip3 ;  If Button is Pressed (Down), Wait Again
;  djnz    DelayCount,MenuRead_Loop3       ;  4
;  djnz    DelayCounthi,MenuRead_Loop3     ;  4  

;  mov     A,R0                  ;  Get the Current Position
;  xrl     A,R5                  ;  Are we at the First Blank?
;  jnz     MenuRead_CheckR6      ;   - No, Check Second  

;  mov     A,R6                  ;  Can we Jump to 2nd?
;  xrl     A,#0FFh
;  jz      MenuRead_NewCursor    ;  No, Jump to Itself

;  mov     0,R6                  ;  Move to the Second Position

;  ajmp    MenuRead_NewCursor

;MenuRead_CheckR6:               ;  Are We at the 2nd Value
;  mov     A,R0                  
;  xrl     A,R6
;  jnz     MenuRead_R7           ;   - No Check Third

;  mov     0,R5                  ;  Assume Can't Jump and Going to Roll

;  mov     A,R7                  ;  Can we Jump to 3rd?
;  xrl     A,#0FFh
;  jz      MenuRead_NewCursor    ;  No, Stick with 1st

;  mov     0,R7

;  ajmp    MenuRead_NewCursor

;MenuRead_R7:                    ;  Go from 3rd to First

;  mov     0,R5

;MenuRead_NewCursor:             ;  Go to the New Cursor Position

;  mov     A,R0                  ;  Move the Cursor
;  orl     A,#0C0h               ;  Set it with a Move Command
;  acall   CharSend

;MenuRead_Skip4:
;  mov     DelayCount,#0         ;  Load With a 20 Msec Wait
;  mov     DelayCounthi,#29
;MenuRead_Loop4:                 ;  Wait for "Select" Button to be Released 20 msec
;  jnb     Select,MenuRead_Skip4 ;  If Button is Pressed (Down), Wait Again
;  djnz    DelayCount,MenuRead_Loop4       ;  4
;  djnz    DelayCounthi,MenuRead_Loop4     ;  4
  
;  ajmp    MenuRead_Loop         ;  Wait for the Next Button Press

;MenuRead_Skip:                  ;  Check to See If Enter Pressed
;  jb      Enter,MenuRead_Loop

;MenuRead_Skip2:
;  mov     DelayCount,#0         ;  Load With a 20 Msec Wait
;  mov     DelayCounthi,#29
;MenuRead_Loop2:                 ;  Wait for the "Enter" Button to be Down 20 msec
;  jb      Enter,MenuRead_Skip2  ;  If Button is Pressed (Down), Wait Again
;  djnz    DelayCount,MenuRead_Loop2       ;  4
;  djnz    DelayCounthi,MenuRead_Loop2     ;  4  

;  ret


;LCDInit:                        ;  LCD Initialize Blank Offsets

;  clr     EStrobe               ;  Make Sure the "E" Line is Low

;  acall   Dlay5                 ;  Wait 30 msecs for the LCD to Power Up
;  acall   Dlay5
;  acall   Dlay5
;  acall   Dlay5
;  acall   Dlay5
;  acall   Dlay5

;  clr     RS                    ;  Sending Instructions

;  mov     P2,#0C0h              ;  Output the Reset Command
;  setb    EStrobe               ;  Try this instead of "E"?
;  clr     EStrobe

;  acall   Dlay5

;  setb    EStrobe               ;  Send the Reset Again
;  clr     EStrobe

;  acall   Dlay200               ;  Wait 200 msecs

;  setb    EStrobe               ;  Send Reset for the Last Time
;  clr     EStrobe

;  acall   Dlay200

;  mov     P2,#040h              ;  Now, Put the LCD in 4 Bit Mode
;  setb    EStrobe
;  clr     EStrobe

;  acall   Dlay200

;  mov     P2,#0F3h              ;  Make Sure All the Bits Are High - Except for 
                                ;   E and RS
;  mov     A,#028h               ;  Set the Number of Display Lines to 2
;  acall   CharSend              ;   and a 5x7 Font

;  mov     A,#008h               ;  Turn the Display Off
;  acall   CharSend

;  mov     A,#001h               ;  Clear the Display RAM
;  acall   CharSend

;  mov     A,#006h               ;  Enable Cursor Increment
;  acall   CharSend

;  mov     A,#00Eh               ;  Turn on the Display
;  acall   CharSend

;  ret


CharSend:                       ;  Send the Character in the Accumulator

  mov     B,P2                  ;  Save the Value in P2
  anl     B,#00Ch               ;  Save the _DCE/DTE Bits
  orl     B,#003h               ;  Make Sure Switches Are ALWAYS Set

  mov     R3,#8                 ;  Have to Reverse the Bits
CSLoop:                         ;  Loop Here Until R4 Has the Value Reversed
  rrc a                         ;  Shift the LSB into the Carry Flag
  xch     A,R4                  
  rlc a                         ;  Shift in the New MSB
  xch     A,R4
  djnz    R3,CSLoop             ;  Loop Around

  mov     A,R4                  ;  Save R4 for Tests

  swap a                        ;  Make Low Byte high Byte...
  anl     A,#0F0h               ;  Make Sure Nothing Else Changes
  orl     A,B
  mov     P2,A                  ;  Output the High Nybble First
  setb    EStrobe
  clr     EStrobe

  mov     A,R4                  ;  Now, Output the Low Nybble
  anl     A,#0F0h               ;  Make Sure Nothing Else Changes
  orl     A,B
  mov     P2,A
  setb    EStrobe
  clr     EStrobe

  acall   Dlay200

  jb      RS,CharSendEnd        ;  If Outputting a Character, Not a Long Instruction

  anl     A,#03Fh               ;  Are we Executing a Long Instruction?
  jnz     CharSendEnd

  acall   Dlay5                 ;  Yes, Delay 5 msec

CharSendEnd:

  ret


;Dlay200:                        ;  Use R7 to Delay 200 usecs

;  mov     R3,#192
;Dlay200Loop:
;  djnz    R3,Dlay200Loop        ;  3 Cycles

;  ret


;Dlay5:                          ;  Use R6 and R7 to Delay 5 msecs

;  mov     R3,#0
;  mov     R4,#19
;Dlay5Loop:
;  djnz    R3,Dlay5Loop          ;  3 Cycles
;  djnz    R4,Dlay5Loop          ;  3x256 + 3 = 771 Cycles

;  ret

⌨️ 快捷键说明

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