Advertisement
kneefer

SMiW - kopiowanie ROM->RAM

Oct 19th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. //;//////////////////////////////////////////////////////////////////////////////
  2. //; Laboratory AVR Microcontrollers Part1
  3. //; Program template for lab 20
  4. //; Authors: Szymon Bartnik, Bartล‚omiej Szostek, Filip Duch
  5. //;
  6. //; Group: 2
  7. //; Section: 1
  8. //;
  9. //; Task: Napisaฤ‡ program, ktรณry kopiuje z romu do ramu
  10. //;
  11. //; Version: 1.0
  12. //;//////////////////////////////////////////////////////////////////////////////
  13. #include <avr/io.h>
  14. #include <avr/pgmspace.h>
  15. #include <avr/power.h>
  16.  
  17. #define nLength 256
  18.  
  19.  #define GET_FAR_ADDRESS(var) \
  20.  ({ \
  21.  uint_farptr_t tmp; \
  22.  __asm__ __volatile__( \
  23.  "ldi %A0, lo8(%1)" "\n\t" \
  24.  "ldi %B0, hi8(%1)" "\n\t" \
  25.  "ldi %C0, hh8(%1)" "\n\t" \
  26.  "clr %D0" "\n\t" \
  27.  : \
  28.  "=d" (tmp) \
  29.  : \
  30.  "p" (&(var)) \
  31.  ); \
  32.  tmp; \
  33. })
  34.  
  35. const uint8_t ROM_TAB[] PROGMEM = { 0x00, 0x01, 0x02, 0x03, 0x00, 0x06, 0x00, 0x00 };
  36. uint8_t RAM_TAB[nLength] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  37.  
  38. void main (void)
  39. {
  40.     DDRA = 0x00;
  41.     DDRB = 0xFF;
  42.    
  43.     int position = 0;
  44.  
  45.     uint8_t firstByte = 0xFF;
  46.     uint8_t lastByte  = 0xFF;
  47.    
  48.     while(1)
  49.     {
  50.         firstByte = pgm_read_byte_far(GET_FAR_ADDRESS(ROM_TAB[0]) + position * sizeof(ROM_TAB[0]));
  51.         if(firstByte == 0)
  52.         {
  53.             lastByte = pgm_read_byte_far(GET_FAR_ADDRESS(ROM_TAB[0]) + (position + 1) * sizeof(ROM_TAB[0]));
  54.             if(lastByte != 0)
  55.             {
  56.                 RAM_TAB[position++] = 0;
  57.                 RAM_TAB[position++] = lastByte;
  58.                 continue;
  59.             }
  60.             else break;
  61.         }
  62.        
  63.         RAM_TAB[position++] = firstByte;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement