home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tcom96 / samples / lcdt.seq < prev    next >
Encoding:
Text File  |  1991-04-15  |  10.2 KB  |  337 lines

  1. \\ LCDT.SEQ     8096 code for LCD driver etc.           by Mike Mayo
  2.  
  3. This is a sample program showing how to use TCOM96, which is an 8096
  4. Forth target compiler adapted from Tom Zimmer's TCOM for 8086.
  5.  
  6. This program has been developed and tested using the Intel 80c196KB chip.
  7. The hardware environment includes 64K bytes of static RAM, two 8K byte
  8. EEPROM's, a 16L8 PAL for address decode, and a Maxim MAX232 chip for
  9. connecting the 80c196's serial port to a COM port of a PC.
  10.  
  11. $Header:   F:/tcom/sampl96/logs/lcdt.sev   1.6   12 Dec 1990 13:45:52   MikeM  $
  12. $Log:   F:/tcom/sampl96/logs/lcdt.sev  $
  13. \    Rev 1.6   12 Dec 1990 13:45:52   MikeM
  14. \    Rev 1.3   18 Sep 1990 12:08:12   MikeM
  15. \ Released to Tom Zimmer
  16.  
  17. {
  18.  
  19. $2000 cseg intvec2000
  20. $2014 cseg eprom-PPW
  21. $2018 cseg bus-config
  22. $2020 cseg null-table-jmp
  23. $2030 cseg intvec2030
  24. $2080 cseg initial-cseg
  25.  
  26. $0C0 CONSTANT PSP0
  27. $100 CONSTANT RP0
  28.  
  29. $F800 constant     DREG \ display register
  30. $200  constant     DBUF \ display data buffer
  31.                                         \ ( 120 bytes per row )
  32.                                         \ ( 7680 bytes in all )
  33.  
  34. registers       \ by default this starts at $24
  35.  
  36. 2variable       DPOINT          \ pointers and counters
  37. variable        DCOUNT          \ for display block move
  38. variable        ROW_COUNTER
  39.  
  40. variable        SP_FLAGS        \ serial port status image
  41.  
  42. variable        tlcdx           \ display output stuff
  43. variable        tlcdy
  44. variable        tcolor
  45.  
  46. variable        tach_sample     \ sample timer2 in here
  47. variable        tach_counter    \ count LCD interrupts for sampling timer2
  48. variable        old_tach        \ previous tach value
  49.  
  50.  
  51. 11 constant SFT_T3              \ HSO command to Start timer 3
  52. $E0 constant    LOAD_TVAL       \ For 50Hz frame rate
  53. 37 constant     TACH_COUNT      \ Frame count for tach samples
  54.  
  55. 64 constant     ROWS
  56. 60 constant     ROW_WORDS
  57.  
  58.  
  59. long_branch
  60. long_library
  61.  
  62. initial-cseg    \ reset entry point
  63.  
  64. : start-here            \ two possible entry points
  65.         start-from-ee   \ $2080 for RESET
  66.         startup         \ $2083 for downloaded code
  67.         ;
  68.  
  69. fload spcode.seq
  70. fload dispcode.seq
  71. fload spcmds.seq
  72.  
  73. code TRAP_INT    \ debugger's TRAP instruction gets us here
  74.         PUSHF
  75.         PUSH    PSP
  76.         PUSH    TTOS
  77.         PUSH    TTOS2
  78.         PUSH    W0
  79.         PUSH    W2
  80.         LD      W0 SP
  81.         CALL    SEND_WORDL
  82.  
  83.         BEGIN   CALL SP_POLL_L   AGAIN   \ now wait for host to do something
  84.         end-code
  85.  
  86. \ Items on stack....
  87. \       Address following the TRAP instruction
  88. \       Machine Flags
  89. \       PSP
  90. \       TTOS
  91. \       TTOS2
  92. \       W0
  93. \       W2
  94. \       Return address into TRAP_INT from SP_POLL
  95.  
  96. CODE UNTRAP  \ debugger's return from a TRAP
  97.         \ discard the return address into TRAP_INT after CALL SP_POLL
  98.         ADD     SP # 2
  99.         \ restore registers saved after the TRAP
  100.         POP     W2
  101.         POP     W0
  102.         POP     TTOS2
  103.         POP     TTOS
  104.         POP     PSP
  105.         POPF
  106.         RET             \ debugger will have modified this return address
  107.         end-code
  108.  
  109.  
  110. code copy-to-EE ( s d n -- f ) \ copy n bytes from s to d in EEPROM
  111.                                \ Make sure that n is less than 32
  112.                                \ and that it will not cross 32-byte
  113.                                \ boundaries in the EEPROM
  114.  
  115.         LDB     TTOS2  TTOS     \ byte count
  116.         LOAD_TTOS               \ address to write to
  117.         LD      W2  TTOS
  118.         LOAD_TTOS               \ source address
  119. 1 $:
  120.         LDB     W0  []+ TTOS    \ get a byte of data to write
  121.         STB     W0  []+ W2      \ write the byte
  122.         DJNZ    TTOS2 1 $
  123.  
  124.         DEC     W2              \ point to last byte written
  125.         LD      TTOS  0
  126. 2 $:
  127.         CMPB    W0  [] W2       \ check to see if it is done
  128.         JE      3 $
  129.         DEC     TTOS
  130.         JNE     2 $             \ $10000 loop timeout
  131. 3 $:
  132.         RET             \ return loop couter on stack
  133.                         \ It is =0 if timed out
  134.         end-code
  135.  
  136. : copy-boot-to-EE ( source dest -- ) \ copy RAM to boot EEPROM
  137.         $2000
  138.         0 do    over c@ over c!
  139.                 begin   over c@  over c@
  140.                         - 0= until
  141.                 1 + swap 1 + swap
  142.                 loop
  143.         drop drop
  144.         0 sp_send
  145.         $2000 $8000
  146.         $2000
  147.         0 do    over c@  over c@
  148.                 - 0= if else leave then
  149.                 1 + swap 1 + swap
  150.                 loop
  151.         drop
  152.         dup $100 / sp_send
  153.         sp_send
  154.         ;
  155. : copy-boot-to-EE1 ( -- ) \ copy RAM to boot EEPROM1
  156.         $2000 $8000
  157.         copy-boot-to-EE
  158.         ;
  159. : copy-boot-to-EE2 ( -- ) \ copy RAM to boot EEPROM2
  160.         $2000 $A000
  161.         copy-boot-to-EE
  162.         ;
  163.  
  164. code set-hso ( n -- ) \ set bits n in the HSO
  165.         LDB     W0  IOS0
  166.         LDB     WSR  # 15
  167.         ORB     W0  # TTOS
  168.         LDB     IOS0  W0
  169.         LDB     WSR  0
  170.         LOAD_TTOS
  171.         ret
  172.         end-code
  173.  
  174. code clear-hso ( n -- ) \ reset bits n in the HSO
  175.         NOTB    TTOS
  176.         LDB     W0  IOS0
  177.         LDB     WSR  # 15
  178.         ANDB    W0  # TTOS
  179.         LDB     IOS0  W0
  180.         LDB     WSR  0
  181.         LOAD_TTOS
  182.         ret
  183.         end-code
  184.  
  185. code TIME_INT  \ timer interrupt service for refreshing a LCD panel.
  186.         PUSHF
  187.         LDB     DPOINT 2+  IOS1
  188.         LDB     HSO_COMMAND  # SFT_T3 $10 +     \ restart the timer
  189.         ADD     HSO_TIME  <--  TIMER1  # LOAD_TVAL
  190.                                 \ Set up the count for the timer
  191.  
  192.         ORB     IOPORT1  # 1            \ set LOAD
  193.         ANDB    IOPORT1  # $0FE         \ clear LOAD
  194.         ANDB    IOPORT1  # $0FD         \ clear FRAME
  195.  
  196.         LD      DPOINT 2+  # DREG
  197.         BMOV    DPOINT  DCOUNT          \ send one row of display data
  198.  
  199.         DEC0= ROW_COUNTER IF
  200.           XORB    IOPORT1  # 4             \ flip DF
  201.           ORB     IOPORT1  # 2             \ set FRAME
  202.           LDB     ROW_COUNTER  # ROWS      \ Loop count for all rows
  203.           LD      DPOINT  # DBUF           \ Point to start of display buffer
  204.           DEC0= TACH_COUNTER IF
  205.                                 \ sample timer2 every so often.
  206.                                 \ It will be counting pulses from a tachometer.
  207.             LD      TACH_SAMPLE TIMER2          \ Get tach count
  208.             CLR     TIMER2                      \ Reset counter
  209.             LDB     TACH_COUNTER  # TACH_COUNT  \ Loop count for
  210.                                                 \  displaying tach*20
  211.           THEN
  212.         THEN
  213.  
  214.         POPF
  215. END-CODE code NULL_INT
  216.         RET     end-code
  217.  
  218.  
  219. CODE START-FROM-EE      \ entry point when booting from EEPROM
  220.         DI
  221.         LD      W2     # $2000  \ source
  222.         LD      TTOS   # $A000  \ destination           \ copy to RAM
  223.         LD      TTOS2  # $1000  \ count
  224. 1 $:
  225.         LD      W0  []+ W2      \ move words from EE to RAM
  226.         ST      W0  []+ TTOS
  227.         DEC     TTOS2
  228.         JNE     1 $
  229.  
  230.         LDB     W0  IOS0
  231.         LDB     WSR  # 15
  232.         OR      W0  # 8
  233.         LDB     IOS0  W0        \ switch to running in RAM
  234.         LDB     WSR  0
  235.         end-code
  236.  
  237. CODE STARTup            \ entry point when downloaded
  238.         DI
  239.         LD      SP # RP0        \ Initialize the return stack.
  240.         LD      PSP # PSP0      \ Initialise the parameter stack.
  241.  
  242.         LDB     IOPORT1  # 2            \ set FRAME
  243.         LDB     ROW_COUNTER  # ROWS     \ Loop count for all rows
  244.         LD      DPOINT  # DBUF          \ Point to start of display buffer
  245.         LD      DCOUNT  # ROW_WORDS     \ words per display row
  246.  
  247.         LDB     IOC2   # $80            \ clear the CAM
  248.         LDB     INT_PEND   0            \ clear pending interrupts
  249.         LDB     INT_PEND1  0
  250.         LDB     HSO_COMMAND  # SFT_T3 $10 +
  251.         ADD     HSO_TIME  <-- TIMER1  # LOAD_TVAL \ Set up the count for the timer
  252.         LDB     INT_MASK  # $20
  253.  
  254.         LDB     IOC0  # 0
  255.         EI
  256.         end-code            \ This must be immediately followed by MAIN
  257. : MAIN                      \ MAIN must be immediately preceded by STARTup
  258.         SP_INIT
  259.         'S' sp_send
  260.         BEGIN
  261.                 SP_POLL
  262.                 ROW_WORDS DCOUNT !
  263.                 dotach
  264.                 AGAIN
  265.         ;
  266.  
  267.  
  268. : showtach
  269.         10 10 at    \ 4 .r
  270.         dup 1000 / dup '0' + l-emit  1000 * -
  271.         dup 100  / dup '0' + l-emit  100 * -
  272.         dup 10   / dup '0' + l-emit  10 * -
  273.                        '0' + l-emit
  274.         ;
  275.  
  276. : dotach  \ display the tachometer measurement
  277.         tach_sample @ 1+ 0=
  278.         not if  tach_sample c@ 20 *
  279.                 dup old_tach - abs      \ put in some hysteresis to
  280.                                         \ stabilise the display
  281.                 3 - 0< if  showtach  else  drop  then
  282.                 -1 tach_sample !
  283.         then
  284.         ;
  285.  
  286. : TEST
  287.         256 0 DO  I SP_SEND  LOOP ;
  288.  
  289.  
  290. intvec2000         \ interrupt vectors
  291. code TBL@2000
  292.         NULL_INT ,      \ Timer overflow interrupt.
  293.         NULL_INT ,      \ A/D Conversion complete interrupt.
  294.         NULL_INT ,      \ HSI Data available.
  295.         NULL_INT ,      \ HSO interrupt
  296.         NULL_INT ,      \ HSI.0 pin
  297.         TIME_INT ,      \ Software timers.
  298.         NULL_INT ,      \ Serial port.
  299.         NULL_INT ,      \ Extint.
  300.         TRAP_INT ,      \ Trap instruction
  301.         NULL_INT ,      \ Unimplemented opcode
  302. END-CODE
  303.  
  304. intvec2030         \ interrupt vectors
  305. code TBL@2030
  306.         NULL_INT ,      \ Transmit interrupt.
  307.         NULL_INT ,      \ Receive interrupt.
  308.         NULL_INT ,      \ 4th entry into HSO FIFO
  309.         NULL_INT ,      \ TIMER2 capture
  310.         NULL_INT ,      \ TIMER2 overflow
  311.         NULL_INT ,      \ Extint pin
  312.         NULL_INT ,      \ HSI FIFO full
  313.         $2080 ,         \ NMI
  314. END-CODE
  315.  
  316. eprom-PPW
  317. code eBUS_CONFG
  318.         $096 C,         \ Programming Pulse Width for 87c196
  319. END-CODE
  320.  
  321. bus-config
  322. code BUS_CONFG
  323.         $0DF C,         \ Bus configuration word
  324. END-CODE
  325.  
  326. null-table-jmp
  327. code TBL@2020
  328.         SJMP $2080      \ Just in case a jump table has blanks in it
  329. END-CODE                \ we can reinitialise from here.
  330.  
  331.  
  332. end-cseg
  333.  
  334.  
  335.