Skip to content

Commit b88df2f

Browse files
committed
feat: add ATmega32 example
1 parent 8a3090b commit b88df2f

4 files changed

Lines changed: 115 additions & 3 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
**********************************************************************************
3+
* @file main.c
4+
* @author Hossein.M (https://github.com/Hossein-M98)
5+
* @brief example code for TM1638 Driver (for ATmega32)
6+
**********************************************************************************
7+
*
8+
* Copyright (c) 2023 Mahda Embedded System (MIT License)
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*
28+
**********************************************************************************
29+
*/
30+
31+
#include <avr/io.h>
32+
#include <util/delay.h>
33+
#include "TM1638.h"
34+
#include "TM1638_platform.h"
35+
36+
37+
int main(void)
38+
{
39+
TM1638_Handler_t Handler = {0};
40+
41+
TM1638_Platform_Init(&Handler);
42+
TM1638_Platform_Init(&Handler);
43+
TM1638_Init(&Handler, TM1638DisplayTypeComCathode);
44+
TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON);
45+
46+
while (1)
47+
{
48+
for (uint16_t i = 0; i < 10000; i++)
49+
{
50+
uint8_t Buffer[4] = {0};
51+
Buffer[0] = i % 10;
52+
Buffer[1] = (i / 10) % 10;
53+
Buffer[2] = (i / 100) % 10;
54+
Buffer[3] = (i / 1000) % 10;
55+
56+
Buffer[1] |= TM1638DecimalPoint;
57+
58+
TM1638_SetMultipleDigit_HEX(&Handler, Buffer, 0, 4);
59+
_delay_ms(100);
60+
}
61+
}
62+
63+
TM1638_DeInit(&Handler);
64+
return 0;
65+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
CC = avr-gcc
2+
OBJCPY = avr-objcopy
3+
4+
MCU = atmega32
5+
CLK = 8000000
6+
OPT = -Os
7+
CFLAGS = -Wall -Wextra -g -std=c99
8+
9+
TARGET = output
10+
BUILD_DIR = build
11+
INC_DIR = ../../../config ../../../src/include ../../../port/ATmega32-GCC
12+
SRC = ./main.c ../../../src/TM1638.c ../../../port/ATmega32-GCC/TM1638_platform.c
13+
14+
15+
ifeq ($(OS),Windows_NT)
16+
FIXPATH = $(subst /,\,$1)
17+
RMD := rd /s /q
18+
MD := mkdir
19+
else
20+
FIXPATH = $1
21+
RMD = rm -r
22+
MD := mkdir -p
23+
endif
24+
25+
26+
SOURCES = $(filter %.c, $(SRC))
27+
INCLUDES = $(patsubst %,-I%, $(INC_DIR:%/=%))
28+
CFLAGS += -mmcu=$(MCU) -DF_CPU=$(CLK) $(OPT)
29+
OUTPUT_ELF = $(addsuffix .elf,$(call FIXPATH,$(BUILD_DIR)/$(TARGET)))
30+
OUTPUT_HEX = $(addsuffix .hex,$(call FIXPATH,$(BUILD_DIR)/$(TARGET)))
31+
32+
33+
all: $(BUILD_DIR) $(TARGET).hex
34+
35+
clean:
36+
$(RMD) $(call FIXPATH,$(BUILD_DIR))
37+
38+
.c.o:
39+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $(call FIXPATH,$(addprefix $(BUILD_DIR)/,$(notdir $@)))
40+
41+
# elf file
42+
$(TARGET).elf: $(SOURCES:.c=.o)
43+
$(CC) $(CFLAGS) $(INCLUDES) -o $(OUTPUT_ELF) $(call FIXPATH,$(addprefix $(BUILD_DIR)/,$(notdir $(SOURCES:.c=.o))))
44+
45+
# hex file
46+
$(TARGET).hex: $(TARGET).elf
47+
$(OBJCPY) -j .text -j .data -O ihex $(OUTPUT_ELF) $(OUTPUT_HEX)
48+
49+
$(BUILD_DIR):
50+
$(MD) $(call FIXPATH,$(BUILD_DIR))

port/ATmega32-GCC/TM1638_platform.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
/* Includes ---------------------------------------------------------------------*/
3232
#include "TM1638_platform.h"
33-
34-
#define F_CPU TM1638_AVR_CLK
3533
#include <avr/io.h>
3634
#include <util/delay.h>
3735

port/ATmega32-GCC/TM1638_platform.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ extern "C" {
4747
/**
4848
* @brief Specify IO Pins of AVR connected to TM1638
4949
*/
50-
#define TM1638_AVR_CLK 8000000UL
5150
#define TM1638_CLK_DDR DDRA
5251
#define TM1638_CLK_PORT PORTA
5352
#define TM1638_CLK_NUM 0

0 commit comments

Comments
 (0)