0.6.0 this is the first version for the new hardware
[digitaldcpower] / Makefile
1 # makefile for digitial dc power supply, written by guido socher
2 MCU=atmega8
3 DUDECPUTYPE=m8
4 # === Edit this and enter the correct device/com-port:
5 # linux (plug in the avrusb500 and type dmesg to see which device it is):
6 LOADCMD=avrdude -P /dev/ttyUSB0
7
8 # mac (plug in the programer and use ls /dev/tty.usbserial* to get the name):
9 #LOADCMD=avrdude -P /dev/tty.usbserial-A9006MOb
10
11 # windows (check which com-port you get when you plugin the avrusb500):
12 #LOADCMD=avrdude -P COM4
13
14 # All operating systems: if you have set the default_serial paramter 
15 # in your avrdude.conf file correctly then you can just use this
16 # and you don't need the above -P option:
17 #LOADCMD=avrdude
18 # === end edit this
19 #
20 LOADARG=-p $(DUDECPUTYPE) -c stk500v2 -e -U flash:w:
21
22
23 CC=avr-gcc
24 OBJCOPY=avr-objcopy
25 # optimize for size:
26 CFLAGS=-g -mmcu=$(MCU) -Wall -W -Os -mcall-prologues
27 # #-------------------
28 .PHONY: test_lcd test_dac all main 
29 #
30 all: main.hex test_lcd.hex test_dac.hex
31 #
32 main: main.hex 
33 #
34 test_lcd: test_lcd.hex
35         echo "OK"
36 #
37 test_dac: test_dac.hex
38         echo "OK"
39 #-------------------
40 size:
41         avr-size *.elf
42 help: 
43         @echo "Usage: make help"
44         @echo "       Print this help"
45         @echo " "
46         @echo "Usage: make all|load|rdfuses|fuses"
47         @echo "       program using the avrdude programmer"
48         @echo " "
49         @echo "Usage: make clean"
50         @echo "       delete all generated files except the pre-compiled ones"
51         @echo "Test programs:"
52         @echo "Usage: make test_lcd|load_test_lcd|test_dac|load_test_dac"
53         @echo "       compile and load test programs"
54 #-------------------
55 main.hex: main.elf 
56         $(OBJCOPY) -R .eeprom -O ihex main.elf main.hex 
57         avr-size main.elf
58         @echo " "
59         @echo "Expl.: data=initialized data, bss=uninitialized data, text=code"
60         @echo " "
61 main.elf: main.o dac.o lcd.o analog.o kbd.o
62         $(CC) $(CFLAGS) -o main.elf -Wl,-Map,main.map main.o dac.o lcd.o analog.o kbd.o
63 main.o: main.c dac.h kbd.h lcd.h lcd_hw.h analog.h hardware_settings.h
64         $(CC) $(CFLAGS) -Os -c main.c 
65 #-------------------
66 test_lcd.hex: test_lcd.elf 
67         $(OBJCOPY) -R .eeprom -O ihex test_lcd.elf test_lcd.hex 
68 test_lcd.elf: test_lcd.o lcd.o kbd.o
69         $(CC) $(CFLAGS) -o test_lcd.elf -Wl,-Map,test_lcd.map test_lcd.o lcd.o kbd.o
70 test_lcd.o: test_lcd.c lcd.h lcd_hw.h kbd.h
71         $(CC) $(CFLAGS) -Os -c test_lcd.c
72 #-------------------
73 test_dac.hex: test_dac.elf 
74         $(OBJCOPY) -R .eeprom -O ihex test_dac.elf test_dac.hex 
75 test_dac.elf: test_dac.o lcd.o kbd.o dac.o
76         $(CC) $(CFLAGS) -o test_dac.elf -Wl,-Map,test_dac.map test_dac.o lcd.o kbd.o dac.o
77 test_dac.o: test_dac.c lcd.h lcd_hw.h kbd.h dac.h
78         $(CC) $(CFLAGS) -Os -c test_dac.c
79 #-------------------
80 lcd.o : lcd.c lcd.h lcd_hw.h
81         $(CC) $(CFLAGS) -Os -c lcd.c
82 #-------------------
83 analog.o : analog.c analog.h hardware_settings.h
84         $(CC) $(CFLAGS) -Os -c analog.c
85 #-------------------
86 dac.o : dac.c dac.h 
87         $(CC) $(CFLAGS) -Os -c dac.c
88 #-------------------
89 kbd.o : kbd.c kbd.h 
90         $(CC) $(CFLAGS) -Os -c kbd.c
91 #-------------------
92 load: main.hex
93         $(LOADCMD) $(LOADARG)main.hex
94 #
95 load_test_lcd: test_lcd.hex
96         $(LOADCMD) $(LOADARG)test_lcd.hex
97 #
98 load_test_dac: test_dac.hex
99         $(LOADCMD) $(LOADARG)test_dac.hex
100 #
101 #-------------------
102 # fuse byte settings:
103 #  Atmel AVR ATmega8 
104 #  Fuse Low Byte      = 0xe1 (1MHz internal), 0xe3 (4MHz internal), 0xe4 (8MHz internal)
105 #  Fuse High Byte     = 0xd9 
106 #  Factory default is 0xe1 for low byte and 0xd9 for high byte
107 # Check this with make rdfuses
108 rdfuses:
109         $(LOADCMD) -p $(DUDECPUTYPE) -c stk500v2 -v -q
110 # use internal RC oscillator 8 Mhz (lf=0xe4 hf=0xd9)
111 fuses:
112         $(LOADCMD) -p  $(DUDECPUTYPE) -c stk500v2 -u -v -U lfuse:w:0xe4:m
113         $(LOADCMD) -p  $(DUDECPUTYPE) -c stk500v2 -u -v -U hfuse:w:0xd9:m
114 fuse:
115         $(LOADCMD) -p  $(DUDECPUTYPE) -c stk500v2 -u -v -U lfuse:w:0xe4:m
116         $(LOADCMD) -p  $(DUDECPUTYPE) -c stk500v2 -u -v -U hfuse:w:0xd9:m
117 #-------------------
118 clean:
119         rm -f *.o *.map *.elf test*.hex main.hex 
120 #-------------------