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

📄 prog47f.asm

📁 主要是8051源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;  PROG47F - Working through the Electronic Breakout Box  
;
;
;  Start Taking User Input.  
;
;  PROG47F - Get and Set the Data Rate.  This is Just a Simulator exercise. 
;
;  PROG47E1 - Put in PROG47E Code, But Look for Problems - Found with the 
;              Mix-Up in Registers, the 5 msec delay wasn't executed with the 
;              change in the registers.  
;
;  PROG47D - Read (and Debounce) the Button
;
;  PROG47C - Output a Table and Save the Blank Positions in R5, R6 and R7 
;
;  Myke Predko
;  98.06.22
;
;  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

  mov    CKCON,#%00000000       ;  Use Internal /12 Clock for Timer1 (Serial Port Clocks)
  mov    TMOD,#%00100000        ;  Timer1 - Uses Internal Clock
                                ;         - Run in Mode 2
  mov    TL1,#253               ;  Start Timer1 at 9600 bps
  mov    TH1,#253
  mov    TCON,#%01000000        ;  Start Timer1 running

  mov    SCON,#%01010000        ;  Run Serial Port 0 in 8 Bit Mode
  mov    SCON1,#%01010000       ;  Run Serial Port 1 in 8 Bit Mode


  acall   LCDInit               ;  Initialize the LCD

Loop:                           ;  Loop Here for Each One

  acall   DTECheck

GetSpeed:                       ;  Get and Set the Speed

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

  mov     A,#4                  ;  Put in the "Speed -"" Message
  acall   MsgSend

  clr     RS                    ;  Put in the Lower Line
  mov     A,#0C0h
  acall   CharSend
  mov     A,#5                  ;  Display The "300/1200/Cont" Message
  acall   MsgSend               ;  Output the Message

  acall   MenuRead              ;  Get the "Speed -" Information

  mov     A,R0                  ;  Do we have 300 bps?
  xrl     A,R5
  jnz     Check1200             ;  No, Check 1200 bps

  mov     TL1,#160              ;  Load the 300 bps Delay
  mov     TH1,#160

  ajmp    GetSpeed_End

Check1200:                      ;  Do we have 1200 bps Selected?
  mov     A,R0
  xrl     A,R6
  jnz     GetSpeed_2nd          ;  No, Do the Next Menu

  mov     TL1,#232              ;  Load the 1200 bps Delay
  mov     TH1,#232

  ajmp    GetSpeed_End

GEtSpeed_2nd:                   ;  Check the Other Display

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

  mov     A,#6                  ;  Put in the "Speed |"" Message
  acall   MsgSend

  clr     RS                    ;  Put in the Lower Line
  mov     A,#0C0h
  acall   CharSend
  mov     A,#7                  ;  Display The "2400/9600/Cont" Message
  acall   MsgSend               ;  Output the Message

  acall   MenuRead              ;  Get the "Speed -" Information

  mov     A,R0                  ;  Do we have 2400 bps?
  xrl     A,R5
  jnz     Check9600             ;  No, Check 9600 bps

  mov     TL1,#244              ;  Load the 2400 bps Delay
  mov     TH1,#244

  ajmp    GetSpeed_End

Check9600:                      ;  Do we have 9600 bps Selected?
  mov     A,R0
  xrl     A,R6
  jnz     GetSpeed              ;  No, Jump to the First Menu

  mov     TL1,#253              ;  Load the 9600 bps Delay
  mov     TH1,#253

GetSpeed_End:                   ;  Finished, Return to the Caller

;  #### - Put in the Different Breakout Box Operations

  mov     SBUF0,#'A'           ;  Output a Character
  mov     SBUF1,#'B'           ;  Output a Character

  ajmp    Loop


;  Subroutines
DTECheck:

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

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

  clr     RS                    ;  Put in the Lower Line
  mov     A,#0C0h
  acall   CharSend
  mov     A,#9                  ;  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,#8                  ;  Put in the "Port Type" Message
  acall   MsgSend

  clr     RS                    ;  Put in the Lower Line
  mov     A,#0C0h
  acall   CharSend
  mov     A,#9                  ;  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:

  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

⌨️ 快捷键说明

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