avatar
Untitled

Guest 77 11th Dec, 2024

MARKUP 2.67 KB
                                           
                         #include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

#define F_CPU 16000000L
#define przycisk PINA 
// Define constants and arrays
#define nLength 500 // Size of TAB_RAM
uint8_t TAB_RAM[nLength];

// TAB_ROM array stored in program memory (flash)
uint8_t const TAB_ROM[] PROGMEM = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x1F,
	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1F, 0x1F,
	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
	0x30, 0x00, 0x00};
#define TAB_ROM_LENGTH (sizeof(TAB_ROM) / sizeof(TAB_ROM[0])) // Get the length of TAB_ROM

int main(void) {
	// Initialize ports
	DDRC = 0xFF; // Set Port C as output (for LEDs)
	PORTC = 0x00; // Turn off all LEDs initially
	DDRB = 0x80; // Set Port B.7 as output (LED connected to Port B.7)
	PORTB = 0x00; // Ensure LED is off initially
	DDRA = 0x00; // Set Port A as input (for buttons)
	PORTA = 0xFF; // Enable pull-up resistors on Port A

	uint16_t tab_ram = 0; // Index for TAB_RAM
	uint16_t tab_rom = 0; // Index for TAB_ROM

	// Wait for a button press on Port A
	while ((PINA & 0xFF) == 0x00) {
		// No button is pressed, keep waiting
	}

	// Copying process starts after a button press
	while (tab_ram < nLength) {
		// Copy every third byte from TAB_ROM to TAB_RAM
		TAB_RAM[tab_ram] = pgm_read_byte(&TAB_ROM[tab_rom]);

		// Display the copied byte on LEDs connected to Port C
		PORTC = ~TAB_RAM[tab_ram];
		_delay_ms(25000);

		// Increment indices
		tab_ram++;
		tab_rom += 3;

		// If tab_rom goes beyond the ROM length, wrap around to the beginning
		if (tab_rom >= TAB_ROM_LENGTH) {
			tab_rom = 0;
		}
	}

	// Indicate completion with LED on Port B.7
	PORTB = 0x80; // Turn on the LED
	_delay_ms(100000);
	PORTB = 0x00; // Turn off the LED

	// Infinite loop to end the program
	while (1) {}

	return 0;
}

/*/
Please turn off all diodes at the beginning of the program. Wait for the button to
be pressed. Copying starts after pressing any button connected to port A. Write a
program that copies every third byte from TAB_ROM to TAB_RAM, one by one. If
the TAB_RAM table is larger than the TAB_ROM, the program will continue to copy
bytes to the end of the TAB_RAM table, starting from the beginning of the
TAB_ROM table. Each copied byte should be displayed on the diodes connected to
port C. The pause between displaying each byte should be 250ms. Turn on the
LED connected to Port B.7 for one second after the program is finished. 
/*/
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
Ta strona używa plików cookie w celu usprawnienia i ułatwienia dostępu do serwisu oraz prowadzenia danych statystycznych. Dalsze korzystanie z tej witryny oznacza akceptację tego stanu rzeczy.
Wykorzystywanie plików Cookie
Jak wyłączyć cookies?
ROZUMIEM