17年也没干个啥,年后就去折腾着玩意儿了,也不知道我折腾它还是它折腾我。反正总之现在勉强可以交作业了,呵呵

硬件:

1.罗耶振荡电路输出一路4v交流,一路25v交流

  其中4v直接驱动灯丝,另一路经电桥整流提供负压给pt6311

2.主控用stm8s003f3

  成本低廉,而且我这几块stm8是x宝掌柜送的,本身性价比也很高,8kflash先在用串口调试附带其他驱动大致用了
1020179-20180121143358131-377208505.png
 也就是大概用完了。其实去掉uart估计要少4k,我寻思加个gps解码的程序应该够用吧。。。23333
3.vfd驱动用前面提到的pt6311
  我买的好像很便宜,1.85一片。但是现在用了三片,其中一片死活有个seg不输出。索性它便宜就不计较了2333
原理图
1020179-20180121143813099-541571474.png
pcb:
1020179-20180121143919099-1714392138.png
按键那部分单独做了块小板子,一来空间不够了,而来后期设计外壳更方便,总之有打印机是方便的很

源码:

沿用我之前写的驱动,并移植了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. /* Includes ------------------------------------------------------------------*/
  6. #include "stm8s.h"
  7. #include "ds3231.h"    //@ds3231.h for macro
  8. /* Private typedef -----------------------------------------------------------*/
  9. /* Private define ------------------------------------------------------------*/
  10. #define I2C_Speed              100000
  11. #define I2C1_SLAVE_ADDRESS7    DS3231_WriteAddress //0xd0
  12. #define EEPROM_BASE_ADDRESS    0x0000
  13. #define Page_Byte_Size    ((u8)8)   /*EEPROM 每页最多写8Byte*/
  14. #define EEPROM_ADDRESS         DS3231_WriteAddress//0xd0
  15. /* Private macro -------------------------------------------------------------*/
  16. /* Private variables ---------------------------------------------------------*/
  17. /* Private function prototypes -----------------------------------------------*/
  18. /* Private functions ---------------------------------------------------------*/
  19. /* Exported macro ------------------------------------------------------------*/
  20. /* Exported functions ------------------------------------------------------- */
  21. void I2C_EEInit(void);
  22. void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr);
  23. //void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite);
  24. void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead);
  25. uint8_t I2C_ReadRegister_SR1();
  26. void I2C_EE_WaitEepromStandbyState(void);
  27. void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite);
  28. #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. * Function Name  : I2C_EE_Init
  11. * Description    : Initializes peripherals used by the I2C EEPROM driver.
  12. * Input          : None
  13. * Output         : None
  14. * Return         : None
  15. *******************************************************************************/
  16. void I2C_EEInit(void)
  17. {
  18.    u8 Input_Clock = 0x0;
  19.   /* Get system clock frequency */
  20.   Input_Clock = CLK_GetClockFreq()/1000000;
  21.   /* I2C Peripheral Enable */
  22.   I2C_Cmd(ENABLE);
  23.   /* Apply I2C configuration after enabling it */
  24.   I2C_Init(I2C_Speed, 0xaa, I2C_DUTYCYCLE_2,\
  25.             I2C_ACK_CURR, I2C_ADDMODE_7BIT, Input_Clock);//use 0xaa as master(mcu)'s addr
  26. }
  27. /*******************************************************************************
  28. * Function Name  : I2C_EE_ByteWrite
  29. * Description    : Writes one byte to the I2C EEPROM.
  30. * Input          : - pBuffer : pointer to the buffer  containing the data to be
  31. *                    written to the EEPROM.
  32. *                  - WriteAddr : EEPROM's internal address to write to.
  33. * Output         : None
  34. * Return         : None
  35. *******************************************************************************/
  36. void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr)
  37. {
  38.   //wait for idle
  39.   while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
  40.   /* Send STRAT condition */
  41.   I2C_GenerateSTART(ENABLE);
  42.   /* Test on EV5 and clear it */
  43.     while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
  44.   /* Send EEPROM address for write */
  45.   I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
  46.   /* Test on EV6 and clear it */
  47.    while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  48.   //for 16 bit
  49. //  /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
  50. //  I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
  51. //  /* Test on EV8 and clear it */
  52. //  while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
  53.   I2C_SendData((u8)(WriteAddr)); /* LSB */
  54.   /* Test on EV8 and clear it */
  55.   while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
  56.   /* Send the byte to be written */
  57.   I2C_SendData(*pBuffer);
  58.   /* Test on EV8 and clear it */
  59.   while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
  60.   /* Send STOP condition */
  61.   I2C_GenerateSTOP(ENABLE);
  62. }
  63. /*******************************************************************************
  64. * Function Name  : I2C_EE_PageWrite
  65. * Description    : Writes more than one byte to the EEPROM with a single WRITE
  66. *                  cycle. The number of byte can't exceed the EEPROM page size.
  67. * Input          : - pBuffer : pointer to the buffer containing the data to be
  68. *                    written to the EEPROM.
  69. *                  - WriteAddr : EEPROM's internal address to write to.
  70. *                  - NumByteToWrite : number of bytes to write to the EEPROM.
  71. * Output         : None
  72. * Return         : None
  73. *******************************************************************************/
  74. //void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite)
  75. //{
  76. //  /* While the bus is busy */
  77. //  while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
  78. //
  79. //  /* Send START condition */
  80. //  I2C_GenerateSTART(ENABLE);
  81. //
  82. //  /* Test on EV5 and clear it */
  83. //  while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
  84. //
  85. //  /* Send EEPROM address for write */
  86. //  I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
  87. //
  88. //  /* Test on EV6 and clear it */
  89. //  while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
  90. //  I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
  91. //
  92. //  /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
  93. //  I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
  94. //  /* Test on EV8 and clear it */
  95. //  while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
  96. //  I2C_SendData((u8)(WriteAddr)); /* LSB */
  97. //  /* Test on EV8 and clear it */
  98. //  while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
  99. //
  100. //
  101. //  /* While there is data to be written */
  102. //  while(NumByteToWrite--)
  103. //  {
  104. //    /* Send the current byte */
  105. //    I2C_SendData(*pBuffer);
  106. //
  107. //    /* Point to the next byte to be written */
  108. //    pBuffer++;
  109. //
  110. //    /* Test on EV8 and clear it */
  111. //    while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  112. //  }
  113. //
  114. //  /* Send STOP condition */
  115. //  I2C_GenerateSTOP(ENABLE);
  116. //}
  117. /*******************************************************************************
  118. * Function Name  : I2C_EE_BufferRead
  119. * Description    : Reads a block of data from the EEPROM.
  120. * Input          : - pBuffer : pointer to the buffer that receives the data read
  121. *                    from the EEPROM.
  122. *                  - ReadAddr : EEPROM's internal address to read from.
  123. *                  - NumByteToRead : number of bytes to read from the EEPROM.
  124. * Output         : None
  125. * Return         : None
  126. *******************************************************************************/
  127. void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead)
  128. {
  129.     /* While the bus is busy */
  130.   while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
  131.   /* Generate start & wait event detection */
  132.     I2C_GenerateSTART(ENABLE);
  133.   /* Test on EV5 and clear it */
  134.     while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
  135.   /* Send slave Address in write direction & wait detection event */
  136.     I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
  137.    /* Test on EV6 and clear it */
  138.     while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  139.     //for 10bit addr
  140.    /* Send Address of first byte to be read & wait event detection */
  141. //    I2C_SendData((u8)(ReadAddr >> 8)); /* MSB */
  142. //    /* Test on EV8 and clear it */
  143. //    while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  144.     I2C_SendData((u8)(ReadAddr)); /* LSB */
  145.   /* Test on EV8 and clear it */
  146.     while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  147.   /* Send STRAT condition a second time */
  148.   I2C_GenerateSTART(ENABLE);
  149.     /* Test on EV5 and clear it */
  150.   while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
  151.   /* Send slave Address in read direction & wait event */
  152.     I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_RX);
  153.    /* Test on EV6 and clear it */
  154.      while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  155.   /* While there is data to be read */
  156.   while(NumByteToRead)
  157.   {
  158.     if(NumByteToRead == 1)
  159.     {
  160.       /* Disable Acknowledgement */
  161.       I2C_AcknowledgeConfig(I2C_ACK_NONE);
  162.       /* Send STOP Condition */
  163.       I2C_GenerateSTOP(ENABLE);
  164.     }
  165.     /* Test on EV7 and clear it */
  166.     if(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
  167.     {
  168.       /* Read a byte from the EEPROM */
  169.       *pBuffer = I2C_ReceiveData();
  170.       /* Point to the next location where the byte read will be saved */
  171.       pBuffer++;
  172.       /* Decrement the read bytes counter */
  173.       NumByteToRead--;
  174.     }
  175.   }
  176.   /* Enable Acknowledgement to be ready for another reception */
  177.   I2C_AcknowledgeConfig(I2C_ACK_CURR);
  178. }
  179. uint8_t I2C_ReadRegister_SR1()
  180. {
  181.   uint8_t temp;
  182.   temp=I2C->SR1;
  183.   return temp;
  184. }
  185. void I2C_EE_WaitEepromStandbyState(void)
  186. {
  187.   u8 SR1_Tmp = 0;
  188.   do
  189.   {
  190.     /* Send START condition */
  191.     I2C_GenerateSTART(ENABLE);
  192.     /* Read I2C1 SR1 register */
  193.     SR1_Tmp =I2C_ReadRegister_SR1();
  194.     /* Send EEPROM address for write */
  195.     I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);;
  196.   }while(!(I2C_ReadRegister_SR1()&0x02));
  197.   /* Clear AF flag */
  198.   I2C_ClearFlag(I2C_FLAG_ACKNOWLEDGEFAILURE);
  199. }
  200. /*******************************************************************************
  201. * Function Name  : I2C_EE_BufferWrite
  202. * Description    : Writes buffer of data to the I2C EEPROM.
  203. * Input          : - pBuffer : pointer to the buffer  containing the data to be
  204. *                    written to the EEPROM.
  205. *                  - WriteAddr : EEPROM's internal address to write to.
  206. *                  - NumByteToWrite : number of bytes to write to the EEPROM.
  207. * Output         : None
  208. * Return         : None
  209. *******************************************************************************/
  210. void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite)
  211. {
  212.   u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0;
  213.   Addr = WriteAddr % Page_Byte_Size ;
  214.   count = Page_Byte_Size  - Addr;
  215.   NumOfPage =  NumByteToWrite / Page_Byte_Size ;
  216.   NumOfSingle = NumByteToWrite % Page_Byte_Size ;
  217.   /* If WriteAddr is I2C_PageSize aligned  */
  218.   if(Addr == 0)
  219.   {
  220.     /* If NumByteToWrite < I2C_PageSize */
  221.     if(NumOfPage == 0)
  222.     {
  223.       I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  224.       I2C_EE_WaitEepromStandbyState();
  225.     }
  226.     /* If NumByteToWrite > I2C_PageSize */
  227.     else
  228.     {
  229.       while(NumOfPage--)
  230.       {
  231.         I2C_EE_PageWrite(pBuffer, WriteAddr, Page_Byte_Size );
  232.         I2C_EE_WaitEepromStandbyState();
  233.         WriteAddr +=  Page_Byte_Size ;
  234.         pBuffer += Page_Byte_Size ;
  235.       }
  236.       if(NumOfSingle!=0)
  237.       {
  238.         I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  239.         I2C_EE_WaitEepromStandbyState();
  240.       }
  241.     }
  242.   }
  243.   /* If WriteAddr is not I2C_PageSize aligned  */
  244.   else
  245.   {
  246.     /* If NumByteToWrite < I2C_PageSize */
  247.     if(NumOfPage== 0)
  248.     {
  249.       I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  250.       I2C_EE_WaitEepromStandbyState();
  251.     }
  252.     /* If NumByteToWrite > I2C_PageSize */
  253.     else
  254.     {
  255.       NumByteToWrite -= count;
  256.       NumOfPage =  NumByteToWrite / Page_Byte_Size ;
  257.       NumOfSingle = NumByteToWrite % Page_Byte_Size ;
  258.       if(count != 0)
  259.       {
  260.         I2C_EE_PageWrite(pBuffer, WriteAddr, count);
  261.         I2C_EE_WaitEepromStandbyState();
  262.         WriteAddr += count;
  263.         pBuffer += count;
  264.       }
  265.       while(NumOfPage--)
  266.       {
  267.         I2C_EE_PageWrite(pBuffer, WriteAddr, Page_Byte_Size );
  268.         I2C_EE_WaitEepromStandbyState();
  269.         WriteAddr += Page_Byte_Size ;
  270.         pBuffer += Page_Byte_Size ;
  271.       }
  272.       if(NumOfSingle != 0)
  273.       {
  274.         I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  275.         I2C_EE_WaitEepromStandbyState();
  276.       }
  277.     }
  278.   }
  279. }
