اخي العزيز
عندما استعملت الزرين فقط لكي اتحكم في المصبحين تتغير شدة الاضاءة
عندما جربت ادافة زرين اخرين تتغير شدة مصباح ولاخر لايتغير
وعندما اابدل المقاومتين اللدان يوجدان في قاعدة الترانزستور يصبح العكس
ارجوا الحل
|
ربما أخطأت في الكود بالتأكيد انت لما أضيف سويجين أخرين لابد من أضافه الكود وأجراء بعض التعديلات
الان أضفت لك سويجين أخرين على RA0 , RA1
كود:
bit oldstate1, oldstate2 ,oldstate3,oldstate4;
sbit sw_inc1 at RB1_bit;
sbit sw_inc1_dir at TRISB1_bit;
sbit sw_dec1 at RB2_bit;
sbit sw_dec1_dir at TRISB2_bit;
sbit sw_inc2 at RA0_bit;
sbit sw_inc2_dir at TRISA0_bit;
sbit sw_dec2 at RA1_bit;
sbit sw_dec2_dir at TRISA1_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=7000 ,ratio2=6000 ;
//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;
time=0;
zero_crosing=1;
kk=0;
}
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 100;
//Enter your code here
}
}
//**********************************************************************//
void main()
{
sw_dec1_dir=1; // input
sw_inc1_dir=1; // input
sw_dec2_dir=1; // input
sw_inc2_dir=1; // input
led_check_dir=0; //output
trigger1_dir=0;//output
trigger2_dir=0;//output
led_check=0;//led off
oldstate1=0;
oldstate2=0;
oldstate3=0;
oldstate4=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;
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_dec1) oldstate1=1;
if(!sw_dec1 && oldstate1)
{
if(ratio1 <8500) ratio1 +=100; //
oldstate1 = 0;
}
//Button to increase the voltage
if(sw_inc1) oldstate2=1;
if(!sw_inc1 && oldstate2)
{
if(ratio1>500)ratio1 -=100;
oldstate2 = 0;
}
//Button to decrease the voltage
if(sw_inc2) oldstate3=1;
if(!sw_inc2 && oldstate3)
{
if(ratio2 <8500) ratio2 +=100; //
oldstate3 = 0;
}
//Button to increase the voltage
if(sw_dec2) oldstate4=1;
if(!sw_dec2 && oldstate4)
{
if(ratio2>500)ratio2 -=100;
oldstate4 = 0;
}
}
}
قارن هذا الكود مع الكود الي نفذته
تحياتي