void exint1() interrupt 2
{
TR0 = 0; //¹Ø±Õ¶¨Ê±Æ÷£»
timer_flag = 1;
switch(adc2dac_flag)
{
case 00:
P1 &= 0xf0; //Çл»µ½±»²âÐźŵçѹͨµÀ¿ªÆô¶¨Ê±Æ÷Æô¶¯20msÑÓʱ
P1 |= 0x02;
TL0 = T20MS; //¶¨Ê±Æ÷¸³³õÖµ£¬20ms¼Æʱ
TH0 = T20MS >> 8;
TR0 = 1;
break;
case 01:
temp1 = TH0; //¼Ç¼ͨµÀ2(µç×èµçѹͨµÀ)·´Ïò»ý·Ö¼Æʱ
temp2 = TL0;
P1 &= 0xf0; //Çл»µ½Ï߶˵çѹͨµÀ¿ªÆô¶¨Ê±Æ÷Æô¶¯20msÑÓʱ
P1 |= 0x01;
TL0 = T20MS; //¶¨Ê±Æ÷¸³³õÖµ£¬20ms¼Æʱ
TH0 = T20MS >> 8;
TR0 = 1; //¿ªÆô¼ÆʱÆ÷
break;
case 02:
temp3 = TH0; //¼Ç¼ͨµÀ2(µç×èµçѹͨµÀ)·´Ïò»ý·Ö¼Æʱ
temp4 = TL0;
P1 &= 0xf0; //Çл»µ½±»²âÐźŵçѹͨµÀ
P1 |= 0x02;
TL0 = T20MS; //¶¨Ê±Æ÷¸³³õÖµ£¬20ms¼Æʱ
TH0 = T20MS >> 8;
TR0 = 1;
timer_flag = 0;
break;
default:
SendData(0xFF);
}
RUNLED = 0;
}
void tm0_isr() interrupt 1 using 2
{
TR0 = 0; //¹Ø±Õ¶¨Ê±Æ÷£»
if(timer_flag)
{
TH0 = TL0 = 0; //¶¨Ê±Æ÷ÖµÇåÁ㣻
P1 &= 0xf0; //Çл»µ½Í¨µÀ7(»ù×¼µçѹÐźÅͨµÀ)¿ªÆô¶¨Ê±Æ÷¼Æʱ£»
P1 |= 0x07;
timer_flag = 0;
}
else
{
P1 &= 0xf0; //Çл»µ½Í¨µÀ7(»ù×¼µçѹÐźÅͨµÀ)¿ªÆô¶¨Ê±Æ÷¼Æʱ£»
P1 |= 0x02;
}
RUNLED = 1;
TR0 = 1; //¿ªÆô¶¨Ê±Æ÷¼Æʱ£»
adc2dac_flag++;
}
void Adc2Dac()
{
SendData(0xBB);
adc2dac_flag = 0;
P1 &= 0xf0; //Çл»µ½Í¨µÀ7(»ù×¼µçѹÐźÅͨµÀ)£¬È·¶¨»ý·ÖÁãλ£»
P1 |= 0x07;
while(adc2dac_flag != 3); //µÈ´ý»ý·Ö½áÊø£»
temp_value = Adc_Process(temp1, temp2, temp3, temp4); //½«·´Ïò»ý·Ö¼Æʱֵ»»Ëã³ÉζÈ
temp2_value = Dac_Process(temp_value); //½«Î¶ÈÖµ»»Ëã³ÉPWM²¨Õ¼¿Õ±È£¬Êä³ö4-20mA
CCAP1H = temp2_value >> 8;
CCAP1L = temp2_value;
}
算是能运行一次Adc2Dac()函数,就执行一次双积分运算。
不过每次上电后发送对同一个信号测量,结果每次都不一样。这个问题我再单独开个帖子提问吧。
|