专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
经不住诱惑,今天开始玩STM8!麻烦过来人进来讲讲心得
2019-12-26 18:53
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
19516
77
77
1、买的STM8 value line discovery板刚到手,从最简单的STM8S003开始吧。
2、下载了STVD/COSMIC。COSMIC_32K坛里有和谐好的,不过要先下载原版安装。
3、争取今晚把LED点亮。
4、其实我很看好STM8L152,之后要测试一下耗电和ADC性能。
5、纯业余玩的,还没想好弄点啥……
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
77条回答
millwood0
2019-12-29 15:48
here is gpio.h
#ifndef __GPIO_H
#define __GPIO_H
//port-related macros for stm8s
//DEFAULT: OPEN DRAIN OUTPUT
//set Px_CR1 and clear Px_CR2 to turn to push_pull output
#define IO_SET(port, bits) port |= (bits) //set bits on port
#define IO_CLR(port, bits) port &=~(bits) //clear bits on port
#define IO_FLP(port, bits) port ^= (bits) //flip bits on port
#define IO_GET(port, bits) ((port) & (bits)) //return bits on port
#define IO_OUT(ddr, bits) ddr |= (bits) //set bits as output. stm8s: sets a bit to make it an output
#define IO_IN(ddr, bits) ddr &=~(bits) //set bits as input. stm8s: clears a bit to make it an input
#define NOP() asm("nop") //nop
#define NOP2() {NOP(); NOP();}
#define NOP4() {NOP2(); NOP2();}
#define NOP8() {NOP4(); NOP4();}
#define NOP16() {NOP8(); NOP8();}
#ifndef ei
#define ei() asm("rim") //enable all interrupts
#endif
#ifndef di
#define di() asm("sim") //disable all interrupts
#endif
#define __enable_interrupt() ei()
#define __disable_interrupt() di()
//fmaster = 16Mhz / 8 -> 2Mhz
//fcpu = fmaster / 1 -> 2Mhz
#define F_MASTER (16000000ul / 8) //fmaster -> default to hsi (16mhz), divided by 8
#define F_CPU (F_MASTER) //fcpu
//define ld1 on stm8sdiscovery board
#define LED1_PORT PD_ODR
#define LED1_DDR PD_DDR
#define LED1 (1<<0)
//#define LED1_ON() IO_CLR(LED1_PORT, LED1) //turn on the leds, assuming output mode
//#define LED1_OFF() IO_SET(LED1_PORT, LED1) //turn off the leds, assuming output mode
//#define LED1_FLP() IO_FLP(LED1_PORT, LED1) //flip leds
//void (*mcu_reset)(void) = 0x0000; //jump to 0x0000 -> software reset
//simple multiples
#define x1(val) (val) //multiply val by 1
#define x2(val) (((val) << 1)) //multiply val by 2
#define x3(val) (x2(val) + (val)) //multiply val by 3
#define x4(val) (((val) << 2)) //multiply val by 4
#define x5(val) (x4(val) + (val)) //multiply val by 5
#define x6(val) (x4(val) + x2(val)) //multiply val by 6
#define x7(val) (x6(val) + (val)) //multiply val by 7
#define x8(val) ((val) << 3) //multiply val by 8
#define x9(val) (x8(val) + (val)) //multiply val by 9
//multiples of 10s
#define x10(val) (x8(val) + x2(val)) //multiply val by 10
#define x100(val) (x10(x10(val))) //multiply val by 100
#define x1000(val) (x100(x10(val))) //multiply val by 1000
#define x1k(val) x1000(val) //multiply val by 1000
#define x10k(val) (x100(x100(val))) //multiply val by 10000
#define x20(val) (x2(x10(val)))
#define x30(val) (x3(x10(val)))
#define x40(val) (x4(x10(val)))
#define x50(val) (x5(x10(val)))
#define x60(val) (x6(x10(val)))
#define x70(val) (x7(x10(val)))
#define x80(val) (x8(x10(val)))
#define x90(val) (x9(x10(val)))
//multiples of 100s
#define x200(val) (x2(x100(val)))
#define x300(val) (x3(x100(val)))
#define x400(val) (x4(x100(val)))
#define x500(val) (x5(x100(val)))
#define x600(val) (x6(x100(val)))
#define x700(val) (x7(x100(val)))
#define x800(val) (x8(x100(val)))
#define x900(val) (x9(x100(val)))
//custom definitions
#define x34(val) (x30(val) + x4(val)) //multiply val by 34
#define x97(val) (x90(val) + x7(val)) //multiply val by 97x
#endif //__gpio_h_
复制代码
you don't need to have all of it. it predefines LED1 (on PD0).
as well as F_CPU (running at 16Mhz / 8).
加载中...
查看其它77个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
- #ifndef __GPIO_H
- #define __GPIO_H
- //port-related macros for stm8s
- //DEFAULT: OPEN DRAIN OUTPUT
- //set Px_CR1 and clear Px_CR2 to turn to push_pull output
- #define IO_SET(port, bits) port |= (bits) //set bits on port
- #define IO_CLR(port, bits) port &=~(bits) //clear bits on port
- #define IO_FLP(port, bits) port ^= (bits) //flip bits on port
- #define IO_GET(port, bits) ((port) & (bits)) //return bits on port
- #define IO_OUT(ddr, bits) ddr |= (bits) //set bits as output. stm8s: sets a bit to make it an output
- #define IO_IN(ddr, bits) ddr &=~(bits) //set bits as input. stm8s: clears a bit to make it an input
- #define NOP() asm("nop") //nop
- #define NOP2() {NOP(); NOP();}
- #define NOP4() {NOP2(); NOP2();}
- #define NOP8() {NOP4(); NOP4();}
- #define NOP16() {NOP8(); NOP8();}
- #ifndef ei
- #define ei() asm("rim") //enable all interrupts
- #endif
- #ifndef di
- #define di() asm("sim") //disable all interrupts
- #endif
- #define __enable_interrupt() ei()
- #define __disable_interrupt() di()
- //fmaster = 16Mhz / 8 -> 2Mhz
- //fcpu = fmaster / 1 -> 2Mhz
- #define F_MASTER (16000000ul / 8) //fmaster -> default to hsi (16mhz), divided by 8
- #define F_CPU (F_MASTER) //fcpu
- //define ld1 on stm8sdiscovery board
- #define LED1_PORT PD_ODR
- #define LED1_DDR PD_DDR
- #define LED1 (1<<0)
- //#define LED1_ON() IO_CLR(LED1_PORT, LED1) //turn on the leds, assuming output mode
- //#define LED1_OFF() IO_SET(LED1_PORT, LED1) //turn off the leds, assuming output mode
- //#define LED1_FLP() IO_FLP(LED1_PORT, LED1) //flip leds
- //void (*mcu_reset)(void) = 0x0000; //jump to 0x0000 -> software reset
- //simple multiples
- #define x1(val) (val) //multiply val by 1
- #define x2(val) (((val) << 1)) //multiply val by 2
- #define x3(val) (x2(val) + (val)) //multiply val by 3
- #define x4(val) (((val) << 2)) //multiply val by 4
- #define x5(val) (x4(val) + (val)) //multiply val by 5
- #define x6(val) (x4(val) + x2(val)) //multiply val by 6
- #define x7(val) (x6(val) + (val)) //multiply val by 7
- #define x8(val) ((val) << 3) //multiply val by 8
- #define x9(val) (x8(val) + (val)) //multiply val by 9
- //multiples of 10s
- #define x10(val) (x8(val) + x2(val)) //multiply val by 10
- #define x100(val) (x10(x10(val))) //multiply val by 100
- #define x1000(val) (x100(x10(val))) //multiply val by 1000
- #define x1k(val) x1000(val) //multiply val by 1000
- #define x10k(val) (x100(x100(val))) //multiply val by 10000
- #define x20(val) (x2(x10(val)))
- #define x30(val) (x3(x10(val)))
- #define x40(val) (x4(x10(val)))
- #define x50(val) (x5(x10(val)))
- #define x60(val) (x6(x10(val)))
- #define x70(val) (x7(x10(val)))
- #define x80(val) (x8(x10(val)))
- #define x90(val) (x9(x10(val)))
- //multiples of 100s
- #define x200(val) (x2(x100(val)))
- #define x300(val) (x3(x100(val)))
- #define x400(val) (x4(x100(val)))
- #define x500(val) (x5(x100(val)))
- #define x600(val) (x6(x100(val)))
- #define x700(val) (x7(x100(val)))
- #define x800(val) (x8(x100(val)))
- #define x900(val) (x9(x100(val)))
- //custom definitions
- #define x34(val) (x30(val) + x4(val)) //multiply val by 34
- #define x97(val) (x90(val) + x7(val)) //multiply val by 97x
- #endif //__gpio_h_
复制代码you don't need to have all of it. it predefines LED1 (on PD0).as well as F_CPU (running at 16Mhz / 8).
一周热门 更多>