Mixly 数码管时钟实验
程序员文章站
2022-05-28 10:02:00
...
Mixly 数码管时钟实验
一、实验目的及要求
【实验一】实现滚动显示自定义字符串。
【实验二】实现显示自定义时间。
【实验三】实现显示秒表。
二、实验原理与内容
实现米思齐的数码管图形化编程。
三、核心代码
【实验一】实现滚动显示自定义字符串。
【实验二】实现显示自定义时间。
核心代码截图
``
【实验三】实现显示秒表。
核心代码
#include <EEPROM.h>
#include <avr/pgmspace.h>
#include <TimerOne.h>
#include <TM1637.h>
int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};
unsigned char ClockPoint = 1;
unsigned char Update;
unsigned char microsecond_10 = 0;
unsigned char second;
unsigned char _microsecond_10 = 0;
unsigned char _second;
unsigned int eepromaddr;
boolean Flag_ReadTime;
#define ON 1
#define OFF 0
TM1637 tm1637(5,4);
void TimeUpdate2(void)
{
if(ClockPoint)tm1637.point(POINT_ON);
else tm1637.point(POINT_OFF);
TimeDisp[2] = _microsecond_10 / 10;
TimeDisp[3] = _microsecond_10 % 10;
TimeDisp[0] = _second / 10;
TimeDisp[1]= _second % 10;
Update = OFF;
}
void TimingISR2()
{
microsecond_10 ++;
Update = ON;
if(microsecond_10 == 100)
{
second ++;
if(second == 60)
{
second = 0;
}
microsecond_10 = 0;
}
ClockPoint =(~ClockPoint) & 0x01;
if(Flag_ReadTime == 0)
{_microsecond_10 = microsecond_10;
_second = second; }
}
void readTime(){
Flag_ReadTime = 1;
if(eepromaddr == 0)
{
Serial.println("The time had been read");
_microsecond_10 = 0;
_second = 0;
}
else{
_second = EEPROM.read(-- eepromaddr);
_microsecond_10 = EEPROM.read(-- eepromaddr);
Serial.println("List the time");
}
Update = ON;
}
void saveTime()
{EEPROM.write(eepromaddr ++,microsecond_10);
EEPROM.write(eepromaddr ++,second);
}
void stopwatchPause()
{
TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
}
void stopwatchReset()
{
stopwatchPause();
Flag_ReadTime = 0;
_microsecond_10 = 0;
_second = 0;
microsecond_10 = 0;
second = 0;
Update = ON;
}
void stopwatchStart()
{
Flag_ReadTime = 0;
TCCR1B |=Timer1.clockSelectBits;
}
void setup(){
tm1637.init();
tm1637.set();
tm1637.init();
Timer1.initialize(10000);
Timer1.attachInterrupt(TimingISR2);
}
void loop(){
stopwatchStart();
if(Update == ON)
{
TimeUpdate2();
tm1637.display(TimeDisp);
}
}
上一篇: Java中的常用类:System 类
下一篇: Mixly数码管时钟实验