Opdracht 3

This commit is contained in:
Guilliam Lutz
2021-03-10 09:59:28 +01:00
parent 0a1a3fd47f
commit f3fa8afa60
20 changed files with 1175 additions and 121 deletions
+127
View File
@@ -0,0 +1,127 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL := cmd.exe
RM := rm -rf
USER_OBJS :=
LIBS :=
PROJ :=
O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
LIB_DEP:=
LINKER_SCRIPT_DEP:=
# Every subdirectory with source files must be described here
SUBDIRS :=
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../main.c
PREPROCESSING_SRCS +=
ASM_SRCS +=
OBJS += \
main.o
OBJS_AS_ARGS += \
main.o
C_DEPS += \
main.d
C_DEPS_AS_ARGS += \
main.d
OUTPUT_FILE_PATH +=opdracht\ C.elf
OUTPUT_FILE_PATH_AS_ARGS +="opdracht C.elf"
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:= ./makedep.mk
LIB_DEP+=
LINKER_SCRIPT_DEP+=
# AVR32/GNU C Compiler
./main.o: .././main.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega128 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
# AVR32/GNU Preprocessing Assembler
# AVR32/GNU Assembler
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
@echo Building target: $@
@echo Invoking: AVR/GNU Linker : 5.4.0
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="opdracht C.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=atmega128 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"
@echo Finished building target: $@
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "opdracht C.elf" "opdracht C.hex"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "opdracht C.elf" "opdracht C.eep" || exit 0
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "opdracht C.elf" > "opdracht C.lss"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "opdracht C.elf" "opdracht C.srec"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "opdracht C.elf"
# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
-$(RM) $(C_DEPS_AS_ARGS)
rm -rf "opdracht C.elf" "opdracht C.a" "opdracht C.hex" "opdracht C.lss" "opdracht C.eep" "opdracht C.map" "opdracht C.srec" "opdracht C.usersignatures"
@@ -0,0 +1,6 @@
################################################################################
# Automatically-generated file. Do not edit or delete the file
################################################################################
main.c
@@ -0,0 +1 @@
:00000001FF
@@ -0,0 +1,327 @@
opdracht C.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00800100 00800100 00000204 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 000001b0 00000000 00000000 00000054 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .comment 00000030 00000000 00000000 00000204 2**0
CONTENTS, READONLY
3 .note.gnu.avr.deviceinfo 0000003c 00000000 00000000 00000234 2**2
CONTENTS, READONLY
4 .debug_aranges 00000070 00000000 00000000 00000270 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_info 00000cd9 00000000 00000000 000002e0 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_abbrev 000008c5 00000000 00000000 00000fb9 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_line 000004b8 00000000 00000000 0000187e 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_frame 000000d8 00000000 00000000 00001d38 2**2
CONTENTS, READONLY, DEBUGGING
9 .debug_str 000004d9 00000000 00000000 00001e10 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_loc 0000016f 00000000 00000000 000022e9 2**0
CONTENTS, READONLY, DEBUGGING
11 .debug_ranges 00000060 00000000 00000000 00002458 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
0: 45 c0 rjmp .+138 ; 0x8c <__ctors_end>
2: 00 00 nop
4: 4b c0 rjmp .+150 ; 0x9c <__bad_interrupt>
6: 00 00 nop
8: 49 c0 rjmp .+146 ; 0x9c <__bad_interrupt>
a: 00 00 nop
c: 47 c0 rjmp .+142 ; 0x9c <__bad_interrupt>
e: 00 00 nop
10: 45 c0 rjmp .+138 ; 0x9c <__bad_interrupt>
12: 00 00 nop
14: 43 c0 rjmp .+134 ; 0x9c <__bad_interrupt>
16: 00 00 nop
18: 41 c0 rjmp .+130 ; 0x9c <__bad_interrupt>
1a: 00 00 nop
1c: 3f c0 rjmp .+126 ; 0x9c <__bad_interrupt>
1e: 00 00 nop
20: 3d c0 rjmp .+122 ; 0x9c <__bad_interrupt>
22: 00 00 nop
24: 3b c0 rjmp .+118 ; 0x9c <__bad_interrupt>
26: 00 00 nop
28: 39 c0 rjmp .+114 ; 0x9c <__bad_interrupt>
2a: 00 00 nop
2c: 37 c0 rjmp .+110 ; 0x9c <__bad_interrupt>
2e: 00 00 nop
30: 35 c0 rjmp .+106 ; 0x9c <__bad_interrupt>
32: 00 00 nop
34: 33 c0 rjmp .+102 ; 0x9c <__bad_interrupt>
36: 00 00 nop
38: 31 c0 rjmp .+98 ; 0x9c <__bad_interrupt>
3a: 00 00 nop
3c: 2f c0 rjmp .+94 ; 0x9c <__bad_interrupt>
3e: 00 00 nop
40: 2d c0 rjmp .+90 ; 0x9c <__bad_interrupt>
42: 00 00 nop
44: 2b c0 rjmp .+86 ; 0x9c <__bad_interrupt>
46: 00 00 nop
48: 29 c0 rjmp .+82 ; 0x9c <__bad_interrupt>
4a: 00 00 nop
4c: 27 c0 rjmp .+78 ; 0x9c <__bad_interrupt>
4e: 00 00 nop
50: 25 c0 rjmp .+74 ; 0x9c <__bad_interrupt>
52: 00 00 nop
54: 23 c0 rjmp .+70 ; 0x9c <__bad_interrupt>
56: 00 00 nop
58: 21 c0 rjmp .+66 ; 0x9c <__bad_interrupt>
5a: 00 00 nop
5c: 1f c0 rjmp .+62 ; 0x9c <__bad_interrupt>
5e: 00 00 nop
60: 1d c0 rjmp .+58 ; 0x9c <__bad_interrupt>
62: 00 00 nop
64: 1b c0 rjmp .+54 ; 0x9c <__bad_interrupt>
66: 00 00 nop
68: 19 c0 rjmp .+50 ; 0x9c <__bad_interrupt>
6a: 00 00 nop
6c: 17 c0 rjmp .+46 ; 0x9c <__bad_interrupt>
6e: 00 00 nop
70: 15 c0 rjmp .+42 ; 0x9c <__bad_interrupt>
72: 00 00 nop
74: 13 c0 rjmp .+38 ; 0x9c <__bad_interrupt>
76: 00 00 nop
78: 11 c0 rjmp .+34 ; 0x9c <__bad_interrupt>
7a: 00 00 nop
7c: 0f c0 rjmp .+30 ; 0x9c <__bad_interrupt>
7e: 00 00 nop
80: 0d c0 rjmp .+26 ; 0x9c <__bad_interrupt>
82: 00 00 nop
84: 0b c0 rjmp .+22 ; 0x9c <__bad_interrupt>
86: 00 00 nop
88: 09 c0 rjmp .+18 ; 0x9c <__bad_interrupt>
...
0000008c <__ctors_end>:
8c: 11 24 eor r1, r1
8e: 1f be out 0x3f, r1 ; 63
90: cf ef ldi r28, 0xFF ; 255
92: d0 e1 ldi r29, 0x10 ; 16
94: de bf out 0x3e, r29 ; 62
96: cd bf out 0x3d, r28 ; 61
98: 67 d0 rcall .+206 ; 0x168 <main>
9a: 88 c0 rjmp .+272 ; 0x1ac <_exit>
0000009c <__bad_interrupt>:
9c: b1 cf rjmp .-158 ; 0x0 <__vectors>
0000009e <wait>:
void displayOff()
{
spi_slaveSelect(0); // Select display chip
spi_write(0x0C); // Register 0B: Shutdown register
spi_write(0x00); // -> 1 = Normal operation
spi_slaveDeSelect(0); // Deselect display chip
9e: 20 e0 ldi r18, 0x00 ; 0
a0: 30 e0 ldi r19, 0x00 ; 0
a2: 08 c0 rjmp .+16 ; 0xb4 <wait+0x16>
a4: e3 ec ldi r30, 0xC3 ; 195
a6: f9 e0 ldi r31, 0x09 ; 9
a8: 31 97 sbiw r30, 0x01 ; 1
aa: f1 f7 brne .-4 ; 0xa8 <wait+0xa>
ac: 00 c0 rjmp .+0 ; 0xae <wait+0x10>
ae: 00 00 nop
b0: 2f 5f subi r18, 0xFF ; 255
b2: 3f 4f sbci r19, 0xFF ; 255
b4: 28 17 cp r18, r24
b6: 39 07 cpc r19, r25
b8: ac f3 brlt .-22 ; 0xa4 <wait+0x6>
ba: 08 95 ret
000000bc <spi_masterInit>:
bc: 8f ef ldi r24, 0xFF ; 255
be: 87 bb out 0x17, r24 ; 23
c0: 87 b3 in r24, 0x17 ; 23
c2: 87 7f andi r24, 0xF7 ; 247
c4: 87 bb out 0x17, r24 ; 23
c6: 88 b3 in r24, 0x18 ; 24
c8: 81 60 ori r24, 0x01 ; 1
ca: 88 bb out 0x18, r24 ; 24
cc: 82 e5 ldi r24, 0x52 ; 82
ce: 8d b9 out 0x0d, r24 ; 13
d0: 08 95 ret
000000d2 <spi_write>:
d2: 8f b9 out 0x0f, r24 ; 15
d4: 77 9b sbis 0x0e, 7 ; 14
d6: fe cf rjmp .-4 ; 0xd4 <spi_write+0x2>
d8: 08 95 ret
000000da <spi_slaveSelect>:
da: 98 b3 in r25, 0x18 ; 24
dc: 21 e0 ldi r18, 0x01 ; 1
de: 30 e0 ldi r19, 0x00 ; 0
e0: 02 c0 rjmp .+4 ; 0xe6 <spi_slaveSelect+0xc>
e2: 22 0f add r18, r18
e4: 33 1f adc r19, r19
e6: 8a 95 dec r24
e8: e2 f7 brpl .-8 ; 0xe2 <spi_slaveSelect+0x8>
ea: 20 95 com r18
ec: 29 23 and r18, r25
ee: 28 bb out 0x18, r18 ; 24
f0: 08 95 ret
000000f2 <spi_slaveDeSelect>:
f2: 98 b3 in r25, 0x18 ; 24
f4: 21 e0 ldi r18, 0x01 ; 1
f6: 30 e0 ldi r19, 0x00 ; 0
f8: 02 c0 rjmp .+4 ; 0xfe <spi_slaveDeSelect+0xc>
fa: 22 0f add r18, r18
fc: 33 1f adc r19, r19
fe: 8a 95 dec r24
100: e2 f7 brpl .-8 ; 0xfa <spi_slaveDeSelect+0x8>
102: 29 2b or r18, r25
104: 28 bb out 0x18, r18 ; 24
106: 08 95 ret
00000108 <spi_writeCommand>:
108: cf 93 push r28
10a: df 93 push r29
10c: d8 2f mov r29, r24
10e: c6 2f mov r28, r22
110: 80 e0 ldi r24, 0x00 ; 0
112: e3 df rcall .-58 ; 0xda <spi_slaveSelect>
114: 8d 2f mov r24, r29
116: dd df rcall .-70 ; 0xd2 <spi_write>
118: 8c 2f mov r24, r28
11a: db df rcall .-74 ; 0xd2 <spi_write>
11c: 80 e0 ldi r24, 0x00 ; 0
11e: e9 df rcall .-46 ; 0xf2 <spi_slaveDeSelect>
120: df 91 pop r29
122: cf 91 pop r28
124: 08 95 ret
00000126 <displayDriverInit>:
126: 80 e0 ldi r24, 0x00 ; 0
128: d8 df rcall .-80 ; 0xda <spi_slaveSelect>
12a: 89 e0 ldi r24, 0x09 ; 9
12c: d2 df rcall .-92 ; 0xd2 <spi_write>
12e: 8f ef ldi r24, 0xFF ; 255
130: d0 df rcall .-96 ; 0xd2 <spi_write>
132: 80 e0 ldi r24, 0x00 ; 0
134: de df rcall .-68 ; 0xf2 <spi_slaveDeSelect>
136: 80 e0 ldi r24, 0x00 ; 0
138: d0 df rcall .-96 ; 0xda <spi_slaveSelect>
13a: 8a e0 ldi r24, 0x0A ; 10
13c: ca df rcall .-108 ; 0xd2 <spi_write>
13e: 84 e0 ldi r24, 0x04 ; 4
140: c8 df rcall .-112 ; 0xd2 <spi_write>
142: 80 e0 ldi r24, 0x00 ; 0
144: d6 df rcall .-84 ; 0xf2 <spi_slaveDeSelect>
146: 80 e0 ldi r24, 0x00 ; 0
148: c8 df rcall .-112 ; 0xda <spi_slaveSelect>
14a: 8b e0 ldi r24, 0x0B ; 11
14c: c2 df rcall .-124 ; 0xd2 <spi_write>
14e: 83 e0 ldi r24, 0x03 ; 3
150: c0 df rcall .-128 ; 0xd2 <spi_write>
152: 80 e0 ldi r24, 0x00 ; 0
154: ce df rcall .-100 ; 0xf2 <spi_slaveDeSelect>
156: 80 e0 ldi r24, 0x00 ; 0
158: c0 df rcall .-128 ; 0xda <spi_slaveSelect>
15a: 8c e0 ldi r24, 0x0C ; 12
15c: ba df rcall .-140 ; 0xd2 <spi_write>
15e: 81 e0 ldi r24, 0x01 ; 1
160: b8 df rcall .-144 ; 0xd2 <spi_write>
162: 80 e0 ldi r24, 0x00 ; 0
164: c6 cf rjmp .-116 ; 0xf2 <spi_slaveDeSelect>
166: 08 95 ret
00000168 <main>:
}
int main()
{
168: cf 93 push r28
DDRB=0x01; // Set PB0 pin as output for display select
16a: 81 e0 ldi r24, 0x01 ; 1
16c: 87 bb out 0x17, r24 ; 23
spi_masterInit(); // Initialize spi module
16e: a6 df rcall .-180 ; 0xbc <spi_masterInit>
displayDriverInit(); // Initialize display chip
170: da df rcall .-76 ; 0x126 <displayDriverInit>
172: c1 e0 ldi r28, 0x01 ; 1
// clear display (all zero's)
for (unsigned char i =1; i<=4; i++)
174: 04 c0 rjmp .+8 ; 0x17e <main+0x16>
176: 6c 2f mov r22, r28
{
// spi_slaveSelect(0); // Select display chip
//spi_write(i); // digit adress: (digit place)
//spi_write(0); // digit value: 0
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
178: 8c 2f mov r24, r28
17a: c6 df rcall .-116 ; 0x108 <spi_writeCommand>
17c: cf 5f subi r28, 0xFF ; 255
{
DDRB=0x01; // Set PB0 pin as output for display select
spi_masterInit(); // Initialize spi module
displayDriverInit(); // Initialize display chip
// clear display (all zero's)
for (unsigned char i =1; i<=4; i++)
17e: c5 30 cpi r28, 0x05 ; 5
180: d0 f3 brcs .-12 ; 0x176 <main+0xe>
//spi_write(i); // digit adress: (digit place)
//spi_write(0); // digit value: 0
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
}
wait(1000);
182: 88 ee ldi r24, 0xE8 ; 232
184: 93 e0 ldi r25, 0x03 ; 3
186: 8b df rcall .-234 ; 0x9e <wait>
188: c1 e0 ldi r28, 0x01 ; 1
// write 4-digit data
for (unsigned char i =1; i<=4; i++)
18a: 07 c0 rjmp .+14 ; 0x19a <main+0x32>
{
//spi_slaveSelect(0); // Select display chip
//spi_write(i); // digit adress: (digit place)
//spi_write(i); // digit value: i (= digit place)
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
18c: 6c 2f mov r22, r28
18e: 8c 2f mov r24, r28
190: bb df rcall .-138 ; 0x108 <spi_writeCommand>
wait(1000);
192: 88 ee ldi r24, 0xE8 ; 232
194: 93 e0 ldi r25, 0x03 ; 3
196: 83 df rcall .-250 ; 0x9e <wait>
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
}
wait(1000);
// write 4-digit data
for (unsigned char i =1; i<=4; i++)
198: cf 5f subi r28, 0xFF ; 255
19a: c5 30 cpi r28, 0x05 ; 5
19c: b8 f3 brcs .-18 ; 0x18c <main+0x24>
//spi_write(i); // digit value: i (= digit place)
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
wait(1000);
}
wait(1000);
19e: 88 ee ldi r24, 0xE8 ; 232
1a0: 93 e0 ldi r25, 0x03 ; 3
1a2: 7d df rcall .-262 ; 0x9e <wait>
1a4: 81 e0 ldi r24, 0x01 ; 1
return (1);
1a6: 90 e0 ldi r25, 0x00 ; 0
1a8: cf 91 pop r28
1aa: 08 95 ret
000001ac <_exit>:
1ac: f8 94 cli
000001ae <__stop_program>:
1ae: ff cf rjmp .-2 ; 0x1ae <__stop_program>
@@ -0,0 +1,29 @@
S01200006F7064726163687420432E737265635A
S113000045C000004BC0000049C0000047C00000CC
S113001045C0000043C0000041C000003FC00000D4
S11300203DC000003BC0000039C0000037C00000E4
S113003035C0000033C0000031C000002FC00000F4
S11300402DC000002BC0000029C0000027C0000004
S113005025C0000023C0000021C000001FC0000014
S11300601DC000001BC0000019C0000017C0000024
S113007015C0000013C0000011C000000FC0000034
S11300800DC000000BC0000009C0000011241FBEF9
S1130090CFEFD0E1DEBFCDBF67D088C0B1CF20E0C5
S11300A030E008C0E3ECF9E03197F1F700C000005C
S11300B02F5F3F4F28173907ACF308958FEF87BBA5
S11300C087B3877F87BB88B3816088BB82E58DB99E
S11300D008958FB9779BFECF089598B321E030E05F
S11300E002C0220F331F8A95E2F72095292328BBEB
S11300F0089598B321E030E002C0220F331F8A959F
S1130100E2F7292B28BB0895CF93DF93D82FC62F6E
S113011080E0E3DF8D2FDDDF8C2FDBDF80E0E9DFA4
S1130120DF91CF91089580E0D8DF89E0D2DF8FEFAF
S1130130D0DF80E0DEDF80E0D0DF8AE0CADF84E069
S1130140C8DF80E0D6DF80E0C8DF8BE0C2DF83E079
S1130150C0DF80E0CEDF80E0C0DF8CE0BADF81E08A
S1130160B8DF80E0C6CF0895CF9381E087BBA6DFD8
S1130170DADFC1E004C06C2F8C2FC6DFCF5FC5303F
S1130180D0F388EE93E08BDFC1E007C06C2F8C2F97
S1130190BBDF88EE93E083DFCF5FC530B8F388EE32
S11301A093E07DDF81E090E0CF910895F894FFCF54
S9030000FC
+136
View File
@@ -0,0 +1,136 @@
/*
* Project name : Demo5_7a : spi - 7 segments display
* Author : Avans-TI, WvdE, JW
* Revision History : 20110228: - initial release; 20120307: - this version
* Description : This program sends data to a 4-digit display with spi
* Test configuration:
MCU: ATmega128
Dev.Board: BIGAVR6
Oscillator: External Clock 08.0000 MHz
Ext. Modules: Serial 7-seg display
SW: AVR-GCC
* NOTES : Turn ON switch 15, PB1/PB2/PB3 to MISO/MOSI/SCK
*/
#define F_CPU 10e6
#include <avr/io.h>
#include <util/delay.h>
#define BIT(x) ( 1<<x )
#define DDR_SPI DDRB // spi Data direction register
#define PORT_SPI PORTB // spi Output register
#define SPI_SCK 1 // PB1: spi Pin System Clock
#define SPI_MOSI 2 // PB2: spi Pin MOSI
#define SPI_MISO 3 // PB3: spi Pin MISO
#define SPI_SS 0 // PB0: spi Pin Slave Select
// wait(): busy waiting for 'ms' millisecond - used library: util/delay.h
void wait(int ms)
{
for (int i=0; i<ms; i++)
_delay_ms(1);
}
void spi_masterInit(void)
{
DDR_SPI = 0xff; // All pins output: MOSI, SCK, SS, SS_display
DDR_SPI &= ~BIT(SPI_MISO); // except: MISO input
PORT_SPI |= BIT(SPI_SS); // SS_ADC == 1: deselect slave
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); // or: SPCR = 0b11010010;
// Enable spi, MasterMode, Clock rate fck/64
// bitrate=125kHz, Mode = 0: CPOL=0, CPPH=0
}
// Write a byte from master to slave
void spi_write( unsigned char data )
{
SPDR = data; // Load byte --> starts transmission
while( !(SPSR & BIT(SPIF)) ); // Wait for transmission complete
}
// Write a byte from master to slave and read a byte from slave - not used here
char spi_writeRead( unsigned char data )
{
SPDR = data; // Load byte --> starts transmission
while( !(SPSR & BIT(SPIF)) ); // Wait for transmission complete
data = SPDR; // New received data (eventually, MISO) in SPDR
return data; // Return received byte
}
// Select device on pinnumer PORTB
void spi_slaveSelect(unsigned char chipNumber)
{
PORTB &= ~BIT(chipNumber);
}
// Deselect device on pinnumer PORTB
void spi_slaveDeSelect(unsigned char chipNumber)
{
PORTB |= BIT(chipNumber);
}
void spi_writeCommand(unsigned char adress, unsigned char data)
{
spi_slaveSelect(0);
spi_write(adress);
spi_write(data);
spi_slaveDeSelect(0);
}
// Initialize the driver chip (type MAX 7219)
void displayDriverInit()
{
spi_slaveSelect(0); // Select display chip (MAX7219)
spi_write(0x09); // Register 09: Decode Mode
spi_write(0xFF); // -> 1's = BCD mode for all digits
spi_slaveDeSelect(0); // Deselect display chip
spi_slaveSelect(0); // Select dispaly chip
spi_write(0x0A); // Register 0A: Intensity
spi_write(0x04); // ->the hex value here selects the intensity (in range [1..F])
spi_slaveDeSelect(0); // Deselect display chip
spi_slaveSelect(0); // Select display chip
spi_write(0x0B); // Register 0B: Scan-limit
spi_write(0x03); // -> 1 = Display digits 0..1 the hex value here selects how many segments get initialized
spi_slaveDeSelect(0); // Deselect display chip
spi_slaveSelect(0); // Select display chip
spi_write(0x0C); // Register 0B: Shutdown register
spi_write(0x01); // -> 1 = Normal operation
spi_slaveDeSelect(0); // Deselect display chip
}
// Set display on ('normal operation')
void displayOn()
{
spi_slaveSelect(0); // Select display chip
spi_write(0x0C); // Register 0B: Shutdown register
spi_write(0x01); // -> 1 = Normal operation
spi_slaveDeSelect(0); // Deselect display chip
}
// Set display off ('shut down')
void displayOff()
{
spi_slaveSelect(0); // Select display chip
spi_write(0x0C); // Register 0B: Shutdown register
spi_write(0x00); // -> 1 = Normal operation
spi_slaveDeSelect(0); // Deselect display chip
}
int main()
{
DDRB=0x01; // Set PB0 pin as output for display select
spi_masterInit(); // Initialize spi module
displayDriverInit(); // Initialize display chip
// clear display (all zero's)
for (unsigned char i =1; i<=4; i++)
{
// spi_slaveSelect(0); // Select display chip
//spi_write(i); // digit adress: (digit place)
//spi_write(0); // digit value: 0
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
}
wait(1000);
// write 4-digit data
for (unsigned char i =1; i<=4; i++)
{
//spi_slaveSelect(0); // Select display chip
//spi_write(i); // digit adress: (digit place)
//spi_write(i); // digit value: i (= digit place)
//spi_slaveDeSelect(0); // Deselect display chip
spi_writeCommand(i,i);
wait(1000);
}
wait(1000);
return (1);
}
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.6.0</CVersion>
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include/</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\avr\iom128.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>JdJ7J9I/SJh965SEyyyVYw==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iom128.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>dYQaOvX+0xpWshrMQ/Jkjg==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>mkKaE95TOoATsuBGv6jmxg==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/atmega128</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATmega_DFP</PackName>
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.6.364/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.6.364</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATmega128</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
</Store>
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>{2df6f5f3-181f-430e-b49a-3d9794f91482}</ProjectGuid>
<avrdevice>ATmega128</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>C</Language>
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>opdracht C</AssemblyName>
<Name>opdracht C</Name>
<RootNamespace>opdracht C</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress />
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue />
<BootSegment>2</BootSegment>
<ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey />
<AsfFrameworkConfig>
<framework-data xmlns="">
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.49.1" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega128 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=atmega128 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega128"</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>