新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于飛思卡爾DZ60的AD 1302 KEY 485 CAN FLASH LCD程序

基于飛思卡爾DZ60的AD 1302 KEY 485 CAN FLASH LCD程序

作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏
if(ReadTimeFlag)
{
ReadTimeFlag = 0;
if(RR ==1)
{
Delay(10);
DE485 = 1;
Ds1302_Read_Time();
asm(nop);
SendSum = (0x6a+Pchange+Failure+ADC1L+ADC1H+ADC2L+ADC2H+P0H+P0L+P1H+P1L+
time_buf1[1]+time_buf1[2]+time_buf1[3]+time_buf1[4]+time_buf1[5]+time_buf1[6]+
MW4L+MW4H+MW5L+MW5H+MW6L+MW6H+MW7L+MW7H+MW8L+MW8H+MW9L+MW9H); //累加和
SCI1send (0x01); //站號(hào)
SCI1send (0x57); //寫命令
SCI1send (0x00); //首地址
SCI1send (0x12); //18個(gè)地址
SCI1send (ADC1H); //MW0高位 電壓
SCI1send (ADC1L); //MW0低位
SCI1send (ADC2H); //MW1 電流
SCI1send (ADC2L);
SCI1send (P0H); //MW2 實(shí)時(shí)功率
SCI1send (P0L);
SCI1send (P1H); //MW3
SCI1send (P1L);
SCI1send (MW4H); //MW4
SCI1send (MW4L);
SCI1send (MW5H); //MW5 當(dāng)前充電電量(一天累計(jì))
SCI1send (MW5L);
SCI1send (MW6H); //MW6
SCI1send (MW6L);
SCI1send (MW7H); //MW7 當(dāng)前放電電量(一次累計(jì))
SCI1send (MW7L);
SCI1send (MW8H); //MW8 當(dāng)前放電電量(一次累計(jì))
SCI1send (MW8L);
SCI1send (MW9H); //MW9 當(dāng)前放電電量(一次累計(jì))
SCI1send (MW9L);
SCI1send (0x00); //MW10 充放電指示00:放電;FF:充電
SCI1send (Pchange);
SCI1send (0x00); //MW11開始為時(shí)間
SCI1send (time_buf1[1]);
SCI1send (0x00);
SCI1send (time_buf1[2]);
SCI1send (0x00);
SCI1send (time_buf1[3]);
SCI1send (0x00);
SCI1send (time_buf1[4]);
SCI1send (0x00);
SCI1send (time_buf1[5]);
SCI1send (0x00);
SCI1send (time_buf1[6]);
SCI1send (0x00); //MW17 過(guò)壓過(guò)流指示
SCI1send (Failure);
SCI1send (SendSum);
asm(nop);
Delay(100);
SendSum = 0x7d+MW21H+MW21L+MW22H+MW22L+MonthC1+DateC1+MW25H+MW25L+MW26L+MW26H+MonthC2+DateC2
+MW29H+MW29L+MW30H+MW30L+MonthF1+DateF1+MW33L+MW33H+MW34H+MW34L+MonthF2+DateF2;
SCI1send (0x01); //站號(hào)
SCI1send (0x57); //寫命令
SCI1send (0x15); //21號(hào)地址
SCI1send (0x10); //16個(gè)地址
SCI1send (MW21H); //MW21高位
SCI1send (MW21L); //MW21低位
SCI1send (MW22H); //MW22
SCI1send (MW22L);
SCI1send (0x00); //月 MW23
SCI1send (MonthC1);
SCI1send (0x00); //日 MW24
SCI1send (DateC1);
SCI1send (MW25H); //MW25
SCI1send (MW25L);
SCI1send (MW26H); //MW26
SCI1send (MW26L);
SCI1send (0x00); //MW27
SCI1send (MonthC2);
SCI1send (0x00); //MW28
SCI1send (DateC2);
SCI1send (MW29H); //MW29
SCI1send (MW29L);
SCI1send (MW30H); //MW30
SCI1send (MW30L);
SCI1send (0x00); //MW31
SCI1send (MonthF1);
SCI1send (0x00); //MW32
SCI1send (DateF1);
SCI1send (MW33H); //MW33
SCI1send (MW33L);
SCI1send (MW34H); //MW34
SCI1send (MW34L);
SCI1send (0x00); //MW35
SCI1send (MonthF2);
SCI1send (0x00); //MW36
SCI1send (DateF2);
SCI1send (SendSum); //累加和
asm(nop);
Delay(10);
SCI1send (0x01); //站號(hào)
SCI1send (0x52); //讀命令
SCI1send (0x13); //19號(hào)地址判斷在哪個(gè)頁(yè)面
SCI1send (0x01); //1個(gè)地址
SCI1send (0x67);
Delay(1); //必須加段延時(shí)確保數(shù)據(jù)發(fā)送出去
DE485 = 0; //485切換到接收狀態(tài)
asm(nop);
}
}
}
}
//==========================================
//定時(shí)器1中斷函數(shù) 中斷向量號(hào)11 250毫秒定時(shí)
//==========================================
void interrupt 11 TPM1_ISR(void)
{
static byte i,j,k;
if((TPM1SC & 0x80)==0x80)
{
TPM1SC_TOF=0;
ADSET = 1;
}
i++;
if(!PAGE8) //
{
j = 0;
}
else
{
j++;
if(j>PAGE8) //大于5秒
{
j = 0;
RR = 2; //轉(zhuǎn)判斷ENT鍵是否按下程序
PAGE8 = 0;
}
}
if(!TENT)
{
k = 0;
}
else
{
k++;
if(k>TENT)
{
k = 0;
T20 = 1; //如果ENT鍵1分鐘內(nèi)沒(méi)有按下則跳轉(zhuǎn)到2界面(顯示電壓,電流)
TENT = 0;
}
}
if(i>3)
{
i = 0;
ReadTimeFlag = 1;
}
}
//==========================================
//串口接收中斷 VectorNumber_Vsci1rx 中斷向量號(hào)17
//==========================================
interrupt VectorNumber_Vsci1rx void SCI_RE(void)
{
static byte j;
static byte i;
byte Rcv;
if(SCI1S1_RDRF) //串口接收中斷標(biāo)志位
{ //清標(biāo)志位
SCI1S1_RDRF = 0; //接收數(shù)據(jù)送緩存
Rcv = SCI1D;
//*********************讀頁(yè)面數(shù)值*****************************
if(RR == 1)
{
if(Rcv == 0x13)
{
j = 1;
Buffer[0]=Rcv;
}
else
{
if(j < 5) //5個(gè)字節(jié)
{
Buffer[j] = Rcv;
j++;
}
}
if((Buffer[3]==0x08)&&(Buffer[4]==0x1d)) //如果檢測(cè)到是第8頁(yè)面則處理數(shù)據(jù)
{
PAGE8 =20; //如果停在8頁(yè)面設(shè)置一個(gè)計(jì)數(shù)器,5秒時(shí)間內(nèi)如果還在則認(rèn)為在修改時(shí)間
TENT = 240; //2分鐘內(nèi)ENT鍵沒(méi)有按下,則跳轉(zhuǎn)到2頁(yè)面;
}
if(Buffer[3]!=0x08) //如果跳轉(zhuǎn)到別的界面,馬上清零
{
PAGE8 = 0;
TENT = 0;
RR = 1; //回到正常狀態(tài)
}
}
//****************判斷ENT鍵按下與否******************************* ENT鍵按下的話20站號(hào)變成1
if(RR ==2)
{
if(Rcv == 0x14)
{
j = 1;
Buffer[0]=Rcv;
}
else
{
if(j < 5) //5個(gè)字節(jié)
{
Buffer[j] = Rcv;
j++;
}
}
if((Buffer[3]==0x01)&&(Buffer[4]==0x17)) //ENT鍵已經(jīng)按下
{
RR = 3;
}
}
//******************************讀取要修改的時(shí)間*******************************
if(RR ==4) //此時(shí)ENT已經(jīng)清零
{
Buffer[j]=Rcv;
if(!i)
{
if(Buffer[j]== 0x0b) //接收到11
{
Buffer[0] =0x0b;
j=1; //才開始類加
}
if(Buffer[1]== 0x06)
{
i = 1;
}
}
if(i)
{
if(j< 15)
{
Buffer[j] = Rcv;
j++;
}
}
if(j==15)
{
i = 0;
}
if(Buffer[14]==(Buffer[3]+Buffer[5]+Buffer[7]+Buffer[9]+Buffer[11]+Buffer[13]+0x12))
{
RR = 0;
time_buf1[1] = Buffer[3] ; //年
time_buf1[2] = Buffer[5] ; //月
time_buf1[3] = Buffer[7] ; //日
time_buf1[4] = Buffer[9] ; //時(shí)
time_buf1[5] = Buffer[11]; //分
time_buf1[6] = Buffer[13]; //秒
}
}
}
}
//==========================================
//ADC轉(zhuǎn)換完成中斷服務(wù)程序 VectorNumber_Vadc中斷向量號(hào)23
//==========================================
interrupt VectorNumber_Vadc void ADC_ISR(void)
{
static byte count;
switch(ADch_s)
{
case 19:
ADCbuffer1[count]=ADCR;
count++;
if (count > N-1){
count = 0;
ADCSC1=0x00;
ADcount = 1;
}
break;
case 11:
ADCbuffer1[count]=ADCR;
count++;
if (count > N-1){
count = 0;
ADCSC1=0x00;
ADcount = 2;
}
break;
case 3:
ADCbuffer1[count]=ADCR;
count++;
if (count > N-1){
count = 0;
ADCSC1=0x00;
ADcount = 3;
}
break;
case 4:
ADCbuffer1[count]=ADCR;
count++;
if (count > N-1){
count = 0;
ADCSC1=0x00;
ADcount = 4;
}
break;
default:break;
}
asm(nop); //在此設(shè)置一個(gè)斷點(diǎn),觀測(cè)ad_h和ad_l的變化
}
上一頁(yè) 1 2 3 下一頁(yè)

關(guān)鍵詞: 飛思卡爾DZ60AD

評(píng)論


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

關(guān)閉