由于热转印没腐蚀好,时间太长把一根10mil的线给蚀断了,跳了一根线
从上往下:
第一个按钮,开启、
开启模式下,4个按钮均无响应
第四个按钮,设置、
设置模式下,第二个按钮减时间,第三个按钮加时间, 再按第四个按钮将设置好的时间写入内部EEROM(写入部分程序没写),红、黄灯在下载时为串口数据指示灯,在工作时,黄灯为开启指示灯同时继电器吸合,定时完毕黄灯灭继电器分离,由于数码管冒号部分未做
电路,红灯在开启时为读秒闪烁灯。
以下为C程序:
main.c:
#include"cfg.h"
#include"tm1650.h"
bool set,start,led,b1,b2,y1,y2;
uchar t,
timeout,t2;
void Timer0Init(void) //50毫秒@11.0592MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x00; //设置定时初值
TH0 = 0x4C; //设置定时初值
TF0 = 0; //清除TF0标志
}
void Timer0() interrupt 1
{
TL0 = 0x00; //设置定时初值
TH0 = 0x4C; //设置定时初值
t++;
t2++;
if (t>=10){
b1=1;
t=0;
}
if (t2>=20){
b2=1;
t2=0;
}
}
void startvoid(){
uchar key;
uchar thetime,timeout2;
thetime=timeout;
t=10;
t2=20;
TR0=1;
P34=0;
P31=0;
thetime--;
timeout2=60;
led=0;
while (1){
if (b1){
b1=0;
P30=led;
led=~led;
}
if (b2){
b2=0;
if (timeout2==0){
if (thetime==0){
P31=1;
P30=1;
TR0=0;
P34=1;
start=0;
break;
}else{
thetime--;
}
timeout2=59;
}else{
timeout2--;
}
displaytm1650(1,LED7Code0[thetime/10]);
displaytm1650(2,LED7Code0[thetime%10]);
displaytm1650(3,LED7Code0[timeout2/10]);
displaytm1650(4,LED7Code0[timeout2%10]);
}
}
displaytm1650(1,LED7Code0[timeout/10]);
displaytm1650(2,LED7Code0[timeout%10]);
}
void setvoid(){
uchar key;
t=10;
TR0=1;
led=0;
while (1){
if (b1){
b1=0;
if (!led){
displaytm1650(0x48,0x08);
led=~led;
}else{
displaytm1650(0x48,(6<<4)|0x09);
led=~led;
}
}
key = getkeytm1650();
if (key==0x47 && set){
while (1){
key=getkeytm1650();
if (key!=0x47){
break;
}
}
TR0=0;
set=0;
displaytm1650(0x48,(6<<4)|0x09);
break;
}
if (key==0x46 && set){
while (1){
key=getkeytm1650();
if (key!=0x46){
break;
}
}
timeout++;
if (timeout>60){
timeout=60;
}
displaytm1650(1,LED7Code0[timeout/10]);
displaytm1650(2,LED7Code0[timeout%10]);
}
if (key==0x45 && set){
while (1){
key=getkeytm1650();
if (key!=0x45){
break;
}
}
timeout--;
if (timeout<1){
timeout=1;
}
displaytm1650(1,LED7Code0[timeout/10]);
displaytm1650(2,LED7Code0[timeout%10]);
}
}
}
void main() {
uchar key;
P3=0xff;
inittm1650();
timeout=1;
displaytm1650(1,LED7Code0[timeout/10]);
displaytm1650(2,LED7Code0[timeout%10]);
displaytm1650(3,LED7Code0[0]);
displaytm1650(4,LED7Code0[0]);
Timer0Init();
ET0=1;
EA=1;
while (1){
key=getkeytm1650();
switch (key){
case 0x44:
if (!set && !start){
start=1;
while (1){
key=getkeytm1650();
if (key!=0x44){
break;
}
}
startvoid();
}
break;
case 0x45:
break;
case 0x46:
break;
case 0x47:
if (!start && !set){
set=1;
while (1){
key=getkeytm1650();
if (key!=0x47){
break;
}
}
setvoid();
}
break;
default:
break;
}
}
}
TM1650驱动:
#ifndef __TM1650_H__
#define __TM1650_H__
//DIG1 = 0x68;
//DIG2 = 0x6A;
//DIG3 = 0x6C;
//DIG4 = 0x6E;
***it TM1650_SCL = P3^3;
***it TM1650_SDA = P3^2;
// ***it TM1650_ERROR = P3^5;
//亮度
uchar TM1650_LEVEL = 6;
uchar code TM1650_ADDRS[4] = {0x68,0x6a,0x6c,0x6e};
void displaytm1650(uchar addr,uchar dat);
uchar getkeytm1650(void);
void inittm1650(void);
void inittm1650() {
uchar i;
uchar length = sizeof(TM1650_ADDRS)/sizeof(TM1650_ADDRS[0]);
displaytm1650(0x48,(TM1650_LEVEL<<4)|0x09);
for (i=0; i
displaytm1650(TM1650_ADDRS
,0x40);
}
}
void START1650() {
TM1650_SCL=1;
TM1650_SDA=1;
nops;
TM1650_SDA=0;
}
void STOP1650() {
TM1650_SCL=1;
TM1650_SDA=0;
nops;
TM1650_SDA=1;
}
void ask1650() {
uchar timeout = 1;
TM1650_SCL=0;
TM1650_SCL=1;
nops;
TM1650_SCL=0;
while((TM1650_SDA)&&(timeout<=100)) {
timeout++;
}
nops;
TM1650_SCL=0;
}
void wrbyte1650(uchar x) {
uchar i;
TM1650_SCL=0;
for(i=0; i<8; i++) {
TM1650_SDA = (x & 0x80)?1:0;
nops;
TM1650_SCL=1;
nops;
TM1650_SCL=0;
nops;
x <<= 1;
}
TM1650_SCL=0;
}
uchar getkeytm1650() {
uchar x,i;
START1650();
TM1650_SCL=0;
wrbyte1650(0x49);
ask1650();
for(i=0; i<8; i++) {
x <<= 1;
TM1650_SCL=1;
nops;
if(TM1650_SDA) {
x = x | 0x01;
}
TM1650_SCL=0;
nops;
}
TM1650_SCL=0;
ask1650();
STOP1650();
return x;
}
void displaytm1650(uchar addr,uchar dat) {
START1650();
switch(addr) {
case 1:
wrbyte1650(TM1650_ADDRS[0]);
ask1650();
wrbyte1650(dat);
ask1650();
break;
case 2:
wrbyte1650(TM1650_ADDRS[1]);
ask1650();
wrbyte1650(dat);
ask1650();
break;
case 3:
wrbyte1650(TM1650_ADDRS[2]);
ask1650();
wrbyte1650(dat);
ask1650();
break;
case 4:
wrbyte1650(TM1650_ADDRS[3]);
ask1650();
wrbyte1650(dat);
ask1650();
break;
default:
wrbyte1650(addr);
ask1650();
wrbyte1650(dat);
ask1650();
break;
}
STOP1650();
}
#endif
以下附件包含所有文件
https://bbs.elecfans.com/forum.php?mod=attachment&aid=NzA4NTY2fDAzZGI0ZGJjN2ZiMjE1ZjRlOGJmZGU1NGI1MDNlNjQzfDE3MzIyNjQyNTE%3D&request=yes&_f=.rar
`