基于C8051F的AD UART0 KEY FLASH TIME3程序
if(BGset>
if(k>
if(Page>
if(!(Mkey&0x08)) //SW5按下吗?右移->
if(direction >
if(keybuffer[0]>
if(Tset>
if(keybuffer[1]>
if(Tset>
if(keybuffer[2]>
if(Tset>
if(keybuffer[3]>
if(Tset>
if(keybuffer[4]>
if(Tset>
if(keybuffer[5]>
delayms(200);
if(!(P4&0x20))
{
BGset = 2;
keybuffer[5]--;
if(keybuffer[5]<=0) //小于1,显示23
{
keybuffer[5] = 59;
}
}
}
if(Tset < 4)
{
TH = keybuffer[5]/10;
TL = keybuffer[5]%10;
number_disp (0,1,0x89,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (0,1,0x89,1,0x20,0x20);
}
}break;
default:break;
}
if(!(Mkey&0x02)) //SW7按下吗?确认ENT 只在6画面设定时间
{
delayms(200);
if(!(Mkey&0x02))
{
BGset =2;
for(i=0;i<6;i++)
{
time_buf1[i+1] = keybuffer[i];
}
Ds1302_Write_Time(); //写DS1302
set = 0;
Page = 1; //退出到1画面
}
}
}
}
}
}
void Pchange(uint PW)
{
TH = PW/10000; //放电万位
TL = (PW-TH*10000)/1000; //千位
TT1 = (PW-TH*10000-TL*1000)/100;
TT2 = (PW-TH*10000-TL*1000-TT1*100)/10;
TT3 = (PW-TH*10000-TL*1000-TT1*100)%10;
if(!TH)
{
TH = 10;
if(!TL)
{
TL = 10;
if(!TT1)
{
TT1 = 10;
}
}
}
}
//-----------------------------------------------------------------------------
// Main 年:0xC4EA 月:0xD4C2 日:0xC8D5 时:0xCAB1: 分0xB7D6: 秒:0xC3EB 的汉字内码
//-----------------------------------------------------------------------------
void main(void)
{
uchar Page1,j;
uchar Runstate ; //Runstate为运行状态指示:DI1=1;DI2=1停机;DI1=0;DI2=1充电;DI1=1;DI2=0放电;DI1=1;DI2=1故障
uint VT,AT,PT,PC1,PF1,PDIS,PdownCount; //电压电流功率功率计数变量
uint ADC1,ADC2,ADC3,ADC4; //四路AD通道变量
long a,PT1,PT2; //P1,P2充放电累计功率
//P0 = 0;
//P1 = 0;
P4 =0xfe;
P2 = 0;
P3 = 0;
Init_Device();
PCA0MD &= ~0x40;
EA = 0;
//BLK = 1;
delayms(1000);
Ds1302_Init();
init_lcd ();
clrram ();
ADC0CF = ((SYSCLK/3000000)-1)<3; // set SAR clock to 3MHz
ADC0CN |=0x10; //写ADC0BUSY位启动转换
TMR3CN = 0x04; //启动TM3
//Timer2_Init(SYSCLK/12/50); //20ms
EA = 1;
DE = 1;
TR1 = 1;
Ds1302_Read_Time();
while(1)
{
//PCA0CPH2 = 1; //喂狗
key_scan();
if(BGset)
{
BLK = 1;
}
if(!BGset)
{
BLK = 0;
} //按键扫描
if((DI1==1)&&(DI2==1)) Runstate = 0xa6; //停机
if((DI1==0)&&(DI2==1)) Runstate = 0xb7; //充电
if((DI1==1)&&(DI2==0)) Runstate = 0xc8; //放电
if((DI1==0)&&(DI2==0)) Runstate = 0xd9; //故障
//if(Runstate == 0xb7) //充电的FLASH存储处理
if(!set)
{
if((time_buf1[2] != CPT_c[10])|| (time_buf1[3] != CPT_c[11])) //读取的当前时间与缓存不等的时候,所有内容依次前移
{
Between[0]=CPT_c[3]; //依次前移
Between[1]=CPT_c[4];
Between[2]=CPT_c[5];
Between[3]=CPT_c[6];//年
Between[4]=CPT_c[7];//月
Between[5]=CPT_c[8];//日
Between[6]=CPT_c[9];
Between[7]=CPT_c[10];
Between[8]=CPT_c[11];
Between[9]=time_buf1[1];
Between[10]=time_buf1[2];
Between[11]=time_buf1[3];
Between[12]=CPT_c[14];
Between[13]=CPT_c[15];
Between[14]=CPT_c[16];
Between[15]=CPT_c[17];
Between[16]=CPT_c[18];
Between[17]=CPT_c[19];
Between[18] = PC1>>8;
Between[19] = PC1&255;
Flash_Erase_CTP();
Flash_Program_CTP(); //保存至FLASH
}
}
//if(Runstate == 0xc8) //放电时FLASH存储处理
if(!set)
{
if((time_buf1[2] != FPT_c[10])|| (time_buf1[3] != FPT_c[11]))
{
Between[0]=FPT_c[3]; //依次前移
Between[1]=FPT_c[4];
Between[2]=FPT_c[5];
Between[3]=FPT_c[6];//年
Between[4]=FPT_c[7];//月
Between[5]=FPT_c[8];//日
Between[6]=FPT_c[9];
Between[7]=FPT_c[10];
Between[8]=FPT_c[11];
Between[9]=time_buf1[1];
Between[10]=time_buf1[2];
Between[11]=time_buf1[3];
Between[12]=FPT_c[14];
Between[13]=FPT_c[15];
Between[14]=FPT_c[16];
Between[15]=FPT_c[17];
Between[16]=FPT_c[18];
Between[17]=FPT_c[19];
Between[18] = PF1>>8;
Between[19] = PF1&255;
Flash_Erase_FTP();
Flash_Program_FTP();
C8051FADUART0TIME 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)