vfd电子时钟制作
17年也没干个啥,年后就去折腾着玩意儿了,也不知道我折腾它还是它折腾我。反正总之现在勉强可以交作业了,呵呵
硬件:
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通讯
//transplanted for ds3231
/* Define to prevent recursive inclusion ------------------------------------ */
#ifndef __I2C_EE_H
#define __I2C_EE_H /* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "ds3231.h" //@ds3231.h for macro /* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define I2C_Speed 100000
#define I2C1_SLAVE_ADDRESS7 DS3231_WriteAddress //0xd0
#define EEPROM_BASE_ADDRESS 0x0000
#define Page_Byte_Size ((u8)8) /*EEPROM 每页最多写8Byte*/
#define EEPROM_ADDRESS DS3231_WriteAddress//0xd0
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void I2C_EEInit(void);
void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr);
//void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite);
void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead);
uint8_t I2C_ReadRegister_SR1();
void I2C_EE_WaitEepromStandbyState(void);
void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite);
#endif /* __I2C_EE_H */
#include "i2c_ee.h"
#include "stm8s_i2c.h"
//transplanted to dsd3231
//modyfied:
//1.only leave 8 bit to work
//2.change the related macro definition
//3.use newer stm8s_i2c.h
//By katachi time:2018-1-20 /*******************************************************************************
* Function Name : I2C_EE_Init
* Description : Initializes peripherals used by the I2C EEPROM driver.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void I2C_EEInit(void)
{
u8 Input_Clock = 0x0;
/* Get system clock frequency */
Input_Clock = CLK_GetClockFreq()/;
/* I2C Peripheral Enable */
I2C_Cmd(ENABLE);
/* Apply I2C configuration after enabling it */
I2C_Init(I2C_Speed, 0xaa, I2C_DUTYCYCLE_2,\
I2C_ACK_CURR, I2C_ADDMODE_7BIT, Input_Clock);//use 0xaa as master(mcu)'s addr
} /*******************************************************************************
* Function Name : I2C_EE_ByteWrite
* Description : Writes one byte to the I2C EEPROM.
* Input : - pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* - WriteAddr : EEPROM's internal address to write to.
* Output : None
* Return : None
*******************************************************************************/
void I2C_EE_ByteWrite(u8* pBuffer, u16 WriteAddr)
{
//wait for idle
while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
/* Send STRAT condition */
I2C_GenerateSTART(ENABLE); /* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for write */
I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX); /* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
//for 16 bit
// /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
// I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
// /* Test on EV8 and clear it */
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
I2C_SendData((u8)(WriteAddr)); /* LSB */
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING)); /* Send the byte to be written */
I2C_SendData(*pBuffer); /* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING)); /* Send STOP condition */
I2C_GenerateSTOP(ENABLE);
} /*******************************************************************************
* Function Name : I2C_EE_PageWrite
* Description : Writes more than one byte to the EEPROM with a single WRITE
* cycle. The number of byte can't exceed the EEPROM page size.
* Input : - pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* - WriteAddr : EEPROM's internal address to write to.
* - NumByteToWrite : number of bytes to write to the EEPROM.
* Output : None
* Return : None
*******************************************************************************/
//void I2C_EE_PageWrite(u8* pBuffer, u16 WriteAddr, u8 NumByteToWrite)
//{
// /* While the bus is busy */
// while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
//
// /* Send START condition */
// I2C_GenerateSTART(ENABLE);
//
// /* Test on EV5 and clear it */
// while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
//
// /* Send EEPROM address for write */
// I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
//
// /* Test on EV6 and clear it */
// while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
// I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
//
// /* Send Address (on 2 bytes) of first byte to be written & wait event detection */
// I2C_SendData((u8)(WriteAddr >> 8)); /* MSB */
// /* Test on EV8 and clear it */
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
// I2C_SendData((u8)(WriteAddr)); /* LSB */
// /* Test on EV8 and clear it */
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING));
//
//
// /* While there is data to be written */
// while(NumByteToWrite--)
// {
// /* Send the current byte */
// I2C_SendData(*pBuffer);
//
// /* Point to the next byte to be written */
// pBuffer++;
//
// /* Test on EV8 and clear it */
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
// }
//
// /* Send STOP condition */
// I2C_GenerateSTOP(ENABLE);
//} /*******************************************************************************
* Function Name : I2C_EE_BufferRead
* Description : Reads a block of data from the EEPROM.
* Input : - pBuffer : pointer to the buffer that receives the data read
* from the EEPROM.
* - ReadAddr : EEPROM's internal address to read from.
* - NumByteToRead : number of bytes to read from the EEPROM.
* Output : None
* Return : None
*******************************************************************************/
void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead)
{
/* While the bus is busy */
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)); /* Generate start & wait event detection */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); /* Send slave Address in write direction & wait detection event */
I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
//for 10bit addr
/* Send Address of first byte to be read & wait event detection */
// I2C_SendData((u8)(ReadAddr >> 8)); /* MSB */
// /* Test on EV8 and clear it */
// while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData((u8)(ReadAddr)); /* LSB */
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Send STRAT condition a second time */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send slave Address in read direction & wait event */
I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_RX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); /* While there is data to be read */
while(NumByteToRead)
{
if(NumByteToRead == )
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_ACK_NONE); /* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
} /* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(); /* Point to the next location where the byte read will be saved */
pBuffer++; /* Decrement the read bytes counter */
NumByteToRead--;
}
} /* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_ACK_CURR);
} uint8_t I2C_ReadRegister_SR1()
{
uint8_t temp;
temp=I2C->SR1;
return temp;
} void I2C_EE_WaitEepromStandbyState(void)
{
u8 SR1_Tmp = ;
do
{
/* Send START condition */
I2C_GenerateSTART(ENABLE);
/* Read I2C1 SR1 register */
SR1_Tmp =I2C_ReadRegister_SR1();
/* Send EEPROM address for write */
I2C_Send7bitAddress(EEPROM_ADDRESS, I2C_DIRECTION_TX);;
}while(!(I2C_ReadRegister_SR1()&0x02)); /* Clear AF flag */
I2C_ClearFlag(I2C_FLAG_ACKNOWLEDGEFAILURE);
} /*******************************************************************************
* Function Name : I2C_EE_BufferWrite
* Description : Writes buffer of data to the I2C EEPROM.
* Input : - pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* - WriteAddr : EEPROM's internal address to write to.
* - NumByteToWrite : number of bytes to write to the EEPROM.
* Output : None
* Return : None
*******************************************************************************/
void I2C_EE_BufferWrite(u8* pBuffer, u8 WriteAddr, u16 NumByteToWrite)
{
u8 NumOfPage = , NumOfSingle = , Addr = , count = ; Addr = WriteAddr % Page_Byte_Size ;
count = Page_Byte_Size - Addr;
NumOfPage = NumByteToWrite / Page_Byte_Size ;
NumOfSingle = NumByteToWrite % Page_Byte_Size ; /* If WriteAddr is I2C_PageSize aligned */
if(Addr == )
{
/* If NumByteToWrite < I2C_PageSize */
if(NumOfPage == )
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
/* If NumByteToWrite > I2C_PageSize */
else
{
while(NumOfPage--)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, Page_Byte_Size );
I2C_EE_WaitEepromStandbyState();
WriteAddr += Page_Byte_Size ;
pBuffer += Page_Byte_Size ;
} if(NumOfSingle!=)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
/* If WriteAddr is not I2C_PageSize aligned */
else
{
/* If NumByteToWrite < I2C_PageSize */
if(NumOfPage== )
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
/* If NumByteToWrite > I2C_PageSize */
else
{
NumByteToWrite -= count;
NumOfPage = NumByteToWrite / Page_Byte_Size ;
NumOfSingle = NumByteToWrite % Page_Byte_Size ; if(count != )
{
I2C_EE_PageWrite(pBuffer, WriteAddr, count);
I2C_EE_WaitEepromStandbyState();
WriteAddr += count;
pBuffer += count;
} while(NumOfPage--)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, Page_Byte_Size );
I2C_EE_WaitEepromStandbyState();
WriteAddr += Page_Byte_Size ;
pBuffer += Page_Byte_Size ;
}
if(NumOfSingle != )
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
}
目前测试过的,初始化肯定不用说,字节写测试通过,连续读测试通过,连续写还未测试,照理也可以的23333
#ifndef DS3231_H
#define DS3231_H #include "pt6311.h"
#include "i2c_ee.h" #define DS3231_WriteAddress 0xD0 //器件写地址
#define DS3231_ReadAddress 0xD1 //器件读地址 #define DS3231_SECOND 0x00 //秒
#define DS3231_MINUTE 0x01 //分
#define DS3231_HOUR 0x02 //时
#define DS3231_WEEK 0x03 //星期
#define DS3231_DAY 0x04 //日
#define DS3231_MONTH 0x05 //月
#define DS3231_YEAR 0x06 //年
//闹铃1
#define DS3231_SALARM1ECOND 0x07 //秒
#define DS3231_ALARM1MINUTE 0x08 //分
#define DS3231_ALARM1HOUR 0x09 //时
#define DS3231_ALARM1WEEK 0x0A //星期/日
//闹铃2
#define DS3231_ALARM2MINUTE 0x0b //分
#define DS3231_ALARM2HOUR 0x0c //时
#define DS3231_ALARM2WEEK 0x0d //星期/日
#define DS3231_CONTROL 0x0e //控制寄存器
#define DS3231_STATUS 0x0f //状态寄存器
#define BSY 2 //忙
#define OSF 7 //振荡器停止标志
#define DS3231_XTAL 0x10 //晶体老化寄存器
#define DS3231_TEMPERATUREH 0x11 //温度寄存器高字节(8位)
#define DS3231_TEMPERATUREL 0x12 //温度寄存器低字节(高2位) u8 BCD2DEC(u8 val); //BCD转换为Byte
u8 DEC2BCD(u8 val); //B码转换为BCD码 void ModifyTime(u8 yea,u8 mon,u8 da,u8 hou,u8 min,u8 sec);
void get_show_time(void);
void get_show_Temperature(void);
#endif
#include "ds3231.h" u8 BCD2DEC(u8 val) //BCD转换为DEC
{
u8 temp;
temp=(val/)*+(val%); return temp;
} u8 DEC2BCD(u8 val) //DEC码转换为BCD码
{
u8 k;
k=(val%)+((val/)<<);
return k;
} void ModifyTime(u8 yea,u8 mon,u8 da,u8 hou,u8 min,u8 sec)
{
u8 temp=; temp=DEC2BCD(yea);
I2C_EE_ByteWrite(&temp,DS3231_YEAR); //修改年 temp=DEC2BCD(mon);
I2C_EE_ByteWrite(&temp,DS3231_MONTH); //修改月 temp=DEC2BCD(da);
I2C_EE_ByteWrite(&temp,DS3231_DAY); //修改日 temp=DEC2BCD(hou);
I2C_EE_ByteWrite(&temp,DS3231_HOUR); //修改时 temp=DEC2BCD(min);
I2C_EE_ByteWrite(&temp,DS3231_MINUTE); //修改分 temp=DEC2BCD(sec);
I2C_EE_ByteWrite(&temp,DS3231_SECOND); //修改秒 } void get_show_time(void)
{
u8 data[],i; //save time I2C_EE_BufferRead(data,,);//S->Y 0->6
data[]&=0x3f;//get true hour
//bcd to dec
for (i=;i<;i++)
data[i]=BCD2DEC(data[i]);
dspseg[]=data[]%;
dspseg[]=data[]/;
dspseg[]=data[]%;
dspseg[]=data[]/;
dspseg[]=data[]%;
dspseg[]=data[]/;
} void get_show_Temperature(void)
{
u8 temp[];
//temph _(sign) _ _ _, _ _ _ _
//templ (point)_ _0 0, 0 0 0 0
I2C_EE_BufferRead(temp,DS3231_TEMPERATUREH,); temp[]=BCD2DEC(temp[]);//int,default in positive temperature
temp[]=(temp[]>>)*;//decimal dspseg[]=temp[]%;
dspseg[]=temp[]/; }
懒得上main.c了,有心人一下子就搞出来了,我api都写的差不多了,剩下按键改时间,以及闹钟设置,可选的gps校时
注意stm8s_i2c.h这个头应该是11年那个比较大的头,起初那个不行,后来根据风驰的eeprom教程移植,它用的也是我说的这个新点的库
晒图:
手工版做了估计有六七块,主要是打印机喷的墨不够,而且油笔不给力,描了也没有用。这几张图是后期版本的,没有大面积铺铜,简直不堪入目233333
vfd电子时钟制作的更多相关文章
- [TPYBoard-Micropython之会python就能做硬件 3] 制作电子时钟
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.TPYboard V102板 一块 2.DS3231 ...
- 3分钟利用TurnipBit制作电子时钟
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 TurnipBit(www.turnipbit.com)是一个面向青少年的开发板 ...
- js傻瓜式制作电子时钟
js傻瓜式制作电子时间 使用到的知识点 setInterval函数 构建函数new Date if判断 demo: //css样式请自行设置 <span id="timer" ...
- Micropython TurnipBit 电子时钟 青少年编程入门
电子时钟是一个很常用但是制作非常简单的小玩具了,对于Micropython初学者来说,制作一个电子时钟是非常简单又容易检验自己学习成果的实验了.TurnipBit相比于其他开发板,制作电子时钟就更加简 ...
- JavaScript电子时钟+倒计时
JavaScript时间类 获取时分秒: getHours() getMinutes(); getSeconds(); 获取 ...
- JS实现电子时钟
目前有个小项目,在首页头部导航栏里需要一个电子时钟的效果,于是我就采用如下代码实现了一个电子时钟的效果.不过不完美,第一种方式容易导致网页莫名其妙的异常,后来觉得可能是做的操作太多了,然后 ...
- 桌面小部件----LED电子时钟实现
桌面控件是通过 Broadcast 的形式来进行控制的,因此每个桌面控件都对应于一个BroadcastReceiver.为了简化桌面控件的开发,Android 系统提供了一个 AppWidgetPro ...
- Qt - 与众不同的电子时钟
Qt的电子时钟是个老掉牙的demo了,但是利用lcdNumber显示的样子非常老土(下图第一个显示效果),一看就知道是从qt帮助文档里摘出来的example,毫无新意. 美化一下系统时钟,抛开固有控 ...
- MFC桌面电子时钟的设计与实现
目录 核心技术 需求分析 程序设计 程序展示 (一)核心技术 MFC(Micosoft Foundation Class Libay,微基础类库)是微基于Windows平台下的C++类库集合,MFC包 ...
随机推荐
- 为什么很多类甚者底层源码要implements Serializable ?
为什么很多类甚者底层源码要implements Serializable ? 在碰到异常类RuntimeException时,发现Throwable实现了 Serializable,还有我们平进的ja ...
- Android 面向协议编程 体会优雅编程之旅
Android中面向协议编程的深入浅出 http://blog.csdn.net/sk719887916/article/details skay编写 说起协议,现实生活中大家第一感觉会想到规则或者约 ...
- MBR和GPT概要学习
MBR和GPT概要学习 1. MBR和GPT 大家所最为熟知的分区方式同时也是最主流的主要有两种:MBR(Master Boot Record)和GPT(GUID Partition Tabl ...
- 【翻译】Ext JS最新技巧——2015-8-11
原文:Top Support Tips Seth Lemmons:使用棒极了的Awesome Font Ext JS 6附带了一个新的海卫一主题,可以使用Font Awesome字体作为背景图像的图标 ...
- Cocos2D:塔防游戏制作之旅(十七)
getHpDamage方法当敌人到达基地时被调用.你需要添加该方法到Enemy.m的update:方法中去,以便检查当敌人到达基地是会发生什么.幸运的是,你已经在之前的代码中实现这些了,你可以接着往下 ...
- Python+Visual Studio
一直在找一个比较好的Python IDE,无奈找来找去都不太好用,由于经常用Visual Studio,所以很希望找到一个能够在VS中的Python扩展.今天发现了一个很给力的VS扩展,可以在VS中方 ...
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十二)
回到Xcode,新建Level1类,继承于CCNode. 打开Level1.m在初始化方法中添加如下方法: -(void)didLoadFromCCB{ [self initBasket]; [sel ...
- chrome "Provisional headers are shown"
我的问题的,每次打开浏览器,点开有视频的页面(云平台的存储),然后当视频还没有加载完,就马上关闭,连续操作很多次(测试的暴力测试把),F12查看就有很多很多在加载中的连接,因为连续点击太多次了,第一个 ...
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十二)
自己的游戏自己更需要多玩,这样才能首先发现不足的地方.所以本猫到现在已经忍一个地方很久了,就是弹出moneyLayer后每次都要输入数字才能关闭,这多少让人不爽.于是本篇我们就修正这个小小的不便. 首 ...
- shell重定向(大于号,小于号,左右,2>&1,&)
本文的例子部分是引用网络上的一篇文章. Linux的IO输入输出有三类 Standard Input 代码 0 Standard Output 代码 1 Standard Error 代码 2 举个例 ...