Assignment #3 Create A Time Delay

  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'schema' in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 26.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: UPDATE cache SET data = 'a:50:{s:6:\"blocks\";a:7:{s:11:\"description\";s:62:\"Stores block settings, such as region and visibility settings.\";s:6:\"fields\";a:13:{s:3:\"bid\";a:3:{s:4:\"type\";s:6:\"serial\";s:8:\"not null\";b:1;s:11:\"description\";s:29:\"Primary Key: Unique block ID.\";}s:6:\"module\";a:5:{s:4:\"type\";s:7:\"varchar\";s:6:\"length\";i:64;s:8:\"not null\";b:1;s:7:\"default\";s:0:\"\";s:11:\"description\";s:126:\"The module from which the block originates; for example, \'user\' for the Who\'s Online block, and \'block\' for any custom blocks.\";}s:5:\"delta\";a:5:{s:4:\"type\";s:7:\"varchar\";s:6:\"length\";i:32;s:8:\"not null\";b:1;s:7:\"default\";s:1 in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 109.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'theme_registry:mattalltech' in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 26.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: UPDATE cache SET data = 'a:127:{s:24:\"block_admin_display_form\";a:7:{s:8:\"template\";s:38:\"modules/block/block-admin-display-form\";s:4:\"file\";s:29:\"modules/block/block.admin.inc\";s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/block\";s:11:\"theme paths\";a:1:{i:0;s:13:\"modules/block\";}s:20:\"preprocess functions\";a:2:{i:0;s:19:\"template_preprocess\";i:1;s:44:\"template_preprocess_block_admin_display_form\";}}s:17:\"color_scheme_form\";a:6:{s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/color\";s:8:\"function\";s:23:\"theme_color_scheme_form\";s:11:\"theme paths\";a in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 109.

Objective

Write a subroutine that creates a 1ms delay by decrementing the X register in a loop for a processor frequencies of 8MHz, 16MHz & 24MHz. Since the program uses the X register, save it to the stack at the beginning of the routine and restore it from the stack at the end of the routine.

Hints

Be sure to download the attached PDF file if you are looking at a more in depth explanation of the math used to calculate the delays

You might want to utilize the stack to preserve your 'X' value when using multiple sub routines. Otherwise your data in each sub routine is basically destroyed when you leave the routine.

Since the 'X' register is a 16 bit register, we could alternatively use just one decrementing loop on one decremented variable.

Be sure to keep in mind that when we jump to a subroutine, the return address is dumped onto the stack. So if we push something onto the stack we need to be sure to retrieve it so that the "program counter" address will be back on top of the stack so that JSR can retrieve the proper value.

  1. *********************************************************
  2. * Assignment #3: Time delay loops *
  3. * Matthew B. Pare, September 22, 2008, EE2662.001 *
  4. *********************************************************
  5.  
  6. ************************************
  7. * Definitions *
  8. ************************************
  9. MHz EQU $0008 ;Define MHz value for Processor
  10. DELAY EQU $00FA ;Define Delay For MHz Processor
  11.  
  12. ************************************
  13. * Start (ORIGIN) of Code in Memory *
  14. ************************************
  15. ORG $800 ;Origin
  16. CLR $3C ;Turn Off Watch Dog Timer
  17.  
  18.  
  19. ********************************************************
  20. * Time Delay Subroutine with nested Loops 1ms for 8MHz *
  21. ********************************************************
  22. TimDel: PSHY ;Push Index Register Y Onto Stack
  23. LDY #MHz ;Load Y Register with DELAY
  24. LoopX: PSHX ;Push Index Register X Onto Stack
  25. LDX #DELAY ;Load X Register with DELAY
  26. DecX: DEX ;Decrement X Register
  27. BNE DecX ;Branch if DELAY limit has not been reached
  28. DEY ;Decrement Y Register
  29. BNE LoopX ;Branch if DELAY limit has not been reached
  30.  
  31. PULX ;Pull Index Register X From Stack
  32. PULY ;Pull Index Register Y From Stack
  33.  
  34. RTS ;Return from DELAY Subroutine

AttachmentSize
Delay Loop Math Explained.pdf14.67 KB

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
Either you're a spam bot or your not, now prove it!
Image CAPTCHA
Enter the characters shown in the image without spaces.