Added input. Adjusted led-driver.

This commit is contained in:
Max Braungardt 2018-03-24 20:27:55 +01:00
parent f3d1ce24a3
commit 068ab575ba
6 changed files with 106 additions and 8 deletions

31
sketches/input/Makefile Normal file
View File

@ -0,0 +1,31 @@
CFLAGS = -Os -Wall --std=c11 -g
CHIP = atmega328p
SOURCE_FILES = $(wildcard *.c)
OBJ_FILES = $(SOURCE_FILES:%.c=%.o)
BIN = input.bin
HEX = input.hex
ASM = input.asm
default: $(HEX)
%.o: %.c
avr-gcc $(CFLAGS) -mmcu=$(CHIP) -o $@ $<
$(BIN): $(OBJ_FILES)
avr-gcc $(CFLAGS) -o $@ $^
$(ASM): $(BIN)
avr-objdump -d -g -l -S $^ > $@
$(HEX): $(BIN)
avr-objcopy -O ihex -j .text -j .data $^ $@
asm: $(ASM)
flash: $(HEX)
avrdude -p $(CHIP) -c arduino -B 115200 -P /dev/ttyACM0 -v -v -e -Uflash:w:$(HEX):a
clean:
$(RM) $(OBJ_FILES) $(BIN) $(HEX) $(ASM)

BIN
sketches/input/input.bin Executable file

Binary file not shown.

50
sketches/input/input.c Normal file
View File

@ -0,0 +1,50 @@
#include <stdint.h>
#include <stddef.h>
#include <avr/io.h>
#define F_CPU 20000000UL
#include <util/delay.h>
#include <stdbool.h>
//~ #define BAUD 9600
//~ #include <util/setbaud.h>
#include <avr/interrupt.h>
uint8_t volatile status = 0;
ISR(INT1_vect){
status = 1;
//~ PCORT0 = 1;
}
int main(){
//~ PORTD |= (1 << PORTD2); // turn On the Pull-up
// PD2 is now an input with pull-up enabled
EICRA |= 0x0F; // External Interrupt Control Register
// INT0 on rising edge
EIMSK |= 0x03; // External Interrupt Mask Register
// Enable INT0 for interrupt
SREG |= 0x80; // Status Register
// Enable global interrupts
//~ PCICR |= 0x04; // Pin Change Interrupt Control Register
//~ // Enabled PCINT[23;16] -> Pin 13,12,11,6,5,4,3,2
//~ PCIFR |= 0x04; // Pin Change Interrupt Flag Register
//~ PCMSK2 = 0xff; // Pin Change Mask Register 2
//~ // Enabled PCINT[23;16] (Single Pins)
DDRC = 0xff;
while(1){
if(status){
PORTC ^= 0x01;
status = 0;
}
PORTC ^= 0x02;
}
return 0;
}

16
sketches/input/input.hex Normal file
View File

@ -0,0 +1,16 @@
:100000000C9434000C9446000C9448000C94460068
:100010000C9446000C9446000C9446000C94460048
:100020000C9446000C9446000C9446000C94460038
:100030000C9446000C9446000C9446000C94460028
:100040000C9446000C9446000C9446000C94460018
:100050000C9446000C9446000C9446000C94460008
:100060000C9446000C94460011241FBECFEFD8E03C
:10007000DEBFCDBF21E0A0E0B1E001C01D92A13004
:10008000B207E1F70E9457000C9473000C94000033
:100090001F920F920FB60F9211248F9381E08093DD
:1000A00000018F910F900FBE0F901F9018958091B7
:1000B00069008F60809369008DB383608DBB8FB7BB
:1000C00080688FBF8FEF87B921E092E080910001B7
:1000D000882329F088B1822788B91092000188B15D
:0A00E000892788B9F3CFF894FFCF09
:00000001FF

BIN
sketches/input/input.o Executable file

Binary file not shown.

View File

@ -58,14 +58,9 @@ void writeZero();
void writeOne();
void writeRGB(uint8_t red, uint8_t green, uint8_t blue);
void writeNothing(uint8_t c);
void mydelay(uint16_t ms);
void mydelay(uint16_t ms) {
while(ms--) {
_delay_loop_2(5000); // 1ms
}
}
int mainz()
int mainParty()
{
DDRC = 1;
uint8_t d = 14;
@ -91,7 +86,7 @@ int mainz()
return 0;
}
int main() {
int main(){
DDRC = 1; // PORT C0 output
// uart_init();
@ -220,3 +215,9 @@ void writeNothing(uint8_t c){
}
_delay_ms(500);
}
void mydelay(uint16_t ms) {
while(ms--) {
_delay_loop_2(5000); // 1ms
}
}