Portál AbcLinuxu, 30. dubna 2025 10:13
Trošku zábavy s atmelom - časť 2
3.11.2012 23:33
| Přečteno: 1018×
| poslední úprava: 4.11.2012 00:45
Tak chystam sa spraviť si LED Cube 8x8x8
momentalne mam spravene 3x3 led na ktorom skusam softver.
pouzil som tabulku ktoru hodim do prog pamete
pripájam moje example
// Turn On/Off LED with loaded values from table
// 2012 Lukas Vesel for Atmel AVR (tiny2313)
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#define nop() asm volatile("nop")
// Function prototypes
int wait_times(int value);
int set_PORTB_bit(int position, int value);
unsigned int j;
const unsigned int Array[] PROGMEM = { 0, 1, 2, 1, 0, 3, 4, 5, 4 , 3, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define ARRAY_LENGTH(x) (sizeof(x))
int main(void)
{
DDRD = 0b00000001;
// PORTD |= 0b00000001; // lights on
DDRB = 0xff;
//PORTB |= 0b11111111; // lights on
//ptr = &my_array[0];
// Set up a forever loop using 'C'-style for loop
// i.e. loop while '1' equals '1'
for ( ;; )
{
for (j=0; j<ARRAY_SIZE(Array); j++) {
unsigned int bit = pgm_read_word(&Array[j]);
if (bit <= 7) {
// Set Bit
set_PORTB_bit(bit,1);
wait_times(50);
// Clear Bit
set_PORTB_bit(bit,0);
wait_times(50);
} else {
PORTD |= (1 << (bit-8));
wait_times(50);
PORTD &= ~(1 << (bit-8));
wait_times(50);
}
}
}
return 1;
}
// Functions
int wait_times(int value)
{
int i=value;
while (i--!=0) {
_delay_ms(10);
}
return 1;
}
int set_PORTB_bit(int position, int value)
{
// Sets or clears the bit in position 'position'
// either high or low (1 or 0) to match 'value'.
// Leaves all other bits in PORTB unchanged.
if (value == 0)
{
PORTB &= ~(1 << position); // Set bit # 'position' low
}
else
{
PORTB |= (1 << position); // Set bit # 'position' high
}
return 1;
}
Tiskni
Sdílej:
Komentáře
Vložit další komentář
Založit nové vlákno •
Nahoru
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.