Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikisama committed Apr 9, 2021
0 parents commit 5acb040
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
93 changes: 93 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig

# Created by https://www.toptal.com/developers/gitignore/api/c,cmake,ninja,vscode
# Edit at https://www.toptal.com/developers/gitignore?templates=c,cmake,ninja,vscode

### C ###
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json

### CMake Patch ###
# External projects
*-prefix/

### Ninja ###
.ninja_deps
.ninja_log

### vscode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/c,cmake,ninja,vscode

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
!.vscode/c_cpp_properties.json
24 changes: 24 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/Users/HP/scoop/apps/sdcc/4.1.0/include",
"C:/Users/HP/scoop/apps/sdcc/4.1.0/non-free/include/pic14",
"${workspaceFolder}/**"
],
"defines": [
"__code=",
"interrupt=",
"__sfr=char",
"__at(x)=",
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c99",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.h": "c",
}
}
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.18.0)

set(CMAKE_USER_MAKE_RULES_OVERRIDE cmake/override.cmake)

set(CMAKE_C_COMPILER "C:/Users/HP/scoop/apps/sdcc/4.1.0/bin/sdcc.exe")

# make CMake happy with sdcc
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_SYSTEM_NAME Generic)

set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE MinSizeRel)

project(firmware
LANGUAGES C
)

add_executable(${PROJECT_NAME} main.c)

# set(PROG_TOOL "pk3")
set(PROG_TOOL "icd3")
set(MCU_ID "12f617")
set(IPECMD "C:/Program Files (x86)/Microchip/MPLABX/v3.55/mplab_ipe/ipecmd.exe")

set(CMAKE_C_FLAGS "--use-non-free -mpic14 -p${MCU_ID}")

# Enable the target power supply - VDD = 4.75 volts.
# -W4.75

add_custom_target(erase
COMMAND
${IPECMD} -TP${PROG_TOOL} -P${MCU_ID} -E -W4.75
COMMENT "erase ${MCU_ID} with ${PROG_TOOL}..."
)

add_custom_target(flash
COMMAND
${IPECMD} -TP${PROG_TOOL} -P${MCU_ID} -M -W4.75 -F\"${CMAKE_BINARY_DIR}/firmware.hex\"
DEPENDS all
COMMENT "flash ${MCU_ID} with ${PROG_TOOL}..."
)
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SDCC PIC12F617 example

## Requirement

1. [SDCC](https://sourceforge.net/projects/sdcc/files/)
2. [GPUTILS](https://sourceforge.net/projects/gputils/files/)
3. [CMake](https://github.com/Kitware/CMake/releases)
4. [Ninja](https://github.com/ninja-build/ninja/releases)

## How to Build

modify the `CMAKE_C_COMPILER` variable in `CMakeLists.txt`

```bash
$ cd build
$ cmake -G Ninja ..
$ ninja
```
8 changes: 8 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.ninja
*.cod
*.lst
log.0
log.1
log.2
MPLABXLog.xml
MPLABXLog.xml.lck
1 change: 1 addition & 0 deletions cmake/override.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(CMAKE_C_OUTPUT_EXTENSION ".o")
72 changes: 72 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdint.h>
#include <pic12f617.h>

__code uint16_t __at(_CONFIG) __configword = _FOSC_INTOSCIO &
_WDTE_OFF &
_PWRTE_OFF &
_MCLRE_OFF &
_CP_OFF &
_IOSCFS_4MHZ &
_BOREN_ON &
_WRT_OFF;

volatile uint8_t tick_reached;
volatile uint8_t sys_ticks = 0;

/* make VSCode happy */
#ifdef __SDCC
#define ISR __interrupt 0
#else
#define ISR
#endif

void isr(void) ISR
{
if (TMR1IF == 1)
{
TMR1IF = 0; /* clear timer1 interrupt flag */
TMR1H = 0xD8; /* ((55535 >> 8) & 0xff) 10ms */
TMR1L = 0xEF; /* ((55535 >> 0) & 0xff) 10ms */
tick_reached = 1; /* set tick flag */
}
}

int main(void)
{
/* LED is on GP5 */
TRISIO &= ~(1u << 5); /* config GP5 output */
ANSEL &= ~(1u << 5); /* config GP5 digital I/O */
WPU &= ~(1u << 5); /* disable GP5 pullup */

/**
* 10ms = 0.01s
* (0.01 * (fOSC/4/pre)) = 65535 - TMR1
* TMR1 = 65535 - (0.01 * (fOSC/4/pre))
* = 65535 - (0.01 * (4000000/4/1))
* = 55535
*/
TMR1CS = 0; /* Timer1 clock source INTOSC */
T1CKPS1 = 0; /* Timer1 prescale 1 */
T1CKPS0 = 0; /* Timer1 prescale 1 */
TMR1H = 0xD8; /* ((55535 >> 8) & 0xff) 10ms */
TMR1L = 0xEF; /* ((55535 >> 0) & 0xff) 10ms */
TMR1ON = 1; /* enable timer1 */
TMR1IE = 1; /* enable timer1 interrupt */

PEIE = 1; /* enable peripheral interrupt */
GIE = 1; /* enable global interrupt */

while (1)
{
if (tick_reached)
{
tick_reached = 0;
sys_ticks++;
if (sys_ticks == 50) /* blink the LED every 10 * 50 ms */
{
GPIO ^= (1u << 5); /* toggle GP5 output */
sys_ticks = 0;
}
}
}
}

0 comments on commit 5acb040

Please sign in to comment.