├── README.md ├── boards.txt ├── cores ├── stc8g │ ├── Arduino.h │ ├── STC8G.h │ ├── dummy_variable_main.h │ ├── main.c │ ├── wiring.c │ └── wiring_private.h └── stc8h │ ├── Arduino.h │ ├── HardwareSerial.c │ ├── HardwareSerial.h │ ├── STC8H.h │ ├── c51_types.h │ ├── dummy_variable_main.h │ ├── main.c │ ├── wiring.c │ ├── wiring_digital.c │ └── wiring_private.h ├── package_ma6254_stcduino_index.json ├── platform.txt ├── programmers.txt └── variants ├── STC8G1K08A ├── pins_arduino.h └── pins_arduino_include.h └── STC8H8K64U ├── pins_arduino.h └── pins_arduino_include.h /README.md: -------------------------------------------------------------------------------- 1 | # Arduino core support for STC based boards 2 | 3 | **This project is under development and is not yet available.** 4 | 5 | ## Introduction 6 | 7 | This repo adds the support of STC MCU in Arduino IDE. 8 | 9 | ## Supported boards 10 | 11 | - STC8H Series 12 | - STC8G Series 13 | 14 | ## Getting Started 15 | 16 | Add this link in the "Additional Boards Managers URLs" field: 17 | 18 | ``` 19 | https://github.com/ma6254/Arduino_Core_STC/raw/main/package_ma6254_stcduino_index.json 20 | ``` 21 | -------------------------------------------------------------------------------- /boards.txt: -------------------------------------------------------------------------------- 1 | # See: https://arduino.github.io/arduino-cli/latest/platform-specification/ 2 | 3 | menu.usb_settings=USB Settings 4 | menu.clock=Clock Source 5 | menu.upload_method=Upload method 6 | 7 | ############################################################## 8 | 9 | #=============================================================================== 10 | # STC8G1K08A 11 | #=============================================================================== 12 | STC8G1K08A.name=STC8G1K08A Board 13 | STC8G1K08A.build.mcu=stc8051 14 | STC8G1K08A.build.core=stc8g 15 | STC8G1K08A.build.board=STC8G1K08A 16 | STC8G1K08A.build.variant=STC8G1K08A 17 | 18 | # XRAM 19 | # offset: 0 20 | # Size: 1K 21 | STC8G1K08A.upload.xdata_location=0 22 | STC8G1K08A.upload.maximum_data_size=1024 23 | 24 | # Flash Size: 8K 25 | STC8G1K08A.upload.maximum_size=8192 26 | 27 | #=============================================================================== 28 | # STC8H 29 | #=============================================================================== 30 | STC8H8K64U.name=STC8H8K64U Board 31 | STC8H8K64U.build.mcu=stc8051 32 | STC8H8K64U.build.core=stc8h 33 | STC8H8K64U.build.board=STC8H8K64U 34 | STC8H8K64U.build.variant=STC8H8K64U 35 | 36 | STC8H8K64U.menu.clock.inel_12M=12 MHz (internal) 37 | STC8H8K64U.menu.clock.inel_12M.build.f_cpu=12000000L 38 | 39 | STC8H8K64U.menu.clock.inel_24M=24 MHz (internal) 40 | STC8H8K64U.menu.clock.inel_24M.build.f_cpu=24000000L 41 | 42 | STC8H8K64U.menu.clock.inel_30M=30 MHz (internal) 43 | STC8H8K64U.menu.clock.inel_30M.build.f_cpu=30000000L 44 | 45 | 46 | STC8H8K64U.upload.protocol=stcburn 47 | 48 | STC8H8K64U.menu.clock.inel_35M=35 MHz (internal) 49 | STC8H8K64U.menu.clock.inel_35M.build.f_cpu=35000000L 50 | 51 | STC8H8K64U.menu.upload_method.stcflash=stcflash 52 | STC8H8K64U.menu.upload_method.stcflash.upload.tool=stcflash 53 | 54 | STC8H8K64U.menu.upload_method.stcgal=stcgal 55 | STC8H8K64U.menu.upload_method.stcgal.upload.tool=stcgal 56 | 57 | # XRAM 58 | # offset: 0 59 | # Size: 8K 60 | STC8H8K64U.upload.xdata_location=0 61 | STC8H8K64U.upload.maximum_data_size=8192 62 | 63 | # Flash Size: 64K 64 | STC8H8K64U.upload.maximum_size=65536 65 | -------------------------------------------------------------------------------- /cores/stc8g/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2005-2013 Arduino Team. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Arduino_h 21 | #define Arduino_h 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | //#include 31 | //#include 32 | //#include 33 | #include "STC8G.h" 34 | // #include "include/ch5xx_usb.h" 35 | #include "pins_arduino_include.h" 36 | //Macro-based digital IO fucntions 37 | // #include "wiring_digital_fast.h" 38 | 39 | //!!!!#include "binary.h" 40 | 41 | // FIXME: workarounds for missing features or unimplemented functions 42 | // cancel out the PROGMEM attribute - used only for atmel CPUs 43 | #define PROGMEM 44 | void yield(void); 45 | 46 | // we use pre-defined IRQ function the way wiring does 47 | #define WIRING 48 | 49 | 50 | 51 | #define HIGH 0x1 52 | #define LOW 0x0 53 | 54 | #define INPUT 0x0 55 | #define OUTPUT 0x1 56 | #define INPUT_PULLUP 0x2 57 | #define OUTPUT_OD 0x03 58 | 59 | // undefine mathlib's pi if encountered 60 | #ifdef PI 61 | #undef PI 62 | #endif 63 | #ifdef HALF_PI 64 | #undef HALF_PI 65 | #endif 66 | #ifdef TWO_PI 67 | #undef TWO_PI 68 | #endif 69 | 70 | #define PI 3.1415926535897932384626433832795 71 | #define HALF_PI 1.5707963267948966192313216916398 72 | #define TWO_PI 6.283185307179586476925286766559 73 | #define DEG_TO_RAD 0.017453292519943295769236907684886 74 | #define RAD_TO_DEG 57.295779513082320876798154814105 75 | #define EULER 2.718281828459045235360287471352 76 | 77 | #define SERIAL 0x0 78 | #define DISPLAY 0x1 79 | 80 | #define LSBFIRST 0 81 | #define MSBFIRST 1 82 | 83 | #define FALLING 1 84 | 85 | /* 86 | #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 87 | #define DEFAULT 0 88 | #define EXTERNAL 1 89 | #define INTERNAL1V1 2 90 | #define INTERNAL INTERNAL1V1 91 | #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 92 | #define DEFAULT 0 93 | #define EXTERNAL 4 94 | #define INTERNAL1V1 8 95 | #define INTERNAL INTERNAL1V1 96 | #define INTERNAL2V56 9 97 | #define INTERNAL2V56_EXTCAP 13 98 | #else 99 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) 100 | #define INTERNAL1V1 2 101 | #define INTERNAL2V56 3 102 | #else 103 | #define INTERNAL 3 104 | #endif 105 | #define DEFAULT 1 106 | #define EXTERNAL 0 107 | #endif 108 | */ 109 | 110 | // undefine stdlib's abs if encountered 111 | #ifdef abs 112 | #undef abs 113 | #endif 114 | 115 | #define min(a,b) ((a)<(b)?(a):(b)) 116 | #define max(a,b) ((a)>(b)?(a):(b)) 117 | #define abs(x) ((x)>0?(x):-(x)) 118 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 119 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 120 | #define radians(deg) ((deg)*DEG_TO_RAD) 121 | #define degrees(rad) ((rad)*RAD_TO_DEG) 122 | #define sq(x) ((x)*(x)) 123 | 124 | #define interrupts() (EA=1) 125 | #define noInterrupts() (EA=0) 126 | 127 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 128 | #define clockCyclesPerMillisecond() ( F_CPU / 1000L ) 129 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 130 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 131 | 132 | #define byte(w) ((uint8_t)(w)) 133 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 134 | #define highByte(w) ((uint8_t) ((w) >> 8)) 135 | 136 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 137 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 138 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 139 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 140 | 141 | #define maskSet(value, mask) ((value) |= (mask)) 142 | #define maskClear(value, mask) ((value) &= ~(mask)) 143 | 144 | 145 | // avr-libc defines _NOP() since 1.6.2 146 | #ifndef _NOP 147 | #define _NOP() do { __asm__ volatile ("nop"); } while (0) 148 | #endif 149 | 150 | #define BEGIN_CRITICAL __critical { 151 | #define END_CRITICAL } 152 | 153 | 154 | typedef unsigned int word; 155 | 156 | #define bit(b) (1UL << (b)) 157 | 158 | typedef unsigned char boolean; 159 | typedef unsigned char byte; 160 | //typedef uint8_t byte; 161 | 162 | void init(void); 163 | //void initVariant(void); // weak 164 | 165 | //int atexit(void (*func)()); // __attribute__((weak)); 166 | //void serialEvent(void); // weak 167 | //extern unsigned char runSerialEvent; 168 | 169 | void pinMode(uint8_t pin, __xdata uint8_t mode); 170 | void digitalWrite(uint8_t pin, __xdata uint8_t val); 171 | uint8_t digitalRead(uint8_t pin); 172 | #if defined(CH559) 173 | uint16_t analogRead(uint8_t pin); 174 | #else 175 | uint8_t analogRead(uint8_t pin); 176 | #endif 177 | void analogWrite(uint8_t pin, __xdata uint16_t val); 178 | 179 | uint32_t millis(void); 180 | uint32_t micros(void); 181 | void delay(uint32_t ms); 182 | void delayMicroseconds(uint16_t us); 183 | //unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 184 | //unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 185 | 186 | //void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 187 | //uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 188 | 189 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), __xdata uint8_t mode); 190 | void detachInterrupt(uint8_t interruptNum); 191 | 192 | void setup(void); 193 | void loop(void); 194 | 195 | // Get the bit location within the hardware port of the given virtual pin. 196 | // This comes from the pins_*.c file for the active board configuration. 197 | 198 | #define analogInPinToBit(P) (P) 199 | 200 | // On the ATmega1280, the addresses of some of the port registers are 201 | // greater than 255, so we can't store them in uint8_t's. 202 | 203 | 204 | #ifdef SUPPORT_ALTERNATE_MAPPINGS 205 | // helper function for STM8S: switch to the alternate pin functions 206 | //void alternateFunction(uint8_t val); 207 | #endif 208 | 209 | 210 | 211 | 212 | 213 | //FIXME#include "WCharacter.h" 214 | //FIXME#include "WString.h" 215 | // #include "HardwareSerial.h" 216 | 217 | //uint16_t makeWord(uint16_t w); 218 | //uint16_t makeWord(byte h, byte l); 219 | 220 | //#define word(...) makeWord(__VA_ARGS__) 221 | 222 | //unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 223 | //unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 224 | 225 | //void tone(uint8_t _pin, unsigned int frequency, unsigned long duration); 226 | //void noTone(uint8_t _pin); 227 | 228 | // WMath prototypes 229 | long random(long howbig); 230 | long random_minmax(long howsmall, __xdata long howbig); 231 | void randomSeed(unsigned long seed); 232 | long map(long x, __xdata long in_min, __xdata long in_max, __xdata long out_min, __xdata long out_max); 233 | 234 | inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 235 | 236 | 237 | /* 238 | * The new interrupt numbers are a combination of the position in the 239 | * internal jump table (value in LSB) and the real STM8S-Interrupt number (MSB) 240 | */ 241 | #define INT_PORTA ( 0| (uint16_t)(ITC_IRQ_PORTA << 8)) 242 | #define INT_PORTB ( 1| (uint16_t)(ITC_IRQ_PORTB << 8)) 243 | #define INT_PORTC ( 2| (uint16_t)(ITC_IRQ_PORTC << 8)) 244 | #define INT_PORTD ( 3| (uint16_t)(ITC_IRQ_PORTD << 8)) 245 | #define INT_PORTE ( 4| (uint16_t)(ITC_IRQ_PORTE << 8)) 246 | #define INT_TIM1_CAPCOM ( 5| (uint16_t)(ITC_IRQ_TIM1_CAPCOM << 8)) 247 | #define INT_TIM1_OVF ( 6| (uint16_t)(ITC_IRQ_TIM1_OVF << 8)) 248 | #define INT_TIM2_CAPCOM ( 7| (uint16_t)(ITC_IRQ_TIM2_CAPCOM << 8)) 249 | #define INT_TIM2_OVF ( 8| (uint16_t)(ITC_IRQ_TIM2_OVF << 8)) 250 | 251 | 252 | //USB Serial functions. Don't exist in Arduino AVR core Arduino.h, may be moved later 253 | bool USBSerial(); 254 | uint8_t USBSerial_print_n(uint8_t * __xdata buf, __xdata int len); 255 | uint8_t USBSerial_write(char c); 256 | void USBSerial_flush(void); 257 | uint8_t USBSerial_available(); 258 | char USBSerial_read(); 259 | // #include "Print.h" 260 | 261 | // Generic selection for print 262 | // #include "genericPrintSelection.h" 263 | 264 | // not quite understans X marco in sduino, use a lot define for now 265 | 266 | #define USBSerial_print_s(P) ( Print_print_s(USBSerial_write,(P)) ) 267 | #define USBSerial_print_sn(P,Q) ( Print_print_sn(USBSerial_write,(P),(Q)) ) 268 | #define USBSerial_print_i(P) ( Print_print_i(USBSerial_write,(P)) ) 269 | #define USBSerial_print_u(P) ( Print_print_u(USBSerial_write,(P)) ) 270 | #define USBSerial_print_ib(P,Q) ( Print_print_ib(USBSerial_write,(P),(Q)) ) 271 | #define USBSerial_print_ub(P,Q) ( Print_print_ub(USBSerial_write,(P),(Q)) ) 272 | #define USBSerial_print_f(P) ( Print_print_f(USBSerial_write,(P)) ) 273 | #define USBSerial_print_fd(P,Q) ( Print_print_fd(USBSerial_write,(P),(Q)) ) 274 | #define USBSerial_print_c(P) ( (USBSerial_write(P)) ) 275 | 276 | #define USBSerial_println_only() ( Print_println(USBSerial_write) ) 277 | #define USBSerial_println_s(P) ( Print_print_s(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 278 | #define USBSerial_println_sn(P,Q) ( Print_print_sn(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 279 | #define USBSerial_println_i(P) ( Print_print_i(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 280 | #define USBSerial_println_u(P) ( Print_print_u(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 281 | #define USBSerial_println_ib(P,Q) ( Print_print_ib(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 282 | #define USBSerial_println_ub(P,Q) ( Print_print_ub(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 283 | #define USBSerial_println_f(P) ( Print_print_f(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 284 | #define USBSerial_println_fd(P,Q) ( Print_print_fd(USBSerial_write,(P),(Q) ) + Print_println(USBSerial_write) ) 285 | #define USBSerial_println_c(P) ( (USBSerial_write(P)) + Print_println(USBSerial_write) ) 286 | 287 | 288 | #define Serial0_print_s(P) ( Print_print_s(Serial0_write,(P)) ) 289 | #define Serial0_print_sn(P,Q) ( Print_print_sn(Serial0_write,(P),(Q)) ) 290 | #define Serial0_print_i(P) ( Print_print_i(Serial0_write,(P)) ) 291 | #define Serial0_print_u(P) ( Print_print_u(Serial0_write,(P)) ) 292 | #define Serial0_print_ib(P,Q) ( Print_print_ib(Serial0_write,(P),(Q)) ) 293 | #define Serial0_print_ub(P,Q) ( Print_print_ub(Serial0_write,(P),(Q)) ) 294 | #define Serial0_print_f(P) ( Print_print_f(Serial0_write,(P)) ) 295 | #define Serial0_print_fd(P,Q) ( Print_print_fd(Serial0_write,(P),(Q)) ) 296 | #define Serial0_print_c(P) ( (Serial0_write(P)) ) 297 | 298 | #define Serial0_println_only() ( Print_println(Serial0_write) ) 299 | #define Serial0_println_s(P) ( Print_print_s(Serial0_write,(P)) + Print_println(Serial0_write) ) 300 | #define Serial0_println_sn(P,Q) ( Print_print_sn(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 301 | #define Serial0_println_i(P) ( Print_print_i(Serial0_write,(P)) + Print_println(Serial0_write) ) 302 | #define Serial0_println_u(P) ( Print_print_u(Serial0_write,(P)) + Print_println(Serial0_write) ) 303 | #define Serial0_println_ib(P,Q) ( Print_print_ib(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 304 | #define Serial0_println_ub(P,Q) ( Print_print_ub(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 305 | #define Serial0_println_f(P) ( Print_print_f(Serial0_write,(P)) + Print_println(Serial0_write) ) 306 | #define Serial0_println_fd(P,Q) ( Print_print_fd(Serial0_write,(P),(Q) ) + Print_println(Serial0_write) ) 307 | #define Serial0_println_c(P) ( (Serial0_write(P)) + Print_println(Serial0_write) ) 308 | 309 | 310 | #define Serial1_print_s(P) ( Print_print_s(Serial1_write,(P)) ) 311 | #define Serial1_print_sn(P,Q) ( Print_print_sn(Serial1_write,(P),(Q)) ) 312 | #define Serial1_print_i(P) ( Print_print_i(Serial1_write,(P)) ) 313 | #define Serial1_print_u(P) ( Print_print_u(Serial1_write,(P)) ) 314 | #define Serial1_print_ib(P,Q) ( Print_print_ib(Serial1_write,(P),(Q)) ) 315 | #define Serial1_print_ub(P,Q) ( Print_print_ub(Serial1_write,(P),(Q)) ) 316 | #define Serial1_print_f(P) ( Print_print_f(Serial1_write,(P)) ) 317 | #define Serial1_print_fd(P,Q) ( Print_print_fd(Serial1_write,(P),(Q)) ) 318 | #define Serial1_print_c(P) ( (Serial1_write(P)) ) 319 | 320 | #define Serial1_println_only() ( Print_println(Serial1_write) ) 321 | #define Serial1_println_s(P) ( Print_print_s(Serial1_write,(P)) + Print_println(Serial1_write) ) 322 | #define Serial1_println_sn(P,Q) ( Print_print_sn(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 323 | #define Serial1_println_i(P) ( Print_print_i(Serial1_write,(P)) + Print_println(Serial1_write) ) 324 | #define Serial1_println_u(P) ( Print_print_u(Serial1_write,(P)) + Print_println(Serial1_write) ) 325 | #define Serial1_println_ib(P,Q) ( Print_print_ib(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 326 | #define Serial1_println_ub(P,Q) ( Print_print_ub(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 327 | #define Serial1_println_f(P) ( Print_print_f(Serial1_write,(P)) + Print_println(Serial1_write) ) 328 | #define Serial1_println_fd(P,Q) ( Print_print_fd(Serial1_write,(P),(Q) ) + Print_println(Serial1_write) ) 329 | #define Serial1_println_c(P) ( (Serial1_write(P)) + Print_println(Serial1_write) ) 330 | 331 | //10K lifecycle DataFlash access on CH551/CH552. 332 | #define eeprom_write_byte(ADDR,VAL) { DPL=(VAL);DPH=(ADDR);eeprom_write_byte_2_params_DPTR(); } 333 | //SDCC is not efficent to convert 2 8bit data to 1 16bit data, se we use DPTR directly. The mismatch of parameter of the H and C is intentional 334 | void eeprom_write_byte_2_params_DPTR(); 335 | uint8_t eeprom_read_byte (uint8_t addr); 336 | 337 | #endif 338 | -------------------------------------------------------------------------------- /cores/stc8g/STC8G.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_REGS_STC8H_H__ 2 | #define __SYS_REGS_STC8H_H__ 3 | 4 | #define SBIT(name, addr, bit) __sbit __at(addr + bit) name 5 | #define SFR(name, addr) __sfr __at(addr) name 6 | #define SFRX(name, addr) __xdata volatile unsigned char __at(addr) name 7 | #define SFR16(name, addr) __sfr16 __at(((addr + 1U) << 8) | addr) name 8 | #define SFR16E(name, fulladdr) __sfr16 __at(fulladdr) name 9 | #define SFR32(name, addr) __sfr32 __at(((addr + 3UL) << 24) | ((addr + 2UL) << 16) | ((addr + 1UL) << 8) | addr) name 10 | #define SFR32E(name, fulladdr) __sfr32 __at(fulladdr) name 11 | 12 | // #ifdef __cplusplus 13 | // extern "C" 14 | // { 15 | // #endif 16 | 17 | /******************************************************************************* 18 | * Interrupt Number 19 | ******************************************************************************/ 20 | #define ISR_NO_INT0 0 // 21 | #define ISR_NO_TIMER0 1 // 22 | #define ISR_NO_INT1 2 // 23 | #define ISR_NO_TIMER1 3 // 24 | #define ISR_NO_UART1 4 // 25 | #define ISR_NO_ADC 5 // 26 | #define ISR_NO_LVD 6 // 27 | #define ISR_NO_PCA 7 // 28 | #define ISR_NO_UART2 8 // 29 | #define ISR_NO_SPI 9 // 30 | #define ISR_NO_INT2 10 // 31 | #define ISR_NO_INT3 11 // 32 | #define ISR_NO_TIMER2 12 // 33 | #define ISR_NO_INT4 16 // 34 | #define ISR_NO_UART3 17 // 35 | #define ISR_NO_UART4 18 // 36 | #define ISR_NO_TIMER3 19 // 37 | #define ISR_NO_TIMER4 20 // 38 | #define ISR_NO_CMP 21 // 39 | #define ISR_NO_PWM0 22 // 40 | #define ISR_NO_PWM0FD 23 // 41 | #define ISR_NO_I2C 24 // 42 | #define ISR_NO_USB 25 // 43 | #define ISR_NO_PWM1 28 // 44 | #define ISR_NO_PWM2 29 // 45 | #define ISR_NO_PWM3 30 // 46 | #define ISR_NO_PWM4 31 // 47 | #define ISR_NO_PWM5 32 // 48 | #define ISR_NO_PWM2FD 33 // 49 | #define ISR_NO_PWM4FD 34 // 50 | #define ISR_NO_TKSU 35 // 51 | 52 | /******************************************************************************* 53 | * Interrupt Registers 54 | ******************************************************************************/ 55 | SFR(IE, 0xA8); // interrupt enable 56 | SBIT(EA, 0xA8, 7); // global isr enable 57 | SBIT(ELVD, 0xA8, 6); // low voltage delect 58 | SBIT(EADC, 0xA8, 5); // adc 59 | SBIT(ES, 0xA8, 4); // uart1 60 | SBIT(ET1, 0xA8, 3); // timer1 61 | SBIT(EX1, 0xA8, 2); // external interrupt 1 62 | SBIT(ET0, 0xA8, 1); // timer0 63 | SBIT(EX0, 0xA8, 0); // external interrupt 0 64 | SFR(IE2, 0xAF); // interrupt enable 65 | SBIT(ETKSUI, 0xAF, 7); // touchkey 66 | SBIT(ET4, 0xAF, 6); // timer4 67 | SBIT(ET3, 0xAF, 5); // timer3 68 | SBIT(ES4, 0xAF, 4); // uart4 69 | SBIT(ES3, 0xAF, 3); // uart3 70 | SBIT(ET2, 0xAF, 2); // timer2 71 | SBIT(ESPI, 0xAF, 1); // spi 72 | SBIT(ES2, 0xAF, 0); // uart2 73 | 74 | /******************************************************************************* 75 | * GPIO Registers 76 | ******************************************************************************/ 77 | SFR(P0, 0x80); // GPIO 0 78 | SBIT(P0_0, 0x80, 0); // .0 79 | SBIT(P0_1, 0x80, 1); // .1 80 | SBIT(P0_2, 0x80, 2); // .2 81 | SBIT(P0_3, 0x80, 3); // .3 82 | SBIT(P0_4, 0x80, 4); // .4 83 | SBIT(P0_5, 0x80, 5); // .5 84 | SBIT(P0_6, 0x80, 6); // .6 85 | SBIT(P0_7, 0x80, 7); // .7 86 | SFR(P1, 0x90); // GPIO 1 87 | SBIT(P1_0, 0x90, 0); // .0 88 | SBIT(P1_1, 0x90, 1); // .1 89 | SBIT(P1_2, 0x90, 2); // .2 90 | SBIT(P1_3, 0x90, 3); // .3 91 | SBIT(P1_4, 0x90, 4); // .4 92 | SBIT(P1_5, 0x90, 5); // .5 93 | SBIT(P1_6, 0x90, 6); // .6 94 | SBIT(P1_7, 0x90, 7); // .7 95 | SFR(P2, 0xA0); // GPIO 2 96 | SBIT(P2_0, 0xA0, 0); // .0 97 | SBIT(P2_1, 0xA0, 1); // .1 98 | SBIT(P2_2, 0xA0, 2); // .2 99 | SBIT(P2_3, 0xA0, 3); // .3 100 | SBIT(P2_4, 0xA0, 4); // .4 101 | SBIT(P2_5, 0xA0, 5); // .5 102 | SBIT(P2_6, 0xA0, 6); // .6 103 | SBIT(P2_7, 0xA0, 7); // .7 104 | SFR(P3, 0xB0); // GPIO 3 105 | SBIT(P3_0, 0xB0, 0); // .0 106 | SBIT(P3_1, 0xB0, 1); // .1 107 | SBIT(P3_2, 0xB0, 2); // .2 108 | SBIT(P3_3, 0xB0, 3); // .3 109 | SBIT(P3_4, 0xB0, 4); // .4 110 | SBIT(P3_5, 0xB0, 5); // .5 111 | SBIT(P3_6, 0xB0, 6); // .6 112 | SBIT(P3_7, 0xB0, 7); // .7 113 | SFR(P4, 0xC0); // GPIO 4 114 | SBIT(P4_0, 0xC0, 0); // .0 115 | SBIT(P4_1, 0xC0, 1); // .1 116 | SBIT(P4_2, 0xC0, 2); // .2 117 | SBIT(P4_3, 0xC0, 3); // .3 118 | SBIT(P4_4, 0xC0, 4); // .4 119 | SBIT(P4_5, 0xC0, 5); // .5 120 | SBIT(P4_6, 0xC0, 6); // .6 121 | SBIT(P4_7, 0xC0, 7); // .7 122 | SFR(P5, 0xC8); // GPIO 5 123 | SBIT(P5_0, 0xC8, 0); // .0 124 | SBIT(P5_1, 0xC8, 1); // .1 125 | SBIT(P5_2, 0xC8, 2); // .2 126 | SBIT(P5_3, 0xC8, 3); // .3 127 | SBIT(P5_4, 0xC8, 4); // .4 128 | SBIT(P5_5, 0xC8, 5); // .5 129 | SBIT(P5_6, 0xC8, 6); // .6 130 | SBIT(P5_7, 0xC8, 7); // .7 131 | 132 | 133 | 134 | // #ifdef __cplusplus 135 | // } 136 | // #endif 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /cores/stc8g/dummy_variable_main.h: -------------------------------------------------------------------------------- 1 | //add a reference to main to pull in main.c 2 | void main(void); void (*dummy_variable) () = main; 3 | 4 | 5 | -------------------------------------------------------------------------------- /cores/stc8g/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Interrupt_INT0(void) __interrupt(ISR_NO_INT0); 4 | void Interrupt_TIMER0(void) __interrupt(ISR_NO_TIMER0); 5 | void Interrupt_INT1(void) __interrupt(ISR_NO_INT1); 6 | void Interrupt_TIMER1(void) __interrupt(ISR_NO_TIMER1); 7 | void Interrupt_UART0(void) __interrupt(ISR_NO_UART0); 8 | void Interrupt_ADC(void) __interrupt(ISR_NO_ADC); 9 | void Interrupt_LVD(void) __interrupt(ISR_NO_LVD); 10 | void Interrupt_PCA(void) __interrupt(ISR_NO_PCA); 11 | void Interrupt_UART2(void) __interrupt(ISR_NO_UART2); 12 | void Interrupt_SPI(void) __interrupt(ISR_NO_SPI); 13 | void Interrupt_INT2(void) __interrupt(ISR_NO_INT2); 14 | void Interrupt_INT3(void) __interrupt(ISR_NO_INT3); 15 | void Interrupt_TIMER2(void) __interrupt(ISR_NO_TIMER2); 16 | void Interrupt_INT4(void) __interrupt(ISR_NO_INT4); 17 | void Interrupt_UART3(void) __interrupt(ISR_NO_UART3); 18 | void Interrupt_UART4(void) __interrupt(ISR_NO_UART4); 19 | void Interrupt_TIMER3(void) __interrupt(ISR_NO_TIMER3); 20 | void Interrupt_TIMER4(void) __interrupt(ISR_NO_TIMER4); 21 | void Interrupt_CMP(void) __interrupt(ISR_NO_CMP); 22 | void Interrupt_I2C(void) __interrupt(ISR_NO_I2C); 23 | void Interrupt_USB(void) __interrupt(ISR_NO_USB); 24 | void Interrupt_PWMA(void) __interrupt(ISR_NO_PWMA); 25 | void Interrupt_PWMB(void) __interrupt(ISR_NO_PWMB); 26 | void Interrupt_TKSU(void) __interrupt(ISR_NO_TKSU); 27 | void Interrupt_RTC(void) __interrupt(ISR_NO_RTC); 28 | void Interrupt_P0INT(void) __interrupt(ISR_NO_P0INT); 29 | void Interrupt_P1INT(void) __interrupt(ISR_NO_P1INT); 30 | void Interrupt_P2INT(void) __interrupt(ISR_NO_P2INT); 31 | void Interrupt_P3INT(void) __interrupt(ISR_NO_P3INT); 32 | void Interrupt_P4INT(void) __interrupt(ISR_NO_P4INT); 33 | void Interrupt_P5INT(void) __interrupt(ISR_NO_P5INT); 34 | void Interrupt_P6INT(void) __interrupt(ISR_NO_P6INT); 35 | void Interrupt_P7INT(void) __interrupt(ISR_NO_P7INT); 36 | void Interrupt_DMA_M2M(void) __interrupt(ISR_NO_DMA_M2M); 37 | void Interrupt_DMA_ADC(void) __interrupt(ISR_NO_DMA_ADC); 38 | void Interrupt_DMA_SPI(void) __interrupt(ISR_NO_DMA_SPI); 39 | void Interrupt_DMA_UR1T(void) __interrupt(ISR_NO_DMA_UR1T); 40 | void Interrupt_DMA_UR1R(void) __interrupt(ISR_NO_DMA_UR1R); 41 | void Interrupt_DMA_UR2T(void) __interrupt(ISR_NO_DMA_UR2T); 42 | void Interrupt_DMA_UR2R(void) __interrupt(ISR_NO_DMA_UR2R); 43 | void Interrupt_DMA_UR3T(void) __interrupt(ISR_NO_DMA_UR3T); 44 | void Interrupt_DMA_UR3R(void) __interrupt(ISR_NO_DMA_UR3R); 45 | void Interrupt_DMA_UR4T(void) __interrupt(ISR_NO_DMA_UR4T); 46 | void Interrupt_DMA_UR4R(void) __interrupt(ISR_NO_DMA_UR4R); 47 | void Interrupt_DMA_LCM(void) __interrupt(ISR_NO_DMA_LCM); 48 | void Interrupt_LCM(void) __interrupt(ISR_NO_LCM); 49 | 50 | void main(void) 51 | { 52 | init(); 53 | 54 | //!!!initVariant(); 55 | 56 | setup(); 57 | 58 | for (;;) 59 | { 60 | loop(); 61 | } 62 | 63 | // return 0; 64 | } 65 | 66 | unsigned char _sdcc_external_startup(void) __nonbanked 67 | { 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /cores/stc8g/wiring.c: -------------------------------------------------------------------------------- 1 | #include "wiring_private.h" 2 | 3 | void init() 4 | { 5 | EA = 0; 6 | EA = 1; 7 | } 8 | -------------------------------------------------------------------------------- /cores/stc8g/wiring_private.h: -------------------------------------------------------------------------------- 1 | #ifndef WiringPrivate_h 2 | #define WiringPrivate_h 3 | 4 | #include 5 | #include 6 | // #include "include/ch5xx.h" 7 | // #include "include/ch5xx_usb.h" 8 | 9 | #include "Arduino.h" 10 | 11 | 12 | typedef void (*voidFuncPtr)(void); 13 | 14 | #define EXTERNAL_INT_0 0 15 | #define EXTERNAL_INT_1 1 16 | 17 | #define EXTERNAL_NUM_INTERRUPTS 2 18 | 19 | #endif -------------------------------------------------------------------------------- /cores/stc8h/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2005-2013 Arduino Team. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Arduino_h 21 | #define Arduino_h 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | //#include 31 | //#include 32 | //#include 33 | #include "STC8H.h" 34 | // #include "include/ch5xx_usb.h" 35 | #include "pins_arduino_include.h" 36 | //Macro-based digital IO fucntions 37 | // #include "wiring_digital_fast.h" 38 | 39 | //!!!!#include "binary.h" 40 | 41 | // FIXME: workarounds for missing features or unimplemented functions 42 | // cancel out the PROGMEM attribute - used only for atmel CPUs 43 | #define PROGMEM 44 | void yield(void); 45 | 46 | // we use pre-defined IRQ function the way wiring does 47 | #define WIRING 48 | 49 | 50 | 51 | #define HIGH 0x1 52 | #define LOW 0x0 53 | 54 | #define INPUT 0x0 55 | #define OUTPUT 0x1 56 | #define INPUT_PULLUP 0x2 57 | #define OUTPUT_OD 0x03 58 | 59 | // undefine mathlib's pi if encountered 60 | #ifdef PI 61 | #undef PI 62 | #endif 63 | #ifdef HALF_PI 64 | #undef HALF_PI 65 | #endif 66 | #ifdef TWO_PI 67 | #undef TWO_PI 68 | #endif 69 | 70 | #define PI 3.1415926535897932384626433832795 71 | #define HALF_PI 1.5707963267948966192313216916398 72 | #define TWO_PI 6.283185307179586476925286766559 73 | #define DEG_TO_RAD 0.017453292519943295769236907684886 74 | #define RAD_TO_DEG 57.295779513082320876798154814105 75 | #define EULER 2.718281828459045235360287471352 76 | 77 | #define SERIAL 0x0 78 | #define DISPLAY 0x1 79 | 80 | #define LSBFIRST 0 81 | #define MSBFIRST 1 82 | 83 | #define FALLING 1 84 | 85 | /* 86 | #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 87 | #define DEFAULT 0 88 | #define EXTERNAL 1 89 | #define INTERNAL1V1 2 90 | #define INTERNAL INTERNAL1V1 91 | #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 92 | #define DEFAULT 0 93 | #define EXTERNAL 4 94 | #define INTERNAL1V1 8 95 | #define INTERNAL INTERNAL1V1 96 | #define INTERNAL2V56 9 97 | #define INTERNAL2V56_EXTCAP 13 98 | #else 99 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) 100 | #define INTERNAL1V1 2 101 | #define INTERNAL2V56 3 102 | #else 103 | #define INTERNAL 3 104 | #endif 105 | #define DEFAULT 1 106 | #define EXTERNAL 0 107 | #endif 108 | */ 109 | 110 | // undefine stdlib's abs if encountered 111 | #ifdef abs 112 | #undef abs 113 | #endif 114 | 115 | #define min(a,b) ((a)<(b)?(a):(b)) 116 | #define max(a,b) ((a)>(b)?(a):(b)) 117 | #define abs(x) ((x)>0?(x):-(x)) 118 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 119 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 120 | #define radians(deg) ((deg)*DEG_TO_RAD) 121 | #define degrees(rad) ((rad)*RAD_TO_DEG) 122 | #define sq(x) ((x)*(x)) 123 | 124 | #define interrupts() (EA=1) 125 | #define noInterrupts() (EA=0) 126 | 127 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 128 | #define clockCyclesPerMillisecond() ( F_CPU / 1000L ) 129 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 130 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 131 | 132 | #define byte(w) ((uint8_t)(w)) 133 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 134 | #define highByte(w) ((uint8_t) ((w) >> 8)) 135 | 136 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 137 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 138 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 139 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 140 | 141 | #define maskSet(value, mask) ((value) |= (mask)) 142 | #define maskClear(value, mask) ((value) &= ~(mask)) 143 | 144 | 145 | // avr-libc defines _NOP() since 1.6.2 146 | #ifndef _NOP 147 | #define _NOP() do { __asm__ volatile ("nop"); } while (0) 148 | #endif 149 | 150 | #define BEGIN_CRITICAL __critical { 151 | #define END_CRITICAL } 152 | 153 | 154 | typedef unsigned int word; 155 | 156 | #define bit(b) (1UL << (b)) 157 | 158 | typedef unsigned char boolean; 159 | typedef unsigned char byte; 160 | //typedef uint8_t byte; 161 | 162 | void init(void); 163 | //void initVariant(void); // weak 164 | 165 | //int atexit(void (*func)()); // __attribute__((weak)); 166 | //void serialEvent(void); // weak 167 | //extern unsigned char runSerialEvent; 168 | 169 | void pinMode(uint8_t pin, __xdata uint8_t mode); 170 | void digitalWrite(uint8_t pin, __xdata uint8_t val); 171 | uint8_t digitalRead(uint8_t pin); 172 | uint16_t analogRead(uint8_t pin); 173 | void analogWrite(uint8_t pin, __xdata uint16_t val); 174 | 175 | uint32_t millis(void); 176 | uint32_t micros(void); 177 | void delay(uint32_t ms); 178 | void delayMicroseconds(uint16_t us); 179 | //unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 180 | //unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 181 | 182 | //void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 183 | //uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 184 | 185 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), __xdata uint8_t mode); 186 | void detachInterrupt(uint8_t interruptNum); 187 | 188 | void setup(void); 189 | void loop(void); 190 | 191 | // Get the bit location within the hardware port of the given virtual pin. 192 | // This comes from the pins_*.c file for the active board configuration. 193 | 194 | #define analogInPinToBit(P) (P) 195 | 196 | // On the ATmega1280, the addresses of some of the port registers are 197 | // greater than 255, so we can't store them in uint8_t's. 198 | 199 | 200 | #ifdef SUPPORT_ALTERNATE_MAPPINGS 201 | // helper function for STM8S: switch to the alternate pin functions 202 | //void alternateFunction(uint8_t val); 203 | #endif 204 | 205 | 206 | 207 | 208 | 209 | //FIXME#include "WCharacter.h" 210 | //FIXME#include "WString.h" 211 | // #include "HardwareSerial.h" 212 | 213 | //uint16_t makeWord(uint16_t w); 214 | //uint16_t makeWord(byte h, byte l); 215 | 216 | //#define word(...) makeWord(__VA_ARGS__) 217 | 218 | //unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 219 | //unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 220 | 221 | //void tone(uint8_t _pin, unsigned int frequency, unsigned long duration); 222 | //void noTone(uint8_t _pin); 223 | 224 | // WMath prototypes 225 | long random(long howbig); 226 | long random_minmax(long howsmall, __xdata long howbig); 227 | void randomSeed(unsigned long seed); 228 | long map(long x, __xdata long in_min, __xdata long in_max, __xdata long out_min, __xdata long out_max); 229 | 230 | inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 231 | 232 | 233 | /* 234 | * The new interrupt numbers are a combination of the position in the 235 | * internal jump table (value in LSB) and the real STM8S-Interrupt number (MSB) 236 | */ 237 | #define INT_PORTA ( 0| (uint16_t)(ITC_IRQ_PORTA << 8)) 238 | #define INT_PORTB ( 1| (uint16_t)(ITC_IRQ_PORTB << 8)) 239 | #define INT_PORTC ( 2| (uint16_t)(ITC_IRQ_PORTC << 8)) 240 | #define INT_PORTD ( 3| (uint16_t)(ITC_IRQ_PORTD << 8)) 241 | #define INT_PORTE ( 4| (uint16_t)(ITC_IRQ_PORTE << 8)) 242 | #define INT_TIM1_CAPCOM ( 5| (uint16_t)(ITC_IRQ_TIM1_CAPCOM << 8)) 243 | #define INT_TIM1_OVF ( 6| (uint16_t)(ITC_IRQ_TIM1_OVF << 8)) 244 | #define INT_TIM2_CAPCOM ( 7| (uint16_t)(ITC_IRQ_TIM2_CAPCOM << 8)) 245 | #define INT_TIM2_OVF ( 8| (uint16_t)(ITC_IRQ_TIM2_OVF << 8)) 246 | 247 | 248 | //USB Serial functions. Don't exist in Arduino AVR core Arduino.h, may be moved later 249 | bool USBSerial(); 250 | uint8_t USBSerial_print_n(uint8_t * __xdata buf, __xdata int len); 251 | uint8_t USBSerial_write(char c); 252 | void USBSerial_flush(void); 253 | uint8_t USBSerial_available(); 254 | char USBSerial_read(); 255 | // #include "Print.h" 256 | 257 | // Generic selection for print 258 | // #include "genericPrintSelection.h" 259 | 260 | // not quite understans X marco in sduino, use a lot define for now 261 | 262 | #define USBSerial_print_s(P) ( Print_print_s(USBSerial_write,(P)) ) 263 | #define USBSerial_print_sn(P,Q) ( Print_print_sn(USBSerial_write,(P),(Q)) ) 264 | #define USBSerial_print_i(P) ( Print_print_i(USBSerial_write,(P)) ) 265 | #define USBSerial_print_u(P) ( Print_print_u(USBSerial_write,(P)) ) 266 | #define USBSerial_print_ib(P,Q) ( Print_print_ib(USBSerial_write,(P),(Q)) ) 267 | #define USBSerial_print_ub(P,Q) ( Print_print_ub(USBSerial_write,(P),(Q)) ) 268 | #define USBSerial_print_f(P) ( Print_print_f(USBSerial_write,(P)) ) 269 | #define USBSerial_print_fd(P,Q) ( Print_print_fd(USBSerial_write,(P),(Q)) ) 270 | #define USBSerial_print_c(P) ( (USBSerial_write(P)) ) 271 | 272 | #define USBSerial_println_only() ( Print_println(USBSerial_write) ) 273 | #define USBSerial_println_s(P) ( Print_print_s(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 274 | #define USBSerial_println_sn(P,Q) ( Print_print_sn(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 275 | #define USBSerial_println_i(P) ( Print_print_i(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 276 | #define USBSerial_println_u(P) ( Print_print_u(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 277 | #define USBSerial_println_ib(P,Q) ( Print_print_ib(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 278 | #define USBSerial_println_ub(P,Q) ( Print_print_ub(USBSerial_write,(P),(Q)) + Print_println(USBSerial_write) ) 279 | #define USBSerial_println_f(P) ( Print_print_f(USBSerial_write,(P)) + Print_println(USBSerial_write) ) 280 | #define USBSerial_println_fd(P,Q) ( Print_print_fd(USBSerial_write,(P),(Q) ) + Print_println(USBSerial_write) ) 281 | #define USBSerial_println_c(P) ( (USBSerial_write(P)) + Print_println(USBSerial_write) ) 282 | 283 | 284 | #define Serial0_print_s(P) ( Print_print_s(Serial0_write,(P)) ) 285 | #define Serial0_print_sn(P,Q) ( Print_print_sn(Serial0_write,(P),(Q)) ) 286 | #define Serial0_print_i(P) ( Print_print_i(Serial0_write,(P)) ) 287 | #define Serial0_print_u(P) ( Print_print_u(Serial0_write,(P)) ) 288 | #define Serial0_print_ib(P,Q) ( Print_print_ib(Serial0_write,(P),(Q)) ) 289 | #define Serial0_print_ub(P,Q) ( Print_print_ub(Serial0_write,(P),(Q)) ) 290 | #define Serial0_print_f(P) ( Print_print_f(Serial0_write,(P)) ) 291 | #define Serial0_print_fd(P,Q) ( Print_print_fd(Serial0_write,(P),(Q)) ) 292 | #define Serial0_print_c(P) ( (Serial0_write(P)) ) 293 | 294 | #define Serial0_println_only() ( Print_println(Serial0_write) ) 295 | #define Serial0_println_s(P) ( Print_print_s(Serial0_write,(P)) + Print_println(Serial0_write) ) 296 | #define Serial0_println_sn(P,Q) ( Print_print_sn(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 297 | #define Serial0_println_i(P) ( Print_print_i(Serial0_write,(P)) + Print_println(Serial0_write) ) 298 | #define Serial0_println_u(P) ( Print_print_u(Serial0_write,(P)) + Print_println(Serial0_write) ) 299 | #define Serial0_println_ib(P,Q) ( Print_print_ib(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 300 | #define Serial0_println_ub(P,Q) ( Print_print_ub(Serial0_write,(P),(Q)) + Print_println(Serial0_write) ) 301 | #define Serial0_println_f(P) ( Print_print_f(Serial0_write,(P)) + Print_println(Serial0_write) ) 302 | #define Serial0_println_fd(P,Q) ( Print_print_fd(Serial0_write,(P),(Q) ) + Print_println(Serial0_write) ) 303 | #define Serial0_println_c(P) ( (Serial0_write(P)) + Print_println(Serial0_write) ) 304 | 305 | 306 | #define Serial1_print_s(P) ( Print_print_s(Serial1_write,(P)) ) 307 | #define Serial1_print_sn(P,Q) ( Print_print_sn(Serial1_write,(P),(Q)) ) 308 | #define Serial1_print_i(P) ( Print_print_i(Serial1_write,(P)) ) 309 | #define Serial1_print_u(P) ( Print_print_u(Serial1_write,(P)) ) 310 | #define Serial1_print_ib(P,Q) ( Print_print_ib(Serial1_write,(P),(Q)) ) 311 | #define Serial1_print_ub(P,Q) ( Print_print_ub(Serial1_write,(P),(Q)) ) 312 | #define Serial1_print_f(P) ( Print_print_f(Serial1_write,(P)) ) 313 | #define Serial1_print_fd(P,Q) ( Print_print_fd(Serial1_write,(P),(Q)) ) 314 | #define Serial1_print_c(P) ( (Serial1_write(P)) ) 315 | 316 | #define Serial1_println_only() ( Print_println(Serial1_write) ) 317 | #define Serial1_println_s(P) ( Print_print_s(Serial1_write,(P)) + Print_println(Serial1_write) ) 318 | #define Serial1_println_sn(P,Q) ( Print_print_sn(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 319 | #define Serial1_println_i(P) ( Print_print_i(Serial1_write,(P)) + Print_println(Serial1_write) ) 320 | #define Serial1_println_u(P) ( Print_print_u(Serial1_write,(P)) + Print_println(Serial1_write) ) 321 | #define Serial1_println_ib(P,Q) ( Print_print_ib(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 322 | #define Serial1_println_ub(P,Q) ( Print_print_ub(Serial1_write,(P),(Q)) + Print_println(Serial1_write) ) 323 | #define Serial1_println_f(P) ( Print_print_f(Serial1_write,(P)) + Print_println(Serial1_write) ) 324 | #define Serial1_println_fd(P,Q) ( Print_print_fd(Serial1_write,(P),(Q) ) + Print_println(Serial1_write) ) 325 | #define Serial1_println_c(P) ( (Serial1_write(P)) + Print_println(Serial1_write) ) 326 | 327 | //10K lifecycle DataFlash access on CH551/CH552. 328 | #define eeprom_write_byte(ADDR,VAL) { DPL=(VAL);DPH=(ADDR);eeprom_write_byte_2_params_DPTR(); } 329 | //SDCC is not efficent to convert 2 8bit data to 1 16bit data, se we use DPTR directly. The mismatch of parameter of the H and C is intentional 330 | void eeprom_write_byte_2_params_DPTR(); 331 | uint8_t eeprom_read_byte (uint8_t addr); 332 | 333 | #endif 334 | -------------------------------------------------------------------------------- /cores/stc8h/HardwareSerial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Arduino.h" 4 | 5 | #include "HardwareSerial.h" 6 | 7 | Serial_t Serial0; 8 | 9 | __xdata uint8_t Receive_Uart0_Buf[SERIAL0_RX_BUFFER_SIZE]; 10 | __xdata uint8_t Transmit_Uart0_Buf[SERIAL0_TX_BUFFER_SIZE]; 11 | volatile __xdata uint8_t uart0_rx_buffer_head = 0; 12 | volatile __xdata uint8_t uart0_rx_buffer_tail = 0; 13 | volatile __xdata uint8_t uart0_tx_buffer_head = 0; 14 | volatile __xdata uint8_t uart0_tx_buffer_tail = 0; 15 | volatile __bit uart0_flag_sending = 0; 16 | 17 | void _Int_UART0_Rx_Handler() 18 | { 19 | uint8_t nextHead = (uart0_rx_buffer_head + 1) % SERIAL0_RX_BUFFER_SIZE; 20 | 21 | if (nextHead != uart0_rx_buffer_tail) 22 | { 23 | Receive_Uart0_Buf[uart0_rx_buffer_head] = SBUF; 24 | uart0_rx_buffer_head = nextHead; 25 | } 26 | } 27 | 28 | void _Int_UART0_Tx_Handler() 29 | { 30 | if (uart0_flag_sending) 31 | { 32 | if (uart0_tx_buffer_head == uart0_tx_buffer_tail) 33 | { 34 | // do no more 35 | uart0_flag_sending &= 0; 36 | } 37 | else 38 | { 39 | SBUF = Transmit_Uart0_Buf[uart0_tx_buffer_tail]; 40 | uart0_tx_buffer_tail = (uart0_tx_buffer_tail + 1) % SERIAL0_TX_BUFFER_SIZE; 41 | } 42 | } 43 | } 44 | 45 | void _HwSerial0_begin(unsigned long baud) 46 | { 47 | uint32_t timeer_set = 0; 48 | 49 | pinMode(PIN_UART0_TXD, OUTPUT); 50 | pinMode(PIN_UART0_RXD, INPUT_PULLUP); 51 | 52 | Set_UART0_clk_div2(); 53 | Set_UART0_clkgen_T1(); 54 | Set_Timer1_1T(); 55 | 56 | SCON = 0x50; 57 | PCON = 0x00; 58 | 59 | timeer_set = 65535 - F_CPU / (baud * 4); 60 | TL1 = (uint8_t)(timeer_set); 61 | TH1 = (uint8_t)(timeer_set >> 8); 62 | 63 | ES = 1; 64 | Set_Timer1_Enable(); 65 | } 66 | 67 | uint8_t _HwSerial0_write(uint8_t SendDat) 68 | { 69 | uint8_t interruptOn = EA; 70 | EA = 0; 71 | 72 | if (interruptOn) 73 | EA = 1; 74 | 75 | // start to send 76 | if ((uart0_tx_buffer_head == uart0_tx_buffer_tail) && (uart0_flag_sending == 0)) 77 | { 78 | uart0_flag_sending = 1; 79 | SBUF = SendDat; 80 | if (interruptOn) 81 | EA = 1; 82 | return 1; 83 | } 84 | 85 | uint8_t nextHeadPos = ((uint8_t)(uart0_tx_buffer_head + 1)) % SERIAL0_TX_BUFFER_SIZE; 86 | 87 | // wait max 100ms or discard 88 | uint16_t waitWriteCount = 0; 89 | while ((nextHeadPos == uart0_tx_buffer_tail)) 90 | { 91 | if (interruptOn) 92 | EA = 1; 93 | delay(10); 94 | waitWriteCount++; 95 | if (waitWriteCount >= 10) 96 | return 0; 97 | } 98 | Transmit_Uart0_Buf[uart0_tx_buffer_head] = SendDat; 99 | 100 | uart0_tx_buffer_head = nextHeadPos; 101 | 102 | return 1; 103 | } 104 | 105 | void _HwSerial0_flush(void) 106 | { 107 | while (uart0_flag_sending) 108 | ; 109 | } 110 | 111 | void _HwSerial_putchar(char c, void *p) 112 | { 113 | __xdata uint8_t serial_port = (uint8_t)(p); 114 | 115 | switch (serial_port) 116 | { 117 | case 0: 118 | _HwSerial0_write(c); 119 | break; 120 | } 121 | } 122 | 123 | int _HwSerial0_print(const char *format, ...) 124 | { 125 | va_list argptr; 126 | int cnt; 127 | 128 | va_start(argptr, format); 129 | cnt = _print_format(_HwSerial_putchar, 0, format, argptr); 130 | va_end(argptr); 131 | 132 | return cnt; 133 | } 134 | 135 | void _HwSerialInit(void) 136 | { 137 | Serial0.write = _HwSerial0_write; 138 | Serial0.begin = _HwSerial0_begin; 139 | Serial0.flush = _HwSerial0_flush; 140 | Serial0.print = _HwSerial0_print; 141 | } 142 | -------------------------------------------------------------------------------- /cores/stc8h/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef HardwareSerial_h 2 | #define HardwareSerial_h 3 | 4 | #define SERIAL0_RX_BUFFER_SIZE 32 5 | #define SERIAL0_TX_BUFFER_SIZE 32 6 | 7 | typedef uint8_t (*_Fn_HwSerial_write)(uint8_t SendDat); 8 | typedef void (*_Fn_HwSerial_begin)(unsigned long baud); 9 | typedef void (*_Fn_HwSerial_flush)(void); 10 | typedef int (*_Fn_HwSerial_print)(const char *format, ...); 11 | 12 | typedef struct 13 | { 14 | _Fn_HwSerial_write write; 15 | _Fn_HwSerial_begin begin; 16 | _Fn_HwSerial_flush flush; 17 | _Fn_HwSerial_print print; 18 | } Serial_t; 19 | 20 | extern Serial_t Serial0; 21 | 22 | void _Int_UART0_Rx_Handler(); 23 | void _Int_UART0_Tx_Handler(); 24 | 25 | void _HwSerialInit(void); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /cores/stc8h/STC8H.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_REGS_STC8H_H__ 2 | #define __SYS_REGS_STC8H_H__ 3 | 4 | #define SBIT(name, addr, bit) __sbit __at(addr + bit) name 5 | #define SFR(name, addr) __sfr __at(addr) name 6 | #define SFRX(name, addr) __xdata volatile unsigned char __at(addr) name 7 | #define SFR16(name, addr) __sfr16 __at(((addr + 1U) << 8) | addr) name 8 | #define SFR16E(name, fulladdr) __sfr16 __at(fulladdr) name 9 | #define SFR32(name, addr) __sfr32 __at(((addr + 3UL) << 24) | ((addr + 2UL) << 16) | ((addr + 1UL) << 8) | addr) name 10 | #define SFR32E(name, fulladdr) __sfr32 __at(fulladdr) name 11 | 12 | // #ifdef __cplusplus 13 | // extern "C" 14 | // { 15 | // #endif 16 | 17 | /******************************************************************************* 18 | * Interrupt Number 19 | ******************************************************************************/ 20 | #define ISR_NO_INT0 0 // 21 | #define ISR_NO_TIMER0 1 // 22 | #define ISR_NO_INT1 2 // 23 | #define ISR_NO_TIMER1 3 // 24 | #define ISR_NO_UART0 4 // 25 | #define ISR_NO_ADC 5 // 26 | #define ISR_NO_LVD 6 // 27 | #define ISR_NO_PCA 7 // 28 | #define ISR_NO_UART2 8 // 29 | #define ISR_NO_SPI 9 // 30 | #define ISR_NO_INT2 10 // 31 | #define ISR_NO_INT3 11 // 32 | #define ISR_NO_TIMER2 12 // 33 | #define ISR_NO_INT4 16 // 34 | #define ISR_NO_UART3 17 // 35 | #define ISR_NO_UART4 18 // 36 | #define ISR_NO_TIMER3 19 // 37 | #define ISR_NO_TIMER4 20 // 38 | #define ISR_NO_CMP 21 // 39 | #define ISR_NO_I2C 24 // 40 | #define ISR_NO_USB 25 // 41 | #define ISR_NO_PWMA 26 // 42 | #define ISR_NO_PWMB 27 // 43 | #define ISR_NO_TKSU 35 // 44 | #define ISR_NO_RTC 36 // 45 | #define ISR_NO_P0INT 37 // 46 | #define ISR_NO_P1INT 38 // 47 | #define ISR_NO_P2INT 39 // 48 | #define ISR_NO_P3INT 40 // 49 | #define ISR_NO_P4INT 41 // 50 | #define ISR_NO_P5INT 42 // 51 | #define ISR_NO_P6INT 43 // 52 | #define ISR_NO_P7INT 44 // 53 | #define ISR_NO_DMA_M2M 47 // DMA: memory to memory 54 | #define ISR_NO_DMA_ADC 48 // DMA: adc 55 | #define ISR_NO_DMA_SPI 49 // DMA: spi 56 | #define ISR_NO_DMA_UR1T 50 // DMA: uart 1 tx 57 | #define ISR_NO_DMA_UR1R 51 // DMA: uart 1 rx 58 | #define ISR_NO_DMA_UR2T 52 // DMA: uart 2 tx 59 | #define ISR_NO_DMA_UR2R 53 // DMA: uart 2 rx 60 | #define ISR_NO_DMA_UR3T 54 // DMA: uart 3 tx 61 | #define ISR_NO_DMA_UR3R 55 // DMA: uart 3 rx 62 | #define ISR_NO_DMA_UR4T 56 // DMA: uart 4 tx 63 | #define ISR_NO_DMA_UR4R 57 // DMA: uart 4 rx 64 | #define ISR_NO_DMA_LCM 58 // DMA: lcm 65 | #define ISR_NO_LCM 59 // 66 | 67 | /******************************************************************************* 68 | * Interrupt Registers 69 | ******************************************************************************/ 70 | SFR(IE, 0xA8); // interrupt enable 71 | SBIT(EA, 0xA8, 7); // global isr enable 72 | SBIT(ELVD, 0xA8, 6); // low voltage delect 73 | SBIT(EADC, 0xA8, 5); // adc 74 | SBIT(ES, 0xA8, 4); // uart1 75 | SBIT(ET1, 0xA8, 3); // timer1 76 | SBIT(EX1, 0xA8, 2); // external interrupt 1 77 | SBIT(ET0, 0xA8, 1); // timer0 78 | SBIT(EX0, 0xA8, 0); // external interrupt 0 79 | SFR(IE2, 0xAF); // interrupt enable 80 | SBIT(EUSB, 0xAF, 7); // usb 81 | SBIT(ET4, 0xAF, 6); // timer4 82 | SBIT(ET3, 0xAF, 5); // timer3 83 | SBIT(ES4, 0xAF, 4); // uart4 84 | SBIT(ES3, 0xAF, 3); // uart3 85 | SBIT(ET2, 0xAF, 2); // timer2 86 | SBIT(ESPI, 0xAF, 1); // spi 87 | SBIT(ES2, 0xAF, 0); // uart2 88 | 89 | /******************************************************************************* 90 | * Clock Registers 91 | ******************************************************************************/ 92 | SFRX(MCLKOCR, 0xFE05); // clock output 93 | 94 | /******************************************************************************* 95 | * Timer 0 Registers 96 | ******************************************************************************/ 97 | SFR(TCON, 0x88); // Timer0 and Timer1 control registers 98 | #define Clr_Timer1_Trig() (TCON &= _BV(7)) 99 | #define Set_Timer1_Enable() (TCON |= _BV(6)) 100 | #define Set_Timer1_Disble() (TCON &= ~_BV(6)) 101 | #define Clr_Timer0_Trig() (TCON &= _BV(5)) 102 | #define Set_Timer0_Enable() (TCON |= _BV(4)) 103 | #define Set_Timer0_Disble() (TCON &= ~_BV(4)) 104 | 105 | SFR(TMOD, 0x89); // Timer0 and Timer1 mode registers 106 | SFR(TL0, 0x8A); 107 | SFR(TH0, 0x8C); 108 | SFR(TL1, 0x8B); 109 | SFR(TH1, 0x8D); 110 | SFR(AUXR, 0x8E); 111 | #define Set_Timer0_T(xTime) \ 112 | { \ 113 | TL0 = (unsigned char)(65536 - (xTime)); \ 114 | TH0 = (unsigned char)((65536 - (xTime)) >> 8); \ 115 | } 116 | #define Set_Timer1_T(xTime) \ 117 | { \ 118 | TL1 = (unsigned char)(65536 - (xTime)); \ 119 | TH1 = (unsigned char)((65536 - (xTime)) >> 8); \ 120 | } 121 | 122 | #define Set_Timer0_12T() (AUXR &= ~_BV(7)) 123 | #define Set_Timer0_1T() (AUXR |= _BV(7)) 124 | 125 | #define Set_Timer1_12T() (AUXR &= ~_BV(6)) 126 | #define Set_Timer1_1T() (AUXR |= _BV(6)) 127 | 128 | /******************************************************************************* 129 | * UART 1 Registers 130 | ******************************************************************************/ 131 | SFR(SCON, 0x98); 132 | SFR(SBUF, 0x99); 133 | SFR(PCON, 0x87); 134 | 135 | #define Set_UART0_clk_div12() (AUXR &= ~_BV(5)) 136 | #define Set_UART0_clk_div2() (AUXR |= _BV(5)) 137 | 138 | #define Set_UART0_clkgen_T1() (AUXR &= ~_BV(0)) 139 | #define Set_UART0_clkgen_T2() (AUXR |= _BV(0)) 140 | 141 | #define Read_UART0_TI() (SCON & _BV(1)) 142 | #define Read_UART0_RI() (SCON & _BV(0)) 143 | 144 | #define Clr_UART0_TI() (SCON &= ~_BV(1)) 145 | #define Clr_UART0_RI() (SCON &= ~_BV(0)) 146 | 147 | /******************************************************************************* 148 | * GPIO Registers 149 | ******************************************************************************/ 150 | SFR(P0, 0x80); // GPIO 0 151 | SBIT(P0_0, 0x80, 0); // .0 152 | SBIT(P0_1, 0x80, 1); // .1 153 | SBIT(P0_2, 0x80, 2); // .2 154 | SBIT(P0_3, 0x80, 3); // .3 155 | SBIT(P0_4, 0x80, 4); // .4 156 | SBIT(P0_5, 0x80, 5); // .5 157 | SBIT(P0_6, 0x80, 6); // .6 158 | SBIT(P0_7, 0x80, 7); // .7 159 | SFR(P1, 0x90); // GPIO 1 160 | SBIT(P1_0, 0x90, 0); // .0 161 | SBIT(P1_1, 0x90, 1); // .1 162 | SBIT(P1_2, 0x90, 2); // .2 163 | SBIT(P1_3, 0x90, 3); // .3 164 | SBIT(P1_4, 0x90, 4); // .4 165 | SBIT(P1_5, 0x90, 5); // .5 166 | SBIT(P1_6, 0x90, 6); // .6 167 | SBIT(P1_7, 0x90, 7); // .7 168 | SFR(P2, 0xA0); // GPIO 2 169 | SBIT(P2_0, 0xA0, 0); // .0 170 | SBIT(P2_1, 0xA0, 1); // .1 171 | SBIT(P2_2, 0xA0, 2); // .2 172 | SBIT(P2_3, 0xA0, 3); // .3 173 | SBIT(P2_4, 0xA0, 4); // .4 174 | SBIT(P2_5, 0xA0, 5); // .5 175 | SBIT(P2_6, 0xA0, 6); // .6 176 | SBIT(P2_7, 0xA0, 7); // .7 177 | SFR(P3, 0xB0); // GPIO 3 178 | SBIT(P3_0, 0xB0, 0); // .0 179 | SBIT(P3_1, 0xB0, 1); // .1 180 | SBIT(P3_2, 0xB0, 2); // .2 181 | SBIT(P3_3, 0xB0, 3); // .3 182 | SBIT(P3_4, 0xB0, 4); // .4 183 | SBIT(P3_5, 0xB0, 5); // .5 184 | SBIT(P3_6, 0xB0, 6); // .6 185 | SBIT(P3_7, 0xB0, 7); // .7 186 | SFR(P4, 0xC0); // GPIO 4 187 | SBIT(P4_0, 0xC0, 0); // .0 188 | SBIT(P4_1, 0xC0, 1); // .1 189 | SBIT(P4_2, 0xC0, 2); // .2 190 | SBIT(P4_3, 0xC0, 3); // .3 191 | SBIT(P4_4, 0xC0, 4); // .4 192 | SBIT(P4_5, 0xC0, 5); // .5 193 | SBIT(P4_6, 0xC0, 6); // .6 194 | SBIT(P4_7, 0xC0, 7); // .7 195 | SFR(P5, 0xC8); // GPIO 5 196 | SBIT(P5_0, 0xC8, 0); // .0 197 | SBIT(P5_1, 0xC8, 1); // .1 198 | SBIT(P5_2, 0xC8, 2); // .2 199 | SBIT(P5_3, 0xC8, 3); // .3 200 | SBIT(P5_4, 0xC8, 4); // .4 201 | SBIT(P5_5, 0xC8, 5); // .5 202 | SBIT(P5_6, 0xC8, 6); // .6 203 | SBIT(P5_7, 0xC8, 7); // .7 204 | SFR(P6, 0xE8); // GPIO 6 205 | SBIT(P6_0, 0xE8, 0); // .0 206 | SBIT(P6_1, 0xE8, 1); // .1 207 | SBIT(P6_2, 0xE8, 2); // .2 208 | SBIT(P6_3, 0xE8, 3); // .3 209 | SBIT(P6_4, 0xE8, 4); // .4 210 | SBIT(P6_5, 0xE8, 5); // .5 211 | SBIT(P6_6, 0xE8, 6); // .6 212 | SBIT(P6_7, 0xE8, 7); // .7 213 | SFR(P7, 0xF8); // GPIO 7 214 | SBIT(P7_0, 0xF8, 0); // .0 215 | SBIT(P7_1, 0xF8, 1); // .1 216 | SBIT(P7_2, 0xF8, 2); // .2 217 | SBIT(P7_3, 0xF8, 3); // .3 218 | SBIT(P7_4, 0xF8, 4); // .4 219 | SBIT(P7_5, 0xF8, 5); // .5 220 | SBIT(P7_6, 0xF8, 6); // .6 221 | SBIT(P7_7, 0xF8, 7); // .7 222 | 223 | SFR(P0M0, 0x94); // P0 Cfg0 224 | SFR(P0M1, 0x93); // P0 Cfg1 225 | SFR(P1M0, 0x92); // P1 Cfg0 226 | SFR(P1M1, 0x91); // P1 Cfg1 227 | SFR(P2M0, 0x96); // P2 Cfg0 228 | SFR(P2M1, 0x95); // P2 Cfg1 229 | SFR(P3M0, 0xB2); // P3 Cfg0 230 | SFR(P3M1, 0xB1); // P3 Cfg1 231 | SFR(P4M0, 0xB4); // P4 Cfg0 232 | SFR(P4M1, 0xB3); // P4 Cfg1 233 | SFR(P5M0, 0xCA); // P5 Cfg0 234 | SFR(P5M1, 0xC9); // P5 Cfg1 235 | SFR(P6M0, 0xCC); // P6 Cfg0 236 | SFR(P6M1, 0xCB); // P6 Cfg1 237 | SFR(P7M0, 0xE2); // P7 Cfg0 238 | SFR(P7M1, 0xE1); // P7 Cfg1 239 | 240 | SFRX(P0PU, 0xFE10); 241 | SFRX(P1PU, 0xFE11); 242 | SFRX(P2PU, 0xFE12); 243 | SFRX(P3PU, 0xFE13); 244 | SFRX(P4PU, 0xFE14); 245 | SFRX(P5PU, 0xFE15); 246 | SFRX(P6PU, 0xFE16); 247 | SFRX(P7PU, 0xFE17); 248 | 249 | SFRX(P0IE, 0xFE30); 250 | SFRX(P1IE, 0xFE31); 251 | SFRX(P2IE, 0xFE32); 252 | SFRX(P3IE, 0xFE33); 253 | SFRX(P4IE, 0xFE34); 254 | SFRX(P5IE, 0xFE35); 255 | SFRX(P6IE, 0xFE36); 256 | SFRX(P7IE, 0xFE37); 257 | 258 | #define _Set_GPIO_In_Res_(port, bits) (P##port##M0 &= ~(bits), P##port##M1 |= (bits)) 259 | #define _Set_GPIO_Out_PP_Res_(port, bits) (P##port##M0 |= (bits), P##port##M1 &= ~(bits)) 260 | #define _Set_GPIO_Out_OD_Res_(port, bits) (P##port##M0 |= (bits), P##port##M1 |= (bits)) 261 | 262 | #define _Set_GPIO_Pullup_Res_(port, bits) (P##port##PU |= (bits)) 263 | #define _Clr_GPIO_Pullup_Res_(port, bits) (P##port##PU &= ~(bits)) 264 | 265 | #define _Set_GPIO_MODE_Digital_Res_(port, bits) (P##port##IE |= (bits)) 266 | #define _Set_GPIO_MODE_Analog_Res_(port, bits) (P##port##IE &= ~(bits)) 267 | 268 | #define Set_GPIO_In(port, bits) _Set_GPIO_In_Res_(port, bits) 269 | #define Set_GPIO_Out_PP(port, bits) _Set_GPIO_Out_PP_Res_(port, bits) 270 | #define Set_GPIO_Out_OD(port, bits) _Set_GPIO_Out_OD_Res_(port, bits) 271 | 272 | #define Set_GPIO_Pullup(port, bits) _Set_GPIO_Pullup_Res_(port, bits) 273 | #define Clr_GPIO_Pullup(port, bits) _Clr_GPIO_Pullup_Res_(port, bits) 274 | 275 | #define Set_GPIO_MODE_Digital(port, bits) _Set_GPIO_MODE_Digital_Res_(port, bits) 276 | #define Set_GPIO_MODE_Analog(port, bits) _Set_GPIO_MODE_Analog_Res_(port, bits) 277 | 278 | // #ifdef __cplusplus 279 | // } 280 | // #endif 281 | 282 | #endif 283 | -------------------------------------------------------------------------------- /cores/stc8h/c51_types.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | CH554.H 3 | Header file for CH554 microcontrollers. 4 | **************************************** 5 | ** Copyright (C) W.ch 1999-2014 ** 6 | ** Web: http://wch.cn ** 7 | **************************************** 8 | --------------------------------------------------------------------------*/ 9 | 10 | #ifndef __BASE_TYPE__ 11 | #define __BASE_TYPE__ 12 | 13 | /*----- constant and type define -----------------------------------------*/ 14 | 15 | #ifndef TRUE 16 | #define TRUE 1 17 | #define FALSE 0 18 | #endif 19 | #ifndef NULL 20 | #define NULL 0 21 | #endif 22 | 23 | #ifndef BOOL 24 | typedef bit BOOL; 25 | #endif 26 | #ifndef UINT8 27 | typedef unsigned char UINT8; 28 | #endif 29 | #ifndef UINT16 30 | typedef unsigned short UINT16; 31 | #endif 32 | #ifndef UINT32 33 | typedef unsigned long UINT32; 34 | #endif 35 | #ifndef UINT8D 36 | typedef unsigned char data UINT8D; 37 | #endif 38 | #ifndef UINT16D 39 | typedef unsigned short data UINT16D; 40 | #endif 41 | #ifndef UINT32D 42 | typedef unsigned long data UINT32D; 43 | #endif 44 | #ifndef UINT8I 45 | typedef unsigned char idata UINT8I; 46 | #endif 47 | #ifndef UINT16I 48 | typedef unsigned short idata UINT16I; 49 | #endif 50 | #ifndef UINT32I 51 | typedef unsigned long idata UINT32I; 52 | #endif 53 | #ifndef UINT8X 54 | typedef unsigned char xdata UINT8X; 55 | #endif 56 | #ifndef UINT16X 57 | typedef unsigned short xdata UINT16X; 58 | #endif 59 | #ifndef UINT32X 60 | typedef unsigned long xdata UINT32X; 61 | #endif 62 | #ifndef UINT8V 63 | typedef unsigned char volatile UINT8V; 64 | #endif 65 | #ifndef UINT8DV 66 | typedef unsigned char volatile data UINT8DV; 67 | #endif 68 | #ifndef UINT8XV 69 | typedef unsigned char volatile xdata UINT8XV; 70 | #endif 71 | #ifndef UINT8PV 72 | typedef unsigned char volatile pdata UINT8PV; 73 | #endif 74 | #ifndef UINT8C 75 | typedef const unsigned char code UINT8C; 76 | #endif 77 | #ifndef PUINT8 78 | typedef unsigned char *PUINT8; 79 | #endif 80 | #ifndef PUINT16 81 | typedef unsigned short *PUINT16; 82 | #endif 83 | #ifndef PUINT32 84 | typedef unsigned long *PUINT32; 85 | #endif 86 | #ifndef PUINT8I 87 | typedef unsigned char idata *PUINT8I; 88 | #endif 89 | #ifndef PUINT16I 90 | typedef unsigned short idata *PUINT16I; 91 | #endif 92 | #ifndef PUINT32I 93 | typedef unsigned long idata *PUINT32I; 94 | #endif 95 | #ifndef PUINT8X 96 | typedef unsigned char xdata *PUINT8X; 97 | #endif 98 | #ifndef PUINT16X 99 | typedef unsigned short xdata *PUINT16X; 100 | #endif 101 | #ifndef PUINT32X 102 | typedef unsigned long xdata *PUINT32X; 103 | #endif 104 | #ifndef PUINT8V 105 | typedef unsigned char volatile *PUINT8V; 106 | #endif 107 | #ifndef PUINT8DV 108 | typedef unsigned char volatile data *PUINT8DV; 109 | #endif 110 | #ifndef PUINT8XV 111 | typedef unsigned char volatile xdata *PUINT8XV; 112 | #endif 113 | #ifndef PUINT8PV 114 | typedef unsigned char volatile pdata *PUINT8PV; 115 | #endif 116 | #ifndef PUINT8C 117 | typedef const unsigned char code *PUINT8C; 118 | #endif 119 | 120 | #ifndef STRUCT_OFFSET 121 | #define STRUCT_OFFSET( s, m ) ( (UINT8)( & (((s) *)0) -> (m) ) ) /* get the offset address for a member of a structure */ 122 | #endif 123 | 124 | #endif // __BASE_TYPE__ 125 | -------------------------------------------------------------------------------- /cores/stc8h/dummy_variable_main.h: -------------------------------------------------------------------------------- 1 | //add a reference to main to pull in main.c 2 | void main(void); void (*dummy_variable) () = main; 3 | 4 | 5 | -------------------------------------------------------------------------------- /cores/stc8h/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // void Interrupt_INT0(void) __interrupt(ISR_NO_INT0); 5 | void Interrupt_TIMER0(void) __interrupt(ISR_NO_TIMER0); 6 | // void Interrupt_INT1(void) __interrupt(ISR_NO_INT1); 7 | // void Interrupt_TIMER1(void) __interrupt(ISR_NO_TIMER1); 8 | void Interrupt_UART0(void) __interrupt(ISR_NO_UART0); 9 | // void Interrupt_ADC(void) __interrupt(ISR_NO_ADC); 10 | // void Interrupt_LVD(void) __interrupt(ISR_NO_LVD); 11 | // void Interrupt_PCA(void) __interrupt(ISR_NO_PCA); 12 | // void Interrupt_UART2(void) __interrupt(ISR_NO_UART2); 13 | // void Interrupt_SPI(void) __interrupt(ISR_NO_SPI); 14 | // void Interrupt_INT2(void) __interrupt(ISR_NO_INT2); 15 | // void Interrupt_INT3(void) __interrupt(ISR_NO_INT3); 16 | // void Interrupt_TIMER2(void) __interrupt(ISR_NO_TIMER2); 17 | // void Interrupt_INT4(void) __interrupt(ISR_NO_INT4); 18 | // void Interrupt_UART3(void) __interrupt(ISR_NO_UART3); 19 | // void Interrupt_UART4(void) __interrupt(ISR_NO_UART4); 20 | // void Interrupt_TIMER3(void) __interrupt(ISR_NO_TIMER3); 21 | // void Interrupt_TIMER4(void) __interrupt(ISR_NO_TIMER4); 22 | // void Interrupt_CMP(void) __interrupt(ISR_NO_CMP); 23 | // void Interrupt_I2C(void) __interrupt(ISR_NO_I2C); 24 | // void Interrupt_USB(void) __interrupt(ISR_NO_USB); 25 | // void Interrupt_PWMA(void) __interrupt(ISR_NO_PWMA); 26 | // void Interrupt_PWMB(void) __interrupt(ISR_NO_PWMB); 27 | // void Interrupt_TKSU(void) __interrupt(ISR_NO_TKSU); 28 | // void Interrupt_RTC(void) __interrupt(ISR_NO_RTC); 29 | // void Interrupt_P0INT(void) __interrupt(ISR_NO_P0INT); 30 | // void Interrupt_P1INT(void) __interrupt(ISR_NO_P1INT); 31 | // void Interrupt_P2INT(void) __interrupt(ISR_NO_P2INT); 32 | // void Interrupt_P3INT(void) __interrupt(ISR_NO_P3INT); 33 | // void Interrupt_P4INT(void) __interrupt(ISR_NO_P4INT); 34 | // void Interrupt_P5INT(void) __interrupt(ISR_NO_P5INT); 35 | // void Interrupt_P6INT(void) __interrupt(ISR_NO_P6INT); 36 | // void Interrupt_P7INT(void) __interrupt(ISR_NO_P7INT); 37 | // void Interrupt_DMA_M2M(void) __interrupt(ISR_NO_DMA_M2M); 38 | // void Interrupt_DMA_ADC(void) __interrupt(ISR_NO_DMA_ADC); 39 | // void Interrupt_DMA_SPI(void) __interrupt(ISR_NO_DMA_SPI); 40 | // void Interrupt_DMA_UR1T(void) __interrupt(ISR_NO_DMA_UR1T); 41 | // void Interrupt_DMA_UR1R(void) __interrupt(ISR_NO_DMA_UR1R); 42 | // void Interrupt_DMA_UR2T(void) __interrupt(ISR_NO_DMA_UR2T); 43 | // void Interrupt_DMA_UR2R(void) __interrupt(ISR_NO_DMA_UR2R); 44 | // void Interrupt_DMA_UR3T(void) __interrupt(ISR_NO_DMA_UR3T); 45 | // void Interrupt_DMA_UR3R(void) __interrupt(ISR_NO_DMA_UR3R); 46 | // void Interrupt_DMA_UR4T(void) __interrupt(ISR_NO_DMA_UR4T); 47 | // void Interrupt_DMA_UR4R(void) __interrupt(ISR_NO_DMA_UR4R); 48 | // void Interrupt_DMA_LCM(void) __interrupt(ISR_NO_DMA_LCM); 49 | // void Interrupt_LCM(void) __interrupt(ISR_NO_LCM); 50 | 51 | void main(void) 52 | { 53 | init(); 54 | 55 | //!!!initVariant(); 56 | 57 | setup(); 58 | 59 | for (;;) 60 | { 61 | loop(); 62 | } 63 | 64 | // return 0; 65 | } 66 | 67 | unsigned char _sdcc_external_startup(void) __nonbanked 68 | { 69 | return 0; 70 | } 71 | 72 | extern uint32_t uptime_millis; 73 | void Interrupt_TIMER0(void) __interrupt(ISR_NO_TIMER0) 74 | { 75 | // TI = 0; 76 | uptime_millis++; 77 | } 78 | 79 | void Interrupt_UART0(void) __interrupt(ISR_NO_UART0) 80 | { 81 | if (Read_UART0_RI()) 82 | { 83 | Clr_UART0_RI(); 84 | _Int_UART0_Rx_Handler(); 85 | } 86 | 87 | if (Read_UART0_TI()) 88 | { 89 | Clr_UART0_TI(); 90 | _Int_UART0_Tx_Handler(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /cores/stc8h/wiring.c: -------------------------------------------------------------------------------- 1 | #include "wiring_private.h" 2 | #include "HardwareSerial.h" 3 | 4 | void init() 5 | { 6 | EA = 0; 7 | 8 | Set_GPIO_MODE_Digital(0, 0xFF); 9 | Set_GPIO_MODE_Digital(1, 0xFF); 10 | Set_GPIO_MODE_Digital(2, 0xFF); 11 | Set_GPIO_MODE_Digital(3, 0xFF); 12 | Set_GPIO_MODE_Digital(4, 0xFF); 13 | Set_GPIO_MODE_Digital(5, 0xFF); 14 | Set_GPIO_MODE_Digital(6, 0xFF); 15 | Set_GPIO_MODE_Digital(7, 0xFF); 16 | 17 | Clr_GPIO_Pullup(0, 0xFF); 18 | Clr_GPIO_Pullup(1, 0xFF); 19 | Clr_GPIO_Pullup(2, 0xFF); 20 | Clr_GPIO_Pullup(3, 0xFF); 21 | Clr_GPIO_Pullup(4, 0xFF); 22 | Clr_GPIO_Pullup(5, 0xFF); 23 | Clr_GPIO_Pullup(6, 0xFF); 24 | Clr_GPIO_Pullup(7, 0xFF); 25 | 26 | Set_GPIO_In(0, 0xFF); 27 | Set_GPIO_In(1, 0xFF); 28 | Set_GPIO_In(2, 0xFF); 29 | Set_GPIO_In(3, 0xFF); 30 | Set_GPIO_In(4, 0xFF); 31 | Set_GPIO_In(5, 0xFF); 32 | Set_GPIO_In(6, 0xFF); 33 | Set_GPIO_In(7, 0xFF); 34 | 35 | ET0 = 1; 36 | Set_Timer0_1T(); 37 | #if F_CPU == 12000000 38 | Set_Timer0_T(12000); 39 | #elif F_CPU == 24000000 40 | Set_Timer0_T(24000); 41 | #elif F_CPU == 30000000 42 | Set_Timer0_T(30000); 43 | #elif F_CPU == 35000000 44 | Set_Timer0_T(35000); 45 | #endif 46 | Set_Timer0_Enable(); 47 | 48 | _HwSerialInit(); 49 | 50 | EA = 1; 51 | } 52 | 53 | uint32_t uptime_millis = 0; 54 | uint32_t millis(void) 55 | { 56 | uint32_t tmp = 0; 57 | 58 | ET0 = 0; 59 | tmp = uptime_millis; 60 | ET0 = 1; 61 | return tmp; 62 | } 63 | 64 | void delay(uint32_t ms) 65 | { 66 | uint32_t start = millis(); 67 | uint8_t i = 0; 68 | 69 | while (millis() < (start + ms)) 70 | { 71 | for (i = 0; i < 255; i++) 72 | { 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /cores/stc8h/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | created by Deqing Sun for use with CH55xduino 3 | */ 4 | 5 | #define ARDUINO_MAIN 6 | // #include "wiring_private.h" 7 | #include 8 | #include 9 | #include "Arduino.h" 10 | 11 | #include "pins_arduino_include.h" 12 | 13 | #include "pins_arduino.h" //only include once in core 14 | 15 | void pinMode(uint8_t pin, __xdata uint8_t mode) 16 | { 17 | uint8_t bit = digitalPinToBitMask(pin); 18 | uint8_t port = digitalPinToPort(pin); 19 | 20 | if (port == NOT_A_PORT) 21 | return; 22 | 23 | if (bit == NOT_A_PIN) 24 | return; 25 | 26 | switch (port) 27 | { 28 | case P0PORT: 29 | Set_GPIO_MODE_Digital(0, bit); 30 | switch (mode) 31 | { 32 | case INPUT: 33 | Clr_GPIO_Pullup(0, bit); 34 | Set_GPIO_In(0, bit); 35 | break; 36 | case OUTPUT: 37 | Clr_GPIO_Pullup(0, bit); 38 | Set_GPIO_Out_PP(0, bit); 39 | break; 40 | case INPUT_PULLUP: 41 | Set_GPIO_Pullup(0, bit); 42 | Set_GPIO_In(0, bit); 43 | break; 44 | case OUTPUT_OD: 45 | Clr_GPIO_Pullup(0, bit); 46 | Set_GPIO_Out_OD(0, bit); 47 | break; 48 | } 49 | break; 50 | case P1PORT: 51 | Set_GPIO_MODE_Digital(1, bit); 52 | switch (mode) 53 | { 54 | case INPUT: 55 | Clr_GPIO_Pullup(1, bit); 56 | Set_GPIO_In(1, bit); 57 | break; 58 | case OUTPUT: 59 | Clr_GPIO_Pullup(1, bit); 60 | Set_GPIO_Out_PP(1, bit); 61 | break; 62 | case INPUT_PULLUP: 63 | Set_GPIO_Pullup(1, bit); 64 | Set_GPIO_In(1, bit); 65 | break; 66 | case OUTPUT_OD: 67 | Clr_GPIO_Pullup(1, bit); 68 | Set_GPIO_Out_OD(1, bit); 69 | break; 70 | } 71 | break; 72 | case P2PORT: 73 | Set_GPIO_MODE_Digital(2, bit); 74 | switch (mode) 75 | { 76 | case INPUT: 77 | Clr_GPIO_Pullup(2, bit); 78 | Set_GPIO_In(2, bit); 79 | break; 80 | case OUTPUT: 81 | Clr_GPIO_Pullup(2, bit); 82 | Set_GPIO_Out_PP(2, bit); 83 | break; 84 | case INPUT_PULLUP: 85 | Set_GPIO_Pullup(2, bit); 86 | Set_GPIO_In(2, bit); 87 | break; 88 | case OUTPUT_OD: 89 | Clr_GPIO_Pullup(2, bit); 90 | Set_GPIO_Out_OD(2, bit); 91 | break; 92 | } 93 | break; 94 | case P3PORT: 95 | Set_GPIO_MODE_Digital(3, bit); 96 | switch (mode) 97 | { 98 | case INPUT: 99 | Clr_GPIO_Pullup(3, bit); 100 | Set_GPIO_In(3, bit); 101 | break; 102 | case OUTPUT: 103 | Clr_GPIO_Pullup(3, bit); 104 | Set_GPIO_Out_PP(3, bit); 105 | break; 106 | case INPUT_PULLUP: 107 | Set_GPIO_Pullup(3, bit); 108 | Set_GPIO_In(3, bit); 109 | break; 110 | case OUTPUT_OD: 111 | Clr_GPIO_Pullup(3, bit); 112 | Set_GPIO_Out_OD(3, bit); 113 | break; 114 | } 115 | break; 116 | case P4PORT: 117 | Set_GPIO_MODE_Digital(4, bit); 118 | switch (mode) 119 | { 120 | case INPUT: 121 | Clr_GPIO_Pullup(4, bit); 122 | Set_GPIO_In(4, bit); 123 | break; 124 | case OUTPUT: 125 | Clr_GPIO_Pullup(4, bit); 126 | Set_GPIO_Out_PP(4, bit); 127 | break; 128 | case INPUT_PULLUP: 129 | Set_GPIO_Pullup(4, bit); 130 | Set_GPIO_In(4, bit); 131 | break; 132 | case OUTPUT_OD: 133 | Clr_GPIO_Pullup(4, bit); 134 | Set_GPIO_Out_OD(4, bit); 135 | break; 136 | } 137 | break; 138 | case P5PORT: 139 | Set_GPIO_MODE_Digital(5, bit); 140 | switch (mode) 141 | { 142 | case INPUT: 143 | Clr_GPIO_Pullup(5, bit); 144 | Set_GPIO_In(5, bit); 145 | break; 146 | case OUTPUT: 147 | Clr_GPIO_Pullup(5, bit); 148 | Set_GPIO_Out_PP(5, bit); 149 | break; 150 | case INPUT_PULLUP: 151 | Set_GPIO_Pullup(5, bit); 152 | Set_GPIO_In(5, bit); 153 | break; 154 | case OUTPUT_OD: 155 | Clr_GPIO_Pullup(5, bit); 156 | Set_GPIO_Out_OD(5, bit); 157 | break; 158 | } 159 | break; 160 | case P6PORT: 161 | Set_GPIO_MODE_Digital(6, bit); 162 | switch (mode) 163 | { 164 | case INPUT: 165 | Clr_GPIO_Pullup(6, bit); 166 | Set_GPIO_In(6, bit); 167 | break; 168 | case OUTPUT: 169 | Clr_GPIO_Pullup(6, bit); 170 | Set_GPIO_Out_PP(6, bit); 171 | break; 172 | case INPUT_PULLUP: 173 | Set_GPIO_Pullup(6, bit); 174 | Set_GPIO_In(6, bit); 175 | break; 176 | case OUTPUT_OD: 177 | Clr_GPIO_Pullup(6, bit); 178 | Set_GPIO_Out_OD(6, bit); 179 | break; 180 | } 181 | break; 182 | case P7PORT: 183 | Set_GPIO_MODE_Digital(7, bit); 184 | switch (mode) 185 | { 186 | case INPUT: 187 | Clr_GPIO_Pullup(7, bit); 188 | Set_GPIO_In(7, bit); 189 | break; 190 | case OUTPUT: 191 | Clr_GPIO_Pullup(7, bit); 192 | Set_GPIO_Out_PP(7, bit); 193 | break; 194 | case INPUT_PULLUP: 195 | Set_GPIO_Pullup(7, bit); 196 | Set_GPIO_In(7, bit); 197 | break; 198 | case OUTPUT_OD: 199 | Clr_GPIO_Pullup(7, bit); 200 | Set_GPIO_Out_OD(7, bit); 201 | break; 202 | } 203 | break; 204 | } 205 | } 206 | 207 | void digitalWrite(uint8_t pin, __xdata uint8_t val) 208 | { 209 | // uint8_t pwm = digitalPinToPWM(pin); 210 | uint8_t bit = digitalPinToBitMask(pin); 211 | uint8_t port = digitalPinToPort(pin); 212 | 213 | if (port == NOT_A_PORT) 214 | return; 215 | 216 | if (bit == NOT_A_PIN) 217 | return; 218 | 219 | switch (port) 220 | { 221 | case P0PORT: 222 | if (val == LOW) 223 | P0 &= ~bit; 224 | else 225 | P0 |= bit; 226 | break; 227 | case P1PORT: 228 | if (val == LOW) 229 | P1 &= ~bit; 230 | else 231 | P1 |= bit; 232 | break; 233 | case P2PORT: 234 | if (val == LOW) 235 | P2 &= ~bit; 236 | else 237 | P2 |= bit; 238 | break; 239 | case P3PORT: 240 | if (val == LOW) 241 | P3 &= ~bit; 242 | else 243 | P3 |= bit; 244 | break; 245 | case P4PORT: 246 | if (val == LOW) 247 | P4 &= ~bit; 248 | else 249 | P4 |= bit; 250 | break; 251 | case P5PORT: 252 | if (val == LOW) 253 | P5 &= ~bit; 254 | else 255 | P5 |= bit; 256 | break; 257 | case P6PORT: 258 | if (val == LOW) 259 | P6 &= ~bit; 260 | else 261 | P6 |= bit; 262 | break; 263 | case P7PORT: 264 | if (val == LOW) 265 | P7 &= ~bit; 266 | else 267 | P7 |= bit; 268 | break; 269 | } 270 | } 271 | 272 | uint8_t digitalRead(uint8_t pin) 273 | { 274 | // uint8_t pwm = digitalPinToPWM(pin); 275 | uint8_t bit = digitalPinToBitMask(pin); 276 | uint8_t port = digitalPinToPort(pin); 277 | 278 | uint8_t portBuf = 0; 279 | 280 | if (port == NOT_A_PORT) 281 | return LOW; 282 | 283 | if (bit == NOT_A_PIN) 284 | return LOW; 285 | 286 | switch (port) 287 | { 288 | case P0PORT: 289 | portBuf = P0; 290 | break; 291 | case P1PORT: 292 | portBuf = P1; 293 | break; 294 | case P2PORT: 295 | portBuf = P2; 296 | break; 297 | case P3PORT: 298 | portBuf = P3; 299 | break; 300 | case P4PORT: 301 | portBuf = P4; 302 | break; 303 | case P5PORT: 304 | portBuf = P5; 305 | break; 306 | case P6PORT: 307 | portBuf = P6; 308 | break; 309 | case P7PORT: 310 | portBuf = P7; 311 | break; 312 | } 313 | 314 | if (portBuf & bit) 315 | return HIGH; 316 | return LOW; 317 | } 318 | -------------------------------------------------------------------------------- /cores/stc8h/wiring_private.h: -------------------------------------------------------------------------------- 1 | #ifndef WiringPrivate_h 2 | #define WiringPrivate_h 3 | 4 | #include 5 | #include 6 | // #include "include/ch5xx.h" 7 | // #include "include/ch5xx_usb.h" 8 | 9 | #include "Arduino.h" 10 | 11 | 12 | typedef void (*voidFuncPtr)(void); 13 | 14 | #define EXTERNAL_INT_0 0 15 | #define EXTERNAL_INT_1 1 16 | 17 | #define EXTERNAL_NUM_INTERRUPTS 2 18 | 19 | #endif -------------------------------------------------------------------------------- /package_ma6254_stcduino_index.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "STCDuino", 5 | "maintainer": "ma6254", 6 | "websiteURL": "https://github.com/ma6254/Arduino_Core_STC", 7 | "email": "9a6c5609806a@gmail.com", 8 | "help": { 9 | "online": "https://github.com/ma6254/Arduino_Core_STC" 10 | }, 11 | "platforms": [ 12 | { 13 | "name": "STCDuino plain C core (non-C++)", 14 | "architecture": "stc8051", 15 | "version": "0.0.1", 16 | "category": "Contributed", 17 | "boards": [ 18 | { 19 | "name": "STC8G1K08A Board" 20 | }, 21 | { 22 | "name": "STC8H8K64U Board" 23 | } 24 | ], 25 | "toolsDependencies": [ 26 | { 27 | "name": "sdcc", 28 | "version": "build.13407", 29 | "packager": "STCDuino" 30 | }, 31 | { 32 | "name": "stc8051_tools", 33 | "version": "v0.0.1", 34 | "packager": "STCDuino" 35 | }, 36 | { 37 | "name": "stcflash", 38 | "version": "v0.0.1", 39 | "packager": "STCDuino" 40 | }, 41 | { 42 | "name": "python3", 43 | "version": "3.7.2-post1", 44 | "packager": "STCDuino" 45 | } 46 | ], 47 | "url": "https://github.com/ma6254/Arduino_Core_STC/archive/refs/heads/main.zip", 48 | "archiveFileName": "main.zip" 49 | } 50 | ], 51 | "tools": [ 52 | { 53 | "name": "sdcc", 54 | "version": "build.13511", 55 | "systems": [ 56 | { 57 | "host": "i686-mingw32", 58 | "url": "https://raw.githubusercontent.com/ma6254/stc8051_tools/main/sdcc-snapshot-i586-mingw32msvc-20220619-13511.zip", 59 | "archiveFileName": "sdcc-snapshot-i586-mingw32msvc-20220619-13511.zip", 60 | "checksum": "SHA-256:D7BA3BAC0427E6A090F3D952CACC17AC63C726935C928DBD72707F1E2855F3D2", 61 | "size": "34606196" 62 | } 63 | ] 64 | }, 65 | { 66 | "name": "sdcc", 67 | "version": "build.13407", 68 | "systems": [ 69 | { 70 | "host": "i686-mingw32", 71 | "url": "https://raw.githubusercontent.com/ma6254/stc8051_tools/main/sdcc-mcs51-i586-mingw32msvc-20220422-13407.tar.bz2", 72 | "archiveFileName": "sdcc-mcs51-i586-mingw32msvc-20220422-13407.tar.bz2", 73 | "checksum": "SHA-256:ee557b269e8256a59f39b428b0597525a09b4a7b80f28481e19f3fc8bac6a4f5", 74 | "size": "2073934" 75 | } 76 | ] 77 | }, 78 | { 79 | "name": "stc8051_tools", 80 | "version": "v0.0.1", 81 | "systems": [ 82 | { 83 | "host": "i686-mingw32", 84 | "url": "https://github.com/ma6254/stc8051_tools/raw/main/stcduino-tools_mingw32-2022.05.06.tar.bz2", 85 | "archiveFileName": "stcduino-tools_mingw32-2022.05.06.tar.bz2", 86 | "checksum": "SHA-256:4577A53ACD3FD56D2A8B39F19F9049AF1C38FE947D83056B42FDA0E05AC554F3", 87 | "size": "718122" 88 | } 89 | ] 90 | }, 91 | { 92 | "name": "stcflash", 93 | "version": "v0.0.1", 94 | "systems": [ 95 | { 96 | "host": "i686-mingw32", 97 | "url": "https://github.com/sms-wyt/stcflash/archive/refs/heads/master.zip", 98 | "archiveFileName": "stcflash-master.zip" 99 | } 100 | ] 101 | }, 102 | { 103 | "version": "3.7.2-post1", 104 | "name": "python3", 105 | "systems": [ 106 | { 107 | "host": "x86_64-mingw32", 108 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-3.7.2.post1-embed-win32v2a.zip", 109 | "archiveFileName": "python3-3.7.2.post1-embed-win32v2a.zip", 110 | "checksum": "SHA-256:f57cb2daf86176d2929e7c58990c2ac32554e3219d454dcac10e464ddda35bf2", 111 | "size": "6428926" 112 | }, 113 | { 114 | "host": "i686-mingw32", 115 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-3.7.2.post1-embed-win32v2a.zip", 116 | "archiveFileName": "python3-3.7.2.post1-embed-win32v2a.zip", 117 | "checksum": "SHA-256:f57cb2daf86176d2929e7c58990c2ac32554e3219d454dcac10e464ddda35bf2", 118 | "size": "6428926" 119 | }, 120 | { 121 | "host": "aarch64-linux-gnu", 122 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-via-env.tar.gz", 123 | "archiveFileName": "python3-via-env.tar.gz", 124 | "checksum": "SHA-256:c9237bfe0f62842d7187a39495baa4a7e3ab8b87c0b433614294b023cf0bc0f3", 125 | "size": "292" 126 | }, 127 | { 128 | "host": "arm-linux-gnueabihf", 129 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-via-env.tar.gz", 130 | "archiveFileName": "python3-via-env.tar.gz", 131 | "checksum": "SHA-256:c9237bfe0f62842d7187a39495baa4a7e3ab8b87c0b433614294b023cf0bc0f3", 132 | "size": "292" 133 | }, 134 | { 135 | "host": "i686-pc-linux-gnu", 136 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-via-env.tar.gz", 137 | "archiveFileName": "python3-via-env.tar.gz", 138 | "checksum": "SHA-256:c9237bfe0f62842d7187a39495baa4a7e3ab8b87c0b433614294b023cf0bc0f3", 139 | "size": "292" 140 | }, 141 | { 142 | "host": "x86_64-apple-darwin", 143 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-macosx-portable.tar.gz", 144 | "archiveFileName": "python3-macosx-portable.tar.gz", 145 | "checksum": "SHA-256:01a5bf1fa264c6f04cfaadf4c6e9f6caaacb6833ef40104dfbe953fcdb9bca1c", 146 | "size": "25494144" 147 | }, 148 | { 149 | "host": "x86_64-pc-linux-gnu", 150 | "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/2.5.0-4/python3-via-env.tar.gz", 151 | "archiveFileName": "python3-via-env.tar.gz", 152 | "checksum": "SHA-256:c9237bfe0f62842d7187a39495baa4a7e3ab8b87c0b433614294b023cf0bc0f3", 153 | "size": "292" 154 | } 155 | ] 156 | } 157 | ] 158 | } 159 | ] 160 | } 161 | -------------------------------------------------------------------------------- /platform.txt: -------------------------------------------------------------------------------- 1 | # STC 8051 Core and platform. 2 | # ------------------------------ 3 | # 4 | # For more info: 5 | # https://arduino.github.io/arduino-cli/latest/platform-specification/ 6 | 7 | name=STC boards groups 8 | version=0.0.1 9 | 10 | # General folder structure variables 11 | # ---------------------------------- 12 | runtime.tools.sdcc.path={runtime.hardware.path}/tools/sdcc 13 | runtime.tools.stc8051_tools.path={runtime.hardware.path}/tools 14 | runtime.tools.stcflash.path={runtime.hardware.path}/tools 15 | runtime.tools.python3.path={runtime.platform.path}/tools/python3 16 | 17 | # compile variables 18 | # --------------------- 19 | compiler.warning_flags= 20 | compiler.warning_flags.none=--less-pedantic 21 | compiler.warning_flags.default= 22 | compiler.warning_flags.more=-Wp-Wall 23 | compiler.warning_flags.all=-Wp-Wall -V 24 | 25 | # Default "compiler.path" is correct, change only if you want to override the initial value 26 | compiler.path={runtime.tools.sdcc.path}/bin 27 | compiler.wrapper.path={runtime.tools.stc8051_tools.path}/wrapper 28 | compiler.wrapper.path.windows={runtime.tools.stc8051_tools.path}/win/busybox" ash "{runtime.tools.stc8051_tools.path}/wrapper 29 | compiler.tools.path={runtime.tools.avr-gcc.path}/bin 30 | 31 | compiler.c.cmd=sdcc 32 | compiler.c.wrapper=sdcc.sh 33 | compiler.c.flags=-MMD -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ {compiler.warning_flags} 34 | compiler.c.elf.flags=--code-size {upload.maximum_size} --xram-size {upload.maximum_data_size} --xram-loc {upload.xdata_location} 35 | 36 | compiler.c.elf.cmd=sdcc 37 | compiler.c.elf.wrapper=sdcc-link.sh 38 | compiler.S.flags=-c -g -x assembler-with-cpp -flto 39 | 40 | compiler.cpp.cmd=sdcc 41 | compiler.cpp.wrapper=sdcc.sh 42 | compiler.cpp.flags={compiler.c.flags} 43 | 44 | compiler.ar.cmd=sdar 45 | compiler.ar.wrapper=sdar.sh 46 | compiler.ar.flags=rcs 47 | 48 | compiler.objcopy.cmd=avr-objcopy 49 | #compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 50 | #compiler.objcopy.eep.flags=-O ihex -j EEPROM EEPROM=0 51 | 52 | compiler.elf2hex.cmd=avr-objcopy 53 | compiler.elf2hex.flags=-O ihex -R DATA -R INITIALIZED -R SSEG 54 | 55 | compiler.syslibs.stdlib.path={runtime.tools.sdcc.path}/share/sdcc 56 | compiler.syslibs.stdlib.path.windows={runtime.tools.sdcc.path} 57 | #compiler.syslibs.spl.path= 58 | 59 | compiler.ldflags= 60 | 61 | #we use mem file directly, because we don't need to use size command 62 | compiler.size.cmd=cat 63 | compiler.size.cmd.windows={runtime.tools.stc8051_tools.path}/win/busybox" cat " 64 | 65 | compiler.systemincludes="-I{compiler.syslibs.stdlib.path}/include" 66 | 67 | # This can be overridden in boards.txt 68 | build.extra_flags= 69 | 70 | # These can be overridden in platform.local.txt 71 | compiler.c.extra_flags= 72 | compiler.c.elf.extra_flags= 73 | compiler.S.extra_flags= 74 | compiler.cpp.extra_flags= 75 | compiler.ar.extra_flags= 76 | compiler.objcopy.eep.extra_flags= 77 | compiler.elf2hex.extra_flags= 78 | 79 | # MCS51 compile patterns 80 | # -------------------- 81 | 82 | ## Compile c files (re1) 83 | recipe.c.o.pattern="{compiler.wrapper.path}/{compiler.c.wrapper}" "{compiler.path}/{compiler.c.cmd}" "{source_file}" "{object_file}" re1 {compiler.c.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DF_EXT_OSC={build.f_oscillator_external} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} {compiler.systemincludes} 84 | 85 | ## Compile c++ files (re2) 86 | recipe.cpp.o.pattern="{compiler.wrapper.path}/{compiler.cpp.wrapper}" "{compiler.path}/{compiler.cpp.cmd}" "{source_file}" "{object_file}" re2 {compiler.cpp.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DF_EXT_OSC={build.f_oscillator_external} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} {compiler.systemincludes} 87 | 88 | ##FIXME Compile S files (re3) 89 | recipe.S.o.pattern="{compiler.path}/{compiler.c.cmd}" re3 {compiler.S.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DF_EXT_OSC={build.f_oscillator_external} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 90 | 91 | ## Create archives (re4) 92 | # archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value 93 | #archive_file_path={build.path}/{archive_file} 94 | recipe.ar.pattern="{compiler.wrapper.path}/{compiler.ar.wrapper}" "{compiler.path}/{compiler.ar.cmd}" "{archive_file_path}" "{object_file}" re4 {compiler.ar.flags} {compiler.ar.extra_flags} 95 | 96 | ## Combine gc-sections, archives, and objects 97 | recipe.c.combine.pattern="{compiler.wrapper.path}/{compiler.c.elf.wrapper}" "{compiler.path}/{compiler.c.elf.cmd}" --nostdlib "-L{build.path}" "-L{compiler.syslibs.stdlib.path}/lib/small" {compiler.c.elf.flags} -mmcs51 -D{build.mcu} {compiler.c.elf.extra_flags} {object_files} "{build.path}/{archive_file}" -lmcs51 -llibsdcc -lliblong -lliblonglong -llibint -llibfloat --out-fmt-ihx -o "{build.path}/{build.project_name}.elf" 98 | 99 | ## Create output files (.eep and .hex) 100 | #recipe.objcopy.eep.pattern="{compiler.tools.path}/{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" 101 | recipe.objcopy.hex.pattern="{compiler.tools.path}/{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" 102 | 103 | ## Save hex 104 | recipe.output.tmp_file={build.project_name}.hex 105 | recipe.output.save_file={build.project_name}.{build.variant}.hex 106 | 107 | ## Compute size 108 | # flash usage = HOME + GSINIT + GSFINAL + CODE + INITIALIZER 109 | # RAM usage = DATA + INITIALIZED 110 | recipe.size.pattern="{compiler.size.cmd}" "{build.path}/{build.project_name}.mem" 111 | recipe.size.regex=^(?:\s+ROM\/EPROM\/FLASH)\s+0x[A-Fa-f0-9]+\s+0x[A-Fa-f0-9]+\s+([0-9]+).* 112 | recipe.size.regex.data=^(?:\s+EXTERNAL RAM)\s+0x[A-Fa-f0-9]+\s+0x[A-Fa-f0-9]+\s+([0-9]+).* 113 | 114 | ## Preprocessor (re11, re12) 115 | preproc.includes.flags=-M -MG -MP 116 | recipe.preproc.includes="{compiler.path.wrapper}/{compiler.cpp.wrapper}" "{compiler.path}/{compiler.cpp.cmd}" re11 {compiler.cpp.flags} {preproc.includes.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DF_EXT_OSC={build.f_oscillator_external} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" 117 | preproc.macros.flags=-E -MC 118 | recipe.preproc.macros="{compiler.wrapper.path}/{compiler.cpp.cmd}.sh" "{compiler.path}/{compiler.cpp.cmd}" "{source_file}" "{preprocessed_file_path}" re12 {compiler.cpp.flags} {preproc.macros.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DF_EXT_OSC={build.f_oscillator_external} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} {compiler.systemincludes} 119 | 120 | 121 | #=============================================================================== 122 | # 123 | # tools: stcflash 124 | # 125 | #=============================================================================== 126 | tools.stcflash.cmd={runtime.tools.python3.path}/python3 127 | tools.stcflash.path={runtime.tools.stcflash.path} 128 | 129 | tools.stcflash.upload.params.verbose= 130 | tools.stcflash.upload.params.quiet= 131 | tools.stcflash.upload.pattern="{cmd}" -I "{tools.stcflash.path}/stcflash.py" -p {serial.port} "{build.path}/{build.project_name}.hex" 132 | -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ma6254/Arduino_Core_STC/8fefbd6ea112012fadefc26a61ed62db25b26a3a/programmers.txt -------------------------------------------------------------------------------- /variants/STC8G1K08A/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_h 2 | #define Pins_Arduino_h 3 | 4 | #include "pins_arduino_include.h" 5 | 6 | #ifndef _BV 7 | #define _BV(X) (1 << (X)) 8 | #endif 9 | 10 | __code uint8_t PROGMEM digital_pin_to_port_PGM[] = { 11 | NOT_A_PORT, // Placeholder 0 12 | // left 13 | P5PORT, // 1 CCP2_2/CCP2/MCLKO/NRST/SCL_2/MOSI/RxD_3/T1CLKO/T0/INT2/ADC4/P5.4 14 | NOT_A_PORT, // 2 Vcc/AVcc 15 | P5PORT, // 3 ECI_2/ECI/CCP2_3/SDA_2/SS/TxD_3/T0CLKO/T1/INT3/ADC5/P5.5 16 | NOT_A_PORT, // 4 Gnd/AGnd 17 | // right 18 | P3PORT, // 5 P3.0/ADC0/RxD/INT4 19 | P3PORT, // 6 P3.1/ADC1/TxD/CCP0_2/ECI_3 20 | P3PORT, // 7 P3.2/ADC2/RxD_2/INT0/SCLK/SCL/CCP0/CCP0_3 21 | P3PORT, // 8 P3.3/ADC3/TxD_2/INT1/MISO/SDA/CCP1/CCP1_2/CCP1_3 22 | }; 23 | 24 | __code uint8_t digital_pin_to_bit_mask_PGM[] = { 25 | NOT_A_PIn, // Placeholder 0 26 | // left 27 | _BV(4), // 1 CCP2_2/CCP2/MCLKO/NRST/SCL_2/MOSI/RxD_3/T1CLKO/T0/INT2/ADC4/P5.4 28 | NOT_A_PIN, // 2 Vcc/AVcc 29 | _BV(5), // 3 ECI_2/ECI/CCP2_3/SDA_2/SS/TxD_3/T0CLKO/T1/INT3/ADC5/P5.5 30 | NOT_A_PIN, // 4 Gnd/AGnd 31 | // right 32 | _BV(0), // 5 P3.0/ADC0/RxD/INT4 33 | _BV(1), // 6 P3.1/ADC1/TxD/CCP0_2/ECI_3 34 | _BV(2), // 7 P3.2/ADC2/RxD_2/INT0/SCLK/SCL/CCP0/CCP0_3 35 | _BV(3), // 8 P3.3/ADC3/TxD_2/INT1/MISO/SDA/CCP1/CCP1_2/CCP1_3 36 | }; 37 | 38 | __code uint8_t digital_pin_to_channel_PGM[] = { 39 | NOT_ANALOG, // Placeholder 0 40 | // left 41 | 4, // 1 CCP2_2/CCP2/MCLKO/NRST/SCL_2/MOSI/RxD_3/T1CLKO/T0/INT2/ADC4/P5.4 42 | NOT_ANALOG, // 2 Vcc/AVcc 43 | 5, // 3 ECI_2/ECI/CCP2_3/SDA_2/SS/TxD_3/T0CLKO/T1/INT3/ADC5/P5.5 44 | NOT_ANALOG, // 4 Gnd/AGnd 45 | // right 46 | 0, // 5 P3.0/ADC0/RxD/INT4 47 | 1, // 6 P3.1/ADC1/TxD/CCP0_2/ECI_3 48 | 2, // 7 P3.2/ADC2/RxD_2/INT0/SCLK/SCL/CCP0/CCP0_3 49 | 3, // 8 P3.3/ADC3/TxD_2/INT1/MISO/SDA/CCP1/CCP1_2/CCP1_3 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /variants/STC8G1K08A/pins_arduino_include.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_Include_h 2 | #define Pins_Arduino_Include_h 3 | 4 | #ifndef _BV 5 | #define _BV(X) (1 << (X)) 6 | #endif 7 | 8 | #define NOT_A_PIN 0 9 | #define NOT_A_PORT 0 10 | 11 | #define P0PORT 1 12 | #define P1PORT 2 13 | #define P2PORT 3 14 | #define P3PORT 4 15 | #define P4PORT 5 16 | 17 | #define NOT_AN_INTERRUPT -1 18 | #define NOT_ANALOG 255 19 | 20 | extern __code uint8_t digital_pin_to_port_PGM[]; 21 | extern __code uint8_t digital_pin_to_bit_mask_PGM[]; 22 | 23 | // Get the bit location within the hardware port of the given virtual pin. 24 | // This comes from the pins_*.c file for the active board configuration. 25 | // 26 | #define digitalPinToPort(P) (digital_pin_to_port_PGM[(P)]) 27 | #define digitalPinToBitMask(P) (digital_pin_to_bit_mask_PGM[(P)]) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /variants/STC8H8K64U/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_h 2 | #define Pins_Arduino_h 3 | 4 | #include "pins_arduino_include.h" 5 | 6 | #ifndef _BV 7 | #define _BV(X) (1 << (X)) 8 | #endif 9 | 10 | __code uint8_t PROGMEM digital_pin_to_port_PGM[] = { 11 | NOT_A_PORT, // Placeholder 0 12 | // bottom 13 | P5PORT, // 1 TxD4_2/P5.3 14 | P0PORT, // 2 T3CLKO/ADC13/AD5/P0.5 15 | P0PORT, // 3 PWMETI2_2/T4/ADC14/AD6/P0.6 16 | P0PORT, // 4 4CLKO/AD7/P0.7 17 | P6PORT, // 5 PWM1P_3/P6.0 18 | P6PORT, // 6 PWM1N_3/P6.1 19 | P6PORT, // 7 PWM2P_3/P6.2 20 | P6PORT, // 8 PWM2N_3/P6.3 21 | P1PORT, // 9 RxD2/PWM1P/ADC0/P1.0 22 | P1PORT, // 10 TxD2/PWM1N/ADC1/P1.1 23 | P4PORT, // 11 TxD2_2/P4.7 24 | P1PORT, // 12 SDA/MISO/PWM3P/ADC4/P1.4 25 | P1PORT, // 13 SCL/SCLK/PWM3N/ADC5/P1.5 26 | P1PORT, // 14 XTALO/MCLKO_2/RxD_3/PWM4P/ADC6/P1.6 27 | P1PORT, // 15 XTALI/PWM5_2/TxD_3/PWM4N/ADC7/P1.7 28 | P1PORT, // 16 T2CLKO/MOSI/PWM2N/ADC3/P1.3 29 | // right 30 | NOT_A_PORT, // 17 UCap 31 | P5PORT, // 18 P5.4/NRST/MCLKO/SS/SS_3/PWM2P/PWM6_2/ADC2/T2 32 | NOT_A_PORT, // 19 Vcc/AVcc 33 | NOT_A_PORT, // 20 ADC_VRef+ 34 | NOT_A_PORT, // 21 Gnd/AGnd 35 | P4PORT, // 22 P4.0/MOSI_3 36 | P6PORT, // 23 P6.4/PWM3P_3 37 | P6PORT, // 24 P6.5/PWM3N_3 38 | P6PORT, // 25 P6.6/PWM4P_3 39 | P6PORT, // 26 P6.7/PWM4N_3 40 | P3PORT, // 27 P3.0/RxD/D-/INT4 41 | P3PORT, // 28 P3.1/TxD/D+ 42 | P3PORT, // 29 P3.2/INT0/SCLK_4/SCL_4/PWMETI/PWMETI2 43 | P3PORT, // 30 P3.3/INT1/MISO_4/SDA_4/PWM4N_4/PWM7_2 44 | P3PORT, // 31 P3.4/T0/T1CLKO/MOSI_4/PWM4P_4/PWM8_2/CMPO 45 | P5PORT, // 32 P5.0/RxD3_2/CMP+_2 46 | // top 47 | P5PORT, // 33 P5.1/TxD3_2/CMP+_3 48 | P3PORT, // 34 P3.5/T1/T0CLKO/SS_4/PWMFLT/PWMFLT2 49 | P3PORT, // 35 P3.6/INT2/RxD_2/CMP- 50 | P3PORT, // 36 P3.7/INT3/TxD_2/CMP+ 51 | P7PORT, // 37 P7.0 52 | P7PORT, // 38 P7.1 53 | P7PORT, // 39 P7.2 54 | P7PORT, // 40 P7.3/PWMETI_3 55 | P4PORT, // 41 P4.1/MISO_3/CMPO_2/PWMETI_2 56 | P4PORT, // 42 P4.2/WR 57 | P4PORT, // 43 P4.3/RxD_4/SCLK_3 58 | P4PORT, // 44 P4.4/RD/TxD_4 59 | P2PORT, // 45 P2.0/A8/PWM1P_2/PWM5 60 | P2PORT, // 46 P2.1/A9/PWM1N_2/PWM6 61 | P2PORT, // 47 P2.2/A10/PWM2P_2/PWM7/SS_2 62 | P2PORT, // 48 P2.3/A11/PWM2N_2/PWM8/MOSI_2 63 | // left 64 | P2PORT, // 49 MISO_2/SDA_2/PWM3P_2/A12/P2.4 65 | P2PORT, // 50 SCLK_2/SCL_2/PWM3N_2/A13/P2.5 66 | P2PORT, // 51 PWM4P_2/A14/P2.6 67 | P2PORT, // 52 PWM4N_2/A15/P2.7 68 | P7PORT, // 53 PWM5_4/P7.4 69 | P7PORT, // 54 PWM6_4/P7.5 70 | P7PORT, // 55 PWM7_4/P7.6 71 | P7PORT, // 56 PWM8_4/P7.7 72 | P4PORT, // 57 ALE/P4.5 73 | P4PORT, // 58 RxD2_2/P4.6 74 | P0PORT, // 59 T3_2/PWM5_3/RxD3/ADC8/AD0/P0.0 75 | P0PORT, // 60 T3CLKO_2/PWM6_3/TxD3/ADC9/AD1/P0.1 76 | P0PORT, // 61 T4_2/PWM7_3/RxD4/ADC10/AD2/P0.2 77 | P0PORT, // 62 T4CLKO_2/PWM8_3/TxD4/ADC11/AD3/P0.3 78 | P0PORT, // 63 T3/ADC12/AD4/P0.4 79 | P5PORT, // 64 RxD4_2/P5.2 80 | }; 81 | 82 | __code uint8_t digital_pin_to_bit_mask_PGM[] = { 83 | NOT_A_PIN, // Placeholder 0 84 | // bottom 85 | _BV(3), // 1 TxD4_2/P5.3 86 | _BV(5), // 2 T3CLKO/ADC13/AD5/P0.5 87 | _BV(6), // 3 PWMETI2_2/T4/ADC14/AD6/P0.6 88 | _BV(7), // 4 4CLKO/AD7/P0.7 89 | _BV(0), // 5 PWM1P_3/P6.0 90 | _BV(1), // 6 PWM1N_3/P6.1 91 | _BV(2), // 7 PWM2P_3/P6.2 92 | _BV(3), // 8 PWM2N_3/P6.3 93 | _BV(0), // 9 RxD2/PWM1P/ADC0/P1.0 94 | _BV(1), // 10 TxD2/PWM1N/ADC1/P1.1 95 | _BV(7), // 11 TxD2_2/P4.7 96 | _BV(4), // 12 SDA/MISO/PWM3P/ADC4/P1.4 97 | _BV(5), // 13 SCL/SCLK/PWM3N/ADC5/P1.5 98 | _BV(6), // 14 XTALO/MCLKO_2/RxD_3/PWM4P/ADC6/P1.6 99 | _BV(7), // 15 XTALI/PWM5_2/TxD_3/PWM4N/ADC7/P1.7 100 | _BV(3), // 16 T2CLKO/MOSI/PWM2N/ADC3/P1.3 101 | // right 102 | NOT_A_PIN, // 17 UCap 103 | _BV(4), // 18 P5.4/NRST/MCLKO/SS/SS_3/PWM2P/PWM6_2/ADC2/T2 104 | NOT_A_PIN, // 19 Vcc/AVcc 105 | NOT_A_PIN, // 20 ADC_VRef+ 106 | NOT_A_PIN, // 21 Gnd/AGnd 107 | _BV(0), // 22 P4.0/MOSI_3 108 | _BV(4), // 23 P6.4/PWM3P_3 109 | _BV(5), // 24 P6.5/PWM3N_3 110 | _BV(6), // 25 P6.6/PWM4P_3 111 | _BV(7), // 26 P6.7/PWM4N_3 112 | _BV(0), // 27 P3.0/RxD/D-/INT4 113 | _BV(1), // 28 P3.1/TxD/D+ 114 | _BV(2), // 29 P3.2/INT0/SCLK_4/SCL_4/PWMETI/PWMETI2 115 | _BV(3), // 30 P3.3/INT1/MISO_4/SDA_4/PWM4N_4/PWM7_2 116 | _BV(4), // 31 P3.4/T0/T1CLKO/MOSI_4/PWM4P_4/PWM8_2/CMPO 117 | _BV(0), // 32 P5.0/RxD3_2/CMP+_2 118 | // top 119 | _BV(1), // 33 P5.1/TxD3_2/CMP+_3 120 | _BV(5), // 34 P3.5/T1/T0CLKO/SS_4/PWMFLT/PWMFLT2 121 | _BV(6), // 35 P3.6/INT2/RxD_2/CMP- 122 | _BV(7), // 36 P3.7/INT3/TxD_2/CMP+ 123 | _BV(0), // 37 P7.0 124 | _BV(1), // 38 P7.1 125 | _BV(2), // 39 P7.2 126 | _BV(3), // 40 P7.3/PWMETI_3 127 | _BV(1), // 41 P4.1/MISO_3/CMPO_2/PWMETI_2 128 | _BV(2), // 42 P4.2/WR 129 | _BV(3), // 43 P4.3/RxD_4/SCLK_3 130 | _BV(4), // 44 P4.4/RD/TxD_4 131 | _BV(0), // 45 P2.0/A8/PWM1P_2/PWM5 132 | _BV(1), // 46 P2.1/A9/PWM1N_2/PWM6 133 | _BV(2), // 47 P2.2/A10/PWM2P_2/PWM7/SS_2 134 | _BV(3), // 48 P2.3/A11/PWM2N_2/PWM8/MOSI_2 135 | // left 136 | _BV(4), // 49 MISO_2/SDA_2/PWM3P_2/A12/P2.4 137 | _BV(5), // 50 SCLK_2/SCL_2/PWM3N_2/A13/P2.5 138 | _BV(6), // 51 PWM4P_2/A14/P2.6 139 | _BV(7), // 52 PWM4N_2/A15/P2.7 140 | _BV(4), // 53 PWM5_4/P7.4 141 | _BV(5), // 54 PWM6_4/P7.5 142 | _BV(6), // 55 PWM7_4/P7.6 143 | _BV(7), // 56 PWM8_4/P7.7 144 | _BV(5), // 57 ALE/P4.5 145 | _BV(6), // 58 RxD2_2/P4.6 146 | _BV(0), // 59 T3_2/PWM5_3/RxD3/ADC8/AD0/P0.0 147 | _BV(1), // 60 T3CLKO_2/PWM6_3/TxD3/ADC9/AD1/P0.1 148 | _BV(2), // 61 T4_2/PWM7_3/RxD4/ADC10/AD2/P0.2 149 | _BV(3), // 62 T4CLKO_2/PWM8_3/TxD4/ADC11/AD3/P0.3 150 | _BV(4), // 63 T3/ADC12/AD4/P0.4 151 | _BV(2), // 64 RxD4_2/P5.2 152 | }; 153 | 154 | __code uint8_t digital_pin_to_channel_PGM[] = { 155 | NOT_ANALOG, // Placeholder 0 156 | // bottom 157 | NOT_ANALOG, // 1 TxD4_2/P5.3 158 | 13, // 2 T3CLKO/ADC13/AD5/P0.5 159 | 14, // 3 PWMETI2_2/T4/ADC14/AD6/P0.6 160 | NOT_ANALOG, // 4 4CLKO/AD7/P0.7 161 | NOT_ANALOG, // 5 PWM1P_3/P6.0 162 | NOT_ANALOG, // 6 PWM1N_3/P6.1 163 | NOT_ANALOG, // 7 PWM2P_3/P6.2 164 | NOT_ANALOG, // 8 PWM2N_3/P6.3 165 | 0, // 9 RxD2/PWM1P/ADC0/P1.0 166 | 1, // 10 TxD2/PWM1N/ADC1/P1.1 167 | NOT_ANALOG, // 11 TxD2_2/P4.7 168 | 4, // 12 SDA/MISO/PWM3P/ADC4/P1.4 169 | 5, // 13 SCL/SCLK/PWM3N/ADC5/P1.5 170 | 6, // 14 XTALO/MCLKO_2/RxD_3/PWM4P/ADC6/P1.6 171 | 7, // 15 XTALI/PWM5_2/TxD_3/PWM4N/ADC7/P1.7 172 | 3, // 16 T2CLKO/MOSI/PWM2N/ADC3/P1.3 173 | // right 174 | NOT_ANALOG, // 17 UCap 175 | 2, // 18 P5.4/NRST/MCLKO/SS/SS_3/PWM2P/PWM6_2/ADC2/T2 176 | NOT_ANALOG, // 19 Vcc/AVcc 177 | NOT_ANALOG, // 20 ADC_VRef+ 178 | NOT_ANALOG, // 21 Gnd/AGnd 179 | NOT_ANALOG, // 22 P4.0/MOSI_3 180 | NOT_ANALOG, // 23 P6.4/PWM3P_3 181 | NOT_ANALOG, // 24 P6.5/PWM3N_3 182 | NOT_ANALOG, // 25 P6.6/PWM4P_3 183 | NOT_ANALOG, // 26 P6.7/PWM4N_3 184 | NOT_ANALOG, // 27 P3.0/RxD/D-/INT4 185 | NOT_ANALOG, // 28 P3.1/TxD/D+ 186 | NOT_ANALOG, // 29 P3.2/INT0/SCLK_4/SCL_4/PWMETI/PWMETI2 187 | NOT_ANALOG, // 30 P3.3/INT1/MISO_4/SDA_4/PWM4N_4/PWM7_2 188 | NOT_ANALOG, // 31 P3.4/T0/T1CLKO/MOSI_4/PWM4P_4/PWM8_2/CMPO 189 | NOT_ANALOG, // 32 P5.0/RxD3_2/CMP+_2 190 | // top 191 | NOT_ANALOG, // 33 P5.1/TxD3_2/CMP+_3 192 | NOT_ANALOG, // 34 P3.5/T1/T0CLKO/SS_4/PWMFLT/PWMFLT2 193 | NOT_ANALOG, // 35 P3.6/INT2/RxD_2/CMP- 194 | NOT_ANALOG, // 36 P3.7/INT3/TxD_2/CMP+ 195 | NOT_ANALOG, // 37 P7.0 196 | NOT_ANALOG, // 38 P7.1 197 | NOT_ANALOG, // 39 P7.2 198 | NOT_ANALOG, // 40 P7.3/PWMETI_3 199 | NOT_ANALOG, // 41 P4.1/MISO_3/CMPO_2/PWMETI_2 200 | NOT_ANALOG, // 42 P4.2/WR 201 | NOT_ANALOG, // 43 P4.3/RxD_4/SCLK_3 202 | NOT_ANALOG, // 44 P4.4/RD/TxD_4 203 | NOT_ANALOG, // 45 P2.0/A8/PWM1P_2/PWM5 204 | NOT_ANALOG, // 46 P2.1/A9/PWM1N_2/PWM6 205 | NOT_ANALOG, // 47 P2.2/A10/PWM2P_2/PWM7/SS_2 206 | NOT_ANALOG, // 48 P2.3/A11/PWM2N_2/PWM8/MOSI_2 207 | // left 208 | NOT_ANALOG, // 49 MISO_2/SDA_2/PWM3P_2/A12/P2.4 209 | NOT_ANALOG, // 50 SCLK_2/SCL_2/PWM3N_2/A13/P2.5 210 | NOT_ANALOG, // 51 PWM4P_2/A14/P2.6 211 | NOT_ANALOG, // 52 PWM4N_2/A15/P2.7 212 | NOT_ANALOG, // 53 PWM5_4/P7.4 213 | NOT_ANALOG, // 54 PWM6_4/P7.5 214 | NOT_ANALOG, // 55 PWM7_4/P7.6 215 | NOT_ANALOG, // 56 PWM8_4/P7.7 216 | NOT_ANALOG, // 57 ALE/P4.5 217 | NOT_ANALOG, // 58 RxD2_2/P4.6 218 | 8, // 59 T3_2/PWM5_3/RxD3/ADC8/AD0/P0.0 219 | 9, // 60 T3CLKO_2/PWM6_3/TxD3/ADC9/AD1/P0.1 220 | 10, // 61 T4_2/PWM7_3/RxD4/ADC10/AD2/P0.2 221 | 11, // 62 T4CLKO_2/PWM8_3/TxD4/ADC11/AD3/P0.3 222 | 12, // 63 T3/ADC12/AD4/P0.4 223 | NOT_ANALOG, // 64 RxD4_2/P5.2 224 | }; 225 | 226 | #endif 227 | -------------------------------------------------------------------------------- /variants/STC8H8K64U/pins_arduino_include.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_Include_h 2 | #define Pins_Arduino_Include_h 3 | 4 | #include "stdint.h" 5 | 6 | #ifndef _BV 7 | #define _BV(X) (1 << (X)) 8 | #endif 9 | 10 | #define NOT_A_PIN 0 11 | #define NOT_A_PORT 0 12 | 13 | #define P0PORT 1 14 | #define P1PORT 2 15 | #define P2PORT 3 16 | #define P3PORT 4 17 | #define P4PORT 5 18 | #define P5PORT 6 19 | #define P6PORT 7 20 | #define P7PORT 8 21 | 22 | #define PIN_UART0_TXD 28 23 | #define PIN_UART0_RXD 27 24 | 25 | #define NOT_AN_INTERRUPT -1 26 | #define NOT_ANALOG 255 27 | 28 | extern __code uint8_t digital_pin_to_port_PGM[]; 29 | extern __code uint8_t digital_pin_to_bit_mask_PGM[]; 30 | 31 | // Get the bit location within the hardware port of the given virtual pin. 32 | // This comes from the pins_*.c file for the active board configuration. 33 | // 34 | #define digitalPinToPort(P) (digital_pin_to_port_PGM[(P)]) 35 | #define digitalPinToBitMask(P) (digital_pin_to_bit_mask_PGM[(P)]) 36 | 37 | #endif 38 | --------------------------------------------------------------------------------