├── LICENSE ├── README.md ├── boards.txt ├── cores ├── STC15 │ ├── Arduino.h │ ├── HardwareSerial.c │ ├── HardwareSerial.h │ ├── Print.c │ ├── Print.h │ ├── Print_float.c │ ├── WMath.c │ ├── main.c │ ├── wiring.c │ ├── wiring.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ └── wiring_shift.c ├── STC8 │ ├── Arduino.h │ ├── HardwareSerial.c │ ├── HardwareSerial.h │ ├── Print.c │ ├── Print.h │ ├── Print_float.c │ ├── WMath.c │ ├── main.c │ ├── wiring.c │ ├── wiring.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ └── wiring_shift.c └── STC89 │ ├── Arduino.h │ ├── HardwareSerial.c │ ├── HardwareSerial.h │ ├── Print.c │ ├── Print.h │ ├── Print_float.c │ ├── WInterrupts.c │ ├── WMath.c │ ├── binary.h │ ├── bsp │ ├── STC89C5xRC.h │ ├── compatible.h │ ├── gpio.h │ ├── intrins.h │ ├── isr.h │ ├── mcu.h │ └── uart.c │ ├── main.c │ ├── wiring.c │ ├── wiring.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ └── wiring_shift.c ├── doc ├── board_chioce.png ├── board_manager_zh.png └── option_zh.png ├── package_nulllab_stc51duino_proxy_index.json ├── platform.txt └── variants ├── STC15 ├── pins_arduino.h └── variant.c ├── STC8 ├── pins_arduino.h └── variant.c └── STC89 ├── pins_arduino.h └── variant.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 null-lab 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STC51duino 2 | 基于[STC](https://www.stcmcudata.com/)公司的8051内核的系类单片机的arduino软件开发支持包,目前先做STC89C52RC这款学习型单片机的支持包,方便开发者学习使用 3 | 后续将陆续适配STC12/STC15/STC8等主流系类芯片。 4 | 5 | ## STC51duino开发板Arduino IDE支持包安装 6 | 7 | 1、**文件->首选项** 8 | 9 | 2、在附加开发板管理器网址输入如下网址: 10 | 11 | > https://cdn.jsdelivr.net/gh/nulllaborg/nulllab_stc51duino/package_nulllab_stc51duino_proxy_index.json 12 | 13 | ![](./doc/option_zh.png) 14 | 15 | 3、**工具->开发板->开发板管理** 16 | 搜索STC51duino,选择最新版本安装(如果搜索不到,请安装arduino IDE1.8.15以上) 17 | 18 | ![board_manage_zh](./doc/board_manager_zh.png) 19 | 20 | 4、**工具->开发板** 21 | ![](./doc/board_chioce.png) 22 | 23 | 代表STC51duino开发环境搭建完成 24 | 25 | ## nulllab STC51duino开发计划 26 | 打勾的代表已经实现并验证,没有打勾的代表正在开发中,期待更多开发者一起维护 27 | 28 | - [x] [开发STC8951C52_Duino学习型开发板]() 29 | - [ ] [开发STC公司8051系类单片机的ISP命令行工具开发]() 30 | - [ ] [开发STC8951C52RC+芯片的arduino api对接]() 31 | - [ ] [开发STC15F2K60S2_Duino学习型开发板]() 32 | - [ ] [开发STC12C5A60S2_Duino学习型开发板]() 33 | - [ ] [开发STC8H8K64S4U_Duino学习型开发板]() -------------------------------------------------------------------------------- /boards.txt: -------------------------------------------------------------------------------- 1 | menu.cpu=Processor 2 | menu.clock_source=Clock source(MHz) 3 | menu.cpu_speed=CPU Frequency(MHz) 4 | menu.mode=Memory Model 5 | menu.intlib=Link libs 6 | menu.floatlib=float lib 7 | menu.userlib=user lib 8 | menu.vcc=Vcc Voltage 9 | 10 | ########################## stc89c52_duino #################################### 11 | stc89c52_duino.name=STC89C52_Duino 12 | 13 | stc89c52_duino.upload.tool=stc_isp 14 | stc89c52_duino.upload.protocol=stc_isp 15 | stc89c52_duino.upload.maximum_size=61440 16 | stc89c52_duino.upload.maximum_idata_size=256 17 | stc89c52_duino.upload.maximum_xdata_size=8192 18 | 19 | stc89c52_duino.build.core=STC89 20 | stc89c52_duino.build.extlib=-llibint -lliblong 21 | stc89c52_duino.build.variant=STC89 22 | stc89c52_duino.build.board=stc89c52_duino 23 | stc89c52_duino.build.mcu=STC89C52RC 24 | stc89c52_duino.build.clock_source=16M 25 | stc89c52_duino.build.f_cpu=16000000L 26 | 27 | stc89c52_duino.menu.mode.large=large 28 | stc89c52_duino.menu.mode.large.build.stdlib=large 29 | stc89c52_duino.menu.mode.small=small 30 | stc89c52_duino.menu.mode.small.build.stdlib=small 31 | stc89c52_duino.menu.mode.medium=medium 32 | stc89c52_duino.menu.mode.medium.build.stdlib=medium 33 | stc89c52_duino.menu.mode.huge=huge 34 | stc89c52_duino.menu.mode.huge.build.stdlib=huge 35 | 36 | ########################## STC8F #################################### 37 | stc8.name=STC8A/G/H/F 38 | 39 | stc8.upload.tool=stc_isp 40 | stc8.upload.protocol=stc_isp 41 | stc8.upload.maximum_size=61440 42 | stc8.upload.maximum_idata_size=256 43 | stc8.upload.maximum_xdata_size=8192 44 | 45 | stc8.build.core=STC8 46 | stc8.build.series=STC8 47 | stc8.build.board=STC8 48 | 49 | stc8.menu.cpu.8G1K17=STC8G1K17 50 | stc8.menu.cpu.8G1K17.build.board=STC8G1K17 51 | stc8.menu.cpu.8G1K17.build.mcu=STC8G1K17 52 | stc8.menu.cpu.8G1K17.build.variant=STC8 53 | stc8.menu.cpu.8G1K17.upload.maximum_size=65536 54 | stc8.menu.cpu.8G1K17.upload.maximum_xdata_size=8192 55 | 56 | stc8.menu.clock_source.f30=IRC30M 57 | stc8.menu.clock_source.f30.build.f_cpu=30000000UL 58 | stc8.menu.clock_source.f27=IRC27M 59 | stc8.menu.clock_source.f27.build.f_cpu=27000000UL 60 | stc8.menu.clock_source.f24r=IRC24M 61 | stc8.menu.clock_source.f24r.build.f_cpu=24000000UL -DHRC=1 62 | stc8.menu.clock_source.f22r=IRC22.1184M 63 | stc8.menu.clock_source.f22r.build.f_cpu=22118400UL -DHRC=1 64 | stc8.menu.clock_source.f12r=IRC12M 65 | stc8.menu.clock_source.f12r.build.f_cpu=12000000UL -DHRC=2 66 | stc8.menu.clock_source.f11r=IRC11.0592M 67 | stc8.menu.clock_source.f11r.build.f_cpu=11059200UL -DHRC=2 68 | stc8.menu.clock_source.f08r=RC8M 69 | stc8.menu.clock_source.f08r.build.f_cpu=8000000UL -DHRC=3 70 | stc8.menu.clock_source.f06r=IRC6M 71 | stc8.menu.clock_source.f06r.build.f_cpu=6000000UL -DHRC=4 72 | stc8.menu.clock_source.f25=OC25M 73 | stc8.menu.clock_source.f25.build.f_cpu=25000000UL -DHXT 74 | stc8.menu.clock_source.f24=OC24M 75 | stc8.menu.clock_source.f24.build.f_cpu=24000000UL -DHXT 76 | stc8.menu.clock_source.f22=OC22.1184M 77 | stc8.menu.clock_source.f22.build.f_cpu=22118400UL -DHXT 78 | stc8.menu.clock_source.f20=OC20M 79 | stc8.menu.clock_source.f20.build.f_cpu=20000000UL -DHXT 80 | stc8.menu.clock_source.f18=OC18.432M 81 | stc8.menu.clock_source.f18.build.f_cpu=18432000UL -DHXT 82 | stc8.menu.clock_source.f16=OC16M 83 | stc8.menu.clock_source.f16.build.f_cpu=16000000UL -DHXT 84 | stc8.menu.clock_source.f12=OC12M 85 | stc8.menu.clock_source.f12.build.f_cpu=12000000UL -DHXT 86 | stc8.menu.clock_source.f11=OC11.0592M 87 | stc8.menu.clock_source.f11.build.f_cpu=11059200UL -DHXT 88 | stc8.menu.clock_source.f10=OC10M 89 | stc8.menu.clock_source.f10.build.f_cpu=10000000UL -DHXT 90 | stc8.menu.clock_source.f08=OC8M 91 | stc8.menu.clock_source.f08.build.f_cpu=8000000UL -DHXT 92 | stc8.menu.clock_source.f06=OC6M 93 | stc8.menu.clock_source.f06.build.f_cpu=6000000UL -DHXT 94 | 95 | stc8.menu.mode.large=large 96 | stc8.menu.mode.large.build.stdlib=large 97 | stc8.menu.mode.small=small 98 | stc8.menu.mode.small.build.stdlib=small 99 | stc8.menu.mode.medium=medium 100 | stc8.menu.mode.medium.build.stdlib=medium 101 | stc8.menu.mode.huge=huge 102 | stc8.menu.mode.huge.build.stdlib=huge 103 | 104 | stc8.menu.vcc_mv.default=default 105 | stc8.menu.vcc_mv.v50=+5.0V 106 | stc8.menu.vcc_mv.v50.build.vcc=-DMENU_VCC=5000 107 | stc8.menu.vcc_mv.v33=+3.3V 108 | stc8.menu.vcc_mv.v33.build.vcc=-DMENU_VCC=3300 109 | 110 | stc8.menu.intlib.long=int+long 111 | stc8.menu.intlib.long.build.ilib=-llibint -lliblong 112 | stc8.menu.intlib.longlong=int+long+longlong 113 | stc8.menu.intlib.longlong.build.ilib=-llibint -lliblong -lliblonglong 114 | 115 | stc8.menu.floatlib.none=none 116 | stc8.menu.floatlib.none.build.extlib={build.ilib} 117 | stc8.menu.floatlib.none.build.print=-DUSE_PRINTF=3 118 | stc8.menu.floatlib.float=float 119 | stc8.menu.floatlib.float.build.extlib={build.ilib} -llibfloat 120 | stc8.menu.floatlib.float.build.print=-DUSE_PRINTF=2 121 | 122 | ########################## STC15 #################################### 123 | stc15.name=STC15F/L/W 124 | 125 | stc15.upload.tool=stc_isp 126 | stc15.upload.protocol=stc_isp 127 | stc15.upload.maximum_size=61440 128 | stc15.upload.maximum_idata_size=256 129 | stc15.upload.maximum_xdata_size=2048 130 | 131 | stc15.build.core=STC15 132 | stc15.build.series=STC15 133 | stc15.build.board=STC15 134 | 135 | stc15.menu.cpu.f2k60s2=STC15F2K60S2 136 | stc15.menu.cpu.f2k60s2.build.board=STC15F2K60S2 137 | stc15.menu.cpu.f2k60s2.build.mcu=STC15F2K 138 | stc15.menu.cpu.f2k60s2.build.variant=STC15 139 | stc15.menu.cpu.f2k60s2.upload.maximum_size=61440 140 | stc15.menu.cpu.f2k60s2.upload.maximum_xdata_size=2048 141 | 142 | stc15.menu.clock_source.f27=IRC27M 143 | stc15.menu.clock_source.f27.build.f_cpu=27000000L -DHXT 144 | stc15.menu.clock_source.f24r=IRC24M 145 | stc15.menu.clock_source.f24r.build.f_cpu=24000000L -DHRC=1 146 | stc15.menu.clock_source.f12r=IRC12M 147 | stc15.menu.clock_source.f12r.build.f_cpu=12000000L -DHRC=2 148 | stc15.menu.clock_source.f06r=IRC6M 149 | stc15.menu.clock_source.f06r.build.f_cpu=6000000L -DHRC=4 150 | stc15.menu.clock_source.f25=OC25M 151 | stc15.menu.clock_source.f25.build.f_cpu=25000000L -DHXT 152 | stc15.menu.clock_source.f24=OC24M 153 | stc15.menu.clock_source.f24.build.f_cpu=24000000L -DHXT 154 | stc15.menu.clock_source.f22=OC22.1184M 155 | stc15.menu.clock_source.f22.build.f_cpu=22118400L -DHXT 156 | stc15.menu.clock_source.f20=OC20M 157 | stc15.menu.clock_source.f20.build.f_cpu=20000000L -DHXT 158 | stc15.menu.clock_source.f18=OC18.432M 159 | stc15.menu.clock_source.f18.build.f_cpu=18432000UL -DHXT 160 | stc15.menu.clock_source.f16=OC16M 161 | stc15.menu.clock_source.f16.build.f_cpu=16000000L -DHXT 162 | stc15.menu.clock_source.f12=OC12M 163 | stc15.menu.clock_source.f12.build.f_cpu=12000000L -DHXT 164 | stc15.menu.clock_source.f11=OC11.0592M 165 | stc15.menu.clock_source.f11.build.f_cpu=11059200L -DHXT 166 | stc15.menu.clock_source.f10=OC10M 167 | stc15.menu.clock_source.f10.build.f_cpu=10000000L -DHXT 168 | stc15.menu.clock_source.f08=OC8M 169 | stc15.menu.clock_source.f08.build.f_cpu=8000000L -DHXT 170 | stc15.menu.clock_source.f06=OC6M 171 | stc15.menu.clock_source.f06.build.f_cpu=6000000L -DHXT 172 | 173 | stc15.menu.mode.large=large 174 | stc15.menu.mode.large.build.stdlib=large 175 | stc15.menu.mode.small=small 176 | stc15.menu.mode.small.build.stdlib=small 177 | stc15.menu.mode.medium=medium 178 | stc15.menu.mode.medium.build.stdlib=medium 179 | stc15.menu.mode.huge=huge 180 | stc15.menu.mode.huge.build.stdlib=huge 181 | 182 | stc15.menu.vcc_mv.default=default 183 | stc15.menu.vcc_mv.v50=+5.0V 184 | stc15.menu.vcc_mv.v50.build.vcc=-DMENU_VCC=5000 185 | stc15.menu.vcc_mv.v33=+3.3V 186 | stc15.menu.vcc_mv.v33.build.vcc=-DMENU_VCC=3300 187 | 188 | stc15.menu.intlib.long=int+long 189 | stc15.menu.intlib.long.build.ilib=-llibint -lliblong 190 | stc15.menu.intlib.longlong=int+long+longlong 191 | stc15.menu.intlib.longlong.build.ilib=-llibint -lliblong -lliblonglong 192 | 193 | stc15.menu.floatlib.float=float 194 | stc15.menu.floatlib.float.build.extlib={build.ilib} -llibfloat 195 | stc15.menu.floatlib.float.build.print=-DUSE_PRINTF=2 196 | stc15.menu.floatlib.none=none 197 | stc15.menu.floatlib.none.build.extlib={build.ilib} 198 | stc15.menu.floatlib.none.build.print=-DUSE_PRINTF=3 199 | 200 | 201 | ########################## STC12 #################################### 202 | stc12.name=STC12C52/12C56/12C5A 203 | 204 | stc12.upload.tool=stc_isp 205 | stc12.upload.protocol=stc_isp 206 | stc12.upload.maximum_size=61440 207 | stc12.upload.maximum_idata_size=256 208 | stc12.upload.maximum_xdata_size=2048 209 | 210 | stc12.build.core=STC12 211 | stc12.build.series=STC12 212 | stc12.build.board=STC12 213 | 214 | stc12.menu.cpu.12C5a60s2=STC12C5A60S2 215 | stc12.menu.cpu.12C5a60s2.build.board=STC12C5A60S2 216 | stc12.menu.cpu.12C5a60s2.build.mcu=STC12C5A60S2 217 | stc12.menu.cpu.12C5a60s2.build.variant=STC12 218 | stc12.menu.cpu.12C5a60s2.upload.maximum_size=61440 219 | stc12.menu.cpu.12C5a60s2.upload.maximum_xdata_size=2048 220 | 221 | stc12.menu.clock_source.f27=IRC27M 222 | stc12.menu.clock_source.f27.build.f_cpu=27000000L -DHXT 223 | stc12.menu.clock_source.f24r=IRC24M 224 | stc12.menu.clock_source.f24r.build.f_cpu=24000000L -DHRC=1 225 | stc12.menu.clock_source.f12r=IRC12M 226 | stc12.menu.clock_source.f12r.build.f_cpu=12000000L -DHRC=2 227 | stc12.menu.clock_source.f06r=IRC6M 228 | stc12.menu.clock_source.f06r.build.f_cpu=6000000L -DHRC=4 229 | stc12.menu.clock_source.f25=OC25M 230 | stc12.menu.clock_source.f25.build.f_cpu=25000000L -DHXT 231 | stc12.menu.clock_source.f24=OC24M 232 | stc12.menu.clock_source.f24.build.f_cpu=24000000L -DHXT 233 | stc12.menu.clock_source.f22=OC22.1184M 234 | stc12.menu.clock_source.f22.build.f_cpu=22118400L -DHXT 235 | stc12.menu.clock_source.f20=OC20M 236 | stc12.menu.clock_source.f20.build.f_cpu=20000000L -DHXT 237 | stc12.menu.clock_source.f18=OC18.432M 238 | stc12.menu.clock_source.f18.build.f_cpu=18432000UL -DHXT 239 | stc12.menu.clock_source.f16=OC16M 240 | stc12.menu.clock_source.f16.build.f_cpu=16000000L -DHXT 241 | stc12.menu.clock_source.f12=OC12M 242 | stc12.menu.clock_source.f12.build.f_cpu=12000000L -DHXT 243 | stc12.menu.clock_source.f11=OC11.0592M 244 | stc12.menu.clock_source.f11.build.f_cpu=11059200L -DHXT 245 | stc12.menu.clock_source.f10=OC10M 246 | stc12.menu.clock_source.f10.build.f_cpu=10000000L -DHXT 247 | stc12.menu.clock_source.f08=OC8M 248 | stc12.menu.clock_source.f08.build.f_cpu=8000000L -DHXT 249 | stc12.menu.clock_source.f06=OC6M 250 | stc12.menu.clock_source.f06.build.f_cpu=6000000L -DHXT 251 | 252 | stc12.menu.mode.large=large 253 | stc12.menu.mode.large.build.stdlib=large 254 | stc12.menu.mode.small=small 255 | stc12.menu.mode.small.build.stdlib=small 256 | stc12.menu.mode.medium=medium 257 | stc12.menu.mode.medium.build.stdlib=medium 258 | stc12.menu.mode.huge=huge 259 | stc12.menu.mode.huge.build.stdlib=huge 260 | 261 | stc12.menu.vcc_mv.default=default 262 | stc12.menu.vcc_mv.v50=+5.0V 263 | stc12.menu.vcc_mv.v50.build.vcc=-DMENU_VCC=5000 264 | stc12.menu.vcc_mv.v33=+3.3V 265 | stc12.menu.vcc_mv.v33.build.vcc=-DMENU_VCC=3300 266 | 267 | stc12.menu.intlib.long=int+long 268 | stc12.menu.intlib.long.build.ilib=-llibint -lliblong 269 | stc12.menu.intlib.longlong=int+long+longlong 270 | stc12.menu.intlib.longlong.build.ilib=-llibint -lliblong -lliblonglong 271 | 272 | stc12.menu.floatlib.float=float 273 | stc12.menu.floatlib.float.build.extlib={build.ilib} -llibfloat 274 | stc12.menu.floatlib.float.build.print=-DUSE_PRINTF=2 275 | stc12.menu.floatlib.none=none 276 | stc12.menu.floatlib.none.build.extlib={build.ilib} 277 | stc12.menu.floatlib.none.build.print=-DUSE_PRINTF=3 278 | 279 | ########################## STC89C #################################### 280 | stc89.name=STC89CxRC/RD+ 281 | 282 | stc89.upload.tool=stc_isp 283 | stc89.upload.protocol=stc_isp 284 | stc89.upload.maximum_size=8192 285 | stc89.upload.maximum_idata_size=256 286 | stc89.upload.maximum_xdata_size=256 287 | 288 | stc89.build.core=STC89 289 | stc89.build.series=STC89 290 | stc89.build.board=STC89C52 291 | 292 | stc89.menu.cpu.c51rc=STC89C51RC 293 | stc89.menu.cpu.c51rc.build.board=STC89C51RC 294 | stc89.menu.cpu.c51rc.build.mcu=STC89C51RC 295 | stc89.menu.cpu.c51rc.build.variant=STC89 296 | stc89.menu.cpu.c51rc.upload.maximum_size=4096 297 | 298 | stc89.menu.cpu.c52rc=STC89C52RC(8k/0.25k) 299 | stc89.menu.cpu.c52rc.build.board=STC89C52RC 300 | stc89.menu.cpu.c52rc.build.mcu=STC89C52 301 | stc89.menu.cpu.c52rc.build.variant=STC89 302 | stc89.menu.cpu.c52rc.upload.maximum_size=8192 303 | 304 | stc89.menu.clock_source.hxt25=25M 305 | stc89.menu.clock_source.hxt25.build.f_cpu=25000000L -DHXT 306 | stc89.menu.clock_source.hxt24=24M 307 | stc89.menu.clock_source.hxt24.build.f_cpu=24000000L -DHXT 308 | stc89.menu.clock_source.hxt22=22.1184M 309 | stc89.menu.clock_source.hxt22.build.f_cpu=22118400L -DHXT 310 | stc89.menu.clock_source.hxt20=20M 311 | stc89.menu.clock_source.hxt20.build.f_cpu=20000000L -DHXT 312 | stc89.menu.clock_source.hxt18=18.432M 313 | stc89.menu.clock_source.hxt18.build.f_cpu=18432000L -DHXT 314 | stc89.menu.clock_source.hxt16=16M 315 | stc89.menu.clock_source.hxt16.build.f_cpu=16000000L -DHXT 316 | stc89.menu.clock_source.hxt12=12M 317 | stc89.menu.clock_source.hxt12.build.f_cpu=12000000L -DHXT 318 | stc89.menu.clock_source.hxt11=11.0592M 319 | stc89.menu.clock_source.hxt11.build.f_cpu=11059200L -DHXT 320 | stc89.menu.clock_source.hxt10=10M 321 | stc89.menu.clock_source.hxt10.build.f_cpu=10000000L -DHXT 322 | stc89.menu.clock_source.hxt08=8M 323 | stc89.menu.clock_source.hxt08.build.f_cpu=8000000L -DHXT 324 | stc89.menu.clock_source.hxt06=6M 325 | stc89.menu.clock_source.hxt06.build.f_cpu=6000000L -DHXT 326 | 327 | stc89.menu.mode.large=large 328 | stc89.menu.mode.large.build.stdlib=large 329 | stc89.menu.mode.small=small 330 | stc89.menu.mode.small.build.stdlib=small 331 | stc89.menu.mode.medium=medium 332 | stc89.menu.mode.medium.build.stdlib=medium 333 | stc89.menu.mode.huge=huge 334 | stc89.menu.mode.huge.build.stdlib=huge 335 | 336 | stc89.menu.vcc_mv.default=default 337 | stc89.menu.vcc_mv.v50=+5.0V 338 | stc89.menu.vcc_mv.v50.build.vcc=-DMENU_VCC=5000 339 | stc89.menu.vcc_mv.v33=+3.3V 340 | stc89.menu.vcc_mv.v33.build.vcc=-DMENU_VCC=3300 341 | 342 | stc89.menu.intlib.long=int+long 343 | stc89.menu.intlib.long.build.ilib=-llibint -lliblong 344 | stc89.menu.intlib.longlong=int+long+longlong 345 | stc89.menu.intlib.longlong.build.ilib=-llibint -lliblong -lliblonglong 346 | 347 | stc89.menu.floatlib.none=none 348 | stc89.menu.floatlib.none.build.extlib={build.ilib} 349 | stc89.menu.floatlib.none.build.print=-DUSE_PRINTF=3 350 | stc89.menu.floatlib.float=float 351 | stc89.menu.floatlib.float.build.extlib={build.ilib} -llibfloat 352 | stc89.menu.floatlib.float.build.print=-DUSE_PRINTF=2 353 | 354 | ######################### end #################################### 355 | -------------------------------------------------------------------------------- /cores/STC15/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 | Modified 2 February 2018 for MSC51 by huaweiwx 20 | */ 21 | 22 | #ifndef Arduino_h 23 | #define Arduino_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "utils/compatible.h" 30 | #include "xmacro.h" 31 | #include "mcu.h" 32 | #include "pins_arduino.h" 33 | #include "bsp/bsp.h" 34 | 35 | // FIXME: workarounds for missing features or unimplemented functions 36 | // cancel out the PROGMEM attribute - used only for atmel CPUs 37 | #define PROGMEM 38 | void yield(void); 39 | 40 | // we use pre-defined IRQ function the way wiring does 41 | #define WIRING 42 | 43 | #define HIGH 0x1 44 | #define LOW 0x0 45 | 46 | /*特定 mnu.h 定义 gpio 模式*/ 47 | /*default*/ 48 | #ifndef QUASI /*准双向口,注意:读外部状态时,先要锁存为1,延时2个nop后再读取外部端口状态*/ 49 | #define QUASI 0x0 50 | #endif 51 | #ifndef OUTPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 52 | #define OUTPUT 0x1 53 | #endif 54 | #ifndef OUTPUT_PP /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 55 | #define OUTPUT_PP 0x1 56 | #endif 57 | #ifndef INPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 58 | #define INPUT 0x2 /*仅为输入*/ 59 | #endif 60 | #ifndef OUTPUT_OD /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 61 | #define OUTPUT_OD 0x3 /*开漏*/ 62 | #endif 63 | 64 | // undefine mathlib's pi if encountered 65 | #ifdef PI 66 | #undef PI 67 | #endif 68 | #ifdef HALF_PI 69 | #undef HALF_PI 70 | #endif 71 | #ifdef TWO_PI 72 | #undef TWO_PI 73 | #endif 74 | 75 | #define PI 3.1415926535897932384626433832795 76 | #define HALF_PI 1.5707963267948966192313216916398 77 | #define TWO_PI 6.283185307179586476925286766559 78 | #define DEG_TO_RAD 0.017453292519943295769236907684886 79 | #define RAD_TO_DEG 57.295779513082320876798154814105 80 | #define EULER 2.718281828459045235360287471352 81 | 82 | #define SERIAL 0x0 83 | #define DISPLAY 0x1 84 | 85 | #define LSBFIRST 0 86 | #define MSBFIRST 1 87 | 88 | #define CHANGE 1 89 | #define FALLING 2 90 | #define RISING 3 91 | 92 | // undefine stdlib's abs if encountered 93 | #ifdef abs 94 | #undef abs 95 | #endif 96 | 97 | #define min(a,b) ((a)<(b)?(a):(b)) 98 | #define max(a,b) ((a)>(b)?(a):(b)) 99 | #define abs(x) ((x)>0?(x):-(x)) 100 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 101 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 102 | #define radians(deg) ((deg)*DEG_TO_RAD) 103 | #define degrees(rad) ((rad)*RAD_TO_DEG) 104 | #define sq(x) ((x)*(x)) 105 | 106 | #define interrupts() sei() 107 | #define noInterrupts() cli() 108 | 109 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 110 | #define clockCyclesPerMillisecond() ( F_CPU / 1000L ) 111 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 112 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 113 | 114 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 115 | #define highByte(w) ((uint8_t) ((w) >> 8)) 116 | 117 | #define bitRead(value, b) (((value) >> (b)) & 0x01) 118 | #define bitSet(value, b) ((value) |= (1UL << (b))) 119 | #define bitClear(value, b) ((value) &= ~(1UL << (b))) 120 | #define bitWrite(value, b, bitvalue) ((bitvalue) ? bitSet(value, b) : bitClear(value, b)) 121 | 122 | #ifndef _BV 123 | #define _BV(x) (1<<(x)) 124 | #endif 125 | #ifndef cbi /*compatible with wiring*/ 126 | #define cbi(a, b) bitClear(a,b) 127 | #endif 128 | #ifndef sbi /*compatible with wiring*/ 129 | #define sbi(a, b) bitSet(a, b) 130 | #endif 131 | 132 | #define maskSet(value, mask) ((value) |= (mask)) 133 | #define maskClear(value, mask) ((value) &= ~(mask)) 134 | 135 | 136 | // avr-libc defines _NOP() since 1.6.2 137 | #ifndef _NOP 138 | #define _NOP() NOP() 139 | #endif 140 | 141 | #ifndef F 142 | #define F(x) 143 | #endif 144 | 145 | /* for SDCC this is supposed to be "__critical{" and "}", but up to 146 | * sdcc version 3.6.4 it is wrongly implemented. */ 147 | /* so geht es nicht: 148 | #define BEGIN_CRITICAL __asm__("push\tcc");__asm__("sim"); 149 | #define END_CRITICAL __asm__("pop\tcc"); 150 | */ 151 | #define BEGIN_CRITICAL __critical { 152 | #define END_CRITICAL } 153 | /* klappt: 154 | #define BEGIN_CRITICAL 155 | #define END_CRITICAL 156 | */ 157 | 158 | 159 | 160 | 161 | // #define bit(b) (1UL << (b)) sdcc bit is __bit keywords 162 | 163 | //typedef bool boolean; 164 | typedef unsigned int word; 165 | typedef unsigned char byte; 166 | 167 | void init(void); 168 | void initVariant(void); // weak 169 | 170 | int atexit(void (*func)()); // __attribute__((weak)); 171 | #ifndef pinMode /* 部分mcu 使用宏定义代替 */ 172 | void pinMode(uint8_t pin, uint8_t mode); 173 | #endif 174 | 175 | #include "wiring_digital.h" 176 | 177 | #ifndef analogRead 178 | int analogRead(uint8_t pin); 179 | #endif 180 | #ifndef analogReference 181 | void analogReference(uint8_t mode); 182 | #endif 183 | #ifndef analogWrite 184 | void analogWrite(uint8_t pin, uint8_t val); 185 | #endif 186 | 187 | #include "wiring.h" 188 | 189 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 190 | unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 191 | 192 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 193 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 194 | 195 | void attachInterrupt(uint8_t, void (*)(void), int mode); 196 | void detachInterrupt(uint8_t); 197 | 198 | void setup(void); 199 | void loop(void); 200 | 201 | // Get the bit location within the hardware port of the given virtual pin. 202 | // This comes from the pins_*.c file for the active board configuration. 203 | 204 | #define analogInPinToBit(P) (P) 205 | 206 | //extern const uint8_t digital_pin_to_port[]; 207 | //extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 208 | //extern const uint8_t digital_pin_to_bit_mask[]; 209 | //extern const uint8_t digital_pin_to_timer[]; 210 | 211 | // Get the bit location within the hardware port of the given virtual pin. 212 | // This comes from the pins_*.c file for the active board configuration. 213 | // 214 | #define digitalPinToPort(pin) (pin >> 4) 215 | #define digitalPinToBitMask(pin) (1 << (pin & 0x0f)) 216 | //#define digitalPinToTimer(P) ( digital_pin_to_timer[(P)] ) 217 | //#define analogInPinToBit(P) (P) 218 | //#define portOutputRegister(P) ( (volatile uint8_t *)( port_to_output[(P)]) ) 219 | //#define portInputRegister(P) ( (volatile uint8_t *)( port_to_input[(P)]) ) 220 | //#define portModeRegister(P) ( (volatile uint8_t *)( port_to_mode[(P)]) ) 221 | 222 | #define NOT_A_PIN 0xff 223 | #define NOT_A_PORT 0xff 224 | 225 | #define NOT_AN_INTERRUPT -1 226 | 227 | #ifdef ARDUINO_MAIN 228 | //#define PA 1 229 | //#define PB 2 230 | //#define PC 3 231 | //#define PD 4 232 | //#define PE 5 233 | //#define PF 6 234 | //#define PG 7 235 | //#define PH 8 236 | //#define PJ 10 237 | //#define PK 11 238 | //#define PL 12 239 | #endif 240 | 241 | //FIXME#include "WCharacter.h" 242 | //FIXME#include "WString.h" 243 | #include "HardwareSerial.h" 244 | 245 | //uint16_t makeWord(uint16_t w); 246 | //uint16_t makeWord(byte h, byte l); 247 | 248 | //#define word(...) makeWord(__VA_ARGS__) 249 | 250 | 251 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration); 252 | void noTone(uint8_t _pin); 253 | 254 | // WMath prototypes 255 | long random(long howbig); 256 | long random_minmax(long howsmall, long howbig); 257 | void randomSeed(unsigned long seed); 258 | long map(long x, long in_min, long in_max, long out_min, long out_max); 259 | 260 | inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 261 | 262 | #endif //Arduino_h 263 | -------------------------------------------------------------------------------- /cores/STC15/HardwareSerial.c: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.c - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | 27 | Modified 2 February 2018 for mcs51 by huaweiwx 28 | */ 29 | 30 | #include "Arduino.h" 31 | 32 | // private data ////////////////////////////////////////////////////////////// 33 | 34 | #ifndef SERIAL_BUFFER_SIZE 35 | # define SERIAL_BUFFER_SIZE 64 36 | #endif 37 | 38 | #if SERIAL_BUFFER_SIZE > 255 39 | typedef struct { 40 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 41 | uint16_t size; 42 | volatile uint16_t head; 43 | volatile uint16_t tail; 44 | } RINGBUF_TypeDef; 45 | #else 46 | typedef struct { 47 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 48 | uint8_t size; 49 | volatile uint8_t head; 50 | volatile uint8_t tail; 51 | } RINGBUF_TypeDef; 52 | #endif 53 | 54 | static XDATA(RINGBUF_TypeDef,rxBuf);// = { { 0 }, 0, 0}; 55 | static bool initialized; //=0 internal status. Returned on HardwareSerial() 56 | 57 | // private functions //////////////////////////////////////////////////////// 58 | static void storeChar(uint8_t c, RINGBUF_TypeDef *buf) 59 | { 60 | noInterrupts(); 61 | int i = (unsigned int)(buf->head + 1) % buf->size; 62 | 63 | // if we should be storing the received character into the location 64 | // just before the tail (meaning that the head would advance to the 65 | // current location of the tail), we're about to overflow the buffer 66 | // and so we don't write the character or advance the head. 67 | if (i != buf->tail) { 68 | buf->buffer[buf->head] = c; 69 | buf->head = i; 70 | } 71 | interrupts(); 72 | } 73 | 74 | // Interrupt handler /////////////////////////////////////////////////////////// 75 | /** 76 | FUNCTION_PURPOSE: serial interrupt, echo received data. 77 | FUNCTION_INPUTS: P0.7(RXD) serial input 78 | FUNCTION_OUTPUTS: P0.6(TXD) serial output 79 | */ 80 | 81 | #if (MENU_SERIAL == 1) 82 | #define InitialUARTx(x) \ 83 | uart_init0(x);\ 84 | attachInterrupt(UART_IRQn,UART_IRQHandler,0); \ 85 | REN = 1; \ 86 | SM2 = 0;\ 87 | ES = 1;\ 88 | EA = 1 89 | 90 | #define RXREG SBUF 91 | void UART_IRQHandler(void) // void Serial_ISR(void) __interrupt 4 92 | { 93 | uint8_t c; 94 | if (RI) 95 | { /* if reception occur */ 96 | RI = 0; /* clear reception flag for next reception */ 97 | c = RXREG; 98 | storeChar(c, &rxBuf); 99 | } 100 | if (TI) 101 | { 102 | TI = 0; /* if emission occur */ 103 | } 104 | } 105 | 106 | size_t HardwareSerial_write(uint8_t c) 107 | { 108 | noInterrupts(); 109 | TI = 0; 110 | RXREG = c; 111 | while (!TI); 112 | interrupts(); 113 | return 1; 114 | } 115 | 116 | #elif (MENU_SERIAL == 2) 117 | #define InitialUARTx(x) \ 118 | uart_init2(x);\ 119 | attachInterrupt(UART2_IRQn,UART2_IRQHandler,0); \ 120 | S2CON |= ( S2REN);\ 121 | S2CON &= (~S2SM2);\ 122 | IE2 |= ( ES2);\ 123 | EA = 1 124 | 125 | #define RXREG S2BUF 126 | void UART2_IRQHandler(void) // uart2_isr, 8 127 | { 128 | uint8_t c; 129 | if ( (S2CON & S2RI) == S2RI ) 130 | { /* if reception occur */ 131 | S2CON &= (~S2RI); /* clear reception flag for next reception */ 132 | c = RXREG; 133 | storeChar(c, &rxBuf); 134 | } 135 | if ((S2CON & S2TI) == S2TI) 136 | { 137 | S2CON &= (~S2TI); /* if emission occur */ 138 | } 139 | } 140 | 141 | size_t HardwareSerial_write(uint8_t c) 142 | { 143 | noInterrupts(); 144 | S2CON &= (~S2TI); /* if emission occur */ 145 | RXREG = c; 146 | while (!(S2CON & S2TI) ); 147 | interrupts(); 148 | return 1; 149 | } 150 | 151 | #else 152 | #error "This case undefined! Please add" 153 | #endif 154 | 155 | 156 | // Public Methods ////////////////////////////////////////////////////////////// 157 | 158 | uint8_t HardwareSerial(void) 159 | { 160 | return initialized; 161 | } 162 | 163 | void HardwareSerial_begin(unsigned long baud) 164 | { 165 | rxBuf.head = rxBuf.tail = 0; 166 | rxBuf.size = sizeof(rxBuf.buffer); 167 | initialized = 1; 168 | putcharFunc = HardwareSerial_write; 169 | InitialUARTx(baud); 170 | } 171 | 172 | void HardwareSerial_end(void) 173 | { 174 | // wait for transmission of outgoing data 175 | rxBuf.head = rxBuf.tail = 0; 176 | initialized = 0; 177 | } 178 | 179 | int HardwareSerial_available(void) 180 | { 181 | unsigned int rtn; 182 | noInterrupts(); 183 | rtn = (rxBuf.size + rxBuf.head - rxBuf.tail) % rxBuf.size; 184 | interrupts(); 185 | return rtn; 186 | } 187 | 188 | int HardwareSerial_peek(void) 189 | { 190 | int rtn; 191 | noInterrupts(); 192 | if (rxBuf.head == rxBuf.tail) { 193 | rtn = -1; 194 | } else { 195 | rtn = rxBuf.buffer[rxBuf.tail]; 196 | } 197 | interrupts(); 198 | return rtn; 199 | } 200 | 201 | int HardwareSerial_read(void) 202 | { 203 | int rtn; 204 | noInterrupts(); 205 | if (rxBuf.head == rxBuf.tail) { 206 | rtn = -1; 207 | } else { 208 | rtn = rxBuf.buffer[rxBuf.tail]; 209 | rxBuf.tail = (unsigned int)(rxBuf.tail + 1) % rxBuf.size; 210 | } 211 | interrupts(); 212 | return rtn; 213 | } 214 | 215 | void HardwareSerial_flush(void) 216 | { 217 | } 218 | 219 | writefunc_p putcharFunc = HardwareSerial_write; /*缺省使用库 HardwareSerial_write*/ 220 | int putchar(int c) 221 | { 222 | putcharFunc((unsigned char)c); /* output character */ 223 | return (c); 224 | } 225 | 226 | //#define PRINTF_TINY 5 227 | //#define PRINTF_SMALL 4 228 | //#define PRINTF_FAST 3 229 | //#define PRINTF_FAST_F 2 230 | //#define PRINTF 1 231 | 232 | #if (USE_PRINTF > 0) /*use printf */ 233 | __code HWSERIAL_TypeDef Serial = { 234 | HardwareSerial_available, 235 | HardwareSerial_begin, 236 | HardwareSerial_write, 237 | HardwareSerial_read, 238 | #if (USE_PRINTF > 4) /*5*/ 239 | printf_tiny, 240 | #elif (USE_PRINTF > 3) 241 | printf_small, 242 | #elif (USE_PRINTF > 2) 243 | printf_fast, 244 | #elif (USE_PRINTF > 1) 245 | printf_fast_f, 246 | #else 247 | printf, 248 | #endif 249 | }; 250 | #endif 251 | -------------------------------------------------------------------------------- /cores/STC15/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | Modified 2 February 2018 for mcs51 by huaweiwx 27 | */ 28 | 29 | #ifndef _HARDWARE_SERIAL_H_ 30 | #define _HARDWARE_SERIAL_H_ 31 | 32 | #include 33 | #include 34 | 35 | // Define config for Serial.begin(baud, config); 36 | /* coding of the bit field: 00sw .pp. 37 | * wordlength w: 0:8 1:9 (5,6,7 not supported) 38 | * parity pp: 0:n 2:e 3:o 39 | * stopbits s: 0:1 1:2 40 | * => 8x1=0x0x, 9x1=0x1x, 8x2=0x2x, 9x2=0x3x 41 | * => n=0xx0, e=0xx4, o=0xx6 42 | */ 43 | #define SERIAL_8N1 0x00 44 | #define SERIAL_9N1 0x10 45 | #define SERIAL_8N2 0x20 46 | #define SERIAL_9N2 0x30 47 | #define SERIAL_8E1 0x04 48 | #define SERIAL_9E1 0x14 49 | #define SERIAL_8E2 0x24 50 | #define SERIAL_9E2 0x34 51 | #define SERIAL_8O1 0x06 52 | #define SERIAL_9O1 0x16 53 | #define SERIAL_8O2 0x26 54 | #define SERIAL_9O2 0x36 55 | 56 | #define MASK_PARITY 0x06 57 | #define MASK_STOPBITS 0x20 58 | #define MASK_DATABITS 0x10 59 | 60 | 61 | // Public Methods ////////////////////////////////////////////////////////////// 62 | 63 | uint8_t HardwareSerial(void); 64 | void HardwareSerial_begin(unsigned long baud); 65 | void HardwareSerial_end(void); 66 | 67 | int HardwareSerial_available(void); 68 | int HardwareSerial_read(void); 69 | size_t HardwareSerial_write(uint8_t c); 70 | void HardwareSerial_flush(void); 71 | extern writefunc_p putcharFunc; 72 | 73 | #if (USE_PRINTF > 0) /*use printf */ 74 | typedef struct { 75 | i_v_funcType available; 76 | v_l_funcType begin; 77 | s_c_funcType write; 78 | i_v_funcType read; 79 | #if (USE_PRINTF > 4) /*5 printf_tiny*/ 80 | v_c_printfType printf; 81 | #elif (USE_PRINTF > 3) /*4 printf_small*/ 82 | v_printfType printf; 83 | #elif (USE_PRINTF > 2) /*3 printf_fast*/ 84 | v_c_printfType printf; 85 | #elif (USE_PRINTF > 1) /*2 printf_fast_f*/ 86 | v_c_printfType printf; 87 | #else 88 | i_printfType printf; /*1 printf*/ 89 | #endif 90 | } HWSERIAL_TypeDef; 91 | extern __code HWSERIAL_TypeDef Serial; 92 | #endif 93 | 94 | // Alias Definitions for a more Arduino-like look //////////////////////////// 95 | 96 | //#define Serial HardwareSerial() 97 | #define Serial_begin HardwareSerial_begin 98 | #define Serial_available HardwareSerial_available 99 | #define Serial_read HardwareSerial_read 100 | #define Serial_write HardwareSerial_write 101 | #define Serial_flush HardwareSerial_flush 102 | #define Serial_end HardwareSerial_end 103 | 104 | 105 | // variants of the standard Serial.print() function: Separate implementations 106 | // for string, char, unsigned, signed int 107 | #define Serial_print_s(S) Print_print_s(HardwareSerial_write,S) 108 | #define Serial_print_sn(S) Print_print_sn(HardwareSerial_write,S,N) 109 | #define Serial_print_c(C) HardwareSerial_write(C) 110 | 111 | // print signed/unsigned integer values (char, short, int, long) as decimal values 112 | #define Serial_print_i(I) Print_print_i(HardwareSerial_write,I) 113 | #define Serial_print_u(U) Print_print_u(HardwareSerial_write,U) 114 | 115 | // print signed/unsigned integer values (char, short, int, long) to base B 116 | #define Serial_print_ib(I,B) Print_print_ib(HardwareSerial_write,I,B) 117 | #define Serial_print_ub(U,B) Print_print_ub(HardwareSerial_write,U,B) 118 | 119 | // print float value 120 | #define Serial_print_f(F) Print_print_fd(HardwareSerial_write,F,2) 121 | #define Serial_print_fd(F,D) Print_print_fd(HardwareSerial_write,F,D) 122 | 123 | #define Serial_println() Print_println(HardwareSerial_write) 124 | #define Serial_println_s(S) Print_println_s(HardwareSerial_write,S) 125 | #define Serial_println_sn(S,N) Print_println_sn(HardwareSerial_write,S,N) 126 | #define Serial_println_u(U) Print_println_u(HardwareSerial_write,U) 127 | #define Serial_println_i(I) Print_println_i(HardwareSerial_write,I) 128 | #define Serial_println_ib(I,B) Print_println_ib(HardwareSerial_write,I,B) 129 | #define Serial_println_ub(U,B) Print_println_ub(HardwareSerial_write,U,B) 130 | #define Serial_println_f(F) Print_println_fd(HardwareSerial_write,F,2) 131 | #define Serial_println_fd(F,D) Print_println_fd(HardwareSerial_write,F,D) 132 | 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /cores/STC15/Print.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | void printNL(void); 46 | 47 | // Public Methods ////////////////////////////////////////////////////////////// 48 | 49 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 50 | { 51 | size_t n = 0; 52 | while (size--) { 53 | if (writefunc(*buffer++)) n++; 54 | else break; 55 | } 56 | return n; 57 | } 58 | 59 | size_t Print_print_s(writefunc_p writefunc, const char *str) 60 | { 61 | size_t n = 0; 62 | char c; 63 | 64 | if (!str) return 0; 65 | 66 | while ( c=*str++ ) { // assignment intented 67 | if (writefunc(c)) n++; 68 | else break; 69 | } 70 | return n; 71 | } 72 | 73 | 74 | size_t Print_print_u(writefunc_p writefunc, unsigned long n) 75 | { 76 | return printNumber(writefunc, n,10); 77 | } 78 | 79 | size_t Print_print_i(writefunc_p writefunc, long n) 80 | { 81 | return printInt(writefunc, n,10); 82 | } 83 | 84 | // Variants of the above functions with an added newline ////////////////////// 85 | 86 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 87 | { 88 | size_t r; 89 | 90 | r = Print_print_sn(writefunc, buffer, size); 91 | return r + Print_println(writefunc); 92 | } 93 | 94 | size_t Print_println_s(writefunc_p writefunc, const char *str) 95 | { 96 | size_t r; 97 | 98 | r = Print_print_s(writefunc, str); 99 | return r + Print_println(writefunc); 100 | } 101 | 102 | size_t Print_println_u(writefunc_p writefunc, unsigned long n) 103 | { 104 | size_t r; 105 | 106 | r = printNumber(writefunc, n,10); 107 | return r + Print_println(writefunc); 108 | } 109 | 110 | size_t Print_println_i(writefunc_p writefunc, long n) 111 | { 112 | size_t r; 113 | 114 | r = printInt(writefunc, n,10); 115 | return r + Print_println(writefunc); 116 | } 117 | 118 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 119 | { 120 | size_t r; 121 | 122 | r = printNumber(writefunc, n,base); 123 | return r + Print_println(writefunc); 124 | } 125 | 126 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base) 127 | { 128 | size_t r; 129 | 130 | r = printInt(writefunc, n,base); 131 | return r + Print_println(writefunc); 132 | } 133 | 134 | 135 | 136 | // (not so) Private Methods ///////////////////////////////////////////////////////////// 137 | 138 | size_t Print_println(writefunc_p writefunc) 139 | { 140 | size_t n; 141 | 142 | n = writefunc(13); 143 | n += writefunc(10); 144 | return n; 145 | } 146 | 147 | 148 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 149 | { 150 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 151 | char *str = &buf[sizeof(buf) - 1]; 152 | 153 | *str = '\0'; 154 | 155 | // prevent crash if called with base == 1 156 | if (base < 2) base = 10; 157 | 158 | do { 159 | char c = n % base; 160 | n /= base; 161 | 162 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 163 | } while(n); 164 | 165 | return Print_print_s(writefunc, str); 166 | } 167 | 168 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base) 169 | { 170 | if (base == 0) { 171 | return writefunc((unsigned char) n); 172 | } else if (base == 10) { 173 | if (n < 0) { 174 | int t = writefunc('-'); 175 | n = -n; 176 | return printNumber(writefunc, n, 10) + t; 177 | } 178 | return printNumber(writefunc, n, 10); 179 | } else { 180 | return printNumber(writefunc, n, base); 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /cores/STC15/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. 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 Print_h 21 | #define Print_h 22 | 23 | #include // for size_t 24 | #include 25 | 26 | //#include "WString.h" 27 | //#include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | 35 | // for the function pointer to the actual write function 36 | typedef size_t (*writefunc_p)(uint8_t c); 37 | 38 | // abreviations of the actual function names, mostly for internal use 39 | #define printBuf Print_print_sn 40 | #define printStr Print_print_s 41 | #define printNumber Print_print_ub 42 | #define printInt Print_print_ib 43 | #define println Print_println 44 | 45 | 46 | // the more sophisticated Arduino-Style functions. Variants of the standard 47 | // Serial.print() function: Separate impementations for different datatype 48 | // to mimic polymorphism. 49 | 50 | // print strings (C-Style or buffer contents) 51 | size_t Print_print_s(writefunc_p writefunc, const char *str); 52 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 53 | 54 | // print signed/unsigned values (char, short, int, long) as decimal values 55 | size_t Print_print_i(writefunc_p writefunc, long n); 56 | size_t Print_print_u(writefunc_p writefunc, unsigned long n); 57 | 58 | // print signed/unsigned integer values (char, short, int, long) to base B 59 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base); 60 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 61 | 62 | // print float values with two digits precision/specified number of digits 63 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits); 64 | //#define Print_print_f(W,N) Print_print_fd(W,N,2) 65 | inline size_t Print_print_f(writefunc_p writefunc, double number) { 66 | return Print_print_fd(writefunc, number, 2); 67 | } 68 | 69 | // Variants of the above with a newline added at the and: 70 | size_t Print_println(writefunc_p writefunc); 71 | size_t Print_println_s(writefunc_p writefunc, const char *str); 72 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 73 | size_t Print_println_i(writefunc_p writefunc, long n); 74 | size_t Print_println_u(writefunc_p writefunc, unsigned long n); 75 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base); 76 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 77 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits); 78 | //#define Print_println_f(W,N) Print_println_fd(W,N,2) 79 | inline size_t Print_println_f(writefunc_p writefunc, double number) { 80 | return Print_println_fd(writefunc, number, 2); 81 | } 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cores/STC15/Print_float.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | // Public Methods ////////////////////////////////////////////////////////////// 46 | 47 | 48 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits) 49 | { 50 | size_t n = 0; 51 | uint8_t i; 52 | unsigned long int_part; 53 | double remainder, rounding; 54 | unsigned int toPrint; 55 | 56 | if (isnan(number)) return printStr(writefunc,"nan"); 57 | if (isinf(number)) return printStr(writefunc,"inf"); 58 | if (number > 4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 59 | if (number <-4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 60 | 61 | // Handle negative numbers 62 | if (number < 0.0) 63 | { 64 | n += writefunc('-'); 65 | number = -number; 66 | } 67 | 68 | // Round correctly so that print(1.999, 2) prints as "2.00" 69 | rounding = 0.5; 70 | for (i=0; i 0) { 82 | n += writefunc('.'); 83 | } 84 | 85 | // Extract digits from the remainder one at a time 86 | while (digits-- > 0) 87 | { 88 | remainder *= 10.0; 89 | toPrint = (unsigned int)(remainder); 90 | n += printNumber(writefunc,toPrint,10); 91 | remainder -= toPrint; 92 | } 93 | 94 | return n; 95 | } 96 | 97 | 98 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits) 99 | { 100 | size_t r; 101 | 102 | r = Print_print_fd(writefunc, number, digits); 103 | return r + Print_println(writefunc); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /cores/STC15/WMath.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #include "stdlib.h" 27 | } 28 | #else 29 | #include "stdlib.h" 30 | #endif 31 | 32 | void randomSeed(unsigned long seed) 33 | { 34 | if (seed != 0) { 35 | srand(seed); 36 | } 37 | } 38 | 39 | long random(long howbig) 40 | { 41 | if (howbig == 0) { 42 | return 0; 43 | } 44 | return rand() % howbig; 45 | } 46 | 47 | long random_minmax(long howsmall, long howbig) 48 | { 49 | long diff; 50 | 51 | if (howsmall >= howbig) { 52 | return howsmall; 53 | } 54 | diff = howbig - howsmall; 55 | return random(diff) + howsmall; 56 | } 57 | 58 | long map(long x, long in_min, long in_max, long out_min, long out_max) 59 | { 60 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 61 | } 62 | 63 | //unsigned int makeWord(unsigned int w) { return w; } 64 | //unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 65 | -------------------------------------------------------------------------------- /cores/STC15/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - Main loop for Arduino sketches 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 | Modified 2 February 2018 for mcs51 by huaweiwx 19 | */ 20 | 21 | #define ARDUINO_MAIN 22 | 23 | #include 24 | #include "bsp/isr.h" 25 | 26 | // make sure to define prototypes for all used interrupts 27 | void init(void); 28 | void initVariant(void); // weak 29 | 30 | int main(void) 31 | { 32 | init(); 33 | 34 | initVariant(); 35 | 36 | setup(); 37 | 38 | for (;;) { 39 | loop(); 40 | } 41 | } 42 | 43 | 44 | void _sdcc_external_startup(void) 45 | { 46 | //PCA0MD &= ~0x40; /*关闭内部看门狗*/ 47 | } -------------------------------------------------------------------------------- /cores/STC15/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the mcs51. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | DELAY_10US)(i) and DELAY_MS(i,j) created by stc-isp-15xx-v6.86s.exe 23 | Modified 2 February 2018 for mcs51 by huaweiwx 24 | */ 25 | 26 | #define WIRING_MAIN 27 | #include "Arduino.h" 28 | 29 | #define T1MS (65536L-F_CPU/1000) //1ms timer calculation method in 1T mode 30 | //#define T1MS (65536L-F_CPU/12/1000) //1ms timer calculation method in 12T mode 31 | 32 | #define TH0_INIT (T1MS >> 8) 33 | #define TL0_INIT (T1MS & 0xff) 34 | 35 | extern void SystemClock_Config(void); 36 | 37 | 38 | 39 | /**************** 简单延时 **************************/ 40 | void delay_loop(unsigned char cnt) 41 | { 42 | while (--cnt); 43 | } 44 | 45 | 46 | #if USE_SYSTICK 47 | 48 | static volatile uint32_t dwTickCount = 0; 49 | 50 | /*************** Timer0 中断函数 *********************/ 51 | void Timer0_IRQHandler (void) //1毫秒 52 | { 53 | TH0 = TH0_INIT; TL0 = TL0_INIT; //重载定时初值 54 | TF0 = 0; //清除TF0标志 55 | dwTickCount++; //systic 计数 56 | } 57 | 58 | void init(void){ 59 | SystemClock_Config(); 60 | dwTickCount = 0; 61 | attachInterrupt(TIMER0_IRQn, Timer0_IRQHandler, 0); 62 | AUXR = 0x80; //timer0 work in 1T mode 63 | TMOD = 0x01; //set timer0 as mode1 (16-bit) 64 | TL0 = TL0_INIT; //initial timer0 low byte 65 | TH0 = TH0_INIT; //initial timer0 high byte 66 | TR0 = 1; //timer0 start running 67 | ET0 = 1; //enable timer0 interrupt 68 | EA = 1; //open global interrupt switch 69 | } 70 | 71 | unsigned long millis() 72 | { 73 | return dwTickCount; 74 | } 75 | 76 | unsigned long micros() 77 | { 78 | uint32_t m,u; 79 | uint8_t hi,lo; 80 | 81 | lo = TL0; hi = TH0; 82 | u = dwTickCount*1000; 83 | 84 | m = ((((hi<<8)| lo)- T1MS)*1000); 85 | u += m/T1MS; 86 | 87 | return u; 88 | } 89 | 90 | void delay(unsigned int ms){ 91 | uint32_t s = dwTickCount; 92 | uint32_t e = s + ms; 93 | if(e < s){ 94 | while(e < millis()); 95 | } 96 | while(millis()< e); 97 | } 98 | 99 | void delayMicroseconds(unsigned int us) 100 | { 101 | uint32_t s = micros(); 102 | uint32_t e = s + us; 103 | if(e < s){ 104 | while(e < micros()); 105 | } 106 | while(micros()< e); 107 | } 108 | 109 | #else 110 | 111 | void init(void){ 112 | SystemClock_Config(); 113 | } 114 | 115 | void delay10us(unsigned int us) 116 | { 117 | unsigned char i; 118 | do{ 119 | DELAY_10US(i); 120 | while (--i); 121 | }while(--us); 122 | } 123 | 124 | void delay(unsigned int ms) 125 | { 126 | unsigned char i, j; 127 | 128 | do { 129 | DELAY_MS(i,j); 130 | do { 131 | while (--j); 132 | } while (--i); 133 | }while (--ms); 134 | } 135 | #endif 136 | -------------------------------------------------------------------------------- /cores/STC15/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h 3 | Modified 2 February 2018 for mcs51 by huaweiwx 4 | */ 5 | #ifndef _WIRING_H_ 6 | #define _WIRING_H_ 7 | 8 | #ifndef USE_SYSTICK 9 | #define USE_SYSTICK 1 10 | #endif 11 | 12 | #if CORE_STCYn > 1 13 | #define T1MS (65536L-F_CPU/1000) //1ms timer calculation method in 1T mode 14 | #elif CORE_STCYn == 1 15 | #define T1MS (65536L-F_CPU/12/1000) //1ms timer calculation method in 12T mode 16 | #else 17 | #error NOT STC core or CORE_STCYn undef! 18 | #endif 19 | 20 | #define TH0_INIT (T1MS >> 8) 21 | #define TL0_INIT (T1MS & 0xff) 22 | 23 | void delay_loop(unsigned char cnt); 24 | 25 | 26 | #if USE_SYSTICK 27 | 28 | unsigned long millis(); 29 | unsigned long micros(); 30 | void delay(unsigned int ms); 31 | void delayMicroseconds(unsigned int us); 32 | 33 | #else 34 | 35 | void delay10us(unsigned int us); 36 | void delay(unsigned int ms); 37 | 38 | #define delayMicroseconds(us) if(us>10){delay10us(us/10);}else{delay_loop(us);} 39 | 40 | #endif //USE_SYSTICK 41 | 42 | #endif //_WIRING_H_ 43 | -------------------------------------------------------------------------------- /cores/STC15/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 2 February 2018 for mcs51 by huaweiwx 23 | */ 24 | #include "Arduino.h" 25 | 26 | /* This char array helps to convert pin map to port*/ 27 | const uint8_t pinToMask[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 28 | 29 | uint8_t portRead(uint8_t ucPort){ 30 | uint8_t rtn = 0; 31 | switch (ucPort){ 32 | #ifdef SFR_P0 33 | case 0: 34 | rtn = P0; 35 | break; 36 | #endif 37 | #ifdef SFR_P1 38 | case 1: 39 | rtn = P1; 40 | break; 41 | #endif 42 | #ifdef SFR_P2 43 | case 2: 44 | rtn = P2; 45 | break; 46 | #endif 47 | #ifdef SFR_P3 48 | case 3: 49 | rtn = P3; 50 | break; 51 | #endif 52 | #ifdef SFR_P4 53 | case 4: 54 | rtn = P4; 55 | break; 56 | #endif 57 | #ifdef SFR_P5 58 | case 5: 59 | rtn = P5; 60 | break; 61 | #endif 62 | } 63 | return rtn; 64 | } 65 | 66 | void portWrite(uint8_t ucPort,uint8_t val){ 67 | switch (ucPort){ 68 | #ifdef SFR_P0 69 | case 0: 70 | P0 = val; 71 | break; 72 | #endif 73 | #ifdef SFR_P1 74 | case 1: 75 | P1 = val; 76 | break; 77 | #endif 78 | #ifdef SFR_P2 79 | case 2: 80 | P2 = val; 81 | break; 82 | #endif 83 | #ifdef SFR_P3 84 | case 3: 85 | P3 = val; 86 | break; 87 | #endif 88 | #ifdef SFR_P4 89 | case 4: 90 | P4 = val; 91 | break; 92 | #endif 93 | #ifdef SFR_P5 94 | case 5: 95 | P5 = val; 96 | break; 97 | #endif 98 | } 99 | } 100 | 101 | void digitalWriteHigh(uint8_t pin){ 102 | uint8_t ucPort,ucPin,mask; 103 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 104 | ucPort = pin >>4; 105 | ucPin = pin & 0x07; 106 | mask = pinToMask[ucPin]; 107 | mask |= portRead(ucPort); 108 | portWrite(ucPort,mask); 109 | } 110 | 111 | void digitalWriteLow(uint8_t pin){ 112 | uint8_t ucPort,ucPin; 113 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 114 | ucPort = pin >>4; 115 | ucPin = pin & 0x07; 116 | portWrite(ucPort,portRead(ucPort) & (~pinToMask[ucPin])); 117 | } 118 | 119 | void digitalToggle(uint8_t pin){ 120 | uint8_t ucPort,ucPin,mask; 121 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 122 | ucPort = pin >>4; 123 | ucPin = pin & 0x07; 124 | mask = pinToMask[ucPin]; 125 | mask ^= portRead(ucPort); 126 | portWrite(ucPort,mask); 127 | } 128 | 129 | void digitalWrite(uint8_t pin, bool val) 130 | { 131 | if(val) { 132 | digitalWriteHigh(pin); 133 | }else{ 134 | digitalWriteLow(pin); 135 | } 136 | } 137 | 138 | bool digitalRead(uint8_t pin) 139 | { 140 | uint8_t readp =0; 141 | uint8_t ucPort,ucPin; 142 | if(NOT_A_PORTPIN(pin)) return 0; /*0b10001000(0x88) is not a pin*/ 143 | ucPort = pin >>4; 144 | ucPin = pin & 0x07; 145 | 146 | readp = portRead(ucPort); 147 | return (readp & pinToMask[ucPin]); 148 | } 149 | -------------------------------------------------------------------------------- /cores/STC15/wiring_digital.h: -------------------------------------------------------------------------------- 1 | /* 2 | Modified 2 February 2018 for mcs51 by huaweiwx 3 | */ 4 | 5 | #ifndef __WIRING_DIGITAL_H__ 6 | #define __WIRING_DIGITAL_H__ 7 | 8 | uint8_t portRead(uint8_t ucPort); 9 | void digitalWriteHigh(uint8_t pin); 10 | void digitalWriteLow(uint8_t pin); 11 | void portWrite(uint8_t ucPort,uint8_t val); 12 | void digitalWrite(uint8_t pin, bool val); 13 | void digitalToggle(uint8_t pin); 14 | bool digitalRead(uint8_t pin); 15 | 16 | #endif //__WIRING_DIGITAL_H__ -------------------------------------------------------------------------------- /cores/STC15/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | #define WIRING_SHIFT_MAIN 23 | 24 | #include "Arduino.h" 25 | 26 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 27 | uint8_t value = 0; 28 | uint8_t i; 29 | 30 | for (i = 0; i < 8; ++i) { 31 | digitalWriteHigh(clockPin); 32 | if (bitOrder == LSBFIRST) 33 | value |= digitalRead(dataPin) << i; 34 | else 35 | value |= digitalRead(dataPin) << (7 - i); 36 | digitalWriteLow(clockPin); 37 | } 38 | return value; 39 | } 40 | 41 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 42 | { 43 | uint8_t i; 44 | 45 | for (i = 0; i < 8; i++) { 46 | if (bitOrder == LSBFIRST) 47 | digitalWrite(dataPin, !!(val & (1 << i))); 48 | else 49 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 50 | 51 | digitalWriteHigh(clockPin); 52 | digitalWriteLow(clockPin); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cores/STC8/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 | Modified 2 February 2018 for MSC51 by huaweiwx 20 | */ 21 | 22 | #ifndef Arduino_h 23 | #define Arduino_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "utils/compatible.h" 30 | #include "xmacro.h" 31 | #include "mcu.h" 32 | #include "pins_arduino.h" 33 | #include "bsp/bsp.h" 34 | 35 | // FIXME: workarounds for missing features or unimplemented functions 36 | // cancel out the PROGMEM attribute - used only for atmel CPUs 37 | #define PROGMEM 38 | void yield(void); 39 | 40 | // we use pre-defined IRQ function the way wiring does 41 | #define WIRING 42 | 43 | #define HIGH 0x1 44 | #define LOW 0x0 45 | 46 | /*特定 mnu.h 定义 gpio 模式*/ 47 | /*default*/ 48 | #ifndef QUASI /*准双向口,注意:读外部状态时,先要锁存为1,延时2个nop后再读取外部端口状态*/ 49 | #define QUASI 0x0 50 | #endif 51 | #ifndef OUTPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 52 | #define OUTPUT 0x1 53 | #endif 54 | #ifndef OUTPUT_PP /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 55 | #define OUTPUT_PP 0x1 56 | #endif 57 | #ifndef INPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 58 | #define INPUT 0x2 /*仅为输入*/ 59 | #endif 60 | #ifndef OUTPUT_OD /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 61 | #define OUTPUT_OD 0x3 /*开漏*/ 62 | #endif 63 | 64 | // undefine mathlib's pi if encountered 65 | #ifdef PI 66 | #undef PI 67 | #endif 68 | #ifdef HALF_PI 69 | #undef HALF_PI 70 | #endif 71 | #ifdef TWO_PI 72 | #undef TWO_PI 73 | #endif 74 | 75 | #define PI 3.1415926535897932384626433832795 76 | #define HALF_PI 1.5707963267948966192313216916398 77 | #define TWO_PI 6.283185307179586476925286766559 78 | #define DEG_TO_RAD 0.017453292519943295769236907684886 79 | #define RAD_TO_DEG 57.295779513082320876798154814105 80 | #define EULER 2.718281828459045235360287471352 81 | 82 | #define SERIAL 0x0 83 | #define DISPLAY 0x1 84 | 85 | #define LSBFIRST 0 86 | #define MSBFIRST 1 87 | 88 | #define CHANGE 1 89 | #define FALLING 2 90 | #define RISING 3 91 | 92 | // undefine stdlib's abs if encountered 93 | #ifdef abs 94 | #undef abs 95 | #endif 96 | 97 | #define min(a,b) ((a)<(b)?(a):(b)) 98 | #define max(a,b) ((a)>(b)?(a):(b)) 99 | #define abs(x) ((x)>0?(x):-(x)) 100 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 101 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 102 | #define radians(deg) ((deg)*DEG_TO_RAD) 103 | #define degrees(rad) ((rad)*RAD_TO_DEG) 104 | #define sq(x) ((x)*(x)) 105 | 106 | #define interrupts() sei() 107 | #define noInterrupts() cli() 108 | 109 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 110 | #define clockCyclesPerMillisecond() ( F_CPU / 1000L ) 111 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 112 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 113 | 114 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 115 | #define highByte(w) ((uint8_t) ((w) >> 8)) 116 | 117 | #define bitRead(value, b) (((value) >> (b)) & 0x01) 118 | #define bitSet(value, b) ((value) |= (1UL << (b))) 119 | #define bitClear(value, b) ((value) &= ~(1UL << (b))) 120 | #define bitWrite(value, b, bitvalue) ((bitvalue) ? bitSet(value, b) : bitClear(value, b)) 121 | 122 | #ifndef _BV 123 | #define _BV(x) (1<<(x)) 124 | #endif 125 | #ifndef cbi /*compatible with wiring*/ 126 | #define cbi(a, b) bitClear(a,b) 127 | #endif 128 | #ifndef sbi /*compatible with wiring*/ 129 | #define sbi(a, b) bitSet(a, b) 130 | #endif 131 | 132 | #define maskSet(value, mask) ((value) |= (mask)) 133 | #define maskClear(value, mask) ((value) &= ~(mask)) 134 | 135 | 136 | // avr-libc defines _NOP() since 1.6.2 137 | #ifndef _NOP 138 | #define _NOP() NOP() 139 | #endif 140 | 141 | #ifndef F 142 | #define F(x) 143 | #endif 144 | 145 | /* for SDCC this is supposed to be "__critical{" and "}", but up to 146 | * sdcc version 3.6.4 it is wrongly implemented. */ 147 | /* so geht es nicht: 148 | #define BEGIN_CRITICAL __asm__("push\tcc");__asm__("sim"); 149 | #define END_CRITICAL __asm__("pop\tcc"); 150 | */ 151 | #define BEGIN_CRITICAL __critical { 152 | #define END_CRITICAL } 153 | /* klappt: 154 | #define BEGIN_CRITICAL 155 | #define END_CRITICAL 156 | */ 157 | 158 | 159 | 160 | 161 | // #define bit(b) (1UL << (b)) sdcc bit is __bit keywords 162 | 163 | //typedef bool boolean; 164 | typedef unsigned int word; 165 | typedef unsigned char byte; 166 | 167 | void init(void); 168 | void initVariant(void); // weak 169 | 170 | int atexit(void (*func)()); // __attribute__((weak)); 171 | 172 | #ifndef pinMode /* 部分mcu 使用宏定义代替 */ 173 | void pinMode(uint8_t pin, uint8_t mode); 174 | #endif 175 | 176 | #include "wiring_digital.h" 177 | 178 | #ifndef analogRead 179 | int analogRead(uint8_t pin); 180 | #endif 181 | #ifndef analogReference 182 | void analogReference(uint8_t mode); 183 | #endif 184 | #ifndef analogWrite 185 | void analogWrite(uint8_t pin, uint8_t val); 186 | #endif 187 | 188 | #include "wiring.h" 189 | 190 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 191 | unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); 192 | 193 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 194 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 195 | 196 | void attachInterrupt(uint8_t, void (*)(void), int mode); 197 | void detachInterrupt(uint8_t); 198 | 199 | void setup(void); 200 | void loop(void); 201 | 202 | // Get the bit location within the hardware port of the given virtual pin. 203 | // This comes from the pins_*.c file for the active board configuration. 204 | 205 | #define analogInPinToBit(P) (P) 206 | 207 | //extern const uint8_t digital_pin_to_port[]; 208 | //extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 209 | //extern const uint8_t digital_pin_to_bit_mask[]; 210 | //extern const uint8_t digital_pin_to_timer[]; 211 | 212 | // Get the bit location within the hardware port of the given virtual pin. 213 | // This comes from the pins_*.c file for the active board configuration. 214 | // 215 | #define digitalPinToPort(pin) (pin >> 4) 216 | #define digitalPinToBitMask(pin) (1 << (pin & 0x0f)) 217 | //#define digitalPinToTimer(P) ( digital_pin_to_timer[(P)] ) 218 | //#define analogInPinToBit(P) (P) 219 | //#define portOutputRegister(P) ( (volatile uint8_t *)( port_to_output[(P)]) ) 220 | //#define portInputRegister(P) ( (volatile uint8_t *)( port_to_input[(P)]) ) 221 | //#define portModeRegister(P) ( (volatile uint8_t *)( port_to_mode[(P)]) ) 222 | 223 | #define NOT_A_PIN 0xff 224 | #define NOT_A_PORT 0xff 225 | 226 | #define NOT_AN_INTERRUPT -1 227 | 228 | #ifdef ARDUINO_MAIN 229 | //#define PA 1 230 | //#define PB 2 231 | //#define PC 3 232 | //#define PD 4 233 | //#define PE 5 234 | //#define PF 6 235 | //#define PG 7 236 | //#define PH 8 237 | //#define PJ 10 238 | //#define PK 11 239 | //#define PL 12 240 | #endif 241 | 242 | //FIXME#include "WCharacter.h" 243 | //FIXME#include "WString.h" 244 | #include "HardwareSerial.h" 245 | 246 | //uint16_t makeWord(uint16_t w); 247 | //uint16_t makeWord(byte h, byte l); 248 | 249 | //#define word(...) makeWord(__VA_ARGS__) 250 | 251 | 252 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration); 253 | void noTone(uint8_t _pin); 254 | 255 | // WMath prototypes 256 | long random(long howbig); 257 | long random_minmax(long howsmall, long howbig); 258 | void randomSeed(unsigned long seed); 259 | long map(long x, long in_min, long in_max, long out_min, long out_max); 260 | 261 | inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 262 | 263 | #endif //Arduino_h 264 | -------------------------------------------------------------------------------- /cores/STC8/HardwareSerial.c: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.c - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | 27 | Modified 2 February 2018 for mcs51 by huaweiwx 28 | */ 29 | 30 | #include "Arduino.h" 31 | 32 | // private data ////////////////////////////////////////////////////////////// 33 | 34 | #ifndef SERIAL_BUFFER_SIZE 35 | # define SERIAL_BUFFER_SIZE 64 36 | #endif 37 | 38 | #if SERIAL_BUFFER_SIZE > 255 39 | typedef struct { 40 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 41 | uint16_t size; 42 | volatile uint16_t head; 43 | volatile uint16_t tail; 44 | } RINGBUF_TypeDef; 45 | #else 46 | typedef struct { 47 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 48 | uint8_t size; 49 | volatile uint8_t head; 50 | volatile uint8_t tail; 51 | } RINGBUF_TypeDef; 52 | #endif 53 | 54 | static XDATA(RINGBUF_TypeDef,rxBuf);// = { { 0 }, 0, 0}; 55 | static bool initialized; //=0 internal status. Returned on HardwareSerial() 56 | 57 | // private functions //////////////////////////////////////////////////////// 58 | static void storeChar(uint8_t c, RINGBUF_TypeDef *buf) 59 | { 60 | noInterrupts(); 61 | int i = (unsigned int)(buf->head + 1) % buf->size; 62 | 63 | // if we should be storing the received character into the location 64 | // just before the tail (meaning that the head would advance to the 65 | // current location of the tail), we're about to overflow the buffer 66 | // and so we don't write the character or advance the head. 67 | if (i != buf->tail) { 68 | buf->buffer[buf->head] = c; 69 | buf->head = i; 70 | } 71 | interrupts(); 72 | } 73 | 74 | // Interrupt handler /////////////////////////////////////////////////////////// 75 | /** 76 | FUNCTION_PURPOSE: serial interrupt, echo received data. 77 | FUNCTION_INPUTS: P0.7(RXD) serial input 78 | FUNCTION_OUTPUTS: P0.6(TXD) serial output 79 | */ 80 | 81 | #if (MENU_SERIAL == 1) 82 | #define InitialUARTx(x) \ 83 | uart_init0(x);\ 84 | REN = 1; \ 85 | SM2 = 0;\ 86 | attachInterrupt(4,UART0_IRQHandler,0); \ 87 | ES = 1;\ 88 | EA = 1 89 | 90 | #define RXREG SBUF 91 | void UART0_IRQHandler(void) // void Serial_ISR(void) __interrupt 4 92 | { 93 | uint8_t c; 94 | if (RI) 95 | { /* if reception occur */ 96 | RI = 0; /* clear reception flag for next reception */ 97 | c = RXREG; 98 | storeChar(c, &rxBuf); 99 | } 100 | if (TI) 101 | { 102 | TI = 0; /* if emission occur */ 103 | } 104 | } 105 | 106 | size_t HardwareSerial_write(uint8_t c) 107 | { 108 | noInterrupts(); 109 | TI = 0; 110 | RXREG = c; 111 | while (!TI); 112 | interrupts(); 113 | return 1; 114 | } 115 | 116 | #elif (MENU_SERIAL == 2) 117 | #define InitialUARTx(x) \ 118 | uart_init2(x);\ 119 | S2CON |= ( S2REN);\ 120 | S2CON &= (~S2SM2);\ 121 | attachInterrupt(UART2_INTNO,UART2_IRQHandler,0); \ 122 | IE2 |= ( ES2);\ 123 | EA = 1 124 | 125 | #define RXREG S2BUF 126 | void UART2_IRQHandler(void)) // void Serial1_ISR(void) __interrupt UART2_INTNO 127 | { 128 | uint8_t c; 129 | if ( (S2CON & S2RI) == S2RI ) 130 | { /* if reception occur */ 131 | S2CON &= (~S2RI); /* clear reception flag for next reception */ 132 | c = RXREG; 133 | storeChar(c, &rxBuf); 134 | } 135 | if ((S2CON & S2TI) == S2TI) 136 | { 137 | S2CON &= (~S2TI); /* if emission occur */ 138 | } 139 | } 140 | 141 | size_t HardwareSerial_write(uint8_t c) 142 | { 143 | noInterrupts(); 144 | S2CON &= (~S2TI); /* if emission occur */ 145 | RXREG = c; 146 | while (!(S2CON & S2TI) ); 147 | interrupts(); 148 | return 1; 149 | } 150 | 151 | #else 152 | #error "This case undefined! Please add" 153 | #endif 154 | 155 | 156 | // Public Methods ////////////////////////////////////////////////////////////// 157 | 158 | uint8_t HardwareSerial(void) 159 | { 160 | return initialized; 161 | } 162 | 163 | void HardwareSerial_begin(unsigned long baud) 164 | { 165 | rxBuf.head = rxBuf.tail = 0; 166 | rxBuf.size = sizeof(rxBuf.buffer); 167 | initialized = 1; 168 | putcharFunc = HardwareSerial_write; 169 | InitialUARTx(baud); 170 | } 171 | 172 | void HardwareSerial_end(void) 173 | { 174 | // wait for transmission of outgoing data 175 | rxBuf.head = rxBuf.tail = 0; 176 | initialized = 0; 177 | } 178 | 179 | int HardwareSerial_available(void) 180 | { 181 | unsigned int rtn; 182 | noInterrupts(); 183 | rtn = (rxBuf.size + rxBuf.head - rxBuf.tail) % rxBuf.size; 184 | interrupts(); 185 | return rtn; 186 | } 187 | 188 | int HardwareSerial_peek(void) 189 | { 190 | int rtn; 191 | noInterrupts(); 192 | if (rxBuf.head == rxBuf.tail) { 193 | rtn = -1; 194 | } else { 195 | rtn = rxBuf.buffer[rxBuf.tail]; 196 | } 197 | interrupts(); 198 | return rtn; 199 | } 200 | 201 | int HardwareSerial_read(void) 202 | { 203 | int rtn; 204 | noInterrupts(); 205 | if (rxBuf.head == rxBuf.tail) { 206 | rtn = -1; 207 | } else { 208 | rtn = rxBuf.buffer[rxBuf.tail]; 209 | rxBuf.tail = (unsigned int)(rxBuf.tail + 1) % rxBuf.size; 210 | } 211 | interrupts(); 212 | return rtn; 213 | } 214 | 215 | void HardwareSerial_flush(void) 216 | { 217 | } 218 | 219 | writefunc_p putcharFunc = HardwareSerial_write; /*缺省使用库 HardwareSerial_write*/ 220 | int putchar(int c) 221 | { 222 | putcharFunc((unsigned char)c); /* output character */ 223 | return (c); 224 | } 225 | 226 | //#define PRINTF_TINY 5 227 | //#define PRINTF_SMALL 4 228 | //#define PRINTF_FAST 3 229 | //#define PRINTF_FAST_F 2 230 | //#define PRINTF 1 231 | 232 | #if (USE_PRINTF > 0) /*use printf */ 233 | __code HWSERIAL_TypeDef Serial = { 234 | HardwareSerial_available, 235 | HardwareSerial_begin, 236 | HardwareSerial_write, 237 | HardwareSerial_read, 238 | #if (USE_PRINTF > 4) /*5*/ 239 | printf_tiny, 240 | #elif (USE_PRINTF > 3) 241 | printf_small, 242 | #elif (USE_PRINTF > 2) 243 | printf_fast, 244 | #elif (USE_PRINTF > 1) 245 | printf_fast_f, 246 | #else 247 | printf, 248 | #endif 249 | }; 250 | #endif 251 | -------------------------------------------------------------------------------- /cores/STC8/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | Modified 2 February 2018 for mcs51 by huaweiwx 27 | */ 28 | 29 | #ifndef _HARDWARE_SERIAL_H_ 30 | #define _HARDWARE_SERIAL_H_ 31 | 32 | #include 33 | #include 34 | 35 | // Define config for Serial.begin(baud, config); 36 | /* coding of the bit field: 00sw .pp. 37 | * wordlength w: 0:8 1:9 (5,6,7 not supported) 38 | * parity pp: 0:n 2:e 3:o 39 | * stopbits s: 0:1 1:2 40 | * => 8x1=0x0x, 9x1=0x1x, 8x2=0x2x, 9x2=0x3x 41 | * => n=0xx0, e=0xx4, o=0xx6 42 | */ 43 | #define SERIAL_8N1 0x00 44 | #define SERIAL_9N1 0x10 45 | #define SERIAL_8N2 0x20 46 | #define SERIAL_9N2 0x30 47 | #define SERIAL_8E1 0x04 48 | #define SERIAL_9E1 0x14 49 | #define SERIAL_8E2 0x24 50 | #define SERIAL_9E2 0x34 51 | #define SERIAL_8O1 0x06 52 | #define SERIAL_9O1 0x16 53 | #define SERIAL_8O2 0x26 54 | #define SERIAL_9O2 0x36 55 | 56 | #define MASK_PARITY 0x06 57 | #define MASK_STOPBITS 0x20 58 | #define MASK_DATABITS 0x10 59 | 60 | 61 | // Public Methods ////////////////////////////////////////////////////////////// 62 | 63 | uint8_t HardwareSerial(void); 64 | void HardwareSerial_begin(unsigned long baud); 65 | void HardwareSerial_end(void); 66 | 67 | int HardwareSerial_available(void); 68 | int HardwareSerial_read(void); 69 | size_t HardwareSerial_write(uint8_t c); 70 | void HardwareSerial_flush(void); 71 | extern writefunc_p putcharFunc; 72 | 73 | #if (USE_PRINTF > 0) /*use printf */ 74 | typedef struct { 75 | i_v_funcType available; 76 | v_l_funcType begin; 77 | s_c_funcType write; 78 | i_v_funcType read; 79 | #if (USE_PRINTF > 4) /*5 printf_tiny*/ 80 | v_c_printfType printf; 81 | #elif (USE_PRINTF > 3) /*4 printf_small*/ 82 | v_printfType printf; 83 | #elif (USE_PRINTF > 2) /*3 printf_fast*/ 84 | v_c_printfType printf; 85 | #elif (USE_PRINTF > 1) /*2 printf_fast_f*/ 86 | v_c_printfType printf; 87 | #else 88 | i_printfType printf; /*1 printf*/ 89 | #endif 90 | } HWSERIAL_TypeDef; 91 | extern __code HWSERIAL_TypeDef Serial; 92 | #endif 93 | 94 | // Alias Definitions for a more Arduino-like look //////////////////////////// 95 | 96 | //#define Serial HardwareSerial() 97 | #define Serial_begin HardwareSerial_begin 98 | #define Serial_available HardwareSerial_available 99 | #define Serial_read HardwareSerial_read 100 | #define Serial_write HardwareSerial_write 101 | #define Serial_flush HardwareSerial_flush 102 | #define Serial_end HardwareSerial_end 103 | 104 | 105 | // variants of the standard Serial.print() function: Separate implementations 106 | // for string, char, unsigned, signed int 107 | #define Serial_print_s(S) Print_print_s(HardwareSerial_write,S) 108 | #define Serial_print_sn(S) Print_print_sn(HardwareSerial_write,S,N) 109 | #define Serial_print_c(C) HardwareSerial_write(C) 110 | 111 | // print signed/unsigned integer values (char, short, int, long) as decimal values 112 | #define Serial_print_i(I) Print_print_i(HardwareSerial_write,I) 113 | #define Serial_print_u(U) Print_print_u(HardwareSerial_write,U) 114 | 115 | // print signed/unsigned integer values (char, short, int, long) to base B 116 | #define Serial_print_ib(I,B) Print_print_ib(HardwareSerial_write,I,B) 117 | #define Serial_print_ub(U,B) Print_print_ub(HardwareSerial_write,U,B) 118 | 119 | // print float value 120 | #define Serial_print_f(F) Print_print_fd(HardwareSerial_write,F,2) 121 | #define Serial_print_fd(F,D) Print_print_fd(HardwareSerial_write,F,D) 122 | 123 | #define Serial_println() Print_println(HardwareSerial_write) 124 | #define Serial_println_s(S) Print_println_s(HardwareSerial_write,S) 125 | #define Serial_println_sn(S,N) Print_println_sn(HardwareSerial_write,S,N) 126 | #define Serial_println_u(U) Print_println_u(HardwareSerial_write,U) 127 | #define Serial_println_i(I) Print_println_i(HardwareSerial_write,I) 128 | #define Serial_println_ib(I,B) Print_println_ib(HardwareSerial_write,I,B) 129 | #define Serial_println_ub(U,B) Print_println_ub(HardwareSerial_write,U,B) 130 | #define Serial_println_f(F) Print_println_fd(HardwareSerial_write,F,2) 131 | #define Serial_println_fd(F,D) Print_println_fd(HardwareSerial_write,F,D) 132 | 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /cores/STC8/Print.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | void printNL(void); 46 | 47 | // Public Methods ////////////////////////////////////////////////////////////// 48 | 49 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 50 | { 51 | size_t n = 0; 52 | while (size--) { 53 | if (writefunc(*buffer++)) n++; 54 | else break; 55 | } 56 | return n; 57 | } 58 | 59 | size_t Print_print_s(writefunc_p writefunc, const char *str) 60 | { 61 | size_t n = 0; 62 | char c; 63 | 64 | if (!str) return 0; 65 | 66 | while ( c=*str++ ) { // assignment intented 67 | if (writefunc(c)) n++; 68 | else break; 69 | } 70 | return n; 71 | } 72 | 73 | 74 | size_t Print_print_u(writefunc_p writefunc, unsigned long n) 75 | { 76 | return printNumber(writefunc, n,10); 77 | } 78 | 79 | size_t Print_print_i(writefunc_p writefunc, long n) 80 | { 81 | return printInt(writefunc, n,10); 82 | } 83 | 84 | // Variants of the above functions with an added newline ////////////////////// 85 | 86 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 87 | { 88 | size_t r; 89 | 90 | r = Print_print_sn(writefunc, buffer, size); 91 | return r + Print_println(writefunc); 92 | } 93 | 94 | size_t Print_println_s(writefunc_p writefunc, const char *str) 95 | { 96 | size_t r; 97 | 98 | r = Print_print_s(writefunc, str); 99 | return r + Print_println(writefunc); 100 | } 101 | 102 | size_t Print_println_u(writefunc_p writefunc, unsigned long n) 103 | { 104 | size_t r; 105 | 106 | r = printNumber(writefunc, n,10); 107 | return r + Print_println(writefunc); 108 | } 109 | 110 | size_t Print_println_i(writefunc_p writefunc, long n) 111 | { 112 | size_t r; 113 | 114 | r = printInt(writefunc, n,10); 115 | return r + Print_println(writefunc); 116 | } 117 | 118 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 119 | { 120 | size_t r; 121 | 122 | r = printNumber(writefunc, n,base); 123 | return r + Print_println(writefunc); 124 | } 125 | 126 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base) 127 | { 128 | size_t r; 129 | 130 | r = printInt(writefunc, n,base); 131 | return r + Print_println(writefunc); 132 | } 133 | 134 | 135 | 136 | // (not so) Private Methods ///////////////////////////////////////////////////////////// 137 | 138 | size_t Print_println(writefunc_p writefunc) 139 | { 140 | size_t n; 141 | 142 | n = writefunc(13); 143 | n += writefunc(10); 144 | return n; 145 | } 146 | 147 | 148 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 149 | { 150 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 151 | char *str = &buf[sizeof(buf) - 1]; 152 | 153 | *str = '\0'; 154 | 155 | // prevent crash if called with base == 1 156 | if (base < 2) base = 10; 157 | 158 | do { 159 | char c = n % base; 160 | n /= base; 161 | 162 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 163 | } while(n); 164 | 165 | return Print_print_s(writefunc, str); 166 | } 167 | 168 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base) 169 | { 170 | if (base == 0) { 171 | return writefunc((unsigned char) n); 172 | } else if (base == 10) { 173 | if (n < 0) { 174 | int t = writefunc('-'); 175 | n = -n; 176 | return printNumber(writefunc, n, 10) + t; 177 | } 178 | return printNumber(writefunc, n, 10); 179 | } else { 180 | return printNumber(writefunc, n, base); 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /cores/STC8/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. 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 Print_h 21 | #define Print_h 22 | 23 | #include // for size_t 24 | #include 25 | 26 | //#include "WString.h" 27 | //#include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | 35 | // for the function pointer to the actual write function 36 | typedef size_t (*writefunc_p)(uint8_t c); 37 | 38 | // abreviations of the actual function names, mostly for internal use 39 | #define printBuf Print_print_sn 40 | #define printStr Print_print_s 41 | #define printNumber Print_print_ub 42 | #define printInt Print_print_ib 43 | #define println Print_println 44 | 45 | 46 | // the more sophisticated Arduino-Style functions. Variants of the standard 47 | // Serial.print() function: Separate impementations for different datatype 48 | // to mimic polymorphism. 49 | 50 | // print strings (C-Style or buffer contents) 51 | size_t Print_print_s(writefunc_p writefunc, const char *str); 52 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 53 | 54 | // print signed/unsigned values (char, short, int, long) as decimal values 55 | size_t Print_print_i(writefunc_p writefunc, long n); 56 | size_t Print_print_u(writefunc_p writefunc, unsigned long n); 57 | 58 | // print signed/unsigned integer values (char, short, int, long) to base B 59 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base); 60 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 61 | 62 | // print float values with two digits precision/specified number of digits 63 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits); 64 | //#define Print_print_f(W,N) Print_print_fd(W,N,2) 65 | inline size_t Print_print_f(writefunc_p writefunc, double number) { 66 | return Print_print_fd(writefunc, number, 2); 67 | } 68 | 69 | // Variants of the above with a newline added at the and: 70 | size_t Print_println(writefunc_p writefunc); 71 | size_t Print_println_s(writefunc_p writefunc, const char *str); 72 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 73 | size_t Print_println_i(writefunc_p writefunc, long n); 74 | size_t Print_println_u(writefunc_p writefunc, unsigned long n); 75 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base); 76 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 77 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits); 78 | //#define Print_println_f(W,N) Print_println_fd(W,N,2) 79 | inline size_t Print_println_f(writefunc_p writefunc, double number) { 80 | return Print_println_fd(writefunc, number, 2); 81 | } 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cores/STC8/Print_float.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | // Public Methods ////////////////////////////////////////////////////////////// 46 | 47 | 48 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits) 49 | { 50 | size_t n = 0; 51 | uint8_t i; 52 | unsigned long int_part; 53 | double remainder, rounding; 54 | unsigned int toPrint; 55 | 56 | if (isnan(number)) return printStr(writefunc,"nan"); 57 | if (isinf(number)) return printStr(writefunc,"inf"); 58 | if (number > 4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 59 | if (number <-4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 60 | 61 | // Handle negative numbers 62 | if (number < 0.0) 63 | { 64 | n += writefunc('-'); 65 | number = -number; 66 | } 67 | 68 | // Round correctly so that print(1.999, 2) prints as "2.00" 69 | rounding = 0.5; 70 | for (i=0; i 0) { 82 | n += writefunc('.'); 83 | } 84 | 85 | // Extract digits from the remainder one at a time 86 | while (digits-- > 0) 87 | { 88 | remainder *= 10.0; 89 | toPrint = (unsigned int)(remainder); 90 | n += printNumber(writefunc,toPrint,10); 91 | remainder -= toPrint; 92 | } 93 | 94 | return n; 95 | } 96 | 97 | 98 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits) 99 | { 100 | size_t r; 101 | 102 | r = Print_print_fd(writefunc, number, digits); 103 | return r + Print_println(writefunc); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /cores/STC8/WMath.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #include "stdlib.h" 27 | } 28 | #else 29 | #include "stdlib.h" 30 | #endif 31 | 32 | void randomSeed(unsigned long seed) 33 | { 34 | if (seed != 0) { 35 | srand(seed); 36 | } 37 | } 38 | 39 | long random(long howbig) 40 | { 41 | if (howbig == 0) { 42 | return 0; 43 | } 44 | return rand() % howbig; 45 | } 46 | 47 | long random_minmax(long howsmall, long howbig) 48 | { 49 | long diff; 50 | 51 | if (howsmall >= howbig) { 52 | return howsmall; 53 | } 54 | diff = howbig - howsmall; 55 | return random(diff) + howsmall; 56 | } 57 | 58 | long map(long x, long in_min, long in_max, long out_min, long out_max) 59 | { 60 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 61 | } 62 | 63 | //unsigned int makeWord(unsigned int w) { return w; } 64 | //unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 65 | -------------------------------------------------------------------------------- /cores/STC8/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - Main loop for Arduino sketches 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 | Modified 2 February 2018 for mcs51 by huaweiwx 19 | */ 20 | 21 | #define ARDUINO_MAIN 22 | 23 | #include 24 | #include "bsp/isr.h" 25 | 26 | // make sure to define prototypes for all used interrupts 27 | void init(void); 28 | void initVariant(void); // weak 29 | 30 | int main(void) 31 | { 32 | init(); 33 | 34 | initVariant(); 35 | 36 | setup(); 37 | 38 | for (;;) { 39 | loop(); 40 | } 41 | } 42 | 43 | 44 | void _sdcc_external_startup(void) 45 | { 46 | //PCA0MD &= ~0x40; /*关闭内部看门狗*/ 47 | } -------------------------------------------------------------------------------- /cores/STC8/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the mcs51. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | DELAY_10US)(i) and DELAY_MS(i,j) created by stc-isp-15xx-v6.86s.exe 23 | Modified 2 February 2018 for mcs51 by huaweiwx 24 | */ 25 | 26 | #define WIRING_MAIN 27 | #include "Arduino.h" 28 | 29 | #define T1MS (65536L-F_CPU/1000) //1ms timer calculation method in 1T mode 30 | //#define T1MS (65536L-F_CPU/12/1000) //1ms timer calculation method in 12T mode 31 | 32 | #define TH0_INIT (T1MS >> 8) 33 | #define TL0_INIT (T1MS & 0xff) 34 | 35 | extern void SystemClock_Config(void); 36 | 37 | 38 | 39 | /**************** 简单延时 **************************/ 40 | void delay_loop(unsigned char cnt) 41 | { 42 | while (--cnt); 43 | } 44 | 45 | 46 | #if USE_SYSTICK 47 | 48 | static volatile uint32_t dwTickCount = 0; 49 | 50 | /*************** Timer0 中断函数 *********************/ 51 | void Timer0_IRQHandler (void) //1毫秒 52 | { 53 | TH0 = TH0_INIT; TL0 = TL0_INIT; //重载定时初值 54 | TF0 = 0; //清除TF0标志 55 | dwTickCount++; //systic 计数 56 | } 57 | 58 | void init(void){ 59 | SystemClock_Config(); 60 | dwTickCount = 0; 61 | attachInterrupt(TIMER0_IRQn, Timer0_IRQHandler, 0); 62 | AUXR = 0x80; //timer0 work in 1T mode 63 | TMOD = 0x01; //set timer0 as mode1 (16-bit) 64 | TL0 = TL0_INIT; //initial timer0 low byte 65 | TH0 = TH0_INIT; //initial timer0 high byte 66 | TR0 = 1; //timer0 start running 67 | ET0 = 1; //enable timer0 interrupt 68 | EA = 1; //open global interrupt switch 69 | } 70 | 71 | unsigned long millis() 72 | { 73 | return dwTickCount; 74 | } 75 | 76 | unsigned long micros() 77 | { 78 | uint32_t m,u; 79 | uint8_t hi,lo; 80 | 81 | lo = TL0; hi = TH0; 82 | u = dwTickCount*1000; 83 | 84 | m = ((((hi<<8)| lo)- T1MS)*1000); 85 | u += m/T1MS; 86 | 87 | return u; 88 | } 89 | 90 | void delay(unsigned int ms){ 91 | uint32_t s = dwTickCount; 92 | uint32_t e = s + ms; 93 | if(e < s){ 94 | while(e < millis()); 95 | } 96 | while(millis()< e); 97 | } 98 | 99 | void delayMicroseconds(unsigned int us) 100 | { 101 | uint32_t s = micros(); 102 | uint32_t e = s + us; 103 | if(e < s){ 104 | while(e < micros()); 105 | } 106 | while(micros()< e); 107 | } 108 | 109 | #else 110 | 111 | void init(void){ 112 | SystemClock_Config(); 113 | } 114 | 115 | void delay10us(unsigned int us) 116 | { 117 | unsigned char i; 118 | do{ 119 | DELAY_10US(i); 120 | while (--i); 121 | }while(--us); 122 | } 123 | 124 | void delay(unsigned int ms) 125 | { 126 | unsigned char i, j; 127 | 128 | do { 129 | DELAY_MS(i,j); 130 | do { 131 | while (--j); 132 | } while (--i); 133 | }while (--ms); 134 | } 135 | #endif 136 | -------------------------------------------------------------------------------- /cores/STC8/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h 3 | Modified 2 February 2018 for mcs51 by huaweiwx 4 | */ 5 | #ifndef _WIRING_H_ 6 | #define _WIRING_H_ 7 | 8 | #ifndef USE_SYSTICK 9 | #define USE_SYSTICK 1 10 | #endif 11 | 12 | #if CORE_STCYn > 1 13 | #define T1MS (65536L-F_CPU/1000) //1ms timer calculation method in 1T mode 14 | #elif CORE_STCYn == 1 15 | #define T1MS (65536L-F_CPU/12/1000) //1ms timer calculation method in 12T mode 16 | #else 17 | #error NOT STC core or CORE_STCYn undef! 18 | #endif 19 | 20 | #define TH0_INIT (T1MS >> 8) 21 | #define TL0_INIT (T1MS & 0xff) 22 | 23 | void delay_loop(unsigned char cnt); 24 | 25 | 26 | #if USE_SYSTICK 27 | 28 | unsigned long millis(); 29 | unsigned long micros(); 30 | void delay(unsigned int ms); 31 | void delayMicroseconds(unsigned int us); 32 | 33 | #else 34 | 35 | void delay10us(unsigned int us); 36 | void delay(unsigned int ms); 37 | 38 | #define delayMicroseconds(us) if(us>10){delay10us(us/10);}else{delay_loop(us);} 39 | 40 | #endif //USE_SYSTICK 41 | 42 | #endif //_WIRING_H_ 43 | -------------------------------------------------------------------------------- /cores/STC8/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 2 February 2018 for mcs51 by huaweiwx 23 | */ 24 | #include "Arduino.h" 25 | 26 | /* This char array helps to convert pin map to port*/ 27 | const uint8_t pinToMask[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 28 | 29 | uint8_t portRead(uint8_t ucPort){ 30 | uint8_t rtn = 0; 31 | switch (ucPort){ 32 | #ifdef SFR_P0 33 | case 0: 34 | rtn = P0; 35 | break; 36 | #endif 37 | #ifdef SFR_P1 38 | case 1: 39 | rtn = P1; 40 | break; 41 | #endif 42 | #ifdef SFR_P2 43 | case 2: 44 | rtn = P2; 45 | break; 46 | #endif 47 | #ifdef SFR_P3 48 | case 3: 49 | rtn = P3; 50 | break; 51 | #endif 52 | #ifdef SFR_P4 53 | case 4: 54 | rtn = P4; 55 | break; 56 | #endif 57 | #ifdef SFR_P5 58 | case 5: 59 | rtn = P5; 60 | break; 61 | #endif 62 | } 63 | return rtn; 64 | } 65 | 66 | void portWrite(uint8_t ucPort,uint8_t val){ 67 | switch (ucPort){ 68 | #ifdef SFR_P0 69 | case 0: 70 | P0 = val; 71 | break; 72 | #endif 73 | #ifdef SFR_P1 74 | case 1: 75 | P1 = val; 76 | break; 77 | #endif 78 | #ifdef SFR_P2 79 | case 2: 80 | P2 = val; 81 | break; 82 | #endif 83 | #ifdef SFR_P3 84 | case 3: 85 | P3 = val; 86 | break; 87 | #endif 88 | #ifdef SFR_P4 89 | case 4: 90 | P4 = val; 91 | break; 92 | #endif 93 | #ifdef SFR_P5 94 | case 5: 95 | P5 = val; 96 | break; 97 | #endif 98 | } 99 | } 100 | 101 | void digitalWriteHigh(uint8_t pin){ 102 | uint8_t ucPort,ucPin,mask; 103 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 104 | ucPort = pin >>4; 105 | ucPin = pin & 0x07; 106 | mask = pinToMask[ucPin]; 107 | mask |= portRead(ucPort); 108 | portWrite(ucPort,mask); 109 | } 110 | 111 | void digitalWriteLow(uint8_t pin){ 112 | uint8_t ucPort,ucPin; 113 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 114 | ucPort = pin >>4; 115 | ucPin = pin & 0x07; 116 | portWrite(ucPort,portRead(ucPort) & (~pinToMask[ucPin])); 117 | } 118 | 119 | void digitalToggle(uint8_t pin){ 120 | uint8_t ucPort,ucPin,mask; 121 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 122 | ucPort = pin >>4; 123 | ucPin = pin & 0x07; 124 | mask = pinToMask[ucPin]; 125 | mask ^= portRead(ucPort); 126 | portWrite(ucPort,mask); 127 | } 128 | 129 | void digitalWrite(uint8_t pin, bool val) 130 | { 131 | if(val) { 132 | digitalWriteHigh(pin); 133 | }else{ 134 | digitalWriteLow(pin); 135 | } 136 | } 137 | 138 | bool digitalRead(uint8_t pin) 139 | { 140 | uint8_t readp =0; 141 | uint8_t ucPort,ucPin; 142 | if(NOT_A_PORTPIN(pin)) return 0; /*0b10001000(0x88) is not a pin*/ 143 | ucPort = pin >>4; 144 | ucPin = pin & 0x07; 145 | 146 | readp = portRead(ucPort); 147 | return (readp & pinToMask[ucPin]); 148 | } 149 | -------------------------------------------------------------------------------- /cores/STC8/wiring_digital.h: -------------------------------------------------------------------------------- 1 | /* 2 | Modified 2 February 2018 for mcs51 by huaweiwx 3 | */ 4 | 5 | #ifndef __WIRING_DIGITAL_H__ 6 | #define __WIRING_DIGITAL_H__ 7 | 8 | uint8_t portRead(uint8_t ucPort); 9 | void digitalWriteHigh(uint8_t pin); 10 | void digitalWriteLow(uint8_t pin); 11 | void portWrite(uint8_t ucPort,uint8_t val); 12 | void digitalWrite(uint8_t pin, bool val); 13 | void digitalToggle(uint8_t pin); 14 | bool digitalRead(uint8_t pin); 15 | 16 | #endif //__WIRING_DIGITAL_H__ -------------------------------------------------------------------------------- /cores/STC8/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | #define WIRING_SHIFT_MAIN 23 | 24 | #include "Arduino.h" 25 | 26 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 27 | uint8_t value = 0; 28 | uint8_t i; 29 | 30 | for (i = 0; i < 8; ++i) { 31 | digitalWriteHigh(clockPin); 32 | if (bitOrder == LSBFIRST) 33 | value |= digitalRead(dataPin) << i; 34 | else 35 | value |= digitalRead(dataPin) << (7 - i); 36 | digitalWriteLow(clockPin); 37 | } 38 | return value; 39 | } 40 | 41 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 42 | { 43 | uint8_t i; 44 | 45 | for (i = 0; i < 8; i++) { 46 | if (bitOrder == LSBFIRST) 47 | digitalWrite(dataPin, !!(val & (1 << i))); 48 | else 49 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 50 | 51 | digitalWriteHigh(clockPin); 52 | digitalWriteLow(clockPin); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cores/STC89/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 | Modified 2 February 2018 for MSC51 by huaweiwx 20 | Modified 2 February 2018 for stc89c52 by nulllab-jun 21 | */ 22 | 23 | #ifndef Arduino_h 24 | #define Arduino_h 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | //#include "utils/compatible.h" 33 | //#include "xmacro.h" 34 | #include "bsp/STC89C5xRC.h" 35 | #include 36 | #include "pins_arduino.h" 37 | 38 | // FIXME: workarounds for missing features or unimplemented functions 39 | // cancel out the PROGMEM attribute - used only for atmel CPUs 40 | #define PROGMEM 41 | void yield(void); 42 | 43 | // we use pre-defined IRQ function the way wiring does 44 | #define WIRING 45 | 46 | #define HIGH 0x1 47 | #define LOW 0x0 48 | 49 | /*特定 mnu.h 定义 gpio 模式*/ 50 | /*default*/ 51 | #ifndef QUASI /*准双向口,注意:读外部状态时,先要锁存为1,延时2个nop后再读取外部端口状态*/ 52 | #define QUASI 0x0 53 | #endif 54 | #ifndef OUTPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 55 | #define OUTPUT 0x1 56 | #endif 57 | #ifndef OUTPUT_PP /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 58 | #define OUTPUT_PP 0x1 59 | #endif 60 | #ifndef INPUT /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 61 | #define INPUT 0x2 /*仅为输入*/ 62 | #endif 63 | #ifndef OUTPUT_OD /*强推挽输出,每个i/o口都可以提供20mA的驱动能力,要接限流电阻,注意整个芯片不要超过120mA*/ 64 | #define OUTPUT_OD 0x3 /*开漏*/ 65 | #endif 66 | 67 | // undefine mathlib's pi if encountered 68 | #ifdef PI 69 | #undef PI 70 | #endif 71 | #ifdef HALF_PI 72 | #undef HALF_PI 73 | #endif 74 | #ifdef TWO_PI 75 | #undef TWO_PI 76 | #endif 77 | 78 | #define PI 3.1415926535897932384626433832795 79 | #define HALF_PI 1.5707963267948966192313216916398 80 | #define TWO_PI 6.283185307179586476925286766559 81 | #define DEG_TO_RAD 0.017453292519943295769236907684886 82 | #define RAD_TO_DEG 57.295779513082320876798154814105 83 | #define EULER 2.718281828459045235360287471352 84 | 85 | #define SERIAL 0x0 86 | #define DISPLAY 0x1 87 | 88 | #define LSBFIRST 0 89 | #define MSBFIRST 1 90 | 91 | #define CHANGE 1 92 | #define FALLING 2 93 | #define RISING 3 94 | 95 | // undefine stdlib's abs if encountered 96 | #ifdef abs 97 | #undef abs 98 | #endif 99 | 100 | #define min(a,b) ((a)<(b)?(a):(b)) 101 | #define max(a,b) ((a)>(b)?(a):(b)) 102 | #define abs(x) ((x)>0?(x):-(x)) 103 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 104 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 105 | #define radians(deg) ((deg)*DEG_TO_RAD) 106 | #define degrees(rad) ((rad)*RAD_TO_DEG) 107 | #define sq(x) ((x)*(x)) 108 | 109 | #define interrupts() EA = 1 110 | #define noInterrupts() EA = 0 111 | 112 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 113 | #define clockCyclesPerMillisecond() ( F_CPU / 1000L ) 114 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 115 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 116 | 117 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 118 | #define highByte(w) ((uint8_t) ((w) >> 8)) 119 | 120 | //#define bitSet(value, b) (__asm__("bset\t")) 121 | //#define bitClear(value, b) (__asm__("bres\t")) 122 | 123 | #define bitRead(value, b) (((value) >> (b)) & 0x01) 124 | #define bitSet(value, b) ((value) |= (1UL << (b))) 125 | #define bitClear(value, b) ((value) &= ~(1UL << (b))) 126 | #define bitWrite(value, b, bitvalue) ((bitvalue) ? bitSet(value, b) : bitClear(value, b)) 127 | 128 | #ifndef _BV 129 | #define _BV(x) (1<<(x)) 130 | #endif 131 | #ifndef cbi /*compatible with wiring*/ 132 | #define cbi(a, b) bitClear(a,b) 133 | #endif 134 | #ifndef sbi /*compatible with wiring*/ 135 | #define sbi(a, b) bitSet(a, b) 136 | #endif 137 | 138 | #define maskSet(value, mask) ((value) |= (mask)) 139 | #define maskClear(value, mask) ((value) &= ~(mask)) 140 | 141 | 142 | // avr-libc defines _NOP() since 1.6.2 143 | #ifndef _NOP 144 | #define _NOP() NOP() 145 | #endif 146 | 147 | #ifndef F 148 | #define F(x) 149 | #endif 150 | 151 | /* for SDCC this is supposed to be "__critical{" and "}", but up to 152 | * sdcc version 3.6.4 it is wrongly implemented. */ 153 | /* so geht es nicht: 154 | #define BEGIN_CRITICAL __asm__("push\tcc");__asm__("sim"); 155 | #define END_CRITICAL __asm__("pop\tcc"); 156 | */ 157 | #define BEGIN_CRITICAL __critical { 158 | #define END_CRITICAL } 159 | /* klappt: 160 | #define BEGIN_CRITICAL 161 | #define END_CRITICAL 162 | */ 163 | 164 | // #define bit(b) (1UL << (b)) sdcc bit is __bit keywords 165 | 166 | //typedef bool boolean; 167 | typedef unsigned int word; 168 | typedef unsigned char byte; 169 | 170 | void init(void); 171 | void initVariant(void); // weak 172 | 173 | int atexit(void (*func)()); // __attribute__((weak)); 174 | void serialEvent(void); // weak 175 | 176 | #include "wiring_digital.h" 177 | 178 | int analogRead(uint8_t); 179 | void analogReference(uint8_t); 180 | void analogWrite(uint8_t, int); 181 | 182 | #include "wiring.h" 183 | 184 | unsigned long pulseIn(uint8_t, uint8_t, unsigned long); 185 | unsigned long pulseInLong(uint8_t, uint8_t, unsigned long); 186 | 187 | //void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 188 | //uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 189 | 190 | void attachInterrupt(uint8_t, void (*)(void), int); 191 | void detachInterrupt(uint8_t); 192 | 193 | void setup(void); 194 | void loop(void); 195 | 196 | // Get the bit location within the hardware port of the given virtual pin. 197 | // This comes from the pins_*.c file for the active board configuration. 198 | 199 | #define analogInPinToBit(P) (P) 200 | 201 | //extern const uint8_t digital_pin_to_port[]; 202 | //extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 203 | //extern const uint8_t digital_pin_to_bit_mask[]; 204 | //extern const uint8_t digital_pin_to_timer[]; 205 | 206 | // Get the bit location within the hardware port of the given virtual pin. 207 | // This comes from the pins_*.c file for the active board configuration. 208 | // 209 | #define digitalPinToPort(pin) (pin >> 4) 210 | #define digitalPinToBitMask(pin) (1 << (pin & 0x0f)) 211 | //#define digitalPinToTimer(P) ( digital_pin_to_timer[(P)] ) 212 | //#define analogInPinToBit(P) (P) 213 | //#define portOutputRegister(P) ( (volatile uint8_t *)( port_to_output[(P)]) ) 214 | //#define portInputRegister(P) ( (volatile uint8_t *)( port_to_input[(P)]) ) 215 | //#define portModeRegister(P) ( (volatile uint8_t *)( port_to_mode[(P)]) ) 216 | 217 | #define NOT_A_PIN 0xff 218 | #define NOT_A_PORT 0xff 219 | #define ARDUINO_PINMASK 0x08 220 | #define ARDUINO_PORTMASK 0x80 221 | #define NOT_A_PORTPIN(x) ((x)&(ARDUINO_PORTMASK|ARDUINO_PINMASK)) 222 | #define IS_A_PIN(x) !NOT_A_PORTPIN(x) 223 | 224 | 225 | #define NOT_AN_INTERRUPT -1 226 | 227 | #ifdef ARDUINO_MAIN 228 | //#define PA 1 229 | //#define PB 2 230 | //#define PC 3 231 | //#define PD 4 232 | //#define PE 5 233 | //#define PF 6 234 | //#define PG 7 235 | //#define PH 8 236 | //#define PJ 10 237 | //#define PK 11 238 | //#define PL 12 239 | #endif 240 | 241 | //FIXME#include "WCharacter.h" 242 | //FIXME#include "WString.h" 243 | #include "HardwareSerial.h" 244 | 245 | //uint16_t makeWord(uint16_t w); 246 | //uint16_t makeWord(byte h, byte l); 247 | 248 | //#define word(...) makeWord(__VA_ARGS__) 249 | 250 | 251 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration); 252 | void noTone(uint8_t _pin); 253 | 254 | // WMath prototypes 255 | long random(long howbig); 256 | long random_minmax(long howsmall, long howbig); 257 | void randomSeed(unsigned long seed); 258 | long map(long x, long in_min, long in_max, long out_min, long out_max); 259 | 260 | inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 261 | 262 | #endif //Arduino_h 263 | -------------------------------------------------------------------------------- /cores/STC89/HardwareSerial.c: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.c - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | 27 | Modified 2 February 2018 for mcs51 by huaweiwx 28 | Review 2021 for stc89c52rc by nulllab-jun 29 | */ 30 | 31 | #include "Arduino.h" 32 | #include "bsp/STC89C5xRC.h" 33 | #include "bsp/mcu.h" 34 | #include "bsp/compatible.h" 35 | #define MENU_SERIAL 1 36 | 37 | // private data ////////////////////////////////////////////////////////////// 38 | 39 | #ifndef SERIAL_BUFFER_SIZE 40 | # define SERIAL_BUFFER_SIZE 64 41 | #endif 42 | 43 | #if SERIAL_BUFFER_SIZE > 255 44 | typedef struct { 45 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 46 | uint16_t size; 47 | volatile uint16_t head; 48 | volatile uint16_t tail; 49 | } RINGBUF_TypeDef; 50 | #else 51 | typedef struct { 52 | uint8_t buffer[SERIAL_BUFFER_SIZE]; 53 | uint8_t size; 54 | volatile uint8_t head; 55 | volatile uint8_t tail; 56 | } RINGBUF_TypeDef; 57 | #endif 58 | 59 | /*如果uart工作于模式0或模式2,此时可以不占用定时器*/ 60 | void uart_init0(unsigned long baud) 61 | { 62 | SCON = 0x50; //8-bit variable UART 63 | TMOD = 0x20; //Set Timer1 as 8-bit auto reload mode 64 | TH1 = TL1 = -(F_CPU/12/32/baud); //Set auto-reload vaule 65 | TR1 = 1; //Timer1 start run 66 | ES = 1; //Enable UART interrupt 67 | EA = 1; //Open master interrupt switch 68 | } 69 | //extern void uart_init0(unsigned long baud); 70 | 71 | static XDATA(RINGBUF_TypeDef, rxBuf);// = { { 0 }, 0, 0}; 72 | static bool initialized; //=0 internal status. Returned on HardwareSerial() 73 | 74 | // private functions //////////////////////////////////////////////////////// 75 | static void storeChar(uint8_t c, RINGBUF_TypeDef *buf) 76 | { 77 | noInterrupts(); 78 | int i = (unsigned int)(buf->head + 1) % buf->size; 79 | 80 | // if we should be storing the received character into the location 81 | // just before the tail (meaning that the head would advance to the 82 | // current location of the tail), we're about to overflow the buffer 83 | // and so we don't write the character or advance the head. 84 | if (i != buf->tail) { 85 | buf->buffer[buf->head] = c; 86 | buf->head = i; 87 | } 88 | interrupts(); 89 | } 90 | 91 | // Interrupt handler /////////////////////////////////////////////////////////// 92 | /** 93 | FUNCTION_PURPOSE: serial interrupt, echo received data. 94 | FUNCTION_INPUTS: P0.7(RXD) serial input 95 | FUNCTION_OUTPUTS: P0.6(TXD) serial output 96 | */ 97 | 98 | #if (MENU_SERIAL == 1) 99 | #define InitialUARTx(x) \ 100 | attachInterrupt(UART_IRQn, UART_IRQHandler, 0); \ 101 | uart_init0(x) 102 | 103 | 104 | #define RXREG SBUF 105 | 106 | 107 | void UART_IRQHandler(void) // UART_ISR, 4 108 | { 109 | uint8_t c; 110 | if (RI) 111 | { /* if reception occur */ 112 | RI = 0; /* clear reception flag for next reception */ 113 | c = RXREG; 114 | storeChar(c, &rxBuf); 115 | } 116 | 117 | if (TI) 118 | { 119 | TI = 0; /* if emission occur */ 120 | } 121 | } 122 | 123 | size_t HardwareSerial_write(uint8_t c) 124 | { 125 | noInterrupts(); 126 | TI = 0; 127 | RXREG = c; 128 | while (!TI); 129 | interrupts(); 130 | return 1; 131 | } 132 | 133 | #else 134 | #error "This case undefined! Please add" 135 | #endif 136 | 137 | 138 | // Public Methods ////////////////////////////////////////////////////////////// 139 | 140 | uint8_t HardwareSerial(void) 141 | { 142 | return initialized; 143 | } 144 | 145 | void HardwareSerial_begin(unsigned long baud) 146 | { 147 | rxBuf.head = rxBuf.tail = 0; 148 | rxBuf.size = sizeof(rxBuf.buffer); 149 | initialized = 1; 150 | putcharFunc = HardwareSerial_write; 151 | InitialUARTx(baud); 152 | } 153 | 154 | void HardwareSerial_end(void) 155 | { 156 | // wait for transmission of outgoing data 157 | rxBuf.head = rxBuf.tail = 0; 158 | initialized = 0; 159 | } 160 | 161 | int HardwareSerial_available(void) 162 | { 163 | unsigned int rtn; 164 | noInterrupts(); 165 | rtn = (rxBuf.size + rxBuf.head - rxBuf.tail) % rxBuf.size; 166 | interrupts(); 167 | return rtn; 168 | } 169 | 170 | int HardwareSerial_peek(void) 171 | { 172 | int rtn; 173 | noInterrupts(); 174 | if (rxBuf.head == rxBuf.tail) { 175 | rtn = -1; 176 | } else { 177 | rtn = rxBuf.buffer[rxBuf.tail]; 178 | } 179 | interrupts(); 180 | return rtn; 181 | } 182 | 183 | int HardwareSerial_read(void) 184 | { 185 | int rtn; 186 | noInterrupts(); 187 | if (rxBuf.head == rxBuf.tail) { 188 | rtn = -1; 189 | } else { 190 | rtn = rxBuf.buffer[rxBuf.tail]; 191 | rxBuf.tail = (unsigned int)(rxBuf.tail + 1) % rxBuf.size; 192 | } 193 | interrupts(); 194 | return rtn; 195 | } 196 | 197 | void HardwareSerial_flush(void) 198 | { 199 | } 200 | 201 | writefunc_p putcharFunc = HardwareSerial_write; /*缺省使用库 HardwareSerial_write*/ 202 | int putchar(int c) 203 | { 204 | putcharFunc((unsigned char)c); /* output character */ 205 | return (c); 206 | } 207 | 208 | //#define PRINTF_TINY 5 209 | //#define PRINTF_SMALL 4 210 | //#define PRINTF_FAST 3 211 | //#define PRINTF_FAST_F 2 212 | //#define PRINTF 1 213 | 214 | #if (USE_PRINTF > 0) /*use printf */ 215 | __code HWSERIAL_TypeDef Serial = { 216 | HardwareSerial_available, 217 | HardwareSerial_begin, 218 | HardwareSerial_write, 219 | HardwareSerial_read, 220 | #if (USE_PRINTF > 4) /*5*/ 221 | printf_tiny, 222 | #elif (USE_PRINTF > 3) 223 | printf_small, 224 | #elif (USE_PRINTF > 2) 225 | printf_fast, 226 | #elif (USE_PRINTF > 1) 227 | printf_fast_f, 228 | #else 229 | printf, 230 | #endif 231 | }; 232 | #endif 233 | -------------------------------------------------------------------------------- /cores/STC89/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for sduino 3 | Copyright (c) 2016 Michael Mayer 4 | 5 | Plain C version of HardwareSerial.cpp of the Arduino project. 6 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | 22 | Modified 23 November 2006 by David A. Mellis 23 | Modified 28 September 2010 by Mark Sproul 24 | Modified 14 August 2012 by Alarus 25 | Modified 15 December 2016 by Michael Mayer 26 | Modified 2 February 2018 for mcs51 by huaweiwx 27 | */ 28 | 29 | #ifndef _HARDWARE_SERIAL_H_ 30 | #define _HARDWARE_SERIAL_H_ 31 | 32 | #include 33 | #include 34 | 35 | // Define config for Serial.begin(baud, config); 36 | /* coding of the bit field: 00sw .pp. 37 | * wordlength w: 0:8 1:9 (5,6,7 not supported) 38 | * parity pp: 0:n 2:e 3:o 39 | * stopbits s: 0:1 1:2 40 | * => 8x1=0x0x, 9x1=0x1x, 8x2=0x2x, 9x2=0x3x 41 | * => n=0xx0, e=0xx4, o=0xx6 42 | */ 43 | #define SERIAL_8N1 0x00 44 | #define SERIAL_9N1 0x10 45 | #define SERIAL_8N2 0x20 46 | #define SERIAL_9N2 0x30 47 | #define SERIAL_8E1 0x04 48 | #define SERIAL_9E1 0x14 49 | #define SERIAL_8E2 0x24 50 | #define SERIAL_9E2 0x34 51 | #define SERIAL_8O1 0x06 52 | #define SERIAL_9O1 0x16 53 | #define SERIAL_8O2 0x26 54 | #define SERIAL_9O2 0x36 55 | 56 | #define MASK_PARITY 0x06 57 | #define MASK_STOPBITS 0x20 58 | #define MASK_DATABITS 0x10 59 | 60 | 61 | // Public Methods ////////////////////////////////////////////////////////////// 62 | 63 | uint8_t HardwareSerial(void); 64 | void HardwareSerial_begin(unsigned long baud); 65 | void HardwareSerial_end(void); 66 | 67 | int HardwareSerial_available(void); 68 | int HardwareSerial_read(void); 69 | size_t HardwareSerial_write(uint8_t c); 70 | void HardwareSerial_flush(void); 71 | extern writefunc_p putcharFunc; 72 | 73 | #if (USE_PRINTF > 0) /*use printf */ 74 | typedef struct { 75 | i_v_funcType available; 76 | v_l_funcType begin; 77 | s_c_funcType write; 78 | i_v_funcType read; 79 | #if (USE_PRINTF > 4) /*5 printf_tiny*/ 80 | v_c_printfType printf; 81 | #elif (USE_PRINTF > 3) /*4 printf_small*/ 82 | v_printfType printf; 83 | #elif (USE_PRINTF > 2) /*3 printf_fast*/ 84 | v_c_printfType printf; 85 | #elif (USE_PRINTF > 1) /*2 printf_fast_f*/ 86 | v_c_printfType printf; 87 | #else 88 | i_printfType printf; /*1 printf*/ 89 | #endif 90 | } HWSERIAL_TypeDef; 91 | extern __code HWSERIAL_TypeDef Serial; 92 | #endif 93 | 94 | // Alias Definitions for a more Arduino-like look //////////////////////////// 95 | 96 | //#define Serial HardwareSerial() 97 | #define Serial_begin HardwareSerial_begin 98 | #define Serial_available HardwareSerial_available 99 | #define Serial_read HardwareSerial_read 100 | #define Serial_write HardwareSerial_write 101 | #define Serial_flush HardwareSerial_flush 102 | #define Serial_end HardwareSerial_end 103 | 104 | 105 | // variants of the standard Serial.print() function: Separate implementations 106 | // for string, char, unsigned, signed int 107 | #define Serial_print_s(S) Print_print_s(HardwareSerial_write,S) 108 | #define Serial_print_sn(S) Print_print_sn(HardwareSerial_write,S,N) 109 | #define Serial_print_c(C) HardwareSerial_write(C) 110 | 111 | // print signed/unsigned integer values (char, short, int, long) as decimal values 112 | #define Serial_print_i(I) Print_print_i(HardwareSerial_write,I) 113 | #define Serial_print_u(U) Print_print_u(HardwareSerial_write,U) 114 | 115 | // print signed/unsigned integer values (char, short, int, long) to base B 116 | #define Serial_print_ib(I,B) Print_print_ib(HardwareSerial_write,I,B) 117 | #define Serial_print_ub(U,B) Print_print_ub(HardwareSerial_write,U,B) 118 | 119 | // print float value 120 | #define Serial_print_f(F) Print_print_fd(HardwareSerial_write,F,2) 121 | #define Serial_print_fd(F,D) Print_print_fd(HardwareSerial_write,F,D) 122 | 123 | #define Serial_println() Print_println(HardwareSerial_write) 124 | #define Serial_println_s(S) Print_println_s(HardwareSerial_write,S) 125 | #define Serial_println_sn(S,N) Print_println_sn(HardwareSerial_write,S,N) 126 | #define Serial_println_u(U) Print_println_u(HardwareSerial_write,U) 127 | #define Serial_println_i(I) Print_println_i(HardwareSerial_write,I) 128 | #define Serial_println_ib(I,B) Print_println_ib(HardwareSerial_write,I,B) 129 | #define Serial_println_ub(U,B) Print_println_ub(HardwareSerial_write,U,B) 130 | #define Serial_println_f(F) Print_println_fd(HardwareSerial_write,F,2) 131 | #define Serial_println_fd(F,D) Print_println_fd(HardwareSerial_write,F,D) 132 | 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /cores/STC89/Print.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | void printNL(void); 46 | 47 | // Public Methods ////////////////////////////////////////////////////////////// 48 | 49 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 50 | { 51 | size_t n = 0; 52 | while (size--) { 53 | if (writefunc(*buffer++)) n++; 54 | else break; 55 | } 56 | return n; 57 | } 58 | 59 | size_t Print_print_s(writefunc_p writefunc, const char *str) 60 | { 61 | size_t n = 0; 62 | char c; 63 | 64 | if (!str) return 0; 65 | 66 | while ( c=*str++ ) { // assignment intented 67 | if (writefunc(c)) n++; 68 | else break; 69 | } 70 | return n; 71 | } 72 | 73 | 74 | size_t Print_print_u(writefunc_p writefunc, unsigned long n) 75 | { 76 | return printNumber(writefunc, n,10); 77 | } 78 | 79 | size_t Print_print_i(writefunc_p writefunc, long n) 80 | { 81 | return printInt(writefunc, n,10); 82 | } 83 | 84 | // Variants of the above functions with an added newline ////////////////////// 85 | 86 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size) 87 | { 88 | size_t r; 89 | 90 | r = Print_print_sn(writefunc, buffer, size); 91 | return r + Print_println(writefunc); 92 | } 93 | 94 | size_t Print_println_s(writefunc_p writefunc, const char *str) 95 | { 96 | size_t r; 97 | 98 | r = Print_print_s(writefunc, str); 99 | return r + Print_println(writefunc); 100 | } 101 | 102 | size_t Print_println_u(writefunc_p writefunc, unsigned long n) 103 | { 104 | size_t r; 105 | 106 | r = printNumber(writefunc, n,10); 107 | return r + Print_println(writefunc); 108 | } 109 | 110 | size_t Print_println_i(writefunc_p writefunc, long n) 111 | { 112 | size_t r; 113 | 114 | r = printInt(writefunc, n,10); 115 | return r + Print_println(writefunc); 116 | } 117 | 118 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 119 | { 120 | size_t r; 121 | 122 | r = printNumber(writefunc, n,base); 123 | return r + Print_println(writefunc); 124 | } 125 | 126 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base) 127 | { 128 | size_t r; 129 | 130 | r = printInt(writefunc, n,base); 131 | return r + Print_println(writefunc); 132 | } 133 | 134 | 135 | 136 | // (not so) Private Methods ///////////////////////////////////////////////////////////// 137 | 138 | size_t Print_println(writefunc_p writefunc) 139 | { 140 | size_t n; 141 | 142 | n = writefunc(13); 143 | n += writefunc(10); 144 | return n; 145 | } 146 | 147 | 148 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base) 149 | { 150 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 151 | char *str = &buf[sizeof(buf) - 1]; 152 | 153 | *str = '\0'; 154 | 155 | // prevent crash if called with base == 1 156 | if (base < 2) base = 10; 157 | 158 | do { 159 | char c = n % base; 160 | n /= base; 161 | 162 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 163 | } while(n); 164 | 165 | return Print_print_s(writefunc, str); 166 | } 167 | 168 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base) 169 | { 170 | if (base == 0) { 171 | return writefunc((unsigned char) n); 172 | } else if (base == 10) { 173 | if (n < 0) { 174 | int t = writefunc('-'); 175 | n = -n; 176 | return printNumber(writefunc, n, 10) + t; 177 | } 178 | return printNumber(writefunc, n, 10); 179 | } else { 180 | return printNumber(writefunc, n, base); 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /cores/STC89/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. 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 Print_h 21 | #define Print_h 22 | 23 | #include // for size_t 24 | #include 25 | 26 | //#include "WString.h" 27 | //#include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | 35 | // for the function pointer to the actual write function 36 | typedef size_t (*writefunc_p)(uint8_t c); 37 | 38 | // abreviations of the actual function names, mostly for internal use 39 | #define printBuf Print_print_sn 40 | #define printStr Print_print_s 41 | #define printNumber Print_print_ub 42 | #define printInt Print_print_ib 43 | #define println Print_println 44 | 45 | 46 | // the more sophisticated Arduino-Style functions. Variants of the standard 47 | // Serial.print() function: Separate impementations for different datatype 48 | // to mimic polymorphism. 49 | 50 | // print strings (C-Style or buffer contents) 51 | size_t Print_print_s(writefunc_p writefunc, const char *str); 52 | size_t Print_print_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 53 | 54 | // print signed/unsigned values (char, short, int, long) as decimal values 55 | size_t Print_print_i(writefunc_p writefunc, long n); 56 | size_t Print_print_u(writefunc_p writefunc, unsigned long n); 57 | 58 | // print signed/unsigned integer values (char, short, int, long) to base B 59 | size_t Print_print_ib(writefunc_p writefunc, long n, uint8_t base); 60 | size_t Print_print_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 61 | 62 | // print float values with two digits precision/specified number of digits 63 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits); 64 | //#define Print_print_f(W,N) Print_print_fd(W,N,2) 65 | inline size_t Print_print_f(writefunc_p writefunc, double number) { 66 | return Print_print_fd(writefunc, number, 2); 67 | } 68 | 69 | // Variants of the above with a newline added at the and: 70 | size_t Print_println(writefunc_p writefunc); 71 | size_t Print_println_s(writefunc_p writefunc, const char *str); 72 | size_t Print_println_sn(writefunc_p writefunc, const uint8_t *buffer, size_t size); 73 | size_t Print_println_i(writefunc_p writefunc, long n); 74 | size_t Print_println_u(writefunc_p writefunc, unsigned long n); 75 | size_t Print_println_ib(writefunc_p writefunc, long n, uint8_t base); 76 | size_t Print_println_ub(writefunc_p writefunc, unsigned long n, uint8_t base); 77 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits); 78 | //#define Print_println_f(W,N) Print_println_fd(W,N,2) 79 | inline size_t Print_println_f(writefunc_p writefunc, double number) { 80 | return Print_println_fd(writefunc, number, 2); 81 | } 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cores/STC89/Print_float.c: -------------------------------------------------------------------------------- 1 | /* 2 | Print.c - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | The float functions are moved to a separate file Print-float.c. This way 6 | we can keep the linker from pulling in all the float functions even when no 7 | floats are used in the sketch. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | Modified 23 November 2006 by David A. Mellis 24 | Modified 03 August 2015 by Chuck Todd 25 | Modified 30 December 2016 by Michael Mayer 26 | */ 27 | 28 | #ifdef _GCC_ 29 | #include 30 | #include 31 | #define PROGMEM 32 | #endif 33 | 34 | #include 35 | #include "Arduino.h" 36 | 37 | #include "Print.h" 38 | 39 | #ifdef _GCC_ 40 | #undef printChr 41 | #define printChr(C) putchar(C) 42 | #endif 43 | 44 | 45 | // Public Methods ////////////////////////////////////////////////////////////// 46 | 47 | 48 | size_t Print_print_fd(writefunc_p writefunc, double number, uint8_t digits) 49 | { 50 | size_t n = 0; 51 | uint8_t i; 52 | unsigned long int_part; 53 | double remainder, rounding; 54 | unsigned int toPrint; 55 | 56 | if (isnan(number)) return printStr(writefunc,"nan"); 57 | if (isinf(number)) return printStr(writefunc,"inf"); 58 | if (number > 4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 59 | if (number <-4294967040.0) return printStr (writefunc,"ovf"); // constant determined empirically 60 | 61 | // Handle negative numbers 62 | if (number < 0.0) 63 | { 64 | n += writefunc('-'); 65 | number = -number; 66 | } 67 | 68 | // Round correctly so that print(1.999, 2) prints as "2.00" 69 | rounding = 0.5; 70 | for (i=0; i 0) { 82 | n += writefunc('.'); 83 | } 84 | 85 | // Extract digits from the remainder one at a time 86 | while (digits-- > 0) 87 | { 88 | remainder *= 10.0; 89 | toPrint = (unsigned int)(remainder); 90 | n += printNumber(writefunc,toPrint,10); 91 | remainder -= toPrint; 92 | } 93 | 94 | return n; 95 | } 96 | 97 | 98 | size_t Print_println_fd(writefunc_p writefunc, double number, uint8_t digits) 99 | { 100 | size_t r; 101 | 102 | r = Print_print_fd(writefunc, number, digits); 103 | return r + Print_println(writefunc); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /cores/STC89/WInterrupts.c: -------------------------------------------------------------------------------- 1 | // for stc89 2 | 3 | #include "Arduino.h" 4 | #include 5 | #include "bsp/compatible.h" 6 | #define INTERRUPT_NUMS 6 7 | 8 | typedef void (*voidFuncPtr)(void); 9 | 10 | XDATA(voidFuncPtr, callback[INTERRUPT_NUMS]) = {NULL}; 11 | 12 | #define INTERRUPT_ISR(a,b) INTERRUPT(a,b){if (callback[b]) callback[b]();} 13 | 14 | INTERRUPT_ISR(int0_isr, 0) 15 | INTERRUPT_ISR(timer0_isr, 1) 16 | INTERRUPT_ISR(int1_isr, 2) 17 | INTERRUPT_ISR(timer1_isr, 3) 18 | INTERRUPT_ISR(uart_isr, 4) 19 | INTERRUPT_ISR(timer2_isr, 5) 20 | 21 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) 22 | { 23 | if (interruptNum < INTERRUPT_NUMS) { 24 | (void)mode; /*UNUSED*/ 25 | callback[interruptNum] = userFunc; 26 | } 27 | } 28 | 29 | void detachInterrupt(uint8_t interruptNum) 30 | { 31 | if (interruptNum < INTERRUPT_NUMS) { 32 | callback[interruptNum] = NULL; 33 | } 34 | } -------------------------------------------------------------------------------- /cores/STC89/WMath.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #include "stdlib.h" 27 | } 28 | #else 29 | #include "stdlib.h" 30 | #endif 31 | 32 | void randomSeed(unsigned long seed) 33 | { 34 | if (seed != 0) { 35 | srand(seed); 36 | } 37 | } 38 | 39 | long random(long howbig) 40 | { 41 | if (howbig == 0) { 42 | return 0; 43 | } 44 | return rand() % howbig; 45 | } 46 | 47 | long random_minmax(long howsmall, long howbig) 48 | { 49 | long diff; 50 | 51 | if (howsmall >= howbig) { 52 | return howsmall; 53 | } 54 | diff = howbig - howsmall; 55 | return random(diff) + howsmall; 56 | } 57 | 58 | long map(long x, long in_min, long in_max, long out_min, long out_max) 59 | { 60 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 61 | } 62 | 63 | //unsigned int makeWord(unsigned int w) { return w; } 64 | //unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 65 | -------------------------------------------------------------------------------- /cores/STC89/binary.h: -------------------------------------------------------------------------------- 1 | /* 2 | binary.h - Definitions for binary constants 3 | Copyright (c) 2006 David A. Mellis. 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 Binary_h 21 | #define Binary_h 22 | 23 | #define B0 0 24 | #define B00 0 25 | #define B000 0 26 | #define B0000 0 27 | #define B00000 0 28 | #define B000000 0 29 | #define B0000000 0 30 | #define B00000000 0 31 | #define B1 1 32 | #define B01 1 33 | #define B001 1 34 | #define B0001 1 35 | #define B00001 1 36 | #define B000001 1 37 | #define B0000001 1 38 | #define B00000001 1 39 | #define B10 2 40 | #define B010 2 41 | #define B0010 2 42 | #define B00010 2 43 | #define B000010 2 44 | #define B0000010 2 45 | #define B00000010 2 46 | #define B11 3 47 | #define B011 3 48 | #define B0011 3 49 | #define B00011 3 50 | #define B000011 3 51 | #define B0000011 3 52 | #define B00000011 3 53 | #define B100 4 54 | #define B0100 4 55 | #define B00100 4 56 | #define B000100 4 57 | #define B0000100 4 58 | #define B00000100 4 59 | #define B101 5 60 | #define B0101 5 61 | #define B00101 5 62 | #define B000101 5 63 | #define B0000101 5 64 | #define B00000101 5 65 | #define B110 6 66 | #define B0110 6 67 | #define B00110 6 68 | #define B000110 6 69 | #define B0000110 6 70 | #define B00000110 6 71 | #define B111 7 72 | #define B0111 7 73 | #define B00111 7 74 | #define B000111 7 75 | #define B0000111 7 76 | #define B00000111 7 77 | #define B1000 8 78 | #define B01000 8 79 | #define B001000 8 80 | #define B0001000 8 81 | #define B00001000 8 82 | #define B1001 9 83 | #define B01001 9 84 | #define B001001 9 85 | #define B0001001 9 86 | #define B00001001 9 87 | #define B1010 10 88 | #define B01010 10 89 | #define B001010 10 90 | #define B0001010 10 91 | #define B00001010 10 92 | #define B1011 11 93 | #define B01011 11 94 | #define B001011 11 95 | #define B0001011 11 96 | #define B00001011 11 97 | #define B1100 12 98 | #define B01100 12 99 | #define B001100 12 100 | #define B0001100 12 101 | #define B00001100 12 102 | #define B1101 13 103 | #define B01101 13 104 | #define B001101 13 105 | #define B0001101 13 106 | #define B00001101 13 107 | #define B1110 14 108 | #define B01110 14 109 | #define B001110 14 110 | #define B0001110 14 111 | #define B00001110 14 112 | #define B1111 15 113 | #define B01111 15 114 | #define B001111 15 115 | #define B0001111 15 116 | #define B00001111 15 117 | #define B10000 16 118 | #define B010000 16 119 | #define B0010000 16 120 | #define B00010000 16 121 | #define B10001 17 122 | #define B010001 17 123 | #define B0010001 17 124 | #define B00010001 17 125 | #define B10010 18 126 | #define B010010 18 127 | #define B0010010 18 128 | #define B00010010 18 129 | #define B10011 19 130 | #define B010011 19 131 | #define B0010011 19 132 | #define B00010011 19 133 | #define B10100 20 134 | #define B010100 20 135 | #define B0010100 20 136 | #define B00010100 20 137 | #define B10101 21 138 | #define B010101 21 139 | #define B0010101 21 140 | #define B00010101 21 141 | #define B10110 22 142 | #define B010110 22 143 | #define B0010110 22 144 | #define B00010110 22 145 | #define B10111 23 146 | #define B010111 23 147 | #define B0010111 23 148 | #define B00010111 23 149 | #define B11000 24 150 | #define B011000 24 151 | #define B0011000 24 152 | #define B00011000 24 153 | #define B11001 25 154 | #define B011001 25 155 | #define B0011001 25 156 | #define B00011001 25 157 | #define B11010 26 158 | #define B011010 26 159 | #define B0011010 26 160 | #define B00011010 26 161 | #define B11011 27 162 | #define B011011 27 163 | #define B0011011 27 164 | #define B00011011 27 165 | #define B11100 28 166 | #define B011100 28 167 | #define B0011100 28 168 | #define B00011100 28 169 | #define B11101 29 170 | #define B011101 29 171 | #define B0011101 29 172 | #define B00011101 29 173 | #define B11110 30 174 | #define B011110 30 175 | #define B0011110 30 176 | #define B00011110 30 177 | #define B11111 31 178 | #define B011111 31 179 | #define B0011111 31 180 | #define B00011111 31 181 | #define B100000 32 182 | #define B0100000 32 183 | #define B00100000 32 184 | #define B100001 33 185 | #define B0100001 33 186 | #define B00100001 33 187 | #define B100010 34 188 | #define B0100010 34 189 | #define B00100010 34 190 | #define B100011 35 191 | #define B0100011 35 192 | #define B00100011 35 193 | #define B100100 36 194 | #define B0100100 36 195 | #define B00100100 36 196 | #define B100101 37 197 | #define B0100101 37 198 | #define B00100101 37 199 | #define B100110 38 200 | #define B0100110 38 201 | #define B00100110 38 202 | #define B100111 39 203 | #define B0100111 39 204 | #define B00100111 39 205 | #define B101000 40 206 | #define B0101000 40 207 | #define B00101000 40 208 | #define B101001 41 209 | #define B0101001 41 210 | #define B00101001 41 211 | #define B101010 42 212 | #define B0101010 42 213 | #define B00101010 42 214 | #define B101011 43 215 | #define B0101011 43 216 | #define B00101011 43 217 | #define B101100 44 218 | #define B0101100 44 219 | #define B00101100 44 220 | #define B101101 45 221 | #define B0101101 45 222 | #define B00101101 45 223 | #define B101110 46 224 | #define B0101110 46 225 | #define B00101110 46 226 | #define B101111 47 227 | #define B0101111 47 228 | #define B00101111 47 229 | #define B110000 48 230 | #define B0110000 48 231 | #define B00110000 48 232 | #define B110001 49 233 | #define B0110001 49 234 | #define B00110001 49 235 | #define B110010 50 236 | #define B0110010 50 237 | #define B00110010 50 238 | #define B110011 51 239 | #define B0110011 51 240 | #define B00110011 51 241 | #define B110100 52 242 | #define B0110100 52 243 | #define B00110100 52 244 | #define B110101 53 245 | #define B0110101 53 246 | #define B00110101 53 247 | #define B110110 54 248 | #define B0110110 54 249 | #define B00110110 54 250 | #define B110111 55 251 | #define B0110111 55 252 | #define B00110111 55 253 | #define B111000 56 254 | #define B0111000 56 255 | #define B00111000 56 256 | #define B111001 57 257 | #define B0111001 57 258 | #define B00111001 57 259 | #define B111010 58 260 | #define B0111010 58 261 | #define B00111010 58 262 | #define B111011 59 263 | #define B0111011 59 264 | #define B00111011 59 265 | #define B111100 60 266 | #define B0111100 60 267 | #define B00111100 60 268 | #define B111101 61 269 | #define B0111101 61 270 | #define B00111101 61 271 | #define B111110 62 272 | #define B0111110 62 273 | #define B00111110 62 274 | #define B111111 63 275 | #define B0111111 63 276 | #define B00111111 63 277 | #define B1000000 64 278 | #define B01000000 64 279 | #define B1000001 65 280 | #define B01000001 65 281 | #define B1000010 66 282 | #define B01000010 66 283 | #define B1000011 67 284 | #define B01000011 67 285 | #define B1000100 68 286 | #define B01000100 68 287 | #define B1000101 69 288 | #define B01000101 69 289 | #define B1000110 70 290 | #define B01000110 70 291 | #define B1000111 71 292 | #define B01000111 71 293 | #define B1001000 72 294 | #define B01001000 72 295 | #define B1001001 73 296 | #define B01001001 73 297 | #define B1001010 74 298 | #define B01001010 74 299 | #define B1001011 75 300 | #define B01001011 75 301 | #define B1001100 76 302 | #define B01001100 76 303 | #define B1001101 77 304 | #define B01001101 77 305 | #define B1001110 78 306 | #define B01001110 78 307 | #define B1001111 79 308 | #define B01001111 79 309 | #define B1010000 80 310 | #define B01010000 80 311 | #define B1010001 81 312 | #define B01010001 81 313 | #define B1010010 82 314 | #define B01010010 82 315 | #define B1010011 83 316 | #define B01010011 83 317 | #define B1010100 84 318 | #define B01010100 84 319 | #define B1010101 85 320 | #define B01010101 85 321 | #define B1010110 86 322 | #define B01010110 86 323 | #define B1010111 87 324 | #define B01010111 87 325 | #define B1011000 88 326 | #define B01011000 88 327 | #define B1011001 89 328 | #define B01011001 89 329 | #define B1011010 90 330 | #define B01011010 90 331 | #define B1011011 91 332 | #define B01011011 91 333 | #define B1011100 92 334 | #define B01011100 92 335 | #define B1011101 93 336 | #define B01011101 93 337 | #define B1011110 94 338 | #define B01011110 94 339 | #define B1011111 95 340 | #define B01011111 95 341 | #define B1100000 96 342 | #define B01100000 96 343 | #define B1100001 97 344 | #define B01100001 97 345 | #define B1100010 98 346 | #define B01100010 98 347 | #define B1100011 99 348 | #define B01100011 99 349 | #define B1100100 100 350 | #define B01100100 100 351 | #define B1100101 101 352 | #define B01100101 101 353 | #define B1100110 102 354 | #define B01100110 102 355 | #define B1100111 103 356 | #define B01100111 103 357 | #define B1101000 104 358 | #define B01101000 104 359 | #define B1101001 105 360 | #define B01101001 105 361 | #define B1101010 106 362 | #define B01101010 106 363 | #define B1101011 107 364 | #define B01101011 107 365 | #define B1101100 108 366 | #define B01101100 108 367 | #define B1101101 109 368 | #define B01101101 109 369 | #define B1101110 110 370 | #define B01101110 110 371 | #define B1101111 111 372 | #define B01101111 111 373 | #define B1110000 112 374 | #define B01110000 112 375 | #define B1110001 113 376 | #define B01110001 113 377 | #define B1110010 114 378 | #define B01110010 114 379 | #define B1110011 115 380 | #define B01110011 115 381 | #define B1110100 116 382 | #define B01110100 116 383 | #define B1110101 117 384 | #define B01110101 117 385 | #define B1110110 118 386 | #define B01110110 118 387 | #define B1110111 119 388 | #define B01110111 119 389 | #define B1111000 120 390 | #define B01111000 120 391 | #define B1111001 121 392 | #define B01111001 121 393 | #define B1111010 122 394 | #define B01111010 122 395 | #define B1111011 123 396 | #define B01111011 123 397 | #define B1111100 124 398 | #define B01111100 124 399 | #define B1111101 125 400 | #define B01111101 125 401 | #define B1111110 126 402 | #define B01111110 126 403 | #define B1111111 127 404 | #define B01111111 127 405 | #define B10000000 128 406 | #define B10000001 129 407 | #define B10000010 130 408 | #define B10000011 131 409 | #define B10000100 132 410 | #define B10000101 133 411 | #define B10000110 134 412 | #define B10000111 135 413 | #define B10001000 136 414 | #define B10001001 137 415 | #define B10001010 138 416 | #define B10001011 139 417 | #define B10001100 140 418 | #define B10001101 141 419 | #define B10001110 142 420 | #define B10001111 143 421 | #define B10010000 144 422 | #define B10010001 145 423 | #define B10010010 146 424 | #define B10010011 147 425 | #define B10010100 148 426 | #define B10010101 149 427 | #define B10010110 150 428 | #define B10010111 151 429 | #define B10011000 152 430 | #define B10011001 153 431 | #define B10011010 154 432 | #define B10011011 155 433 | #define B10011100 156 434 | #define B10011101 157 435 | #define B10011110 158 436 | #define B10011111 159 437 | #define B10100000 160 438 | #define B10100001 161 439 | #define B10100010 162 440 | #define B10100011 163 441 | #define B10100100 164 442 | #define B10100101 165 443 | #define B10100110 166 444 | #define B10100111 167 445 | #define B10101000 168 446 | #define B10101001 169 447 | #define B10101010 170 448 | #define B10101011 171 449 | #define B10101100 172 450 | #define B10101101 173 451 | #define B10101110 174 452 | #define B10101111 175 453 | #define B10110000 176 454 | #define B10110001 177 455 | #define B10110010 178 456 | #define B10110011 179 457 | #define B10110100 180 458 | #define B10110101 181 459 | #define B10110110 182 460 | #define B10110111 183 461 | #define B10111000 184 462 | #define B10111001 185 463 | #define B10111010 186 464 | #define B10111011 187 465 | #define B10111100 188 466 | #define B10111101 189 467 | #define B10111110 190 468 | #define B10111111 191 469 | #define B11000000 192 470 | #define B11000001 193 471 | #define B11000010 194 472 | #define B11000011 195 473 | #define B11000100 196 474 | #define B11000101 197 475 | #define B11000110 198 476 | #define B11000111 199 477 | #define B11001000 200 478 | #define B11001001 201 479 | #define B11001010 202 480 | #define B11001011 203 481 | #define B11001100 204 482 | #define B11001101 205 483 | #define B11001110 206 484 | #define B11001111 207 485 | #define B11010000 208 486 | #define B11010001 209 487 | #define B11010010 210 488 | #define B11010011 211 489 | #define B11010100 212 490 | #define B11010101 213 491 | #define B11010110 214 492 | #define B11010111 215 493 | #define B11011000 216 494 | #define B11011001 217 495 | #define B11011010 218 496 | #define B11011011 219 497 | #define B11011100 220 498 | #define B11011101 221 499 | #define B11011110 222 500 | #define B11011111 223 501 | #define B11100000 224 502 | #define B11100001 225 503 | #define B11100010 226 504 | #define B11100011 227 505 | #define B11100100 228 506 | #define B11100101 229 507 | #define B11100110 230 508 | #define B11100111 231 509 | #define B11101000 232 510 | #define B11101001 233 511 | #define B11101010 234 512 | #define B11101011 235 513 | #define B11101100 236 514 | #define B11101101 237 515 | #define B11101110 238 516 | #define B11101111 239 517 | #define B11110000 240 518 | #define B11110001 241 519 | #define B11110010 242 520 | #define B11110011 243 521 | #define B11110100 244 522 | #define B11110101 245 523 | #define B11110110 246 524 | #define B11110111 247 525 | #define B11111000 248 526 | #define B11111001 249 527 | #define B11111010 250 528 | #define B11111011 251 529 | #define B11111100 252 530 | #define B11111101 253 531 | #define B11111110 254 532 | #define B11111111 255 533 | 534 | #endif 535 | -------------------------------------------------------------------------------- /cores/STC89/bsp/STC89C5xRC.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------*/ 2 | /* --- 宏晶科技 STCMCU ---------------------------*/ 3 | /* --- Mobile: (86)13922805190 -------------------*/ 4 | /* --- Fax: 86-755-82944243 ----------------------*/ 5 | /* --- Tel: 86-755-82948412 ----------------------*/ 6 | /* --- Web: www.STCMCU.com -----------------------*/ 7 | /* 适用于: STC89C5xRC STC89LE5xRC --------------*/ 8 | /* ------- STC89C5xRD+ STC89LE5xRD+ --------------*/ 9 | /*------------------------------------------------*/ 10 | 11 | #ifndef __STC89C5xRC_RDP_H_ 12 | #define __STC89C5xRC_RDP_H_ 13 | #include 14 | #include /*bool*/ 15 | #include /*sdcc sfr def*/ 16 | 17 | #define SFR_PSW 0xd0 18 | //程序状态字 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 19 | //位描述 CY AC F0 RS1 RS0 OV F1 P 20 | //初始值,0000,0000 0 0 0 0 0 0 0 0 21 | 22 | SFR(PSW, SFR_PSW); 23 | SBIT(CY, SFR_PSW, 7); //进位标志 24 | SBIT(AC, SFR_PSW, 6); //辅助进位标志 25 | SBIT(F0, SFR_PSW, 5); //用户标志 26 | SBIT(RS1,SFR_PSW, 4); //寄存器组选择位1 27 | SBIT(RS0,SFR_PSW, 3); //寄存器组选择位0 28 | SBIT(OV, SFR_PSW, 2); //溢出标志 29 | SBIT(P, SFR_PSW, 0); //ACC的偶校验位 30 | 31 | #define SFR_ACC 0xe0 32 | //累加器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 33 | //初始值,0000,0000 0 0 0 0 0 0 0 0 34 | SFR(ACC, SFR_ACC); 35 | SBIT(ACC7, SFR_ACC, 7); //累加器第7位 36 | SBIT(ACC6, SFR_ACC, 6); //累加器第6位 37 | SBIT(ACC5, SFR_ACC, 5); //累加器第5位 38 | SBIT(ACC4, SFR_ACC, 4); //累加器第4位 39 | SBIT(ACC3, SFR_ACC, 3); //累加器第3位 40 | SBIT(ACC2, SFR_ACC, 2); //累加器第2位 41 | SBIT(ACC1, SFR_ACC, 1); //累加器第1位 42 | SBIT(ACC0, SFR_ACC, 0); //累加器第0位 43 | 44 | 45 | SFR(B,0xf0); //B寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 46 | //初始值=0000,0000 0 0 0 0 0 0 0 0 47 | 48 | SFR(SP,0x81); //堆栈指针 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 49 | //初始值=0000,0111 0 0 0 0 0 1 1 1 50 | 51 | SFR(DPL,0x82); //数据指针低字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 52 | //初始值=0000,0000 0 0 0 0 0 0 0 0 53 | 54 | SFR(DPH,0x83); //数据指针高字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 55 | //初始值=0000,0000 0 0 0 0 0 0 0 0 56 | 57 | SFR(PCON,0x87); //电源控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 58 | //位描述 SMOD SMOD0 - POF GF1 GF0 PD IDL 59 | //初始值=00x1,0000 0 0 x 1 0 0 0 0 60 | 61 | #define SMOD 0x80 //串口波特率倍速位,置1可使波特率快1倍 62 | #define SMOD0 0x40 //FE/SM0选择位,0:SCON.7为SM0 1:SCON.7为FE 63 | #define POF 0x10 //上电复位标志位,上电时由硬件置1,需由软件清0 64 | #define GF1 0x08 //通用标志位1 65 | #define GF0 0x04 //通用标志位0 66 | #define PD 0x02 //掉电控制位,写1可以使MCU进入PowerDown模式 67 | #define IDL 0x01 //空闲控制位,写1可以使MCU进入Idle模式 68 | 69 | SFR(WDT_CONTR,0xe1); //看门狗定时器控制器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 70 | //位描述 - - EN_WDT CLR_WDT IDL_WDT PS2 PS1 PS0 71 | //初始值=xx00,0000 x x 0 0 0 0 0 0 72 | 73 | #define EN_WDT 0x20 //软件使能看门狗,打开后不能用软件的方式关闭 74 | #define CLR_WDT 0x10 //清看门狗定时器 75 | #define IDLE_WDT 0x08 //IDLE模式下,看门狗定时器是否继续计时 76 | 77 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 78 | 79 | SFR(AUXR,0x8e); //辅助寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 80 | //位描述 - - - - - - EXTRAM S1BRS 81 | //初始值=xxxx,xx00 x x x x x x 0 0 82 | 83 | #define EXTRAM 0x02 //内部扩展RAM禁能位,0:内部扩展RAM有效 1:禁用内部扩展RAM 84 | #define ALEOFF 0x01 //禁止ALE信号输出,0:使能ALE信号输出 1:关闭ALE信号输出 85 | 86 | ///////////////////////////////// 87 | 88 | SFR(AUXR1,0xa2); //辅助寄存器1 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 89 | //位描述 - - - - GF2 - - DPS 90 | //初始值=xxxx,0xx0 x x x x 0 x x 0 91 | 92 | #define GF2 0x08 //通用标志位2 93 | #define DPS 0x01 //DPTR0/DPTR1选择位,0:DPTR0 1:DPTR1 94 | 95 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 96 | #define SFR_P0 0x80 97 | SFR(P0, SFR_P0); //I/O端口0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 98 | //位描述 P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 99 | //初始值,1111,1111 1 1 1 1 1 1 1 1 100 | 101 | SBIT(P07, SFR_P0, 7); //I/O口P0.7 102 | SBIT(P06, SFR_P0, 6); //I/O口P0.6 103 | SBIT(P05, SFR_P0, 5); //I/O口P0.5 104 | SBIT(P04, SFR_P0, 4); //I/O口P0.4 105 | SBIT(P03, SFR_P0, 3); //I/O口P0.3 106 | SBIT(P02, SFR_P0, 2); //I/O口P0.2 107 | SBIT(P01, SFR_P0, 1); //I/O口P0.1 108 | SBIT(P00, SFR_P0, 0); //I/O口P0.0 109 | 110 | #define SFR_P1 0x90 111 | SFR(P1,SFR_P1); //I/O端口0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 112 | //位描述 P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 113 | //初始值,1111,1111 1 1 1 1 1 1 1 1 114 | SBIT(P17, SFR_P1, 7); //I/O口P1.7 115 | SBIT(P16, SFR_P1, 6); //I/O口P1.6 116 | SBIT(P15, SFR_P1, 5); //I/O口P1.5 117 | SBIT(P14, SFR_P1, 4); //I/O口P1.4 118 | SBIT(P13, SFR_P1, 3); //I/O口P1.3 119 | SBIT(P12, SFR_P1, 2); //I/O口P1.2 120 | SBIT(P11, SFR_P1, 1); //I/O口P1.1 121 | SBIT(P10, SFR_P1, 0); //I/O口P1.0 122 | 123 | ///////////////////////////////// 124 | #define SFR_P2 0xa0 125 | SFR(P2,SFR_P2); //I/O端口2 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 126 | //位描述 P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 127 | //初始值,1111,1111 1 1 1 1 1 1 1 1 128 | 129 | SBIT(P27, SFR_P2, 7); //I/O口P2.7 130 | SBIT(P26, SFR_P2, 6); //I/O口P2.6 131 | SBIT(P25, SFR_P2, 5); //I/O口P2.5 132 | SBIT(P24, SFR_P2, 4); //I/O口P2.4 133 | SBIT(P23, SFR_P2, 3); //I/O口P2.3 134 | SBIT(P22, SFR_P2, 2); //I/O口P2.2 135 | SBIT(P21, SFR_P2, 1); //I/O口P2.1 136 | SBIT(P20, SFR_P2, 0); //I/O口P2.0 137 | 138 | #define SFR_P3 0xb0 139 | SFR(P3,SFR_P3); //I/O端口3 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 140 | //位描述 P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0 141 | //初始值,1111,1111 1 1 1 1 1 1 1 1 142 | 143 | SBIT(P37, SFR_P3, 7); //I/O口P3.7 144 | SBIT(P36, SFR_P3, 6); //I/O口P3.6 145 | SBIT(P35, SFR_P3, 5); //I/O口P3.5 146 | SBIT(P34, SFR_P3, 4); //I/O口P3.4 147 | SBIT(P33, SFR_P3, 3); //I/O口P3.3 148 | SBIT(P32, SFR_P3, 2); //I/O口P3.2 149 | SBIT(P31, SFR_P3, 1); //I/O口P3.1 150 | SBIT(P30, SFR_P3, 0); //I/O口P3.0 151 | 152 | SBIT(RXD,SFR_P3,0); //串口1的数据接收口 153 | SBIT(TXD,SFR_P3,1); //串口1的数据发送口 154 | SBIT(INT0,SFR_P3,2); //外部中断0的信号输入口 155 | SBIT(INT1,SFR_P3,3); //外部中断1的信号输出口 156 | SBIT(T0,SFR_P3,4); //定时器0的外部信号输入口 157 | SBIT(T1,SFR_P3,5); //定时器1的外部信号输入口 158 | SBIT(WR,SFR_P3,6); //外部数据存储器的写信号 159 | SBIT(RD,SFR_P3,7); //外部数据存储器的读信号 160 | 161 | ///////////////////////////////// 162 | #define SFR_P4 0xc0 163 | 164 | SFR(P4,SFR_P4); //I/O端口4 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 165 | //位描述 P4.7 P4.6 P4.5 P4.4 P4.3 P4.2 P4.1 P4.0 166 | //初始值,1111,1111 1 1 1 1 1 1 1 1 167 | 168 | SBIT(P46,SFR_P4,6); //I/O口P4.6 169 | SBIT(P45,SFR_P4,5); //I/O口P4.5 170 | SBIT(P44,SFR_P4,4); //I/O口P4.4 171 | SBIT(P43,SFR_P4,3); //I/O口P4.3 172 | SBIT(P42,SFR_P4,2); //I/O口P4.2 173 | SBIT(P41,SFR_P4,1); //I/O口P4.1 174 | SBIT(P40,SFR_P4,0); //I/O口P4.0 175 | 176 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 177 | #define SFR_IE 0xa8 178 | 179 | SFR(IE,SFR_IE); //中断使能寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 180 | //位描述 EA ELVD EADC ES ET1 EX1 ET0 EX0 181 | //初始值,0000,0000 0 0 0 0 0 0 0 0 182 | 183 | SBIT(EA, SFR_IE, 7); //总中断开关 184 | SBIT(ELVD, SFR_IE, 6); //LVD中断使能位 185 | SBIT(EADC, SFR_IE, 5); //ADC中断使能位 186 | SBIT(ES, SFR_IE, 4); //串口中断使能位 187 | SBIT(ET1, SFR_IE, 3); //定时器1中断使能位 188 | SBIT(EX1, SFR_IE, 2); //外部中断1中断使能位 189 | SBIT(ET0, SFR_IE, 1); //定时器0中断使能位 190 | SBIT(EX0, SFR_IE, 0); //外部中断0中断使能位 191 | 192 | ///////////////////////////////// 193 | 194 | SFR(IPH,0xb7); //中断优先级寄存器高位 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 195 | //位描述 PX3H PX2H PT2H PSH PT1H PX1H PT0H PX0H 196 | //初始值=0000,0000 0 0 0 0 0 0 0 0 197 | 198 | #define PX3H 0x80 //外部中断3中断优先级控制高位 199 | #define PX2H 0x40 //外部中断2中断优先级控制高位 200 | #define PT2H 0x20 //定时器2中断优先级控制高位 201 | #define PSH 0x10 //串口中断优先级控制高位 202 | #define PT1H 0x08 //定时器1中断优先级控制高位 203 | #define PX1H 0x04 //外部中断1中断优先级控制高位 204 | #define PT0H 0x02 //定时器0中断优先级控制高位 205 | #define PX0H 0x01 //外部中断0中断优先级控制高位 206 | 207 | ///////////////////////////////// 208 | #define SFR_IP 0xb8 209 | SFR(IP,SFR_IP); //中断优先级寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 210 | //位描述 - - PT2 PS PT1 PX1 PT0 PX0 211 | //初始值=xx00,0000 x x 0 0 0 0 0 0 212 | 213 | SBIT(PT2, SFR_IP, 5); //定时器2中断优先级控制低位 214 | SBIT(PS, SFR_IP, 4); //串口中断优先级控制低位 215 | SBIT(PT1, SFR_IP, 3); //定时器1中断优先级控制低位 216 | SBIT(PX1, SFR_IP, 2); //外部中断1中断优先级控制低位 217 | SBIT(PT0, SFR_IP, 1); //定时器0中断优先级控制低位 218 | SBIT(PX0, SFR_IP, 0); //外部中断0中断优先级控制低位 219 | 220 | ///////////////////////////////// 221 | #define SFR_XICON 0xe8 222 | 223 | SFR(XICON,0xe8); //辅助中断使能寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 224 | //位描述 PX3 EX3 IE3 IT3 PX2 EX2 IE2 IT2 225 | //初始值=0000,0000 0 0 0 0 0 0 0 0 226 | 227 | SBIT(PX3, SFR_XICON, 7); //外部中断3中断优先级控制低位 228 | SBIT(EX3, SFR_XICON, 6); //使能外部中断3 229 | SBIT(IE3, SFR_XICON, 5); //外部中断3的中断请求位,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 230 | SBIT(IT3, SFR_XICON, 4); //外部中断3的触发类型,0:低电平触发外部中断 1:下降沿触发外部中断 231 | SBIT(PX2, SFR_XICON, 3); //外部中断2中断优先级控制低位 232 | SBIT(EX2, SFR_XICON, 2); //使能外部中断2 233 | SBIT(IE2, SFR_XICON, 1); //外部中断2的中断请求位,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 234 | SBIT(IT2, SFR_XICON, 0); //外部中断2的触发类型,0:低电平触发外部中断 1:下降沿触发外部中断 235 | 236 | #define X0_INTNO 0 //外部中断0中断号,入口地址为0003H 237 | #define T0_INTNO 1 //定时器0中断号,入口地址为000BH 238 | #define X1_INTNO 2 //外部中断1中断号,入口地址为0013H 239 | #define T1_INTNO 3 //定时器1中断号,入口地址为001BH 240 | #define UART_INTNO 4 //串口中断号,入口地址为0023H 241 | #define T2_INTNO 5 //定时器2中断号,入口地址为002BH 242 | #define X2_INTNO 6 //外部中断2中断号,入口地址为0033H 243 | #define X3_INTNO 7 //外部中断3中断号,入口地址为003BH 244 | 245 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 246 | #define SFR_TCON 0x88 247 | SFR(TCON,SFR_TCON); //定时器0/1控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 248 | //位描述 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 249 | //初始值=0000,0000 0 0 0 0 0 0 0 0 250 | 251 | SBIT(TF1, SFR_TCON, 7); //定时器1溢出标志,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 252 | SBIT(TR1, SFR_TCON, 6); //定时器1的启动控制位,1:启动定时器 0:停止定时器 253 | SBIT(TF0, SFR_TCON, 5); //定时器0溢出标志,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 254 | SBIT(TR0, SFR_TCON, 4); //定时器0的启动控制位,1:启动定时器 0:停止定时器 255 | SBIT(IE1, SFR_TCON, 3); //外部中断1的中断请求位,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 256 | SBIT(IT1, SFR_TCON, 2); //外部中断1的触发类型,0:低电平触发外部中断 1:下降沿触发外部中断 257 | SBIT(IE0, SFR_TCON, 1); //外部中断0的中断请求位,由硬件置1,可由软件清0或者在中断处理程序完成后由硬件自动清0 258 | SBIT(IT0, SFR_TCON, 0); //外部中断0的触发类型,0:低电平触发外部中断 1:下降沿触发外部中断 259 | 260 | ///////////////////////////////// 261 | 262 | SFR(TMOD,0x89); //定时器0/1模式寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 263 | //位描述 GATE C/T# M1 M0 GATE C/T# M1 M0 264 | //初始值=0000,0000 0 0 0 0 0 0 0 0 265 | 266 | #define GATE1 0x80 /*定时器1启动控制位,0:TR1为1时启动定时器1 1:TR1为1且INT1为高电平时才启动定时器1 */ 267 | #define C_T1 0x40 /*定时器/计数器选择位,0:定时器(时钟源为内部时钟) 1:计数器(时钟源为T1引脚的外部时钟) */ 268 | #define T1_M0 0x00 /*定时器1操作模式0:13位定时器 */ 269 | #define T1_M1 0x10 /*定时器1操作模式1:16位定时器 */ 270 | #define T1_M2 0x20 /*定时器1操作模式2:8位自动重载定时器 */ 271 | #define T1_M3 0x30 /*定时器1操作模式3:定时器1停止 */ 272 | #define GATE0 0x08 /*定时器1启动控制位,0:TR0为1时启动定时器1 1:TR0为1且INT0为高电平时才启动定时器0 */ 273 | #define C_T0 0x04 /*定时器/计数器选择位,0:定时器(时钟源为内部时钟) 1:计数器(时钟源为T0引脚的外部时钟) */ 274 | #define T0_M0 0x00 /*定时器0操作模式0:13位定时器 */ 275 | #define T0_M1 0x01 /*定时器0操作模式1:16位定时器 */ 276 | #define T0_M2 0x02 /*定时器0操作模式2:8位自动重载定时器 */ 277 | #define T0_M3 0x03 /*定时器0操作模式3:TL0和TH0为两组独立8位定时器 */ 278 | 279 | ///////////////////////////////// 280 | 281 | SFR(TL0,0x8a); //定时器0的低8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 282 | //初始值,0000,0000 0 0 0 0 0 0 0 0 283 | 284 | ///////////////////////////////// 285 | 286 | SFR(TL1,0x8b); //定时器1的低8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 287 | //初始值,0000,0000 0 0 0 0 0 0 0 0 288 | 289 | ///////////////////////////////// 290 | 291 | SFR(TH0,0x8c); //定时器0的高8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 292 | //初始值,0000,0000 0 0 0 0 0 0 0 0 293 | 294 | ///////////////////////////////// 295 | 296 | SFR(TH1,0x8d); //定时器1的高8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 297 | //初始值,0000,0000 0 0 0 0 0 0 0 0 298 | 299 | ///////////////////////////////// 300 | #define SFR_T2CON 0xc8 301 | SFR(T2CON,SFR_T2CON); //定时器2控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 302 | //位描述 TF2 EXF2 RCLK TCLK EXEN2 TR2 C/T2# CP/RL# 303 | //初始值,0000,0000 0 0 0 0 0 0 0 0 304 | 305 | SBIT(TF2 ,SFR_T2CON,7); //定时器2溢出标志,由硬件置1,必须由软件清0 306 | SBIT(EXF2 ,SFR_T2CON,6); //定时器2的外部标志,由硬件置1,必须由软件清0 307 | SBIT(RCLK ,SFR_T2CON,5); //接收时钟标志,0:使用定时器1作为串口接收发生器 1:使用定时器2作为串口接收发生器 308 | SBIT(TCLK ,SFR_T2CON,4); //发送时钟标志,0:使用定时器1作为串口发送发生器 1:使用定时器2作为串口发送发生器 309 | SBIT(EXEN2 ,SFR_T2CON,3); //定时器2的外部使能标志 310 | SBIT(TR2 ,SFR_T2CON,2); //启动定时期2 311 | SBIT(C_T2 ,SFR_T2CON,1); //定时器/计数器选择位,0:定时器(时钟源为内部时钟) 1:计数器(时钟源为T2引脚的外部时钟) 312 | SBIT(CP_RL2,SFR_T2CON,0); //捕获/重载标志 313 | 314 | ///////////////////////////////// 315 | 316 | SFR(T2MOD,0xc9); //定时器0/1模式寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 317 | //位描述 - - - - - - T2OE DCEN 318 | //初始值,xxxx,xx00 x x x x x x 0 0 319 | 320 | #define T2OE 0x02 //定时器2输出使能,输出溢出率到T2脚 321 | #define DCEN 0x01 //定时器2向下计数,0:向上计数 1:向下计数 322 | 323 | ///////////////////////////////// 324 | 325 | SFR(RCAP2L,0xca); //定时器2重载/捕获低8位 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 326 | //初始值,0000,0000 0 0 0 0 0 0 0 0 327 | 328 | ///////////////////////////////// 329 | 330 | SFR(RCAP2H,0xcb); //定时器2重载/捕获高8位 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 331 | //初始值,0000,0000 0 0 0 0 0 0 0 0 332 | 333 | ///////////////////////////////// 334 | 335 | SFR(TL2,0xcc); //定时器2的低8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 336 | //初始值,0000,0000 0 0 0 0 0 0 0 0 337 | 338 | ///////////////////////////////// 339 | 340 | SFR(TH2,0xcd); //定时器2的高8位计数值 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 341 | //初始值,0000,0000 0 0 0 0 0 0 0 0 342 | 343 | ///////////////////////////////// 344 | #define SFR_SCON 0x98 345 | 346 | SFR(SCON,SFR_SCON); //串口控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 347 | //位描述 SM0/FE SM1 SM2 REN TB8 RB8 TI Ri 348 | //初始值,0000,0000 0 0 0 0 0 0 0 0 349 | 350 | SBIT(FE, SFR_SCON, 7); //帧错误检测位,当串口模块在接收数据时没有检测到正确的停止位时,FE被硬件置1,需要由软件来清0(当SMOD0为1时,FE有效) 351 | SBIT(SM0, SFR_SCON, 7); //串口模式设置位 352 | SBIT(SM1, SFR_SCON, 6); //SM0/SM1,0/0:移位寄存器 0/1:8位可变波特率 1/0:9位固定波特率 1/1:9位可变波特率 353 | SBIT(SM2, SFR_SCON, 5); //自动地址识别使能位 354 | SBIT(REN, SFR_SCON, 4); //使能串口接收模块 355 | SBIT(TB8, SFR_SCON, 3); //发送的第9位数据 356 | SBIT(RB8, SFR_SCON, 2); //接收的第9位数据 357 | SBIT(TI, SFR_SCON, 1); //发送完成中断标志 358 | SBIT(RI, SFR_SCON, 0); //接收完成中断标志 359 | 360 | ///////////////////////////////// 361 | 362 | SFR(SBUF,0x99); //串口接收/发送数据 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 363 | //初始值,xxxx,xxxx x x x x x x x x 364 | 365 | ///////////////////////////////// 366 | 367 | SFR(SADDR,0xa9); //串口设备从地址寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 368 | //初始值,0000,0000 0 0 0 0 0 0 0 0 369 | 370 | ///////////////////////////////// 371 | 372 | SFR(SADEN,0xb9); //串口设备从地址屏蔽位 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 373 | //初始值,0000,0000 0 0 0 0 0 0 0 0 374 | 375 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 376 | 377 | SFR(ISP_DATA,0xe2); //ISP数据寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 378 | //初始值,1111,1111 1 1 1 1 1 1 1 1 379 | 380 | ///////////////////////////////// 381 | 382 | SFR(ISP_ADDRH,0xe3); //ISP地址高位寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 383 | //初始值,0000,0000 0 0 0 0 0 0 0 0 384 | 385 | ///////////////////////////////// 386 | 387 | SFR(ISP_ADDRL,0xe4); //ISP地址低位寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 388 | //初始值,0000,0000 0 0 0 0 0 0 0 0 389 | 390 | ///////////////////////////////// 391 | 392 | SFR(ISP_CMD,0xe5); //ISP命令寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 393 | //初始值,xxxx,xx00 x x x x x 0 0 0 394 | 395 | #define ISP_IDLE 0x00 //ISP待机命令 396 | #define ISP_READ 0x01 //ISP读字节数据命令 397 | #define ISP_PROGRAM 0x02 //ISP字节编程命令 398 | #define ISP_ERASE 0x03 //ISP扇区擦除命令(每扇区512字节)) 399 | 400 | ///////////////////////////////// 401 | 402 | SFR(ISP_TRIG,0xe6); //ISP命令触发寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 403 | //初始值,xxxx,xxxx x x x x x x x x 404 | 405 | #define ISP_TRIG0 0x46 //ISP功能触发命令1 406 | #define ISP_TRIG1 0xb9 //ISP功能触发命令2 407 | 408 | ///////////////////////////////// 409 | 410 | SFR(ISP_CONTR,0xe7); //ISP控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 411 | //位描述 ISPEN SWBS SWRST - - WT2 WT1 WT0 412 | //初始值,000x,x000 0 0 0 x x 0 0 0 413 | 414 | #define ISPEN 0x80 /* ISP使能开关 */ 415 | #define SWBS 0x40 /* 软启动选择,0:从用户AP启动 1:从ISP启动 */ 416 | #define SWRST 0x20 /* 触发软件复位 */ 417 | 418 | #endif 419 | -------------------------------------------------------------------------------- /cores/STC89/bsp/compatible.h: -------------------------------------------------------------------------------- 1 | /* 2 | compatible.h - Definitions for compatible with sdcc 3 | Copyright (c) 2019 huaweiwx@sina.com. 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 _compatible_h_ 21 | #define _compatible_h_ 22 | 23 | //#include "binary.h" 24 | #include "intrins.h" 25 | 26 | #ifdef COMPATIBLE 27 | #define bit __bit 28 | #define idata __idata 29 | #define pdata __pdata 30 | #define xdata __xdata 31 | #define data __data 32 | #define code __code 33 | #define interrupt __interrupt 34 | #define reentrant __reentrant 35 | #define _push_ __push /* keil intrins.h */ 36 | #define _pop_ __pop /* keil intrins.h */ 37 | #endif 38 | 39 | #if defined(__SDCC_mcs51) /*for sdcc c51 */ 40 | #define IDATA(t,v) __idata t v 41 | #define PDATA(t,v) __pdata t v 42 | #define XDATA(t,v) __xdata t v 43 | #define DATA(t,v) __data t v 44 | #define CODE(t,v) __code t v 45 | #elif defined(__CX51__) /* for keil c51 */ 46 | #define IDATA(t,v) t __idata v 47 | #define PDATA(t,v) t __pdata v 48 | #define XDATA(t,v) t __xdata v 49 | #define DATA(t,v) t __data v 50 | #define CODE(t,v) t __code v 51 | #else /*other for stm8/pic */ 52 | #define IDATA(t,v) t v 53 | #define PDATA(t,v) t v 54 | #define XDATA(t,v) t v 55 | #define DATA(t,v) t v 56 | #define CODE(t,v) const t v 57 | #endif 58 | 59 | // SDCC defines a special bool type, use that if available 60 | #ifdef __bool_true_false_are_defined 61 | #define TRUE true 62 | #define FALSE false 63 | #else 64 | typedef enum {FALSE = 0, TRUE = !FALSE} bool; 65 | #endif 66 | typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus, BitAction; 67 | typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; 68 | typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus; 69 | 70 | 71 | 72 | #ifndef UNUSED 73 | #define UNUSED(x) (void)x 74 | #endif 75 | 76 | #endif //_compatible_h_ 77 | -------------------------------------------------------------------------------- /cores/STC89/bsp/gpio.h: -------------------------------------------------------------------------------- 1 | #ifndef __GPIO_H__ 2 | #define __GPIO_H__ 3 | 4 | #define CHIP_PIN_LIST \ 5 | PIN(0,0), /*0 P00*/\ 6 | PIN(0,1), /*1 P01*/\ 7 | PIN(0,2), /*2 P02*/\ 8 | PIN(0,3), /*3 P03*/\ 9 | PIN(0,4), /*4 P04*/\ 10 | PIN(0,5), /*5 P05*/\ 11 | PIN(0,6), /*6 P06*/\ 12 | PIN(0,7), /*7 P07*/\ 13 | PIN(1,0),, /*8 P10*/\ 14 | PIN(1,1), /*9 P11*/\ 15 | PIN(1,2), /*10 P12*/\ 16 | PIN(1,3), /*11 P13*/\ 17 | PIN(1,4), /*12 P14*/\ 18 | PIN(1,5), /*13 P15*/\ 19 | PIN(1,6), /*14 P16*/\ 20 | PIN(1,7), /*15 P17*/\ 21 | PIN(2,0), /*16 P20*/\ 22 | PIN(2,1), /*17 P21*/\ 23 | PIN(2,2), /*18 P22*/\ 24 | PIN(2,3), /*19 P23*/\ 25 | PIN(2,4), /*20 P24*/\ 26 | PIN(2,5), /*21 P25*/\ 27 | PIN(2,6), /*22 P26*/\ 28 | PIN(2,7), /*23 P27*/\ 29 | PIN(3,0), /*24 P30*/\ 30 | PIN(3,1), /*25 P31*/\ 31 | PIN(3,2), /*26 P32*/\ 32 | PIN(3,3), /*27 P33*/\ 33 | PIN(3,4), /*28 P34*/\ 34 | PIN(3,5), /*29 P35*/\ 35 | PIN(3,6), /*30 P36*/\ 36 | PIN(3,7), /*31 P37*/\ 37 | PIN(4,0), /*32 P40*/\ 38 | PIN(4,1), /*33 P41*/\ 39 | PIN(4,2), /*34 P42*/\ 40 | PIN(4,3), /*35 P43*/\ 41 | PIN(4,4), /*36 P44*/\ 42 | PIN(4,5), /*37 P45*/\ 43 | PIN(4,6), /*38 P46*/\ 44 | PIN(4,7) /*39 P47*/ 45 | 46 | #ifdef VARIANT_PIN_LIST 47 | #define PIN_LIST VARIANT_PIN_LIST 48 | #else 49 | #define PIN_LIST CHIP_PIN_LIST 50 | #endif 51 | 52 | /*使用宏定义,GPIO mode set 兼容与 stc 8 */ 53 | #define gpioMode_QS(a,b) 54 | #define gpioMode_PP(a,b) 55 | #define gpioMode_IN(a,b) P##a##b = 1 56 | #define gpioMode_OUT(a,b) 57 | #define gpioMode_OD(a,b) 58 | #define gpioMode(a,b,m) 59 | 60 | #define portMode_QS(a) 61 | #define portMode_PP(a) 62 | #define portMode_OUT(a) 63 | #define portMode_IN(a) P##a=0xff 64 | #define portMode_OD(a) 65 | #define portMode(a,m) 66 | 67 | #endif //__GPIO_H__ 68 | -------------------------------------------------------------------------------- /cores/STC89/bsp/intrins.h: -------------------------------------------------------------------------------- 1 | /* 2 | keil c51 intrins.h 兼容头文件 for SDCC by huaweiwx@sina.com 2017.5.19 3 | 实现 void _push_ (unsigned char _sfr) / void _pop_ (unsigned char _sfr) 4 | */ 5 | 6 | #ifndef _INTRINS_H_ 7 | #define _INTRINS_H_ 8 | 9 | /* warning: __push __pop 使用堆栈临时保存 sfr 数据,必需成对使用! 10 | __push(x); 11 | ... // 保护代码块 12 | __pop(x); //缺少无该语句编译不会出错,但运行错误! 13 | */ 14 | #define __push(x) __asm push _##x __endasm /* void _push_ (unsigned char _sfr); */ 15 | #define __pop(x) __asm pop _##x __endasm /* void _pop_ (unsigned char _sfr); */ 16 | 17 | /* 安全使用保护宏: 18 | pushSfr(x); 19 | ... // 受保护代码块 20 | popSfr(x); // 缺少无该语句编译出错,确保生成正确代码。 21 | */ 22 | #define pushSfr(x) do{\ 23 | __push(x) 24 | 25 | #define popSfr(x) __pop(x);\ 26 | }while(0) 27 | 28 | #endif //_INTRINS_H_ 29 | -------------------------------------------------------------------------------- /cores/STC89/bsp/isr.h: -------------------------------------------------------------------------------- 1 | /* for stc12c56 */ 2 | #ifndef __ISR_H__ 3 | #define __ISR_H__ 4 | 5 | #define INT0_IRQn 0 6 | #define TIMER0_IRQn 1 7 | #define INT1_IRQn 2 8 | #define TIMER1_IRQn 3 9 | 10 | #define UART_IRQn 4 11 | 12 | #define TIMER2_IRQn 5 13 | 14 | /* AT89C52 IRQn compatible */ 15 | #ifndef IE0_VECTOR 16 | #define IE0_VECTOR 0 /* 0x03 external interrupt 0 */ 17 | #define TF0_VECTOR 1 /* 0x0b timer 0 */ 18 | #define IE1_VECTOR 2 /* 0x13 external interrupt 1 */ 19 | #define TF1_VECTOR 3 /* 0x1b timer 1 */ 20 | #define SI0_VECTOR 4 /* 0x23 serial port 0 */ 21 | #define TF2_VECTOR 5 /* 0x2B timer 2 */ 22 | #endif 23 | 24 | /*仅 sdcc 需要在 main 函数前显式声明 */ 25 | #if defined (SDCC) || defined (__SDCC) 26 | 27 | INTERRUPT(int0_isr ,0); 28 | INTERRUPT(timer0_isr,1); 29 | INTERRUPT(int1_isr ,2); 30 | INTERRUPT(timer1_isr,3); 31 | INTERRUPT(uart_isr ,4); 32 | INTERRUPT(timer2_isr,5); 33 | 34 | #endif 35 | 36 | #endif //__ISR_H__ -------------------------------------------------------------------------------- /cores/STC89/bsp/mcu.h: -------------------------------------------------------------------------------- 1 | #ifndef _MCU_H_ 2 | #define _MCU_H_ 3 | #include "STC89C5xRC.h" 4 | 5 | #define CORE_STCYn 1 6 | 7 | #define SBIT_XSTRING(PORT,PIN) PORT##PIN 8 | 9 | /*creat by stc-isp.exer*/ 10 | #if (F_CPU == 6000000L) 11 | # define DELAY_10US(i) i = 2 12 | #elif (F_CPU == 8000000L) 13 | # define DELAY_10US(i) i = 3 14 | # define DELAY_MS(i,j) i = 2;j=72 15 | #elif (F_CPU == 10000000L) 16 | # define DELAY_10US(i) i = 4 17 | # define DELAY_MS(i,j) i = 2;j=155 18 | #elif (F_CPU == 11059200L) 19 | # define DELAY_10US(i) i = 4 20 | # define DELAY_MS(i,j) i = 2;j=199 21 | #elif (F_CPU == 12000000L) 22 | # define DELAY_10US(i) i = 5 23 | # define DELAY_MS(i,j) i = 2;j=239 24 | #elif (F_CPU == 16000000L) 25 | # define DELAY_10US(i) i = 6 26 | # define DELAY_MS(i,j) i = 16;j=140 27 | #elif (F_CPU == 18432000L) 28 | # define DELAY_10US(i) i = 7 29 | # define DELAY_MS(i,j) i = 3;j=250 30 | #elif (F_CPU == 20000000L) 31 | # define DELAY_10US(i) i = 8 32 | # define DELAY_MS(i,j) i = 4;j=58 33 | #elif (F_CPU == 22118400L) 34 | # define DELAY_10US(i) i = 9 35 | # define DELAY_MS(i,j) i = 4;j=146 36 | #elif (F_CPU == 24000000L) 37 | # define DELAY_10US(i) i = 9 38 | # define DELAY_MS(i,j) i = 4;j=225 39 | #elif (F_CPU == 25000000L) 40 | # define DELAY_10US(i) i = 10 41 | # define DELAY_MS(i,j) i = 5;j=9 42 | #elif (F_CPU == 38000000L) 43 | # define DELAY_10US(i) i = 15 44 | # define DELAY_MS(i,j) i = 7;j=37 45 | #else 46 | # error "F_CPU undef! please add me" 47 | #endif 48 | 49 | #define sei() EA=1 50 | #define cli() EA=0 51 | 52 | #define INT0_IRQn 0 53 | #define TIMER0_IRQn 1 54 | #define INT1_IRQn 2 55 | #define TIMER1_IRQn 3 56 | #define UART_IRQn 4 57 | #define TIMER2_IRQn 5 58 | 59 | /*AT98x52 兼容 中断矢量定义 */ 60 | #define IE0_VECTOR X0_INTNO //外部中断0中断号,入口地址为0003H 61 | #define TF0_VECTOR T0_INTNO //定时器0中断号,入口地址为000BH 62 | #define IE1_VECTOR X1_INTNO //外部中断1中断号,入口地址为0013H 63 | #define TF1_VECTOR T1_INTNO //定时器1中断号,入口地址为001BH 64 | #define SI0_VECTOR UART_INTNO //串口中断号,入口地址为0023H 65 | #define TF2_VECTOR T2_INTNO //定时器2中断号,入口地址为002BH 66 | #define IE2_VECTOR X2_INTNO //外部中断2中断号,入口地址为0033H 67 | #define IE3_VECTOR X3_INTNO //外部中断3中断号,入口地址为003BH 68 | 69 | #endif //_MCU_H_ 70 | -------------------------------------------------------------------------------- /cores/STC89/bsp/uart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nulllaborg/nulllab_stc51duino/8f6f54f84ea8ff84d61d0754d57b06a591d8577c/cores/STC89/bsp/uart.c -------------------------------------------------------------------------------- /cores/STC89/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - Main loop for Arduino sketches 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 | Modified 2 February 2018 for mcs51 by huaweiwx 19 | */ 20 | 21 | #define ARDUINO_MAIN 22 | 23 | #include 24 | #include "bsp/isr.h" 25 | 26 | // make sure to define prototypes for all used interrupts 27 | void init(void); 28 | //void initVariant(void); // weak 29 | 30 | int main(void) 31 | { 32 | //init(); 33 | 34 | //initVariant(); 35 | 36 | setup(); 37 | 38 | for (;;) { 39 | loop(); 40 | } 41 | } 42 | 43 | 44 | void _sdcc_external_startup(void) 45 | { 46 | //PCA0MD &= ~0x40; /*关闭内部看门狗*/ 47 | } -------------------------------------------------------------------------------- /cores/STC89/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the mcs51. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | DELAY_10US)(i) and DELAY_MS(i,j) created by stc-isp-15xx-v6.86s.exe 23 | Modified 2 February 2018 for mcs51 by huaweiwx 24 | */ 25 | 26 | #define WIRING_MAIN 27 | #include "Arduino.h" 28 | #include "bsp/mcu.h" 29 | #include "bsp/STC89C5xRC.h" 30 | // #define USE_SYSTICK 1 31 | 32 | extern void SystemClock_Config(void); 33 | 34 | /**************** 简单延时 **************************/ 35 | void delay_loop(unsigned char cnt) 36 | { 37 | while (--cnt); 38 | } 39 | 40 | 41 | #if USE_SYSTICK 42 | 43 | static volatile uint32_t dwTickCount = 0; 44 | 45 | /*************** Timer0 中断函数 *********************/ 46 | void Timer0_IRQHandler (void) //1毫秒 47 | { 48 | TH0 = TH0_INIT; TL0 = TL0_INIT; //重载定时初值 49 | TF0 = 0; //清除TF0标志 50 | dwTickCount++; //systic 计数 51 | } 52 | 53 | void init(void){ 54 | SystemClock_Config(); 55 | dwTickCount = 0; 56 | attachInterrupt(TIMER0_IRQn, Timer0_IRQHandler, 0); 57 | TMOD = 0x01; //set timer0 as mode1 (16-bit) 58 | TL0 = TL0_INIT; //initial timer0 low byte 59 | TH0 = TH0_INIT; //initial timer0 high byte 60 | TR0 = 1; //timer0 start running 61 | ET0 = 1; //enable timer0 interrupt 62 | EA = 1; //open global interrupt switch 63 | } 64 | 65 | unsigned long millis() 66 | { 67 | return dwTickCount; 68 | } 69 | 70 | unsigned long micros() 71 | { 72 | uint32_t m,u; 73 | uint8_t hi,lo; 74 | 75 | lo = TL0; hi = TH0; 76 | u = dwTickCount*1000; 77 | 78 | m = ((((hi<<8)| lo)- T1MS)*1000); 79 | u += m/T1MS; 80 | 81 | return u; 82 | } 83 | 84 | void delay(unsigned int ms){ 85 | uint32_t s = dwTickCount; 86 | uint32_t e = s + ms; 87 | if(e < s){ 88 | while(e < millis()); 89 | } 90 | while(millis()< e); 91 | } 92 | 93 | void delayMicroseconds(unsigned int us) 94 | { 95 | uint32_t s = micros(); 96 | uint32_t e = s + us; 97 | if(e < s){ 98 | while(e < micros()); 99 | } 100 | while(micros()< e); 101 | } 102 | 103 | #else 104 | 105 | void init(void){ 106 | SystemClock_Config(); 107 | } 108 | 109 | void delay10us(unsigned int us) 110 | { 111 | unsigned char i; 112 | do{ 113 | DELAY_10US(i); 114 | while (--i); 115 | }while(--us); 116 | } 117 | 118 | void delay(unsigned int ms) 119 | { 120 | unsigned char i, j; 121 | 122 | do { 123 | DELAY_MS(i,j); 124 | do { 125 | while (--j); 126 | } while (--i); 127 | }while (--ms); 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /cores/STC89/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h 3 | Modified 2 February 2018 for mcs51 by huaweiwx 4 | */ 5 | #ifndef _WIRING_H_ 6 | #define _WIRING_H_ 7 | 8 | #ifndef USE_SYSTICK 9 | #define USE_SYSTICK 1 10 | #endif 11 | 12 | #define CORE_STCYn 1 13 | 14 | #if CORE_STCYn > 1 15 | #define T1MS (65536L-F_CPU/1000) //1ms timer calculation method in 1T mode 16 | #elif CORE_STCYn == 1 17 | #define T1MS (65536L-F_CPU/12/1000) //1ms timer calculation method in 12T mode 18 | #else 19 | #error NOT STC core or CORE_STCYn undef! 20 | #endif 21 | 22 | #define TH0_INIT (T1MS >> 8) 23 | #define TL0_INIT (T1MS & 0xff) 24 | 25 | void delay_loop(unsigned char cnt); 26 | 27 | 28 | #if USE_SYSTICK 29 | 30 | unsigned long millis(); 31 | unsigned long micros(); 32 | void delay(unsigned int ms); 33 | void delayMicroseconds(unsigned int us); 34 | 35 | #else 36 | 37 | void delay10us(unsigned int us); 38 | void delay(unsigned int ms); 39 | 40 | #define delayMicroseconds(us) if(us>10){delay10us(us/10);}else{delay_loop(us);} 41 | 42 | #endif //USE_SYSTICK 43 | 44 | #endif //_WIRING_H_ 45 | -------------------------------------------------------------------------------- /cores/STC89/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 2 February 2018 for mcs51 by huaweiwx 23 | */ 24 | #include "Arduino.h" 25 | 26 | /* This char array helps to convert pin map to port*/ 27 | const uint8_t pinToMask[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 28 | 29 | uint8_t portRead(uint8_t ucPort){ 30 | uint8_t rtn = 0; 31 | switch (ucPort){ 32 | #ifdef SFR_P0 33 | case 0: 34 | rtn = P0; 35 | break; 36 | #endif 37 | #ifdef SFR_P1 38 | case 1: 39 | rtn = P1; 40 | break; 41 | #endif 42 | #ifdef SFR_P2 43 | case 2: 44 | rtn = P2; 45 | break; 46 | #endif 47 | #ifdef SFR_P3 48 | case 3: 49 | rtn = P3; 50 | break; 51 | #endif 52 | #ifdef SFR_P4 53 | case 4: 54 | rtn = P4; 55 | break; 56 | #endif 57 | #ifdef SFR_P5 58 | case 5: 59 | rtn = P5; 60 | break; 61 | #endif 62 | } 63 | return rtn; 64 | } 65 | 66 | void portWrite(uint8_t ucPort,uint8_t val){ 67 | switch (ucPort){ 68 | #ifdef SFR_P0 69 | case 0: 70 | P0 = val; 71 | break; 72 | #endif 73 | #ifdef SFR_P1 74 | case 1: 75 | P1 = val; 76 | break; 77 | #endif 78 | #ifdef SFR_P2 79 | case 2: 80 | P2 = val; 81 | break; 82 | #endif 83 | #ifdef SFR_P3 84 | case 3: 85 | P3 = val; 86 | break; 87 | #endif 88 | #ifdef SFR_P4 89 | case 4: 90 | P4 = val; 91 | break; 92 | #endif 93 | #ifdef SFR_P5 94 | case 5: 95 | P5 = val; 96 | break; 97 | #endif 98 | } 99 | } 100 | 101 | static void digitalWriteHigh(uint8_t pin){ 102 | uint8_t ucPort, ucPin,mask; 103 | if(pin & 0x88) return; /*0b10001000(0x88) is not a pin*/ 104 | ucPort = pin >>4; 105 | ucPin = pin & 0x07; 106 | mask = pinToMask[ucPin]; 107 | mask |= portRead(ucPort); 108 | portWrite(ucPort,mask); 109 | } 110 | 111 | static void digitalWriteLow(uint8_t pin){ 112 | uint8_t ucPort,ucPin; 113 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 114 | ucPort = pin >>4; 115 | ucPin = pin & 0x07; 116 | portWrite(ucPort,portRead(ucPort) & (~pinToMask[ucPin])); 117 | } 118 | 119 | void digitalToggle(uint8_t pin){ 120 | uint8_t ucPort,ucPin,mask; 121 | if(NOT_A_PORTPIN(pin)) return; /*0b10001000(0x88) is not a pin*/ 122 | ucPort = pin >>4; 123 | ucPin = pin & 0x07; 124 | mask = pinToMask[ucPin]; 125 | mask ^= portRead(ucPort); 126 | portWrite(ucPort,mask); 127 | } 128 | 129 | void digitalWrite(uint8_t pin, bool val) 130 | { 131 | if(val) { 132 | digitalWriteHigh(pin); 133 | }else{ 134 | digitalWriteLow(pin); 135 | } 136 | } 137 | 138 | bool digitalRead(uint8_t pin) 139 | { 140 | uint8_t readp =0; 141 | uint8_t ucPort,ucPin; 142 | if(NOT_A_PORTPIN(pin)) return 0; /*0b10001000(0x88) is not a pin*/ 143 | ucPort = pin >>4; 144 | ucPin = pin & 0x07; 145 | 146 | readp = portRead(ucPort); 147 | return (readp & pinToMask[ucPin]); 148 | } 149 | 150 | void pinMode(uint8_t pin, uint8_t mode){ 151 | if(mode == INPUT) digitalWriteHigh(pin); /*STC89/90 is QUASI/OD, set to HIGH for read */ 152 | } 153 | -------------------------------------------------------------------------------- /cores/STC89/wiring_digital.h: -------------------------------------------------------------------------------- 1 | /* 2 | Modified 2 February 2018 for mcs51 by huaweiwx 3 | */ 4 | #ifndef __WIRING_DIGITAL_H__ 5 | #define __WIRING_DIGITAL_H__ 6 | 7 | /* 8 | void pinMode(uint8_t pin, uint8_t mode); 9 | uint8_t portRead(uint8_t ucPort); 10 | void digitalWriteHigh(uint8_t pin); 11 | void digitalWriteLow(uint8_t pin); 12 | void portWrite(uint8_t ucPort,uint8_t val); 13 | void digitalWrite(uint8_t pin, bool val); 14 | void digitalToggle(uint8_t pin); 15 | bool digitalRead(uint8_t pin); 16 | */ 17 | 18 | #endif //__WIRING_DIGITAL_H__ -------------------------------------------------------------------------------- /cores/STC89/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | */ 22 | #define WIRING_SHIFT_MAIN 23 | 24 | #include "Arduino.h" 25 | 26 | /* 27 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 28 | uint8_t value = 0; 29 | uint8_t i; 30 | 31 | for (i = 0; i < 8; ++i) { 32 | digitalWriteHigh(clockPin); 33 | if (bitOrder == LSBFIRST) 34 | value |= digitalRead(dataPin) << i; 35 | else 36 | value |= digitalRead(dataPin) << (7 - i); 37 | digitalWriteLow(clockPin); 38 | } 39 | return value; 40 | } 41 | 42 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 43 | { 44 | uint8_t i; 45 | 46 | for (i = 0; i < 8; i++) { 47 | if (bitOrder == LSBFIRST) 48 | digitalWrite(dataPin, !!(val & (1 << i))); 49 | else 50 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 51 | 52 | digitalWriteHigh(clockPin); 53 | digitalWriteLow(clockPin); 54 | } 55 | } 56 | */ 57 | -------------------------------------------------------------------------------- /doc/board_chioce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nulllaborg/nulllab_stc51duino/8f6f54f84ea8ff84d61d0754d57b06a591d8577c/doc/board_chioce.png -------------------------------------------------------------------------------- /doc/board_manager_zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nulllaborg/nulllab_stc51duino/8f6f54f84ea8ff84d61d0754d57b06a591d8577c/doc/board_manager_zh.png -------------------------------------------------------------------------------- /doc/option_zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nulllaborg/nulllab_stc51duino/8f6f54f84ea8ff84d61d0754d57b06a591d8577c/doc/option_zh.png -------------------------------------------------------------------------------- /package_nulllab_stc51duino_proxy_index.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "STC51duino", 5 | "maintainer": "nulllab", 6 | "websiteURL": "https://github.com/nulllaborg/nulllab_stc51duino", 7 | "email": "nulljun@nulllab.cn", 8 | "help": { 9 | "online": "www.nulllab.org" 10 | }, 11 | "platforms" : [ 12 | { 13 | "name": "STC51Duino mcs51 plain C core (non-C++)", 14 | "architecture": "mcs51", 15 | "version": "0.0.1", 16 | "category": "Contributed", 17 | "url": "https://github.com.cnpmjs.org/nulllaborg/nulllab_stc51duino/releases/download/v0.0.1/nulllab_stc51duino-0.0.1.zip", 18 | "archiveFileName": "nulllab_stc51duino-0.0.1.zip", 19 | "help": { 20 | "online": "https://github.com/nulllab/nulllab_stc51duino/issues" 21 | }, 22 | "boards": [ 23 | {"name": "STC89C52RC_Duino"}, 24 | {"name": "STC8A/G/H/F"}, 25 | {"name": "STC15F/L/W"}, 26 | {"name": "STC12"}, 27 | {"name": "STC89"} 28 | ], 29 | "toolsDependencies": [ 30 | { 31 | "name": "mcs51tools", 32 | "version": "2021.12.20", 33 | "packager": "STC51duino" 34 | }, 35 | { 36 | "name": "sdcc", 37 | "version": "v1.0", 38 | "packager": "STC51duino" 39 | } 40 | ] 41 | } 42 | ], 43 | "tools" : [ 44 | { 45 | "name": "mcs51tools", 46 | "version": "2021.12.20", 47 | "systems": [ 48 | { 49 | "host": "i686-mingw32", 50 | "url": "https://github.com.cnpmjs.org/nulllaborg/nulllab_stc51duino/releases/download/v0.0.1/mcs51tools-i586-mingw32-v1.0.zip", 51 | "archiveFileName":"mcs51tools-i586-mingw32-v1.0.zip", 52 | "checksum": "SHA-256:deb01e3bca29a068d999e08a810eb7fff6e4f5c9dec76f4ccd74f635e5e1d494", 53 | "size": "3232764" 54 | } 55 | ] 56 | }, 57 | { 58 | "name": "sdcc", 59 | "version": "v1.0", 60 | "systems": [ 61 | { 62 | "host": "i686-mingw32", 63 | "url": "https://github.com.cnpmjs.org/nulllaborg/nulllab_stc51duino/releases/download/v0.0.1/sdcc-mingw32-v1.0.zip", 64 | "archiveFileName": "sdcc-mingw32-v1.0.zip", 65 | "checksum": "SHA-256:68f1eb6775aca6dfb68026dd8292cf4b3fc52921991fba56afc0a10a7cfe9be1", 66 | "size": "4409341" 67 | },{ 68 | "host": "x86_64-apple-darwin", 69 | "url": "https://github.com.cnpmjs.org/nulllaborg/nulllab_stc51duino/releases/download/v0.0.1/sdcc-macosx-v1.0.zip", 70 | "archiveFileName": "sdcc-macosx-v1.0.zip", 71 | "checksum": "SHA-256:a35c86fed596b52d4e8e27bcb8f9f24506fac1cedbde3d61b50a5ed293d264f9", 72 | "size": "3816529" 73 | },{ 74 | "host": "x86_64-pc-linux-gnu", 75 | "url": "https://github.com.cnpmjs.org/nulllaborg/nulllab_stc51duino/releases/download/v0.0.1/sdcc-linux-v1.0.zip", 76 | "archiveFileName": "sdcc-linux-v1.0.zip", 77 | "checksum": "SHA-256:6ef5627753c0761238d717471ee003acc20d33447e3ec7c5adaa3ce2e3523594", 78 | "size": "3816529" 79 | } 80 | ] 81 | } 82 | ] 83 | } 84 | ] 85 | } 86 | -------------------------------------------------------------------------------- /platform.txt: -------------------------------------------------------------------------------- 1 | 2 | # Arduino STC51 Core and platform. 3 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification 4 | # Modified by nulllab 5 | 6 | name=STC51 Boards 7 | version=0.0.1 8 | 9 | # General folder structure variables 10 | # ---------------------------------- 11 | # For Board Manager installs these variables are already predefined and will 12 | # not be overwritten. This assignment is done only for manual installs. 13 | #runtime.tools.sdcc.path={runtime.hardware.path}/tools/sdcc 14 | #runtime.tools.mcs51tools.path={runtime.hardware.path}/tools 15 | 16 | # MCS51 compile variables 17 | # --------------------- 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.mcs51tools.path}/wrapper 28 | compiler.wrapper.path.windows={runtime.tools.mcs51tools.path}/win/busybox" ash "{runtime.tools.mcs51tools.path}/wrapper 29 | compiler.tools.path={runtime.tools.sdcc.path}/bin 30 | 31 | compiler.c.cmd=sdcc 32 | compiler.c.wrapper=sdcc.sh 33 | compiler.c.flags=-MMD -c -Ddouble=float -D__PROG_TYPES_COMPAT__ {compiler.warning_flags} --model-{build.stdlib} 34 | compiler.c.elf.flags=--code-size {upload.maximum_size} --iram-size {upload.maximum_idata_size} --xram-size {upload.maximum_xdata_size} --model-{build.stdlib} 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=sdobjcopy 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=sdobjcopy 53 | compiler.elf2hex.flags=-O ihex -R DATA -R INITIALIZED -R SSEG 54 | 55 | compiler.syslibs.stdlib.path.windows={runtime.tools.sdcc.path} 56 | 57 | compiler.ldflags= 58 | 59 | compiler.size.cmd=grep 60 | compiler.size.wrapper=sdcc-size.sh 61 | 62 | compiler.includes="-I{compiler.syslibs.stdlib.path}/inc" "-I{compiler.syslibs.stdlib.path}/include/msc51" 63 | 64 | # This can be overridden in boards.txt 65 | build.extra_flags= 66 | build.vcc= 67 | 68 | # These can be overridden in platform.local.txt 69 | compiler.c.extra_flags= 70 | compiler.c.elf.extra_flags= 71 | compiler.S.extra_flags= 72 | compiler.cpp.extra_flags= 73 | compiler.ar.extra_flags= 74 | compiler.objcopy.eep.extra_flags= 75 | compiler.elf2hex.extra_flags= 76 | 77 | # MCS51 compile patterns 78 | # -------------------- 79 | 80 | ## Compile c files (re1) 81 | 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} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.vcc} {compiler.includes} {includes} 82 | #recipe.c.o.pattern="{compiler.path}/{compiler.c.cmd}" "{source_file}" "{object_file}" re1 {compiler.c.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.vcc} {compiler.includes} {includes} 83 | 84 | ## Compile c++ files (re2) 85 | 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} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.vcc} {compiler.includes} {includes} 86 | 87 | ##FIXME Compile S files (re3) 88 | recipe.S.o.pattern="{compiler.path}/{compiler.c.cmd}" re3 {compiler.S.flags} -mmcs51 -D{build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.includes} {includes} "{source_file}" -o "{object_file}" 89 | 90 | ## Create archives (re4) 91 | #archive_file_path={build.path}/{archive_file} 92 | 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} 93 | 94 | ## Combine gc-sections, archives, and objects 95 | 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/{build.stdlib}" {compiler.c.elf.flags} -mmcs51 -D{build.mcu} {compiler.c.elf.extra_flags} {object_files} "{build.path}/{archive_file}" "{build.path}/core/main.c.rel" -lmcs51 -llibsdcc {build.extlib} --out-fmt-ihx -o "{build.path}/{build.project_name}.hex" 96 | 97 | ## Create output files (.eep and .hex) 98 | #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" 99 | #recipe.objcopy.ihx.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" 100 | 101 | ## Save hex 102 | recipe.output.tmp_file.hex={build.project_name}.hex 103 | recipe.output.save_file.hex={build.project_name}.{build.variant}.hex 104 | recipe.output.tmp_file.mem={build.project_name}.mem 105 | recipe.output.save_file.mem={build.project_name}.{build.variant}.mem 106 | 107 | ## Compute size 108 | recipe.size.pattern="{compiler.wrapper.path}/{compiler.size.wrapper}" "{runtime.tools.mcs51tools.path}/win/{compiler.size.cmd}" "{build.path}/{build.project_name}.mem" 109 | recipe.size.regex=^(?:HOME|GSINIT|GSFINAL|CODE|INITIALIZER)\s+([0-9]+).* 110 | recipe.size.regex.data=^(?:XSEG|PSEG|ISEG|BSEG)\s+([0-9]+).* 111 | recipe.size.regex.eeprom=^(?:EEPROM)\s+([0-9]+).* 112 | 113 | ## Preprocessor (re11, re12) 114 | preproc.includes.flags=-M -MG -MP 115 | recipe.preproc.includes=asfaf"{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} -DHIRC_VALUE={build.hirc} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" 116 | preproc.macros.flags=-E -MC 117 | 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} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} {compiler.includes} 118 | 119 | # ------------------ 120 | # stc_isp Uploader 121 | tools.stc_isp.cmd=stc_isp 122 | tools.stc_isp.path={runtime.hardware.path}/tools/linux 123 | tools.stc_isp.path.windows={runtime.hardware.path}/tools/win/stc 124 | tools.stc_isp.path.macosx={runtime.hardware.path}/tools/macosx 125 | #tools.stc_isp.path.linux64={runtime.hardware.path}/tools/linux64 126 | 127 | #tools.stc_isp.upload.params.verify= 128 | tools.stc_isp.upload.params.verbose= 129 | tools.stc_isp.upload.params.quiet= 130 | tools.stc_isp.upload.pattern="{path}/{cmd}" "{serial.port}" "{build.path}/{build.project_name}.hex" -pause -loop 131 | -------------------------------------------------------------------------------- /variants/STC15/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 2 February 2018 for STC15 by huaweiwx 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | #define P0_0 0x00 /*P00*/ 29 | #define P0_1 0x01 /*P01*/ 30 | #define P0_2 0x02 /*P02*/ 31 | #define P0_3 0x03 /*P03*/ 32 | #define P0_4 0x04 /*P04*/ 33 | #define P0_5 0x05 /*P05*/ 34 | #define P0_6 0x06 /*P06*/ 35 | #define P0_7 0x07 /*P07*/ 36 | #define P1_0 0x10 /*P10*/ 37 | #define P1_1 0x11 /*P11*/ 38 | #define P1_2 0x12 /*P12*/ 39 | #define P1_3 0x13 /*P13*/ 40 | #define P1_4 0x14 /*P14*/ 41 | #define P1_5 0x15 /*P15*/ 42 | #define P1_6 0x16 /*P16*/ 43 | #define P1_7 0x17 /*P17*/ 44 | #define P2_0 0x20 /*P20*/ 45 | #define P2_1 0x21 /*P21*/ 46 | #define P2_2 0x22 /*P22*/ 47 | #define P2_3 0x23 /*P23*/ 48 | #define P2_4 0x24 /*P24*/ 49 | #define P2_5 0x25 /*P25*/ 50 | #define P2_6 0x26 /*P26*/ 51 | #define P2_7 0x27 /*P27*/ 52 | #define P3_0 0x30 /*P30*/ 53 | #define P3_1 0x31 /*P31*/ 54 | #define P3_2 0x32 /*P32*/ 55 | #define P3_3 0x33 /*P33*/ 56 | #define P3_4 0x34 /*P34*/ 57 | #define P3_5 0x35 /*P35*/ 58 | #define P3_6 0x36 /*P36*/ 59 | #define P3_7 0x37 /*P37*/ 60 | #define P4_0 0x40 /*P40*/ 61 | #define P4_1 0x41 /*P41*/ 62 | #define P4_2 0x42 /*P42*/ 63 | #define P4_3 0x43 /*P43*/ 64 | #define P4_4 0x44 /*P44*/ 65 | #define P4_5 0x45 /*P45*/ 66 | #define P4_6 0x46 /*P46*/ 67 | #define P4_7 0x47 /*P47*/ 68 | 69 | 70 | #define A0 AIN0 /* P1_0 */ 71 | #define A1 AIN1 /* P1_1 */ 72 | #define A2 AIN2 /* P1_2 */ 73 | #define A3 AIN3 /* P1_3 */ 74 | #define A4 AIN4 /* P1_4 */ 75 | #define A5 AIN5 /* P1_5 */ 76 | #define A6 AIN6 /* P1_6 */ 77 | #define A7 AIN7 /* P1_7 */ 78 | 79 | /*在工程中 HAL_config.h 或 boards.txt 中定义,可覆盖以下定义*/ 80 | #ifndef LED_BUILTIN 81 | #define LED_BUILTIN P0_0 /*fixed me!*/ 82 | #define LED_BUILTIN_MASK 0x00 /* low in on */ 83 | #endif 84 | 85 | #ifndef POWER_VCC 86 | # ifdef MENU_VCC 87 | # define POWER_VCC MENU_VCC 88 | # else 89 | # define POWER_VCC 5000 90 | # endif 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /variants/STC15/variant.c: -------------------------------------------------------------------------------- 1 | 2 | #include "Arduino.h" 3 | 4 | void SystemClock_Config(void) { 5 | 6 | } -------------------------------------------------------------------------------- /variants/STC8/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 2 February 2018 for STC8 by huaweiwx 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | /*44PIN*/ 29 | #define P0_0 0x00 /*P00*/ 30 | #define P0_1 0x01 /*P01*/ 31 | #define P0_2 0x02 /*P02*/ 32 | #define P0_3 0x03 /*P03*/ 33 | #define P0_4 0x04 /*P04*/ 34 | #define P0_5 0x05 /*P05*/ 35 | #define P0_6 0x06 /*P06*/ 36 | #define P0_7 0x07 /*P07*/ 37 | #define P1_0 0x10 /*P10*/ 38 | #define P1_1 0x11 /*P11*/ 39 | #define P1_2 0x12 /*P12*/ 40 | #define P1_3 0x13 /*P13*/ 41 | #define P1_4 0x14 /*P14*/ 42 | #define P1_5 0x15 /*P15*/ 43 | #define P1_6 0x16 /*P16*/ 44 | #define P1_7 0x17 /*P17*/ 45 | #define P2_0 0x20 /*P20*/ 46 | #define P2_1 0x21 /*P21*/ 47 | #define P2_2 0x22 /*P22*/ 48 | #define P2_3 0x23 /*P23*/ 49 | #define P2_4 0x24 /*P24*/ 50 | #define P2_5 0x25 /*P25*/ 51 | #define P2_6 0x26 /*P26*/ 52 | #define P2_7 0x27 /*P27*/ 53 | #define P3_0 0x30 /*P30*/ 54 | #define P3_1 0x31 /*P31*/ 55 | #define P3_2 0x32 /*P32*/ 56 | #define P3_3 0x33 /*P33*/ 57 | #define P3_4 0x34 /*P34*/ 58 | #define P3_5 0x35 /*P35*/ 59 | #define P3_6 0x36 /*P36*/ 60 | #define P3_7 0x37 /*P37*/ 61 | #define P4_0 0x40 /*P40*/ 62 | #define P4_1 0x41 /*P41*/ 63 | #define P4_2 0x42 /*P42*/ 64 | #define P4_3 0x43 /*P43*/ 65 | #define P4_4 0x44 /*P44*/ 66 | #define P4_5 0x45 /*P45*/ 67 | #define P4_6 0x46 /*P46*/ 68 | #define P4_7 0x47 /*P47*/ 69 | #define P5_0 0x50 /*P50*/ 70 | #define P5_1 0x51 /*P51*/ 71 | #define P5_2 0x52 /*P52*/ 72 | #define P5_3 0x53 /*P53*/ 73 | 74 | #if defined(STC8F8K)||defined(STC8F4K) 75 | #define A0 AIN0 /* P1_0 */ 76 | #define A1 AIN1 /* P1_1 */ 77 | #define A2 AIN2 /* P1_2 */ 78 | #define A3 AIN3 /* P1_3 */ 79 | #define A4 AIN4 /* P1_4 */ 80 | #define A5 AIN5 /* P1_5 */ 81 | #define A6 AIN6 /* P1_6 */ 82 | #define A7 AIN7 /* P1_7 */ 83 | #define A8 AIN8 /* P0_0 */ 84 | #define A9 AIN9 /* P0_1 */ 85 | #define A10 AIN10 /* P0_2 */ 86 | #define A11 AIN11 /* P0_3 */ 87 | #define A12 AIN12 /* P0_4 */ 88 | #define A13 AIN13 /* P0_5 */ 89 | #define A14 AIN14 /* P0_6 */ 90 | #define A15 AIN15 /* vref */ 91 | #endif 92 | 93 | /*在工程中 HAL_config.h 或 boards.txt 中定义,可覆盖以下定义*/ 94 | #ifndef LED_BUILTIN 95 | #define LED_BUILTIN P0_0 /*fixed me!*/ 96 | #define LED_BUILTIN_MASK 0x00 /* low in on */ 97 | #endif 98 | 99 | #ifndef POWER_VCC 100 | # ifdef MENU_VCC 101 | # define POWER_VCC MENU_VCC 102 | # else 103 | # define POWER_VCC 5000 104 | # endif 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /variants/STC8/variant.c: -------------------------------------------------------------------------------- 1 | 2 | #include "Arduino.h" 3 | 4 | void SystemClock_Config(void) { 5 | #ifdef HXT 6 | P_SW2 = 0x80; 7 | XOSCCR = 0xc0; //启动外部晶振 8 | while (!(XOSCCR & 1)); //等待时钟稳定 9 | CKDIV = 0x00; //时钟不分频 10 | CKSEL = 0x01; //选择外部晶振 11 | #else 12 | char *IRC; 13 | #if (F_CPU == 22118400UL)||(F_CPU == 11059200UL) 14 | IRC = (__idata char *)0xfa; //22M 15 | #else 16 | IRC = (__idata char *) 0xfb; //24M 17 | #endif 18 | IRCCR = *IRC; //装载24MHz/22.1184MHz的IRC参数 19 | 20 | #if HRC>0 21 | CLKDIV = HRC; //主时钟预分频 22 | #endif 23 | P_SW2 = 0x80; 24 | CKSEL = 0x00; //选择内部IRC ( 默认 ) 25 | #endif 26 | P_SW2 = 0x00; 27 | 28 | } -------------------------------------------------------------------------------- /variants/STC89/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_h 2 | #define Pins_Arduino_h 3 | 4 | #define P0_0 0x00 /*P00*/ 5 | #define P0_1 0x01 /*P01*/ 6 | #define P0_2 0x02 /*P02*/ 7 | #define P0_3 0x03 /*P03*/ 8 | #define P0_4 0x04 /*P04*/ 9 | #define P0_5 0x05 /*P05*/ 10 | #define P0_6 0x06 /*P06*/ 11 | #define P0_7 0x07 /*P07*/ 12 | #define P1_0 0x10 /*P10*/ 13 | #define P1_1 0x11 /*P11*/ 14 | #define P1_2 0x12 /*P12*/ 15 | #define P1_3 0x13 /*P13*/ 16 | #define P1_4 0x14 /*P14*/ 17 | #define P1_5 0x15 /*P15*/ 18 | #define P1_6 0x16 /*P16*/ 19 | #define P1_7 0x17 /*P17*/ 20 | #define P2_0 0x20 /*P20*/ 21 | #define P2_1 0x21 /*P21*/ 22 | #define P2_2 0x22 /*P22*/ 23 | #define P2_3 0x23 /*P23*/ 24 | #define P2_4 0x24 /*P24*/ 25 | #define P2_5 0x25 /*P25*/ 26 | #define P2_6 0x26 /*P26*/ 27 | #define P2_7 0x27 /*P27*/ 28 | #define P3_0 0x30 /*P30*/ 29 | #define P3_1 0x31 /*P31*/ 30 | #define P3_2 0x32 /*P32*/ 31 | #define P3_3 0x33 /*P33*/ 32 | #define P3_4 0x34 /*P34*/ 33 | #define P3_5 0x35 /*P35*/ 34 | #define P3_6 0x36 /*P36*/ 35 | #define P3_7 0x37 /*P37*/ 36 | #define P4_0 0x40 /*P40*/ 37 | #define P4_1 0x41 /*P41*/ 38 | #define P4_2 0x42 /*P42*/ 39 | #define P4_3 0x43 /*P43*/ 40 | #define P4_4 0x44 /*P44*/ 41 | #define P4_5 0x45 /*P45*/ 42 | #define P4_6 0x46 /*P46*/ 43 | #define P4_7 0x47 /*P47*/ 44 | 45 | /*在工程中 HAL_config.h 或 boards.txt 中定义,可覆盖以下定义*/ 46 | #ifndef LED_BUILTIN 47 | #define LED_BUILTIN P0_0 /*fixed me!*/ 48 | #define LED_BUILTIN_MASK 0x00 /* low in on */ 49 | #endif 50 | 51 | #ifndef POWER_VCC 52 | # ifdef MENU_VCC 53 | # define POWER_VCC MENU_VCC 54 | # else 55 | # define POWER_VCC 5000 56 | # endif 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /variants/STC89/variant.c: -------------------------------------------------------------------------------- 1 | 2 | #include "Arduino.h" 3 | 4 | void SystemClock_Config(void) { 5 | 6 | } --------------------------------------------------------------------------------