📄 main.c
字号:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "24c02.h"
int counter=0;
int i;
unsigned char p=0;
unsigned char q=0;
unsigned int shuju;
unsigned int b1,b2,b3,b4,b5,b1r,b2r,b3r,b4r,b=0;
unsigned int d1,d2,d3,d4,d5,d1r,d2r,d3r,d4r,d=0;
const unsigned int tab[]={0xFB,0xF7,0xEF,0xDF,0xBF,0x00};
//{0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF};
const unsigned char duanma[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
//void sendbyte(void);
void delay (int k);
void printNum(void);
void printNum2(void);
void MCU_init(void); /* Device initialization function declaration */
unsigned char data[]={
0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,
0X80,0X90,0X88,0X83,0XC6,0XA7,0XA1,0X86,
0X8E,0X89,0X8B,0XC7,0XAB,0XC8,0XA3,0X8C,
0XAF,0X87,0XC1,0X89,0XBF,0X7F,0XFF,0XFF,};//显示字符库
unsigned char date1[8]={0};
unsigned char date2[8]={0};
unsigned char date3[8]={0};
unsigned char date4[8]={0};
unsigned char date5[8]={//定义时间初始化数据缓存
0};
unsigned char j;
void main(void) {
MCU_init(); /* call Device Initialization */
PTA &= (unsigned char)~0xBC;
PTA |= (unsigned char)0xa1;
DDRA |= (unsigned char)0xBD;
j=WriteEEPROM((unsigned char *)data ,0,8);
/* include your code here */
j= ReadEEPROM((unsigned char *)date1,0 ,8);
j=WriteEEPROM((unsigned char *)(data+8) ,8,8 );
/* include your code here */
j= ReadEEPROM(date2,8 ,8 );
j=WriteEEPROM((unsigned char *)(data+16) ,16,8);
/* include your code here */
j= ReadEEPROM(date3,16 ,8 );
j=WriteEEPROM((unsigned char *)(data+24) ,24,8 );
/* include your code here */
j= ReadEEPROM(date4,24,8 );
//j=WriteEEPROM((unsigned char *)data5,32,8);//清除记录的时间
j= ReadEEPROM(date5,32,8);
shuju=date5[2]*255;
b=date5[1]+shuju;
for(;;) {
for(;q==0;){
PTB=0XFF;
date5[2]=(unsigned char)(b/255);
date5[1]=(unsigned char)(b%255);
j=WriteEEPROM((unsigned char *)date5,32,8);
q++;
}
if(p==255)printNum2();
else printNum();
}
}
void delay (int k){//一般的延时程序
for(i=0;i<=k;i++);
}
void sendbyte(unsigned int i)
{
unsigned int num,c;
num=tab[i];
for(c=0;c<8;c++){
PTD_PTD4=0;
PTD_PTD1=num&0x01;
PTD_PTD4=1;
num>>=1;
}
}
void printNum(void){ //时间转换显示
//显示到数码管上
b1=(unsigned int)b/10000;sendbyte(5);
if(b1>8){
PTB=date2[(b1-8)];
}
else PTB=date1[b1];
b1r=(unsigned int)(b%10000);
delay(450); //延时
b2=(unsigned int)b1r/1000;sendbyte(4);
if(b2>8){
PTB=date2[(b2-8)];
}
else PTB=date1[b2];
b2r=(unsigned int)(b%1000);
delay(450);//延时
b3=(unsigned int)b2r/100;sendbyte(3);
if(b2>8){
PTB=date2[(b3-8)];
}
else PTB=date1[b3];
b3r=(unsigned int)(b%100);
delay(450);//延时
b4=(unsigned int)b3r/10;sendbyte(2);
if(b2>8){
PTB=date2[(b4-8)];
}
else PTB=date1[b4];
b4r=(unsigned int)(b%10);
delay(450);//延时
b5=(unsigned int)b4r;
sendbyte(1);
if(b5>8){
PTB=date2[(b5-8)];
}
else PTB=date1[b5];
delay(450);//延时
}
void printNum2(void){//AD转换显示
//显示到数码管上
d=(unsigned int)(date5[3]*196);//adr/255*10000将0-255的数转换为百分数,因为不好处理小数,所以扩大10000
d1=(unsigned int)d/10000;sendbyte(5);PTB=duanma[d1];delay(300);
sendbyte(5);PTB=0X7F;
d1r=(unsigned int)d%10000;
d2=(unsigned int)d1r/1000;sendbyte(4);PTB=duanma[d2];delay(300);d2r=(unsigned int)d%1000;
d3=(unsigned int)d2r/100;sendbyte(3);PTB=duanma[d3];delay(300);d3r=(unsigned int)d%100;
d4=(unsigned int)d3r/10;sendbyte(2);PTB=duanma[d4];delay(300);d4r=(unsigned int)d%10;
d5=(unsigned int)d4r;sendbyte(1);PTB=duanma[d5];delay(300);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -