Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2.  
  3. #include <util/delay.h>
  4. #include <avr/interrupt.h>
  5. #include <avr/pgmspace.h>
  6.  
  7. #define F_CPU 4000000UL
  8.  
  9. #define GET_FAR_ADDRESS(var) \
  10. ({ \
  11.     uint_farptr_t tmp; \
  12.     \
  13.     __asm__ __volatile__( \
  14.     \
  15.     "ldi %A0, lo8(%1)" "\n\t" \
  16.     "ldi %B0, hi8(%1)" "\n\t" \
  17.     "ldi %C0, hh8(%1)" "\n\t" \
  18.     "clr %D0" "\n\t" \
  19.     : \
  20.     "=d" (tmp) \
  21.     : \
  22.     "p" (&(var)) \
  23.     ); \
  24.     tmp; \
  25. })
  26.  
  27. const uint8_t tablica[] PROGMEM = {0x00, 0x01, 0xff, 0x03, 0xff, 0x05, 0xFF, 0xFF };
  28.    
  29. void showROM(uint8_t *wsk)
  30. {  
  31.     uint8_t *tablica = wsk;
  32.     uint8_t x,y;
  33.     while(1)
  34.     {
  35.         x = pgm_read_byte_far(GET_FAR_ADDRESS(tablica));
  36.         y = pgm_read_byte_far(GET_FAR_ADDRESS (++tablica));
  37.         if(x==0xFF) {
  38.             if(y==0xFF) {
  39.                 tablica=wsk;
  40.                 break;
  41.             }
  42.         }
  43.         PORTB = ~x;
  44.     }
  45. }
  46.  
  47. int main(void)
  48. {
  49.     DDRA = 0x00;// Port A - przyciski, wejściowy
  50.     PORTA = 0xFF;
  51.     DDRB = 0xFF; // Port B - diody, wyjściowy
  52.     PORTB = 0x00;
  53.    
  54.     showROM( &tablica[0]);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement