Skip to content

Commit

Permalink
feat: add ATmega32 example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hossein-M98 committed Nov 22, 2023
1 parent 8a3090b commit b88df2f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
65 changes: 65 additions & 0 deletions example/ATmega32-GCC/counter/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
**********************************************************************************
* @file main.c
* @author Hossein.M (https://github.com/Hossein-M98)
* @brief example code for TM1638 Driver (for ATmega32)
**********************************************************************************
*
* Copyright (c) 2023 Mahda Embedded System (MIT License)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************************
*/

#include <avr/io.h>
#include <util/delay.h>
#include "TM1638.h"
#include "TM1638_platform.h"


int main(void)
{
TM1638_Handler_t Handler = {0};

TM1638_Platform_Init(&Handler);
TM1638_Platform_Init(&Handler);
TM1638_Init(&Handler, TM1638DisplayTypeComCathode);
TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON);

while (1)
{
for (uint16_t i = 0; i < 10000; i++)
{
uint8_t Buffer[4] = {0};
Buffer[0] = i % 10;
Buffer[1] = (i / 10) % 10;
Buffer[2] = (i / 100) % 10;
Buffer[3] = (i / 1000) % 10;

Buffer[1] |= TM1638DecimalPoint;

TM1638_SetMultipleDigit_HEX(&Handler, Buffer, 0, 4);
_delay_ms(100);
}
}

TM1638_DeInit(&Handler);
return 0;
}
50 changes: 50 additions & 0 deletions example/ATmega32-GCC/counter/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CC = avr-gcc
OBJCPY = avr-objcopy

MCU = atmega32
CLK = 8000000
OPT = -Os
CFLAGS = -Wall -Wextra -g -std=c99

TARGET = output
BUILD_DIR = build
INC_DIR = ../../../config ../../../src/include ../../../port/ATmega32-GCC
SRC = ./main.c ../../../src/TM1638.c ../../../port/ATmega32-GCC/TM1638_platform.c


ifeq ($(OS),Windows_NT)
FIXPATH = $(subst /,\,$1)
RMD := rd /s /q
MD := mkdir
else
FIXPATH = $1
RMD = rm -r
MD := mkdir -p
endif


SOURCES = $(filter %.c, $(SRC))
INCLUDES = $(patsubst %,-I%, $(INC_DIR:%/=%))
CFLAGS += -mmcu=$(MCU) -DF_CPU=$(CLK) $(OPT)
OUTPUT_ELF = $(addsuffix .elf,$(call FIXPATH,$(BUILD_DIR)/$(TARGET)))
OUTPUT_HEX = $(addsuffix .hex,$(call FIXPATH,$(BUILD_DIR)/$(TARGET)))


all: $(BUILD_DIR) $(TARGET).hex

clean:
$(RMD) $(call FIXPATH,$(BUILD_DIR))

.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $(call FIXPATH,$(addprefix $(BUILD_DIR)/,$(notdir $@)))

# elf file
$(TARGET).elf: $(SOURCES:.c=.o)
$(CC) $(CFLAGS) $(INCLUDES) -o $(OUTPUT_ELF) $(call FIXPATH,$(addprefix $(BUILD_DIR)/,$(notdir $(SOURCES:.c=.o))))

# hex file
$(TARGET).hex: $(TARGET).elf
$(OBJCPY) -j .text -j .data -O ihex $(OUTPUT_ELF) $(OUTPUT_HEX)

$(BUILD_DIR):
$(MD) $(call FIXPATH,$(BUILD_DIR))
2 changes: 0 additions & 2 deletions port/ATmega32-GCC/TM1638_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

/* Includes ---------------------------------------------------------------------*/
#include "TM1638_platform.h"

#define F_CPU TM1638_AVR_CLK
#include <avr/io.h>
#include <util/delay.h>

Expand Down
1 change: 0 additions & 1 deletion port/ATmega32-GCC/TM1638_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ extern "C" {
/**
* @brief Specify IO Pins of AVR connected to TM1638
*/
#define TM1638_AVR_CLK 8000000UL
#define TM1638_CLK_DDR DDRA
#define TM1638_CLK_PORT PORTA
#define TM1638_CLK_NUM 0
Expand Down

0 comments on commit b88df2f

Please sign in to comment.