本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
请问下大家 如何在主程序中由显示程序切换到其他程序当中并停留在其他程序中,待其他程序调整完后返回显示程序。 例如下面的程序:在主程序中如何保持在display_shezhi1()并且可以返回到主程序
while(1)中。谢谢了大家 ,帮帮忙吧
下面是程序:
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
uchar shi,fen,miao,shi_fen,ge_fen,shi_shi,ge_shi,shi_miao,ge_miao,num;
uint t;
#define rst RB0
#define sclk RB1
#define DATE RB2
#define sclk_HIGH() TRISB2=0,RB1=1
#define sclk_LOW() TRISB2=1,RB1=0
#define SET RB3
#define JIA RB4
#define JIAN RB5
#define RESET RB6
#define SR RB7
__CONFIG(0X3B31);
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f};
const uchar table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};
const uchar table2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint z);
void display_sfm(uchar date,uchar date1,uchar date2);
void get_sfm1302sj();
void init();
uchar read_1302z(uchar add);
void write_1302z(uchar add,uchar date);
uchar read_1302();
void write_1302(uchar date);
void display_shezhi1();
void display_shezhi2();
void main()
{
init();
while(1)
{
get_sfm1302sj();
display_sfm(shi,fen,miao);
if(SR=1)
{
display_shezhi1();
}
}
}
void write_1302(uchar date)
{
uint i;
sclk_LOW();
NOP();
NOP();
for(i=8;i>0;i--)
{
DATE=date&0x01;
NOP();
NOP();
sclk_HIGH();
NOP();
NOP();
sclk_LOW();
date=date>>1;
}
}
uchar read_1302()
{
uchar date;
NOP();
NOP();
for(t=8;t>0;t--)
{
date=date>>1;
if(DATE==1)
{
date=date|0x80;
}
sclk_HIGH();
NOP();
NOP();
sclk_LOW();
NOP();
NOP();
}
return(date);
}
void write_1302z(uchar add,uchar date)
{
rst=0;
NOP();
NOP();
rst=1;
write_1302(add);
write_1302(date);
NOP();
NOP();
rst=0;
}
uchar read_1302z(uchar add)
{
uchar date;
rst=0;
NOP();
NOP();
rst=1;
write_1302(add);
date=read_1302();
read_1302();
rst=0;
return(date);
}
void init()
{
uchar second,q;
second=read_1302z(0x80);
num=5;
TRISB0=0;
TRISB1=0;
TRISB3=1;
TRISB4=1;
TRISB5=1;
TRISB6=1;
TRISB7=1;
TRISD=0;
TRISC=0;
PORTD=0XEF;
PORTC=0x3f;
delay(5);
PORTD=0XdF;
PORTC=0x3f;
delay(5);
PORTD=0XbF;
PORTC=0x3f;
delay(5);
PORTD=0X7F;
PORTC=0x3f;
q=second|0x80;
if(q==0)
{
write_1302z(0x8e,0x00);
write_1302z(0x8c,0x07);
write_1302z(0x88,0x07);
write_1302z(0x86,0x25);
write_1302z(0x8a,0x07);
write_1302z(0x84,0x23);
write_1302z(0x82,0x59);
write_1302z(0x80,0x55);
write_1302z(0x8e,0x80);
}
}
void get_sfm1302sj()
{
uchar readvalue,l,o;
readvalue=read_1302z(0x83);
fen=((readvalue&0x70)>>4)*10+(readvalue&0x0f);
l=read_1302z(0x85);
shi=((l&0x70)>>4)*10+(l&0x0f);
o=read_1302z(0x81);
miao=((o&0x70)>>4)*10+(o&0x0f);
}
void display_sfm(uchar date,uchar date1,uchar date2)
{
shi_fen=fen/10;
ge_fen=fen%10;
shi_shi=shi/10;
ge_shi=shi%10;
shi_miao=miao/10;
ge_miao=miao%10;
PORTD=0Xfb;
PORTC=table[shi_shi];
delay(5);
PORTD=0Xf7;
PORTC=table1[ge_shi];
delay(5);
PORTD=0XeF;
PORTC=table[shi_fen];
delay(5);
PORTD=0XdF;
PORTC=table1[ge_fen];
delay(5);
PORTD=0XbF;
PORTC=table[shi_miao];
delay(5);
PORTD=0X7F;
PORTC=table[ge_miao];
}
void display_shezhi1()
{
PORTD=0XFB;
PORTC=table2[15];
delay(5);
PORTD=0xf7;
PORTC=table[0];
delay(5);
PORTD=0xef;
PORTC=table[5];
delay(5);
}
void display_shezhi2()
{
shi_num=num/10;
ge_num=num%10;
PORTD=0xf7;
PORTC=table[shi_num];
delay(5);
PORTD=0xef;
PORTC=table[ge_num];
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
} |
|