Created
October 14, 2012 22:23
-
-
Save l3kn/3890010 to your computer and use it in GitHub Desktop.
l3cube 4*4 Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#define LED_CONFIG (DDRD |= (1<<1)) | |
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | |
#define DIT 80 /* unit time for morse code */ | |
#define FPS 2; | |
int lvl_arr[4] = {0b1000,0b0100,0b0010,0b0001}; | |
volatile int frame = 0; | |
int frame_arr[5][4] = {{0b1001,0b1001,0b1111,0b1001}, {0b1111,0b1000,0b1110,0b1111}, {0b1111,0b1000,0b1000,0b1000}, {0b1111,0b1000,0b1000,0b1000},{0b1111,0b1001,0b1001,0b1111}}; | |
int main(void) | |
{ | |
int lvl; | |
// set for 16 MHz clock, and make sure the LED is off | |
CPU_PRESCALE(0); | |
// set b & d ports as output | |
DDRD = 255; | |
DDRB = 255; | |
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode | |
TIMSK1 |= (1 << OCIE1A); // Enable CTC interrupt | |
sei(); // Enable global interrupts | |
OCR1A = 15624/FPS; // Set CTC compare value to 1Hz at 1MHz AVR clock, with a prescaler of 64 | |
TCCR1B |= ((1 << CS10) | (1 << CS12)); // Start timer at Fcpu/64 | |
while (1) | |
{ | |
for(lvl=0;lvl<=3;lvl++) | |
{ | |
PORTB = lvl_arr[lvl]; | |
PORTD = frame_arr[frame][lvl]; | |
_delay_ms(2); | |
} | |
} | |
} | |
ISR(TIMER1_COMPA_vect) | |
{ | |
frame++; | |
if (frame > 4) | |
{ | |
frame=0; | |
} | |
} | |
/* | |
MAKEFILE: | |
# Name: Teensy Makefile | |
# Author: Leon Rische (@l3kn) | |
# This is a prototype Makefile. Modify it according to your needs. | |
# You should at least check the settings for | |
# DEVICE ....... Teensy++ 2.0 | |
# CLOCK ........ 16 MHz | |
# OBJECTS ...... The object files created from your source files. This list is | |
# usually the same as the list of source files with suffix ".o". | |
# PROGRAMMER ... Teensy Loader App | |
DEVICE = at90usb1286 | |
CLOCK = 16000000 | |
OBJECTS = blinky.o | |
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) | |
# symbolic targets: | |
all: main.hex | |
.c.o: | |
$(COMPILE) -c $< -o $@ | |
.S.o: | |
$(COMPILE) -x assembler-with-cpp -c $< -o $@ | |
# "-x assembler-with-cpp" should not be necessary since this is the default | |
# file type for the .S (with capital S) extension. However, upper case | |
# characters are not always preserved on Windows. To ensure WinAVR | |
# compatibility define the file type manually. | |
.c.s: | |
$(COMPILE) -S $< -o $@ | |
flash: all | |
$(AVRDUDE) -U flash:w:main.hex:i | |
#fuse: | |
# $(AVRDUDE) $(FUSES) | |
# Xcode uses the Makefile targets "", "clean" and "install" | |
install: flash fuse | |
# if you use a bootloader, change the command below appropriately: | |
load: all | |
bootloadHID main.hex | |
clean: | |
rm -f main.hex main.elf $(OBJECTS) | |
# file targets: | |
main.elf: $(OBJECTS) | |
$(COMPILE) -o main.elf $(OBJECTS) | |
main.hex: main.elf | |
rm -f main.hex | |
avr-objcopy -j .text -j .data -O ihex main.elf main.hex | |
avr-size --format=avr --mcu=$(DEVICE) main.elf | |
# If you have an EEPROM section, you must also create a hex file for the | |
# EEPROM and add it to the "flash" target. | |
# Targets for code debugging and analysis: | |
disasm: main.elf | |
avr-objdump -d main.elf | |
cpp: | |
$(COMPILE) -E main.c | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment