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

📄 prog49b.asm

📁 主要是8051源代码
💻 ASM
字号:
;  Prog49B - Do Some Real Video Output  
;
;
;  This Program Will Write Some Characters on the Screen.  
;  
;  To get the Correct Voltage Levels:
;   0.00 Volts (Synch/"Blacker than Black")
;   0.35 Volts (Synch)
;   0.43 Volts (Black)
;   0.87 Volts (White)
;
;  Myke Predko
;  98.07.02
;
;  Hardware Notes:
;  DS87C520 is used as the Microcontroller
;   - Oscillator Speed is 11.0592 MHz
;  P0.0 is Used for "Synch" Select
;  P0.1 is Used for "Blank" Select
;  P0.2 is Used for "Black" Select  


;  Constant Declarations
Zero    EQU 0FEh                ;  Zero Volts Output Using P0
Synch   EQU 0FBh                ;  Synch Voltage
Black   EQU 0FDh                ;  Black Level
White   EQU 0FFh                ;  White on the Screen

;  Variable Declarations
Flags   EQU 020h                ;  Bit Flags
Odd     EQU   0                 ;   - Bit 0, When Set, the "Odd" Field
NewLine EQU   1                 ;   - Bit 1, When Set, Increment the Display Line

Buffer EQU 080h                 ;  16 Character Message Buffer 


;  Macros


;  Mainline
 org 0                          ;  Execution Starts Here

  clr     Odd                   ;  Start on an "Even" Field

  clr     NewLine               ;  Start with the 2 Line Display

  mov     R0,#0                 ;  Put in a Pattern to Look At
  mov     R1,#Buffer            ;  Start of the Buffer
  mov     R2,#4                 ;  Use R2 as the Character Counter
  mov     R3,#4                 ;  Use R3 as the Row Counter  
LoadBuffer:
  mov     A,R0
  acall   GetMsg                ;  Get the Character for the Counter
  mov     R4,A                  ;  Save the Character

  acall   FontLine0             ;  Get the Bit Pattern for Row0
  mov     @R1,A

  mov     A,R1                  ;  Move to the Next Line
  add     A,#4
  mov     R1,A
  mov     A,R4                  ;  Put in the Second Line
  acall   FontLine1
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Third Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  acall   FontLine2
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Forth Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  acall   FontLine3
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Fifth Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  acall   FontLine4
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Sixth Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  acall   FontLine5
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Seventh Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  acall   FontLine6
  mov     @R1,A

  mov     A,R1                  ;  Move and Save on the the Eigth Line
  add     A,#4
  mov     R1,A
  mov     A,R4
  lcall   FontLine7
  mov     @R1,A

  mov     A,R1                  ;  Reset the Counter
  clr     C
  subb    A,#(4 * 7)            ;  Go back to the First Address
  inc     A                     ;  Go to the Next Character
  mov     R1,A

  inc     R0                    ;  Do the Next Character

  djnz    R2,LoadBuffer

  mov     A,R1                  ;  Point to the Next Row Character
  add     A,#(4 * 7)
  mov     R1,A

  mov     R2,#4                 ;  Do 4x

  djnz    R3,LoadBuffer

  mov     P0,#Zero              ;  3 - Put in the First Synch Pulse

  ajmp    FieldStart            ;  3

FieldStart:                     ;  Come Here with the Last Backporch (13 Cycles)

  mov     P0,#Synch             ;  3 - Back Up to Synch

  mov     C,Odd                 ;  2 - Get the "Odd" Bit
  mov     A,#5                  ;  2 - Get the Number of Pre Synch Half Lines Remaining
  addc    A,#0                  ;  2 - Add the Carry to the Number
  mov     R4,A                  ;  1 - R4 Contains the Leading Number of Cycles

  mov     R3,#6                 ;  2 - Get the Number of Synch Cycles

  mov     C,Odd                 ;  2 
  mov     A,#6                  ;  2 - Get the Number of Post Synch Half Lines
  subb    A,#0                  ;  2
  mov     R5,A                  ;  1 - R5 Contains the Number of Post Synch Cycles
  
  mov     C,Odd                 ;  2
  mov     A,#10                 ;  2 - Get the Number of Post Synch Full Lines
  addc    A,#0                  ;  2
  mov     R6,A                  ;  1 - R6 Contains the Number of Post Synch Cycles

  mov     R7,#243               ;  2 - Number of Lines to Display

  cpl     Odd                   ;  2 - Change Odd to Even and vica versa

  mov     R0,#16                ;  2 - Delay 52 Cycles Before Doing the Vertical Sych
