Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;********************************************************************                                         *
  2. ;*                                                                  *
  3. ;* This program illustrates how to use the I/O functionality        *
  4. ;* It has 3 Subroutines which use different input devices to output *
  5. ;* in different locations. each subroutine is explained below.      *
  6. ;*                                                                  *
  7. ;* Author: Scott Goddard 500723518                                  *
  8. ;********************************************************************
  9.  
  10. ; export symbols
  11.  XDEF Entry, _Startup ; export ‘Entry’ symbol
  12.  ABSENTRY Entry ; for absolute assembly: mark
  13. ; this as applicat. entry point
  14. ; Include derivative-specific definitions
  15.  INCLUDE 'derivative.inc'
  16.  
  17.  
  18. ROMStart    EQU  $4000  ; absolute address to place my code/constant data
  19.  
  20. ; variable/data section
  21.  
  22.             ORG RAMStart  
  23. ; Insert here your data definition.
  24. Counter     DS.W 1
  25. FiboRes     DS.W 1
  26.  
  27. ;*******************************************************************
  28. ;* Writing to the LCD                                              *
  29. ;*******************************************************************
  30. ; Definitions
  31. LCD_DAT   EQU PTS   ; LCD data port S, pins PS7,PS6,PS5,PS4
  32. LCD_CNTR  EQU PORTE ; LCD control port E, pins PE7(RS),PE4(E)
  33. LCD_E     EQU $10   ; LCD enable signal, pin PE4
  34. LCD_RS    EQU $80   ; LCD reset signal, pin PE7
  35.  
  36.           ORG   $3000
  37.  
  38. var1 FCB $AB
  39. var2 FCB $CD            
  40. mem1 RMB 1
  41. mem2 RMB 1
  42. mem3 RMB 1  
  43. mem4 RMB 1  
  44. mem5 RMB 1
  45.  
  46.  
  47. ; code section
  48.           ORG $4000
  49. Entry:
  50. _Startup:
  51.           LDS #$4000  ; initialize stack pointer
  52.           JSR initLCD ; initialize LCD
  53. ;*******************************************************************
  54. ;* Program starts here                                             *
  55. ;*******************************************************************
  56. MainLoop  JSR clrLCD      ; clear LCD & home cursor
  57.  
  58.           LDX #msg1         ; display msg1
  59.           JSR putsLCD     ; -"-
  60.          
  61.           LDAA $3000 ; load contents at $3000 into A
  62.           JSR leftHLF ; convert left half of A into ASCII
  63.           STAA mem1 ; store the ASCII byte into mem1
  64.          
  65.           LDAA $3000 ; load contents at $3000 into A
  66.           JSR rightHLF ; convert right half of A into ASCII
  67.           STAA mem2 ; store the ASCII byte into mem2
  68.          
  69.           LDAA $3001 ; load contents at $3001 into A
  70.           JSR leftHLF ; convert left half of A into ASCII
  71.           STAA mem3 ; store the ASCII byte into mem3
  72.          
  73.           LDAA $3001 ; load contents at $3001 into A
  74.           JSR rightHLF ; convert right half of A into ASCII
  75.           STAA mem4 ; store the ASCII byte into mem4
  76.          
  77.           LDAA #$00 ; load 0 into A
  78.           STAA mem5 ; store string termination character 00 into mem5
  79.          
  80.           LDX #mem1 ; output the 4 ASCII characters
  81.           JSR putsLCD ; -"-
  82.          
  83.           LDY #$4E20 ; Delay = 1s  (20000 * 50*10e-6 = 1)
  84.           JSR del_50us
  85.           BRA MainLoop ; Loop
  86.          
  87. msg1      dc.b "Testing many characters???? ",0
  88.  
  89. ;subroutine section
  90. ;*******************************************************************
  91. ;* Initialization of the LCD: 4-bit data width, 2-line display,    *
  92. ;* turn on display, cursor and blinking off. Shift cursor right.   *
  93. ;*******************************************************************
  94. initLCD   BSET DDRS,%11110000 ; configure pins PS7,PS6,PS5,PS4 for output
  95.           BSET DDRE,%10010000 ; configure pins PE7,PE4 for output
  96.           LDY #2000 ; wait for LCD to be ready
  97.           JSR del_50us ; -"-
  98.           LDAA #$28 ; set 4-bit data, 2-line display
  99.           JSR cmd2LCD ; -"-
  100.           LDAA #$0C ; display on, cursor off, blinking off
  101.           JSR cmd2LCD ; -"-
  102.           LDAA #$06 ; move cursor right after entering a character
  103.           JSR cmd2LCD ; -"-
  104.           RTS
  105.          
  106. ;*******************************************************************
  107. ;* Clear display and home cursor                                   *
  108. ;*******************************************************************
  109. clrLCD    LDAA #$01 ; clear cursor and return to home position
  110.           JSR cmd2LCD ; -"-
  111.           LDY #40 ; wait until "clear cursor" command is complete
  112.           JSR del_50us ; -"-
  113.           RTS
  114.          
  115. ;*******************************************************************
  116. ;* ([Y] x 50us)-delay subroutine. E-clk=41,67ns.                   *
  117. ;*******************************************************************
  118. del_50us:   PSHX ;2 E-clk
  119. eloop:      LDX #36 ;2 E-clk -
  120. iloop:      PSHA ;2 E-clk |
  121.             PULA ;3 E-clk |
  122.            
  123.             PSHA ;2 E-clk |
  124.             PULA ;3 E-clk |
  125.             PSHA ;2 E-clk |
  126.             PULA ;3 E-clk |
  127.             PSHA ;2 E-clk |
  128.             PULA ;3 E-clk |
  129.             PSHA ;2 E-clk |
  130.             PULA ;3 E-clk |
  131.            
  132.                                
  133.             PSHA ;2 E-clk | 50us
  134.             PULA ;3 E-clk |
  135.             NOP  ;1 E-clk |
  136.             NOP  ;1 E-clk |
  137.             DBNE X,iloop ;3 E-clk -                
  138.             DBNE Y,eloop ;3 E-clk
  139.             PULX ;3 E-clk
  140.             RTS ;5 E-clk
  141.            
  142. ;*******************************************************************
  143. ;* This function sends a command in accumulator A to the LCD       *
  144. ;*******************************************************************
  145. cmd2LCD:  BCLR LCD_CNTR,LCD_RS ; select the LCD Instruction Register (IR)
  146.           JSR dataMov ; send data to IR
  147.           RTS
  148.          
  149. ;*******************************************************************
  150. ;* This function outputs a NULL-terminated string pointed to by X  *
  151. ;*******************************************************************
  152. putsLCD   LDAA 1,X+ ; get one character from the string
  153.           BEQ donePS ; reach NULL character?
  154.           JSR putcLCD
  155.           BRA putsLCD
  156.          
  157. donePS    RTS
  158.  
  159. ;*******************************************************************
  160. ;* This function outputs the character in accumulator in A to LCD  *
  161. ;*******************************************************************
  162. putcLCD   BSET LCD_CNTR,LCD_RS ; select the LCD Data register (DR)
  163.           JSR dataMov ; send data to DR
  164.           RTS
  165.          
  166. ;*******************************************************************
  167. ;* This function sends data to the LCD IR or DR depening on RS     *
  168. ;*******************************************************************
  169. dataMov   BSET LCD_CNTR,LCD_E ; pull the LCD E-sigal high
  170.           STAA LCD_DAT ; send the upper 4 bits of data to LCD
  171.           BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
  172.          
  173.           LSLA ; match the lower 4 bits with the LCD data pins
  174.           LSLA ; -"-
  175.           LSLA ; -"-
  176.           LSLA ; -"-
  177.          
  178.           BSET LCD_CNTR,LCD_E ; pull the LCD E signal high
  179.           STAA LCD_DAT ; send the lower 4 bits of data to LCD
  180.           BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
  181.          
  182.           LDY #1 ; adding this delay will complete the internal
  183.           JSR del_50us ; operation for most instructions
  184.           RTS
  185.          
  186. ;*******************************************************************
  187. ;* Binary to ASCII                                                 *
  188. ;*******************************************************************
  189. leftHLF   LSRA ; shift data to right
  190.           LSRA
  191.           LSRA
  192.           LSRA
  193.          
  194. rightHLF  ANDA #$0F ; mask top half
  195.           ADDA #$30 ; convert to ascii
  196.           CMPA #$39
  197.           BLE out ; jump if 0-9
  198.           ADDA #$07 ; convert to hex A-F
  199.          
  200. out       RTS
  201.  
  202. ;********************************************************************
  203. ;* Interrupt Vectors                                                *
  204. ;********************************************************************
  205.  
  206.         ORG   $FFFE
  207.         FDB   Entry ; Reset Vector
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement