1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | PROJECT=hello.ftdi.44.ledswitch SOURCES=$(PROJECT).c MMCU=attiny44 F_CPU = 20000000 CFLAGS=-mmcu=$(MMCU) -Wall -Os -DF_CPU=$(F_CPU) $(PROJECT).hex: $(PROJECT).out avr-objcopy -O ihex $(PROJECT).out $(PROJECT).c.hex;\ avr-size --mcu=$(MMCU) --format=avr $(PROJECT).out $(PROJECT).out: $(SOURCES) avr-gcc $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES) program-bsd: $(PROJECT).hex avrdude -p t44 -c bsd -U flash:w:$(PROJECT).c.hex program-dasa: $(PROJECT).hex avrdude -p t44 -P /dev/ttyUSB0 -c dasa -U flash:w:$(PROJECT).c.hex program-avrisp2: $(PROJECT).hex avrdude -p t44 -P usb -c avrisp2 -U flash:w:$(PROJECT).c.hex program-avrisp2-fuses: $(PROJECT).hex avrdude -p t44 -P usb -c avrisp2 -U lfuse:w:0x7E:m program-usbtiny: $(PROJECT).hex avrdude -p t44 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex program-usbtiny-fuses: $(PROJECT).hex avrdude -p t44 -P usb -c usbtiny -U lfuse:w:0x7E:m program-dragon: $(PROJECT).hex avrdude -p t44 -P usb -c dragon_isp -U flash:w:$(PROJECT).c.hex |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #define F_CPU 20E6 #include <avr/io.h> #include <util/delay.h> int main( void ) { DDRA = 0x80; /* make the LED pin an output */ //DDRA = 1 << 7; /* make the LED pin an output */ for (;;){ if ((PINA & (1 << 3)) == 0){ PORTA = 0x80; /* turn on the LED */ //PORTA = 1 << 7; /* same to 0x80 */ } else { PORTA = 0x00; /* turn off the LED*/ //PORTA = 0 << 7; /* same to 0x00 */ } } } |
shift for 0 bit to the left | 00000001 |
shift for 1 bit to the left | 00000010 |
shift for 2 bits to the left | 00000100 |
shift for 3 bits to the left | 00001000 |
shift for 4 bits to the left | 00010000 |
shift for 5 bits to the left | 00100000 |
shift for 6 bits to the left | 01000000 |
shift for 7 bits to the left | 10000000 |
1 | sample |