Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Hagen-002 #65

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ build/*
config
.pioenvs
.piolibdeps
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/.browse.c_cpp.db*
.vscode/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SDCC ?= sdcc
STCCODESIZE ?= 4089
SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59
SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 0 --data-loc 0x30
SDCCREV ?= -Dstc15f204ea
STCGAL ?= stcgal/stcgal.py
STCGALOPTS ?=
Expand Down
40 changes: 40 additions & 0 deletions Makefile.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SDCC ?= sdcc
STCCODESIZE ?= 4089
SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59
SDCCREV ?= -Dstc15f204ea
STCGAL ?= stcgal/stcgal.py
STCGALOPTS ?=
STCGALPORT ?= /dev/ttyUSB0
STCGALPROT ?= auto
FLASHFILE ?= main.hex
SYSCLK ?= 11059
CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY

SRC = src/adc.c src/ds1302.c

OBJ=$(patsubst src%.c,build%.rel, $(SRC))

all: main

build/%.rel: src/%.c src/%.h
mkdir -p $(dir $@)
$(SDCC) $(SDCCOPTS) $(SDCCREV) -o $@ -c $<

main: $(OBJ)
$(SDCC) -o build/ src/[email protected] $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $^
@ tail -n 5 build/main.mem | head -n 2
@ tail -n 1 build/main.mem
cp build/[email protected] [email protected]

eeprom:
sed -ne '/:..1/ { s/1/0/2; p }' main.hex > eeprom.hex

flash:
$(STCGAL) -p $(STCGALPORT) -P $(STCGALPROT) -t $(SYSCLK) $(STCGALOPTS) $(FLASHFILE)

clean:
rm -f *.ihx *.hex *.bin
rm -rf build/*

cpp: SDCCOPTS+=-E
cpp: main
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# STC DIY Clock Kit firmware

Firmware replacement for STC15F mcu-based DIY Clock Kit (available from banggood [see below for link], aliexpress, et al.) Uses [sdcc](http://sdcc.sf.net) to build and [stcgal](https://github.com/grigorig/stcgal) to flash firmware on to STC15F204EA (and STC15W408AS) series microcontroller.
Firmware replacement for STC15 mcu-based DIY Clock Kit (available from banggood [see below for link], aliexpress, et al.) Uses [sdcc](http://sdcc.sf.net) to build and [stcgal](https://github.com/grigorig/stcgal) to flash firmware on to STC15F204EA (and STC15W408AS) series microcontroller.

![Image of Banggood SKU972289](http://img.banggood.com/thumb/large/2014/xiemeijuan/03/SKU203096/A3.jpg?p=WX0407753399201409DA)

Expand All @@ -18,7 +18,7 @@ Firmware replacement for STC15F mcu-based DIY Clock Kit (available from banggood
* hourly chime

## Experimental support
* time sync to GPS receiver outputting serial NMEA data
* time sync to serial NMEA data output from GPS receiver
* on `gps` branch: https://github.com/zerog2k/stc_diyclock/tree/gps
* for STC15W408AS or STC15W404AS (sorry no STC15F204EA, not enough ram/code, no hw uart)
* very experimental at this point (help wanted to polish this)
Expand Down
22 changes: 22 additions & 0 deletions do_make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off
echo make clean
del main.hex
del build\*.?*
echo make
rem mkdir -p build/
if not exist build mkdir build

SET SDCC_FLAGS=-Dstc15f204ea --code-size 4089 --xram-size 0 --data-loc 0x30
rem SET SDCC_FLAGS=-Dstc15w404as --code-size 4089 --xram-size 256 --data-loc 0x30
rem SET SDCC_FLAGS=-Dstc15w408as --code-size 8185 --xram-size 256 --data-loc 0x30

rem We do NOT disable these warnings globally: --disable-warning 126 --disable-warning 59
SET MAIN_FLAGS=%SDCC_FLAGS% -DSHOW_TEMP_DATE_WEEKDAY
sdcc %SDCC_FLAGS% -o build\adc.rel -c src\adc.c
sdcc %SDCC_FLAGS% -o build\ds1302.rel -c src\ds1302.c
sdcc %MAIN_FLAGS% -o build\ src\main.c build\adc.rel build\ds1302.rel
rem tail -n 5 build/main.mem | head -n 2
rem tail -n 1 build/main.mem
copy build\main.ihx main.hex
echo make flash
echo stcgal -p /dev/ttyUSB0 -P auto -t 11059 main.hex
2 changes: 1 addition & 1 deletion docs/modifiedItems.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Modification items to stc_diyclock by KazHat
By this change, easily recognize day of the week even some alphabet's shape is not match the actual alphabet.
For example, T looks 7, I is 1, W is upsidedown of A and so on.

2. Add smooth function.
2. Add snooze function.
When push S1 button (upper button), stop the alarm and alarm again after 5 minutes later.
This continues up to 1 hour to avoid alarm forever.
Push + button (lower button) for stopping the alarm.
Expand Down
61 changes: 18 additions & 43 deletions src/adc.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
/*---------------------------------------------------------------------------------*/
/* --- STC MCU International Limited -------------------------------------
*/
/* --- STC 15 Series MCU A/D Conversion Demo -----------------------
*/
/* --- Mobile: (86)13922805190 --------------------------------------------
*/
/* --- Fax: 86-755-82944243 -------------------------------------------------*/
/* --- Tel: 86-755-82948412 -------------------------------------------------
*/
/* --- Web: www.STCMCU.com --------------------------------------------
*/
/* If you want to use the program or the program referenced in the ---*/
/* article, please specify in which data and procedures from STC ---
*/
/*----------------------------------------------------------------------------------*/
#include "stc15.h"
// STC15 Series MCU A/D Conversion Demo from www.stcmcu.com
#include "adc.h"

/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC(uint8_t chan)
{
P1ASF |= 1 << chan; //enable channel ADC function
ADC_RES = 0; //Clear previous result
ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
//Delay(2); //ADC power-on and delay
void InitADC(uint8_t chan) {
P1ASF |= 1 << chan; // enable channel ADC function
ADC_RES = 0; // Clear previous result
ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
// Delay(2); // ADC power-on and delay
}

/*----------------------------
Get ADC result - 10 bit
----------------------------*/
uint16_t getADCResult(uint8_t chan)
{
uint8_t upper8;
upper8 = getADCResult8(chan);
return upper8 << 2 | (ADC_RESL & 0b11) ; //Return ADC result, 10 bits
// Get ADC result - 10 bits
uint16_t getADCResult(uint8_t chan) {
uint8_t upper8 = getADCResult8(chan);
return (upper8 << 2) | (ADC_RESL & 0b11); // Return ADC result, 10 bits
}

uint8_t getADCResult8(uint8_t chan)
{
ADC_CONTR = ADC_POWER | ADC_SPEEDHH | ADC_START | chan;
_nop_; //Must wait before inquiry
while (!(ADC_CONTR & ADC_FLAG)); //Wait complete flag
ADC_CONTR &= ~ADC_FLAG; //Close ADC
return ADC_RES; //Return ADC result, 8 bits
// Get ADC result - 8 bits
uint8_t getADCResult8(uint8_t chan) {
ADC_CONTR = ADC_POWER | ADC_SPEEDHH | ADC_START | chan;
_nop_; // Must wait before inquiry
while (!(ADC_CONTR & ADC_FLAG))
/* wait */; // Wait complete flag
ADC_CONTR &= ~ADC_FLAG; // Close ADC
return ADC_RES; // Return ADC result, 8 bits
}


50 changes: 13 additions & 37 deletions src/adc.h
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
/*---------------------------------------------------------------------------------*/
/* --- STC MCU International Limited -------------------------------------
*/
/* --- STC 15 Series MCU A/D Conversion Demo -----------------------
*/
/* --- Mobile: (86)13922805190 --------------------------------------------
*/
/* --- Fax: 86-755-82944243 -------------------------------------------------*/
/* --- Tel: 86-755-82948412 -------------------------------------------------
*/
/* --- Web: www.STCMCU.com --------------------------------------------
*/
/* If you want to use the program or the program referenced in the ---*/
/* article, please specify in which data and procedures from STC ---
*/
/*----------------------------------------------------------------------------------*/
#include "stc15.h"
// STC15 Series MCU A/D Conversion Demo from www.stcmcu.com
#include <stdint.h>

#include "stc15.h"

#define _nop_ __asm nop __endasm;

/*Define ADC operation const for ADC_CONTR*/
#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC complete flag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //540 clocks
#define ADC_SPEEDL 0x20 //360 clocks
#define ADC_SPEEDH 0x40 //180 clocks
#define ADC_SPEEDHH 0x60 //90 clocks
// Define ADC_CONTR operation constants
#define ADC_POWER 0x80 // ADC power control bit
#define ADC_FLAG 0x10 // ADC complete flag
#define ADC_START 0x08 // ADC start control bit
#define ADC_SPEEDLL 0x00 // 540 clocks
#define ADC_SPEEDL 0x20 // 360 clocks
#define ADC_SPEEDH 0x40 // 180 clocks
#define ADC_SPEEDHH 0x60 // 90 clocks

/*----------------------------
Initialize ADC sfr
----------------------------*/
void InitADC(uint8_t chan);

/*----------------------------
Get ADC result - 10 bits
----------------------------*/
// Get ADC result - 10 bits
uint16_t getADCResult(uint8_t chan);

/*----------------------------
Get ADC result - 8 bits
----------------------------*/
// Get ADC result - 8 bits
uint8_t getADCResult8(uint8_t chan);



Loading