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

📄 prog47g.asm

📁 主要是8051源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
  cjne    R0,#0,Right_DTE       ;  DCE Requested

  clr     RightDCE               ;  DCE Specified

  ajmp    Finished_DTECheck

Right_DTE:

  setb    RightDCE              ;  DTE Specified
  
Finished_DTECheck:

  ret


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      ' 300 1200 Cont',0    ;  Message  5
  db      'Speed |',0           ;  Message  6
  db      ' 2400 9600 Cont', 0  ;  Message  7
  db      'Port Type',0         ;  Message  8
  db      ' DCE DTE',0          ;  Message  9
  db      'Modem Ctrl',0        ;  Message 10
  db      ' Enble Pass None',0  ;  Message 11
  db      'Display',0           ;  Message 12
  db      ' String Byte/Bit',0  ;  Message 13
  db      07Eh,'               ',0  ;  Message 14 - Point to Incoming Data
  db      '               ',07Fh,0  ;  Message 15 - Point to Incoming Data


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     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

  mov     A,R4
  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 + -