硬件:
1.罗耶振荡电路输出一路4v交流,一路25v交流
其中4v直接驱动灯丝,另一路经电桥整流提供负压给pt6311
2.主控用stm8s003f3
成本低廉,而且我这几块stm8是x宝掌柜送的,本身性价比也很高,8kflash先在用串口调试附带其他驱动大致用了
也就是大概用完了。其实去掉uart估计要少4k,我寻思加个gps解码的程序应该够用吧。。。23333
3.vfd驱动用前面提到的pt6311
我买的好像很便宜,1.85一片。但是现在用了三片,其中一片死活有个seg不输出。索性它便宜就不计较了2333
原理图
pcb:
按键那部分单独做了块小板子,一来空间不够了,而来后期设计外壳更方便,总之有打印机是方便的很
源码:
沿用我之前写的驱动,并移植了st官方的eeprom的库来驱动硬件iic与ds3231通讯
1 //transplanted for ds3231
2 /* Define to prevent recursive inclusion ------------------------------------ */
3 #ifndef __I2C_EE_H
4 #define __I2C_EE_H
5
6 /* Includes ------------------------------------------------------------------*/
7 #include "stm8s.h"
8 #include "ds3231.h" //@ds3231.h for macro
9
10 /* Private typedef -----------------------------------------------------------*/
11 /* Private define ------------------------------------------------------------*/
12 #define I2C_Speed 100000
13 #define I2C1_SLAVE_ADDRESS7 DS3231_WriteAddress //0xd0
14 #define EEPROM_BASE_ADDRESS 0x0000
15 #define Page_Byte_Size ((u8)8) /*EEPROM 每页最多写8Byte*/
16 #define EEPROM_ADDRESS DS3231_WriteAddress//0xd0
17 /* Private macro -------------------------------------------------------------*/
18 /* Private variables ---------------------------------------------------------*/
19
20 /* Private function prototypes -----------------------------------------------*/
21 /* Private functions ---------------------------------------------------------*/
22
23 /* Exported macro ------------------------------------------------------------*/
24 /* Exported functions ------------------------------------------------------- */
25 void I2C_EEInit(void);
26 void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr);
27 //void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite);
28 void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead);
29 uint8_t I2C_ReadRegister_SR1();
30 void I2C_EE_WaitEepromStandbyState(void);
31 void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite);
32 #endif /* __I2C_EE_H */
1 #include "i2c_ee.h"
2 #include "stm8s_i2c.h"
3 //transplanted to dsd3231
4 //modyfied:
5 //1.only leave 8 bit to work
6 //2.change the related macro definition
7 //3.use newer stm8s_i2c.h
8 //By katachi time:2018-1-20
9
10 /*******************************************************************************
11 * Function Name : I2C_EE_Init
12 * Description : Initializes peripherals used by the I2C EEPROM driver.
13 * Input : None
14 * Output : None
15 * Return : None
16 *******************************************************************************/
17 void I2C_EEInit(void)
18 {
19 u8 Input_Clock = 0x0;
20 /* Get system clock frequency */
21 Input_Clock = CLK_GetClockFreq()/1000000;
22 /* I2C Peripheral Enable */
23 I2C_Cmd(ENABLE);
24 /* Apply I2C configuration after enabling it */
25 I2C_Init(I2C_Speed, 0xaa, I2C_DUTYCYCLE_2,
26 I2C_ACK_CURR, I2C_ADDMODE_7BIT, Input_Clock);//use 0xaa as master(mcu)'s addr
27 }
28
29 /*******************************************************************************
30 * Function Name : I2C_EE_ByteWrite
31 * Description : Writes one byte to the I2C EEPROM.
32 * Input : - pBuffer : pointer to the buffer containing the data to be
33 * written to the EEPROM.
34 * - WriteAddr : EEPROM's internal address to write to.
35 * Output : None
36 * Return : None
37 *******************************************************************************/
38 void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr)
39 {
40 //wait for idle
41 while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
42 /* Send STRAT condition */
43 I2C_GenerateSTART(ENABLE);
44
45 /* Test on EV5 and clear it */
46 while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
47 /* Send EEPROM address for write */
48 I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
49
50 /* Test on EV6 and clear it */
51 while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
52 //for 16 bit
53 // /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
54 // I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
55 // /* Test on EV8 and clear it */
56 // while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
57 I2C_SendData((u8)(WriteAddr)); /* LSB */
58 /* Test on EV8 and clear it */
59 while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
60
61 /* Send the byte to be written */
62 I2C_SendData(*pBuffer);
63
64 /* Test on EV8 and clear it */
65 while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
66
67 /* Send STOP condition */
68 I2C_GenerateSTOP(ENABLE);
69 }
70
71 /*******************************************************************************
72 * Function Name : I2C_EE_PageWrite
73 * Description : Writes more than one byte to the EEPROM with a single WRITE
74 * cycle. The number of byte can't exceed the EEPROM page size.
75 * Input : - pBuffer : pointer to the buffer containing the data to be
76 * written to the EEPROM.
77 * - WriteAddr : EEPROM's internal address to write to.
78 * - NumByteToWrite : number of bytes to write to the EEPROM.
79 * Output : None
80 * Return : None
81 *******************************************************************************/
82 //void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite)
83 //{
84 // /* While the bus is busy */
85 // while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
86 //
87 // /* Send START condition */
88 // I2C_GenerateSTART(ENABLE);
89 //
90 // /* Test on EV5 and clear it */
91 // while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
92 //
93 // /* Send EEPROM address for write */
94 // I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
95 //
96 // /* Test on EV6 and clear it */
97 // while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
98 // I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
99 //
100 // /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
101 // I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
102 // /* Test on EV8 and clear it */
103 // while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
104 // I2C_SendData((u8)(WriteAddr)); /* LSB */
105 // /* Test on EV8 and clear it */
106 // while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
107 //
108 //
109 // /* While there is data to be written */
110 // while(NumByteToWrite--)
111 // {
112 // /* Send the current byte */
113 // I2C_SendData(*pBuffer);
114 //
115 // /* Point to the next byte to be written */
116 // pBuffer++;
117 //
118 // /* Test on EV8 and clear it */
119 // while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
120 // }
121 //
122 // /* Send STOP condition */
123 // I2C_GenerateSTOP(ENABLE);
124 //}
125
126 /*******************************************************************************
127 * Function Name : I2C_EE_BufferRead
128 * Description : Reads a block of data from the EEPROM.
129 * Input : - pBuffer : pointer to the buffer that receives the data read
130 * from the EEPROM.
131 * - ReadAddr : EEPROM's internal address to read from.
132 * - NumByteToRead : number of bytes to read from the EEPROM.
133 * Output : None
134 * Return : None
135 *******************************************************************************/
136 void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead)
137 {
138 /* While the bus is busy */
139 while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
140
上一篇:vfd with stm8
下一篇:MI200e电力线通讯
设计资源 培训 开发板 精华推荐
- 使用 Analog Devices 的 LTC7851IUHH 的参考设计
- ADAU1702,评估板是独立的 28 位/56 位音频 DSP,可处理所有系统处理
- 使用 Microchip Technology 的 MCP2510T-E 的参考设计
- MICRF213 的典型应用:3.3V、Qwik-Radio 315MHz 接收器
- 使用 ROHM Semiconductor 的 BA33BC0WFP-E2 的参考设计
- ESP32墙壁开关
- 较低成本三极管三路循环流水灯
- AM1/4S-4812SZ 12V 0.25 瓦 DC/DC 转换器的典型应用
- 80W, 3.3V, 12V, 24V AC 到 DC 多路输出电源 PoE 电源
- LT1308BIS8 SEPIC(单端初级电感转换器)的典型应用电路将 3V 至 10V 输入转换为 5V/500mA 稳压输出