اخي العزيز
هل لا يمكن ادافة ديمر تاني على نفس البيك
ادا استعملت 16f877a هل يصلح لوضع 2 ديمر
|
السلام عليكم
تم تصحيح الكود وان شالله يعمل (( صراحه لم أجربه ولكن حسب بروتيس دائره تعمل ))
كود:
bit oldstate, oldstate1;
sbit sw_inc at RB1_bit;
sbit sw_inc_dir at TRISB1_bit;
sbit sw_dec at RB2_bit;
sbit sw_dec_dir at TRISB2_bit;
sbit trigger1 at RB3_bit;
sbit trigger1_dir at TRISB3_bit;
sbit trigger2 at RB5_bit;
sbit trigger2_dir at TRISB5_bit;
sbit led_check at RB4_bit;
sbit led_check_dir at TRISB4_bit;
char zero_crosing=0 ,x , state ,kk=0;
unsigned int time=0 ,ratio1=5000 ,ratio2=2500 ;
//Timer0
//Prescaler 1:128; TMR0 Preload = 100; Actual Interrupt Time : 19.968 ms
//Place/Copy this part in declaration section
void InitTimer0(){
OPTION_REG = 0x86;
TMR0 = 100;
}
void interrupt()
{
if(INTCON.INTF)
{
INTCON.INTF=0;
tmr0=100;
zero_crosing=1;
kk=0;
}
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 100;
//Enter your code here
}
}
void main()
{
sw_dec_dir=1; // input
sw_inc_dir=1; // input
led_check_dir=0; //output
trigger1_dir=0;//output
trigger2_dir=0;//output
led_check=0;//led off
oldstate=0;
oldstate1=0;
intcon=0xB0;
InitTimer0();
for( x=0;x<6;x++) {led_check=~led_check; delay_ms(500); }
while(1)
{
if(zero_crosing)
{
led_check=1;
time=0;
if(ratio1>=ratio2 && kk==0)state=2;
else if(kk==0) state=1;
if(state==1)
{
kk++;
state=2;
while(time<ratio1) time=128*(tmr0-100);
led_check=0;
trigger1=1;
delay_us(100);
trigger1=0;
}
else if(state==2)
{
kk++;
state=1;
while(time<ratio2) time=128*(tmr0-100);
led_check=0;
trigger2=1;
delay_us(100);
trigger2=0;
}
if(kk==2)zero_crosing=0;
}
//Button to decrease the voltage
if(sw_dec) oldstate=1;
if(!sw_dec && oldstate)
{
if(ratio1 <8500) ratio1 +=100; //
if(ratio2 <8500) ratio2 +=100; //
oldstate = 0;
}
//Button to increase the voltage
if(sw_inc) oldstate1=1;
if(!sw_inc && oldstate1)
{
if(ratio1>500)ratio1 -=100;
if(ratio2>500)ratio2 -=100;
oldstate1 = 0;
}
}
}
طبعا انا خليت دايمر1 و2 بنفس سويج فقط للفحص انت بالامكان عزلهما فيما بعد
أنتبه مخرج النبضه لديمر 2 على RB5
تحياتي