Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //;//////////////////////////////////////////////////////////////////////////////
- //; Laboratory AVR Microcontrollers Part1
- //; Program template for lab 20
- //; Authors: Szymon Bartnik, Bartłomiej Szostek, Filip Duch
- //;
- //; Group: 2
- //; Section: 1
- //;
- //; Task: Napisać program, który kopiuje z romu do ramu
- //;
- //; Version: 1.0
- //;//////////////////////////////////////////////////////////////////////////////
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <avr/power.h>
- #define nLength 256
- #define GET_FAR_ADDRESS(var) \
- ({ \
- uint_farptr_t tmp; \
- __asm__ __volatile__( \
- "ldi %A0, lo8(%1)" "\n\t" \
- "ldi %B0, hi8(%1)" "\n\t" \
- "ldi %C0, hh8(%1)" "\n\t" \
- "clr %D0" "\n\t" \
- : \
- "=d" (tmp) \
- : \
- "p" (&(var)) \
- ); \
- tmp; \
- })
- const uint8_t ROM_TAB[] PROGMEM = { 0x00, 0x01, 0x02, 0x03, 0x00, 0x06, 0x00, 0x00 };
- uint8_t RAM_TAB[nLength] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- void main (void)
- {
- DDRA = 0x00;
- DDRB = 0xFF;
- int position = 0;
- uint8_t firstByte = 0xFF;
- uint8_t lastByte = 0xFF;
- while(1)
- {
- firstByte = pgm_read_byte_far(GET_FAR_ADDRESS(ROM_TAB[0]) + position * sizeof(ROM_TAB[0]));
- if(firstByte == 0)
- {
- lastByte = pgm_read_byte_far(GET_FAR_ADDRESS(ROM_TAB[0]) + (position + 1) * sizeof(ROM_TAB[0]));
- if(lastByte != 0)
- {
- RAM_TAB[position++] = 0;
- RAM_TAB[position++] = lastByte;
- continue;
- }
- else break;
- }
- RAM_TAB[position++] = firstByte;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement