Skip to content

Instantly share code, notes, and snippets.

View TG9541's full-sized avatar

Thomas TG9541

View GitHub Profile
@TG9541
TG9541 / Clrdisplay.fs
Last active July 22, 2017 07:19
STM8EF Snippets
: Clrdisplay ( -- ) \ clear anything showing
32 E7S 32 E7S 32 E7S ;
@TG9541
TG9541 / servo.fs
Last active November 17, 2017 05:48
STM8S103F3 RC servo control
\ STM8 eForth interactive RC-servo demo
\ set compilation target for STARTTEMP / ENDTEMP
: TARGET NVM ;
#require hw/pwm.fs
#require OPT!
#include STARTTEMP
@TG9541
TG9541 / W1209-HC-SR04.fs
Last active March 3, 2022 07:31
A W1209 thermostat displays distance captured by an HC-SR04 ultrasonic sensor
\ The HC-SR04 "trig" pin is connected to the SET key input (PC3).
\ The "echo" pin is connected to the same GPIO with a 1k resistor
\ Uses TIM1 with 1µs clock -> 3.4mm resolution.
#require ]B!
\res MCU: STM8S103
\res export PC_DDR PC_ODR PC_CR1
\res export TIM1_PSCRH TIM1_SR1 TIM1_CCMR3 TIM1_CCMR4 TIM1_CCER2 TIM1_CR1
\res export TIM1_CCR3HTIM1_CCR4H
@TG9541
TG9541 / ECHO
Created February 3, 2018 08:29
Make local echo in STM8 eForth optional
\ STM8 eForth ECHO
\ Make local echo in STM8 eForth optional
\ Note1: since this code patches TAP, and sets the startup word,
\ it should be loaded with #require ECHO
\ Note2: the RAM address of variable TAPECHO must be below 0x0100,
\ it's recommended to #require ECHO early on in the main file
\ Note3: this file sets the 'BOOT vector for initializing TAPECHO -
\ any startup code must execute this task!
#require TAP
@TG9541
TG9541 / GET
Created February 3, 2018 09:37
GET and print variable as fixed point in STM8 eForth interpreter
RAM
#require TOKEN
#require >IN
#require .ID
#require .0
NVM
: GET ( string -- )
\ interpretion semantics: get and print variable
>IN @ TOKEN CR .ID ." ="
>IN ! ' EXECUTE
@TG9541
TG9541 / EEALL.fs
Last active April 16, 2018 18:52
ALIAS loader for STM8S003F3 EECORE dictionary demo
#require <#
\ #require $,"
#require $"
\ #require $"|
#require #
#require #>
\ #require 0
\ #require 1
\ #require -1
#require 2DROP
@TG9541
TG9541 / globconf.inc
Created March 27, 2018 20:49
EECORE global configuration for STM8 eForth v2.2.22.pre
; STM8EF Global Configuration File
; Minimal config for STM8S Value Line, defaults with few extras (e.g. NVM)
HAS_CPNVM = 1 ; Can compile to Flash, always interpret to RAM
BAREBONES = 1 ; Remove or unlink some more: hi HERE .R U.R SPACES @EXECUTE AHEAD CALL, EXIT COMPILE [COMPILE]
WORDS_EXTRACORE = 1 ; Extra core words: =0 I
WORDS_EXTRAEEPR = 1 ; Extra EEPROM lock/unlock words: LOCK ULOCK ULOCKF LOCKF
; RESET RAM NVM LOCK ULOCK WORDS .S DUMP IMMEDIATE ALLOT VARIABLE CONSTANT CREATE ] : ;
; OVERT ." AFT REPEAT WHILE ELSE THEN IF AGAIN UNTIL BEGIN NEXT FOR LITERAL C, , ' CR [
@TG9541
TG9541 / free.fs
Created June 18, 2018 21:14
get free memory in the RAM dictionary, and in the variable area
#require PAD
: SP@ ( -- a ) \ push current stack pointer
[ $9093 , \ LDW Y,X
$5A C, \ DECW X
$5A C, \ DECW X
$FF C, ] \ LDW (X),Y
;
: dict.free SP@ PAD - . ;
@TG9541
TG9541 / solar.fs
Last active September 24, 2018 18:52
Simple solar heating controller based on a MINDEV board
\res MCU: STM8S103
\res export PA_ODR
\res export PA_DDR
\res export PA_CR1
\res export PC_DDR
\res export PC_CR1
#require ]B!
1 CONSTANT _COL \ PA1 low side KTY10 solar collector
@TG9541
TG9541 / ntctheta
Last active July 9, 2023 11:27
Solar water heater control with transmission of collector and storage temperature via nRF24L01+
\ W1209 temperature measurement with filter and noise suppression
\ © 2017 TG9541, refer to https://github.com/TG9541/W1209/blob/master/LICENSE
\ Note: W1209 thermostats may require adjustment,
\ especially when used outside the range of -5C to +20C
\ Refer to https://github.com/TG9541/W1209/wiki/W1209-Sensor
RAM
900 CONSTANT USENSMAX \ max temperature