目前测试过的,初始化肯定不用说,字节写测试通过,连续读测试通过,连续写还未测试,照理也可以的23333
  1. #ifndef DS3231_H
  2. #define DS3231_H
  3. #include "pt6311.h"
  4. #include "i2c_ee.h"
  5. #define DS3231_WriteAddress 0xD0    //器件写地址
  6. #define DS3231_ReadAddress  0xD1    //器件读地址
  7. #define DS3231_SECOND       0x00    //秒
  8. #define DS3231_MINUTE       0x01    //分
  9. #define DS3231_HOUR         0x02    //时
  10. #define DS3231_WEEK         0x03    //星期
  11. #define DS3231_DAY          0x04    //日
  12. #define DS3231_MONTH        0x05    //月
  13. #define DS3231_YEAR         0x06    //年
  14. //闹铃1
  15. #define DS3231_SALARM1ECOND 0x07    //秒
  16. #define DS3231_ALARM1MINUTE 0x08    //分
  17. #define DS3231_ALARM1HOUR   0x09    //时
  18. #define DS3231_ALARM1WEEK   0x0A    //星期/日
  19. //闹铃2
  20. #define DS3231_ALARM2MINUTE 0x0b    //分
  21. #define DS3231_ALARM2HOUR   0x0c    //时
  22. #define DS3231_ALARM2WEEK   0x0d    //星期/日
  23. #define DS3231_CONTROL      0x0e    //控制寄存器
  24. #define DS3231_STATUS       0x0f    //状态寄存器
  25. #define BSY                 2       //忙
  26. #define OSF                 7       //振荡器停止标志
  27. #define DS3231_XTAL         0x10    //晶体老化寄存器
  28. #define DS3231_TEMPERATUREH 0x11    //温度寄存器高字节(8位)
  29. #define DS3231_TEMPERATUREL 0x12    //温度寄存器低字节(高2位)
  30. u8 BCD2DEC(u8 val);    //BCD转换为Byte
  31. u8 DEC2BCD(u8 val);    //B码转换为BCD码
  32. void ModifyTime(u8 yea,u8 mon,u8 da,u8 hou,u8 min,u8 sec);
  33. void get_show_time(void);
  34. void get_show_Temperature(void);
  35. #endif

  1. #include "ds3231.h"
  2. u8 BCD2DEC(u8 val)    //BCD转换为DEC
  3. {
  4.     u8 temp;
  5.     temp=(val/16)*10+(val%16);
  6.     return temp;
  7. }
  8. u8 DEC2BCD(u8 val)    //DEC码转换为BCD码
  9. {
  10.     u8 k;
  11.     k=(val%10)+((val/10)<<4);
  12.     return k;
  13. }
  14. void ModifyTime(u8 yea,u8 mon,u8 da,u8 hou,u8 min,u8 sec)
  15. {
  16.     u8 temp=0;
  17.     temp=DEC2BCD(yea);
  18.     I2C_EE_ByteWrite(&temp,DS3231_YEAR);   //修改年
  19.     temp=DEC2BCD(mon);
  20.     I2C_EE_ByteWrite(&temp,DS3231_MONTH);  //修改月
  21.     temp=DEC2BCD(da);
  22.     I2C_EE_ByteWrite(&temp,DS3231_DAY);    //修改日
  23.     temp=DEC2BCD(hou);
  24.     I2C_EE_ByteWrite(&temp,DS3231_HOUR);   //修改时
  25.     temp=DEC2BCD(min);
  26.     I2C_EE_ByteWrite(&temp,DS3231_MINUTE); //修改分
  27.     temp=DEC2BCD(sec);
  28.     I2C_EE_ByteWrite(&temp,DS3231_SECOND); //修改秒
  29. }
  30. void get_show_time(void)
  31. {
  32.     u8 data[7],i; //save time
  33.     I2C_EE_BufferRead(data,0,7);//S->Y 0->6
  34.     data[2]&=0x3f;//get true hour
  35.     //bcd to dec
  36.     for (i=0;i<7;i++)
  37.         data[i]=BCD2DEC(data[i]);
  38.     dspseg[11]=data[0]%10;
  39.     dspseg[10]=data[0]/10;
  40.     dspseg[9]=data[1]%10;
  41.     dspseg[8]=data[1]/10;
  42.     dspseg[7]=data[2]%10;
  43.     dspseg[6]=data[2]/10;
  44. }
  45. void get_show_Temperature(void)
  46. {
  47.     u8 temp[2];
  48.    //temph  _(sign) _ _ _, _ _ _ _
  49.     //templ (point)_ _0 0, 0 0 0 0
  50.     I2C_EE_BufferRead(temp,DS3231_TEMPERATUREH,2);
  51.     temp[0]=BCD2DEC(temp[0]);//int,default in positive temperature
  52.     temp[1]=(temp[1]>>6)*25;//decimal
  53.     dspseg[5]=temp[0]%10;
  54.     dspseg[4]=temp[0]/10;
  55. }
懒得上main.c了,有心人一下子就搞出来了,我api都写的差不多了,剩下按键改时间,以及闹钟设置,可选的gps校时

注意stm8s_i2c.h这个头应该是11年那个比较大的头,起初那个不行,后来根据风驰的eeprom教程移植,它用的也是我说的这个新点的库

晒图:
1020179-20180121145531381-335971610.png
1020179-20180121145558178-1394809927.png
1020179-20180121145618474-1337796425.png
1020179-20180121145637131-2081479573.png
手工版做了估计有六七块,主要是打印机喷的墨不够,而且油笔不给力,描了也没有用。这几张图是后期版本的,没有大面积铺铜,简直不堪入目233333