V_Loop:
  djnz    R0,V_Loop             ;  3
  nop                           ;  1
  nop                           ;  1

V1_Loop:                        ;      Do Remaining Cycles

  mov     P0,#Zero              ;  3 - Synch Low for 6 Cycles
  nop                           ;  1
  nop                           ;  1
  nop                           ;  1
  mov     P0,#Synch             ;  3 - Synch High

  mov     R0,#24                ;  2 - Now Delay 74 Cycles to get 88 Cycles for H-Line 
V1_Loop1:
  djnz    R0,V1_Loop1           ;  3   
  nop                           ;  1
  nop                           ;  1

  djnz    R4,V1_Loop            ;  3 - Do Another Synch?    

V2_Loop:
 
  mov     P0,#Zero              ;  3 - Output Zero Voltage for 76 Instruction Cycles

  mov     R1,#23                ;  2 - Delay the 76 Cycles
V2_Loop1:
  djnz    R1,V2_Loop1           ;  3
  nop                           ;  1 
  nop                           ;  1

  mov     P0,#Synch             ;  3 - Now, Output the Synch Pulse

  mov     R1,#1                 ;  2 - Delay 12 Cycles
V2_Loop2:
  djnz    R1,V2_Loop2           ;  3
  nop                           ;  1

  djnz    R3,V2_Loop            ;  3 - Do the Next Vertical Synch Pulse?

V3_Loop:                        ;      Do the Post 1/2 Cycles

  mov     P0,#Zero              ;  3 - Synch Low for 6 Cycles
  nop                           ;  1
  nop                           ;  1
  nop                           ;  1
  mov     P0,#Synch             ;  3 - Synch High

  mov     R0,#24                ;  2 - Now Delay 74 Cycles to get 88 Cycles for H-Line 
V3_Loop1:
  djnz    R0,V3_Loop1           ;  3   
  nop                           ;  1
  nop                           ;  1

  djnz    R5,V3_Loop            ;  3 - Do Another Synch?    

V4_Loop:                        ;      Do the Post Full Cycles

  mov     P0,#Zero              ;  3 - Synch Low for 6 Cycles

  mov     R1,#2                 ;  2 - Delay 12 Cycles
V4_Loop1:
  djnz    R1,V4_Loop1           ;  3
  nop                           ;  1

  mov     P0,#Synch             ;  3 - Synch High

  mov     R0,#52                ;  2 - Delay 52 Cycles
V4_Loop2:
  djnz    R0,V4_Loop2           ;  3   

  djnz    R6,V4_Loop            ;  3 - Do Another Synch?


  mov     P0,#Zero              ;  3 - Start the Next Horizontal Pulse

  ajmp    DataField             ;  3 - Match Other Synchs


DF_NoDisp1:                     ;  7 - Delay for 5 Cycles

  nop                           ;  1
  nop                           ;  1

  ajmp    DF_NoDisp             ;  3

DF_NoDisp:                      ; 12 - Delay for 123 Cycles

  mov     R1,#Buffer            ;  2

  mov     R0,#38                ;  2 - Delay the Remaining 119 Cycles
DF_NoDispLoop:
  djnz    R0,DF_NoDispLoop      ;  3
  nop                           ;  1
  nop                           ;  1

  ajmp    LineDone              ;  3 


DataField:                      ;  Now, Output the Data

;  NOTE: The Backporch is at the End of each Data Line  

  mov     R0,#1                 ;  2 - Delay 13 Cycles for the Synch Pulse
