新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 基于C8051F的AD UART0 KEY FLASH TIME3程序

基于C8051F的AD UART0 KEY FLASH TIME3程序

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
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 的漢字內(nèi)碼
//-----------------------------------------------------------------------------
void main(void)
{
uchar Page1,j;
uchar Runstate ; //Runstate為運(yùn)行狀態(tài)指示:DI1=1;DI2=1停機(jī);DI1=0;DI2=1充電;DI1=1;DI2=0放電;DI1=1;DI2=1故障
uint VT,AT,PT,PC1,PF1,PDIS,PdownCount; //電壓電流功率功率計數(shù)變量
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位啟動轉(zhuǎn)換
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; //停機(jī)
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])) //讀取的當(dāng)前時間與緩存不等的時候,所有內(nèi)容依次前移
{
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(); //保存至FLASH
}
}
if(PDD)
{
PDD = 0;
if(Runstate == 0xb7) //如果充電
{
PdownCount++; //秒累加
PT1 = PT1+PT; //秒累計的功率,
PC1 = PT1/3600; //實際充電功率,按小時計算,注意此時累計電量為實際的10倍,為了送小數(shù)顯示
if(PdownCount > T) //超過半個小時開始寫入EEPROM
{
PdownCount = 0;
for(j=0;j<20;j++) //先讀出FLASH里的時間
{
Between[j]=CPT_c[j];
}
if((time_buf1[2] == Between[10])&& (time_buf1[3] == Between[11])) //當(dāng)前時間等于緩存時間,繼續(xù)寫入緩存
{
Between[18] = PC1>>8;
Between[19] = PC1&255;
Flash_Program_CTP(); //寫功率和時間到FLASH
}
}
}
if(Runstate == 0xc8) //如果放電
{
PdownCount++; //秒累加
PT2 = PT2+PT; //秒累計的功率
PF1 = PT2/3600; //實際放電功率,按小時計算,,注意此時累計電量為實際的10倍,為了送小數(shù)顯示
if(PdownCount > T) //超過半個小時開始寫入EEPROM
{
PdownCount = 0;
for(j=0;j<20;j++) //先讀出FLASH里的時間
{
Between[j]=FPT_c[j];
}
if((time_buf1[2] == Between[10])&& (time_buf1[3] == Between[11])) //當(dāng)前時間等于緩存時間,繼續(xù)寫入緩存
{
Between[18] = PF1>>8;
Between[19] = PF1&255;
Flash_Program_FTP(); //寫功率和時間到FLASH
}
}
}
}
if(Disptime)
{
Disptime = 0;
Ds1302_Read_Time();
if(Page!=Page1)
{
clrram (); //如果頁面變化,需要清屏;
}
switch(Page)
{
case 1: //畫面1:顯示當(dāng)前電壓電流
{
string_disp (1,0,0x80,10,tab1); //顯示電壓
string_disp (1,0,0x90,10,tab2); //顯示電流
string_disp (0,1,0x80,10,tab3); //顯示功率
string_disp (0,1,0x90,10,tab4);
if(Runstate == 0xa6)string_disp (0,1,0x96,4,run1); //顯示停機(jī)
if(Runstate == 0xb7)string_disp (0,1,0x96,4,run2); //顯示充電
if(Runstate == 0xc8)string_disp (0,1,0x96,4,run3); //顯示放電
if(Runstate == 0xd9)string_disp (0,1,0x96,4,run4); //顯示故障
TH= VT/1000; //拆分送顯示千位
TL = (VT%1000)/100; //拆分送顯示百位
TT1 = ((VT%1000)%100)/10; //拆分送顯示十位
TT2 = ((VT%1000)%100)%10; //拆分送顯示個位
if(!TH)
{
TH = 10;
if(!TL)
{
TL = 10;
}
}
number_disp (1,0,0x85,1,TAB[TH],TAB[TL]); //電壓送顯示
number_disp (1,0,0x86,1,TAB[TT1],0x2E);
number_disp (1,0,0x87,1,TAB[TT2],0x20);
number_disp (1,0,0x88,1,0x56,0x20);
TH= AT/1000; //拆分送顯示千位
TL = (AT%1000)/100; //拆分送顯示百位
TT1 = ((AT%1000)%100)/10; //拆分送顯示十位
TT2 = ((AT%1000)%100)%10; //拆分送顯示個位
if(!TH) //高位為零,滅零處理
{
TH = 10;
if(!TL)
{
TL = 10;
}
}
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]); //電流送顯示
number_disp (1,0,0x96,1,TAB[TT1],0x2E);
number_disp (1,0,0x97,1,TAB[TT2],0x20);
number_disp (1,0,0x98,1,0x41,0x20);
TH= PT/1000; //拆分送顯示千位
TL = (PT%1000)/100; //拆分送顯示百位
TT1 = ((PT%1000)%100)/10; //拆分送顯示十位
TT2 = ((PT%1000)%100)%10; //拆分送顯示個位
if(!TH) //高位為零,滅零處理
{
TH = 10;
if(!TL)
{
TL = 10;
}
}
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]); //功率送顯示
number_disp (0,1,0x86,1,TAB[TT1],0x2E);
number_disp (0,1,0x87,1,TAB[TT2],0x4B);
number_disp (0,1,0x88,1,0x57,0x20);
Page1=Page; //保存當(dāng)前頁面值
}break;
case 2:
{
string_disp (1,0,0x80,12,run6);
string_disp (0,1,0x80,12,run7);
Pchange(PC1);
number_disp (1,0,0x94,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x95,1,TAB[TT1],TAB[TT2]);
number_disp (1,0,0x96,1,0x2e,TAB[TT3]);
number_disp (1,0,0x97,1,0x4b,0x57);
Pchange(PF1);
number_disp (0,1,0x94,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x95,1,TAB[TT1],TAB[TT2]);
number_disp (0,1,0x96,1,0x2e,TAB[TT3]);
number_disp (0,1,0x97,1,0x4b,0x57);
Page1=Page;
}break;
case 3: //顯示歷史充電記錄
{
string_disp (1,0,0x80,12,tab5); //
//第1條信息
if((CPT_c[0]>99)||(CPT_c[1]>12)||(CPT_c[2]>31))
{
string_disp (1,0,0x90,8,tab9);
} //如果讀取時間不對,顯示“暫無記錄”
else
{
number_disp (1,0,0x90,1,0x32,0x30); //0送顯示
TH = CPT_c[0]/10;
TL = CPT_c[0]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x92,1,0xc4,0xea); //年
TH = CPT_c[1]/10;
TL = CPT_c[1]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x94,1,0xd4,0xc2); //月
TH = CPT_c[2]/10;
TL = CPT_c[2]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x96,1,0xc8,0xd5); //日
PDIS = CPT_c[12];
PDIS = PDIS<<8 + CPT_c[13];
Pchange(PDIS);
number_disp (1,0,0x98,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x99,1,TAB[TT1],TAB[TT2]);
number_disp (1,0,0x9A,1,0x2e,TAB[TT3]);
number_disp (1,0,0x9B,1,0x4b,0x57);
}
//第2條信息
if((CPT_c[3]>99)||(CPT_c[4]>12)||(CPT_c[5]>31))
{
string_disp (0,1,0x80,8,tab9);
} //如果讀取時間不對,顯示“暫無記錄”
else
{
number_disp (0,1,0x80,1,0x32,0x30); //0送顯示
TH = CPT_c[3]/10;
TL = CPT_c[3]%10;
number_disp (0,1,0x81,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x82,1,0xc4,0xea); //年
TH = CPT_c[4]/10;
TL = CPT_c[4]%10;
number_disp (0,1,0x83,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x84,1,0xd4,0xc2); //月
TH = CPT_c[5]/10;
TL = CPT_c[5]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x86,1,0xc8,0xd5); //日
PDIS = CPT_c[14];
PDIS = PDIS<<8 + CPT_c[15];
Pchange(PDIS);
number_disp (0,1,0x88,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x89,1,TAB[TT1],TAB[TT2]);
number_disp (0,1,0x8A,1,0x2e,TAB[TT3]);
number_disp (0,1,0x8B,1,0x4b,0x57);
}
//第3條信息
if((CPT_c[6]>99)||(CPT_c[7]>12)||(CPT_c[8]>31))
{
string_disp (0,1,0x90,8,tab9); //如果讀取時間不對,顯示“暫無記錄”
}
else
{
number_disp (0,1,0x90,1,0x32,0x30); //0送顯示
TH = CPT_c[6]/10;
TL = CPT_c[6]%10;
number_disp (0,1,0x91,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x92,1,0xc4,0xea); //年
TH = CPT_c[7]/10;
TL = CPT_c[7]%10;
number_disp (0,1,0x93,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x94,1,0xd4,0xc2); //月
TH = CPT_c[8]/10;
TL = CPT_c[8]%10;
number_disp (0,1,0x95,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x96,1,0xc8,0xd5); //日
PDIS = CPT_c[16];
PDIS = PDIS<<8 + CPT_c[17];
Pchange(PDIS);
number_disp (0,1,0x98,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x99,1,TAB[TT1],TAB[TT2]);
number_disp (0,1,0x9A,1,0x2e,TAB[TT3]);
number_disp (0,1,0x9B,1,0x4b,0x57);
}
Page1=Page;
}break;
case 4: //顯示歷史放電記錄
{
string_disp (1,0,0x80,12,tab6); //
//第1條信息
if((FPT_c[0]>99)||(FPT_c[1]>12)||(FPT_c[2]>31)) //如果讀取時間不對,顯示“暫無記錄”
{
string_disp (1,0,0x90,8,tab9);
}
else
{
number_disp (1,0,0x90,1,0x32,0x30); //0送顯示
TH = FPT_c[0]/10;
TL = FPT_c[0]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x92,1,0xc4,0xea); //年
TH = FPT_c[1]/10;
TL = FPT_c[1]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x94,1,0xd4,0xc2); //月
TH = FPT_c[2]/10;
TL = FPT_c[2]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x96,1,0xc8,0xd5); //日
PDIS = FPT_c[12];
PDIS = PDIS<<8 + FPT_c[13];
Pchange(PDIS);
number_disp (1,0,0x98,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x99,1,TAB[TT1],TAB[TT2]);
number_disp (1,0,0x9A,1,0x2e,TAB[TT3]);
number_disp (1,0,0x9B,1,0x4b,0x57);
}
//第2條信息
if((FPT_c[3]>99)||(FPT_c[4]>12)||(FPT_c[5]>31))
{
string_disp (0,1,0x80,8,tab9); //如果讀取時間不對,顯示“暫無記錄”
}
else
{
number_disp (0,1,0x80,1,0x32,0x30); //0送顯示
TH = FPT_c[3]/10;
TL = FPT_c[3]%10;
number_disp (0,1,0x81,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x82,1,0xc4,0xea); //年
TH = FPT_c[4]/10;
TL = FPT_c[4]%10;
number_disp (0,1,0x83,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x84,1,0xd4,0xc2); //月
TH = FPT_c[5]/10;
TL = FPT_c[5]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x86,1,0xc8,0xd5); //日
PDIS = FPT_c[14];
PDIS = PDIS<<8 + FPT_c[15];
Pchange(PDIS);
number_disp (0,1,0x88,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x89,1,TAB[TT1],TAB[TT2]);
number_disp (0,1,0x8A,1,0x2e,TAB[TT3]);
number_disp (0,1,0x8B,1,0x4b,0x57);
}
//第3條信息
if((FPT_c[6]>99)||(FPT_c[7]>12)||(FPT_c[8]>31))
{
string_disp (0,1,0x90,8,tab9);
}
else
{
number_disp (0,1,0x90,1,0x32,0x30); //0送顯示
TH = FPT_c[6]/10;
TL = FPT_c[6]%10;
number_disp (0,1,0x91,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x92,1,0xc4,0xea); //年
TH = FPT_c[7]/10;
TL = FPT_c[7]%10;
number_disp (0,1,0x93,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x94,1,0xd4,0xc2); //月
TH = FPT_c[8]/10;
TL = FPT_c[8]%10;
number_disp (0,1,0x95,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x96,1,0xc8,0xd5);
PDIS = FPT_c[16];
PDIS = PDIS<<8 + FPT_c[17];
Pchange(PDIS);
number_disp (0,1,0x98,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x99,1,TAB[TT1],TAB[TT2]);
number_disp (0,1,0x9A,1,0x2e,TAB[TT3]);
number_disp (0,1,0x9B,1,0x4b,0x57);
}
Page1=Page;
}break;
case 5: //顯示當(dāng)前時間
{
string_disp (1,0,0x80,10,tab7);
number_disp (1,0,0x90,1,0x32,0x30); //0送顯示
TH = time_buf1[1]/10;
TL = time_buf1[1]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x92,1,0xc4,0xea); //年
TH = time_buf1[2]/10;
TL = time_buf1[2]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x94,1,0xd4,0xc2); //月
TH = time_buf1[3]/10;
TL = time_buf1[3]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x96,1,0xc8,0xd5); //日
TH = time_buf1[4]/10;
TL = time_buf1[4]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]); //
number_disp (0,1,0x86,1,0xca,0xb1); //時
TH = time_buf1[5]/10;
TL = time_buf1[5]%10;
number_disp (0,1,0x87,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x88,1,0xb7,0xd6); //分
TH = time_buf1[6]/10;
TL = time_buf1[6]%10;
number_disp (0,1,0x89,1,TAB[TH],TAB[TL]); //
number_disp (0,1,0x8a,1,0xc3,0xeb); //秒
Page1=Page;
}break;
case 6: //修改時間
{
if(!set) //沒有按SET鍵
{
string_disp (1,0,0x80,10,tab8);
number_disp (1,0,0x90,1,0x32,0x30); //0送顯示
TH = time_buf1[1]/10;
TL = time_buf1[1]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x92,1,0xc4,0xea); //年
TH = time_buf1[2]/10;
TL = time_buf1[2]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x94,1,0xd4,0xc2); //月
TH = time_buf1[3]/10;
TL = time_buf1[3]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
number_disp (1,0,0x96,1,0xc8,0xd5); //日
TH = time_buf1[4]/10;
TL = time_buf1[4]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]); //
number_disp (0,1,0x86,1,0xca,0xb1); //時
TH = time_buf1[5]/10;
TL = time_buf1[5]%10;
number_disp (0,1,0x87,1,TAB[TH],TAB[TL]);
number_disp (0,1,0x88,1,0xb7,0xd6); //分
TH = time_buf1[6]/10;
TL = time_buf1[6]%10;
number_disp (0,1,0x89,1,TAB[TH],TAB[TL]); //
number_disp (0,1,0x8a,1,0xc3,0xeb); //秒
for (j = 0;j<6;j++)
{
keybuffer[j] = time_buf1[j+1];
}
}
Page1=Page; //保存當(dāng)前頁面值
}break;
case 0: //顯示故障狀態(tài)
{
string_disp (1,0,0x90,12,run5);
string_disp (0,1,0x85,12,run8);
Page1=Page; //保存當(dāng)前頁面值
}break;
default:break;
}
}
if(ADsend)
{
ADsend = 0;
if(ADcount == 1)
{
filter();
ADC1= (sum/(N-2));
if(ADC1<5)
{
ADC1 = 0;
}
a = (long)7500*ADC1/1021; //放大10倍,為了送顯示小數(shù)點(diǎn)
VT = a; //
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
AMX0P = 0x06; //下一個轉(zhuǎn)換通道P30
AD0EN = 1;
}
if(ADcount == 2)
{
filter();
ADC2= (sum/(N-2));
a = (long)4000*ADC2/1021; //放大10倍,為了送顯示
AT = a;
a =(long)VT*AT/10000; //放大10倍的功率,單位KW
PT = a;
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
AMX0P = 0x08; //下一個轉(zhuǎn)換通道P26
AD0EN = 1;
}
if(ADcount == 3)
{
filter();
ADC3= (sum/(N-2));
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
AMX0P = 0x09; //下一個轉(zhuǎn)換通道P34
AD0EN = 1;
}
if(ADcount == 4)
{
filter();
ADC4= (sum/(N-2));
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
AMX0P = 0x05; //下一個轉(zhuǎn)換通道P35
AD0EN = 1;
}
}
}
}
void UART0_ISR(void) interrupt 4
{
static uchar Rcv;
if(RI0)
{
Rcv = SBUF0;
RI0 =0;
}
/*if(Rcv == 0x7E) //
{
i = 1;
buffer[0] = Rcv;
}
else
{
if(i < 13) //12個字節(jié)
{
buffer[i] = Rcv;
i++;
}
} */
}
/*void TIME2_ISR (void) interrupt 5
{
TF2H = 0; //清標(biāo)志位
count1++;
if(count1 ==5)
{
count1 = 0;
}
} */
void ADC0_ISR (void) interrupt 10
{
static uchar count; // Loop counter
AD0INT = 0; //清中斷標(biāo)志位
switch( AMX0P ) //通道轉(zhuǎn)換
{
case 0x05: //P2.6
ADCbuffer1[count]=ADC0;
count++;
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
if (count > N-1){
count = 0;
AD0EN = 0; //禁止轉(zhuǎn)換
ADcount = 1;
}
break;
case 0x06: //P3.0
ADCbuffer1[count]=ADC0;
count++;
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
if (count > N-1){
count = 0;
AD0EN = 0;
ADcount = 2;
}
break;
case 0x08: //P3.4
ADCbuffer1[count]=ADC0;
count++;
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
if (count > N-1){
count = 0;
AD0EN = 0;
ADcount = 3;
}
break;
case 0x09: //P3.5
ADCbuffer1[count]=ADC0;
count++;
ADC0CN |=0x10; //寫ADC0BUSY位啟動轉(zhuǎn)換
if (count > N-1){
count = 0;
AD0EN = 0;
ADcount = 4;
}
break;
default:break;
}
}
//-----------------------------------------------------------------------------
//TIMER3中斷
//-----------------------------------------------------------------------------
void Timer3_ISR(void) interrupt 14
{
static uchar i,j,k;
TMR3CN &=~(0x80); //清標(biāo)志位
count++;
i++;
j++;
if(count == 8) //200ms
{
count = 0;
ADsend = 1; //開始進(jìn)行AD處理標(biāo)志
Tset++;
if(Tset>5)
{
Tset = 0;
}
}
if(i==20)
{
i = 0;
Disptime = 1;
}
if(j==39) //1秒誤差累積;正常是40
{
j = 0;
PDD = 1; //一秒時間到,開始計算功率
if(BGset)
{
k++;
if(k>240) //4分鐘關(guān)背光
{
k=0;
BGset = 0;
}
}
}
}
上一頁 1 2 3 下一頁

關(guān)鍵詞: C8051FADUART0TIME

評論


技術(shù)專區(qū)

關(guān)閉