home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / aaa / 01pgm.s next >
Text File  |  1986-11-30  |  3KB  |  139 lines

  1. #m 6801
  2. # Program to check, program, and verify a 68701.
  3. # Copied from Motorola ap note AN-832.
  4. # Timing constants assume 4Mhz crystal.
  5.  
  6. # Variables for code stolen from 68701 data sheet.
  7. .=128
  8. imbeg:    .=.+2            # Start of data block.
  9. imend:    .=.+2            # End of data block.
  10. pntr:    .=.+2            # Start of EPROM area to be done.
  11. wait:    .=.+2            # Counter value.
  12.  
  13. # Startup code.
  14. .=0xb850
  15. start:
  16.     lds.i =0xff        # Initialize stack.
  17.     ldaa.i 0x7        # Initialize port 1...
  18.     staa.d p1ddr        # ...bottom 3 bits outputs...
  19.     staa.d p1        # ...all LEDs off.
  20.  
  21. # Check if EPROM has been erased properly.
  22.     ldx.i =0xf800        # Start of EPROM.
  23.     stx.d pntr        # Initialize pntr while number is handy.
  24.     ldab.i 0        # Prepare to compare.  [Why not clrb???]
  25. erase:    ldaa.x 0        # Pick up EPROM byte.
  26.     cba
  27.     bne %error1        # Branch if not zero.
  28.     cpx.i =0xffff        # Are we done?
  29.     beq %next        # Branch on done.
  30.     inx
  31.     bra %erase
  32.  
  33. # Turn on "erased" LED.
  34. next:    ldaa.i 0x6        # First LED on.
  35.     staa.d p1
  36.  
  37. # Delay a while (3.5 s) to be sure Vpp is up.
  38.     stx.d wait        # [this seems useless]
  39.     ldx.i =70        # 70 times through loop.
  40. stall1:    dex
  41.     ldd.i =0xc350        # 50 ms loop.
  42.     addd.d timer        # Relative to current timer value.
  43.     clr.e =tcsr        # Clear output-compare bit.
  44.     std.d outcmp
  45.     ldaa.i 0x40        # Now wait for bit to come high.
  46. stall2:    bita.d tcsr
  47.     beq %stall2        # Branch on bit still 0.
  48.     cpx.i =0        # 70 times yet?  [Why not tstx???]
  49.     bne %stall1        # Branch on no.
  50.     bra %pgint        # Branch on yes.
  51.  
  52. # Light error LED only.
  53. error1:    ldaa.i 0x83        # Error LED only.  [Why not just 0x3???]
  54.     staa.d p1
  55.     bra %self
  56.  
  57. # Initialize variables for programming code.
  58. pgint:    ldx.i =0x7800        # Start of data memory.
  59.     stx.d imbeg
  60.     ldx.i =0x7fff        # End of data memory.
  61.     stx.d imend
  62.     ldx.i =0xc350        # Programming delay, 50 ms.
  63.     stx.d wait
  64.     # pntr has been initialized earlier.
  65.  
  66. # Basic programming code, from 68701 data sheet.
  67. eprom:    ldx.d pntr        # Save initial pntr on stack.
  68.     pshx
  69.     ldx.d imbeg        # x -> data
  70.  
  71. # Program a byte.
  72. epr002:    pshx            # Save data ptr on stack.
  73.     ldaa.i 0xfe        # Remove Vpp, set latch.
  74.     staa.d epromcr        # PPC=1, PLC=0.
  75.     ldaa.x 0        # Pick up data.
  76.     ldx.d pntr        # x -> dest
  77.     staa.x 0        # Store into latch.
  78.     inx            # Update destination addr...
  79.     stx.d pntr
  80.     ldaa.i 0xfc        # Fire up Vpp.
  81.     staa.d epromcr        # PPC=PLC=0.
  82.  
  83. # Wait 50 ms for programming to happen.
  84.     ldd.d wait        # d = delay.
  85.     addd.d timer        # d = time to wake up.
  86.     clr.e =tcsr        # Clear output-compare flag.
  87.     std.d outcmp        # Set alarm.
  88.     ldaa.i 0x40        # Wait for flag.
  89. epr004:    bita.d tcsr
  90.     beq %epr004        # Branch on not set yet.
  91.  
  92. # Set up for next byte.
  93.     pulx            # x -> data
  94.     inx
  95.     cpx.d imend        # Are we done?
  96.     bls %epr002        # Branch on no, with x -> next data.
  97.     ldaa.i 0xff        # Turn off Vpp, inhibit latch...
  98.     staa.d epromcr
  99.     pulx            # Put pntr back as it was...
  100.     stx.d pntr
  101.  
  102. # Verify.  End of datasheet code.
  103.     ldx.i =0x7800        # x -> data
  104. verf2:    pshx            # Save data ptr on stack.
  105.     ldaa.x 0        # a = data
  106.     ldx.d pntr        # x -> eprom
  107.     ldab.x 0        # a = eprom data
  108.     cba            # Same?
  109.     bne %error2        # Branch on different.
  110.     inx            # Next...
  111.     stx.d pntr
  112.     pulx            # x -> data
  113.     inx
  114.     cpx.i =0x8000        # Done yet?
  115.     bne %verf2        # Branch on no.
  116.  
  117. # We're done.  Light the verify LED.
  118.     ldaa.i 0x84        # Erased & verified.  [Why not just 0x4???]
  119.     staa.d p1
  120.  
  121. # Branch-to-self loop for completion and errors.
  122. self:    bra %self
  123.  
  124. # Verify error.
  125. error2:    ldaa.i 0x82        # Erased & error LEDS.  [Why not 0x2???]
  126.     staa.d p1
  127.     bra %self
  128.  
  129. # Vectors.
  130. .=0xbff0
  131.     =self
  132.     =self
  133.     =self
  134.     =self
  135.     =self
  136.     =self
  137.     =self
  138.     =start            # Reset vector.
  139.