DF_Loop1:
  djnz    R0,DF_Loop1           ;  3
  nop                           ;  1
  nop                           ;  1

  mov     P0,#Synch             ;  3 - Delay 13 Cycles for the Back Porch

  mov     R0,#2                 ;  2
DF_Loop2:
  djnz    R0,DF_Loop2           ;  3
  nop                           ;  1
  nop                           ;  1

  mov     P0,#Black             ;  3 - Now, Display the Data

;  #### - Display Information Below - 135 Cycles

  mov     A,R7                  ;  1 - Are we Above the Display Area for the Screen?
  clr     C                     ;  1
  subb    A,#060h               ;  2
  jc      DF_NoDisp1            ;  3 - If Carry Set, Below the Bottom

  subb    A,#040h               ;  2 
  jnc     DF_NoDisp             ;  3 - If Carry NOT Set, Above the Top

DF_Disp:                        ;      Display the Current Line in 118 Cycles

  mov     A,@R1                 ;  1 - Get the Byte to Display
  rlc A                         ;  1 - Output the MSB
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 6
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 5
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 4
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 3
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 2
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 1
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 0
  mov     P0.1,C                ;  2
  inc     R1                    ;  1 
  clr     P0.1                  ;  2 - Output a Black

  mov     A,@R1                 ;  1 - Get the Byte to Display
  rlc A                         ;  1 - Output the MSB
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 6
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 5
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 4
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 3
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 2
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 1
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 0
  mov     P0.1,C                ;  2
  inc     R1                    ;  1
  clr     P0.1                  ;  2 - Output a Black

  mov     A,@R1                 ;  1 - Get the Byte to Display
  rlc A                         ;  1 - Output the MSB
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 6
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 5
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 4
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 3
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 2
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 1
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 0
  mov     P0.1,C                ;  2
  inc     R1                    ;  1 - Point to the Next Character
  clr     P0.1                  ;  2 - Output a Black

  mov     A,@R1                 ;  1 - Get the Byte to Display
  rlc A                         ;  1 - Output the MSB
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 6
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 5
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 4
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 3
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 2
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 1
  mov     P0.1,C                ;  2
  rlc A                         ;  1 - Output Bit 0
  mov     P0.1,C                ;  2
  inc     R1                    ;  1 - Point to the Next Character
  clr     P0.1                  ;  2 - Output a Black

  cpl     NewLine               ;  2 - Do we Reset R1?

  jnb     NewLine,DF_Skip       ;  4 - If Originally Set, then "Yes"

  mov     A,R1                  ;  1 - Subtract 4 to do the Next Line
  clr     C                     ;  1
  subb    A,#4                  ;  2
  mov     R1,A                  ;  1

;  #### - Display Information Above - 135 Cycles

LineDone:

  mov     P0,#Black             ;  3

  dec     R7                    ;  1 - Display another Line?  
  mov     A,R7                  ;  1 - See if Decrement == 0
  jz      DF_NewField           ;  3 - If Zero, Display a New Field

  mov     P0,#Synch             ;  3 - Else, Output the Front Porch
  nop                           ;  1 -  Front Porch is 4 Cycles Long

  mov     P0,#Zero              ;  3 - Start the Synch Pulse
  
  ajmp    DataField             ;  3 - Display the Next Loop

DF_NewField:                    ;      Have to Start a New Field

  mov     P0,#Synch             ;  3
  nop                           ;  1

  mov     P0,#Zero              ;  3 - Start the Synch Pulses Again

  ajmp    FieldStart            ;  3


DF_Skip:                        ;130 - Have to Delay 5 Cycles

  nop                           ;  1
  nop                           ;  1

  ajmp    LineDone              ;  3


;  Message to be Displayed on the TV Screen
GetMsg:

  inc     A                     ;  Return the Character for the Offset in "A"

  movc A,@A+PC

  ret

  db      'How '                ;  It's a Very Simple, Four Line Message
  db      'are '
  db      'you '
  db      'Myke'

;  Font Information Follows

$include font.inc

⌨️ 快捷键说明

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