https://www.youtube.com/watch?v=gceXRdqUbiw
يوجد بالرابط مخطط دائره
او
أخي هذا التعديل جديد للكود
كود:
// Software PWMconnections
sbit Soft_PWM_PIN at RB3_bit;
sbit Direction_Soft_PWM_PIN at TRISB3_bit;
// End Software PWMconnections
bit oldstate, oldstate1;
unsigned char cont=0 ;
unsigned short error=0;
char duty_change=0;
char zero_crosing=0;
void interrupt()
{
if(TMR0IF_bit)Soft_PWM_Inter();
if(INTCON.INTF)
{
INTCON.INTF=0;
zero_crosing=1;
}
}
void main()
{
TRISB=0b00000111;//pin rb0,rb1,rb2 input & rb3 output
cmcon=7;
oldstate=0;
oldstate1=0;
intcon=0x90;
OPTION_REG=0;
error=Soft_PWM_Init(100); // initialize the software PWMat 100 HZ or 10ms ((half cycle))
while(!error);
Soft_PWM_Start(); // Start Software PWM
while(1)
{
if(zero_crosing)
{
Soft_PWM_Set_Duty(cont); // change the duty ratio
zero_crosing=0;
}
//Button to decrease the voltage
if(PORTB.F1) oldstate=1;
if(!PORTB.F1 && oldstate)
{
cont++;
if(cont >101) cont = 100;// 10ms
oldstate = 0;
}
//Button to increase the voltage
if(PORTB.F2) oldstate1=1;
if(!PORTB.F2 && oldstate1)
{
if(cont!=0)cont--;
if(cont < 1) cont= 1; // msec
oldstate = 0;
}
}
}
اذا أخذت ملف وعملت محاكاه راح يعطيك error لانك عليك ان تضيف مكتبه جديده الى كومبايلر مايكروسي اسمها soft _pwm
ارجو متابعه هذا موضوع
http://www.qariya.info/vb/showthread...143596&page=12
مكتبه في مشاركه 93 ولكن عليك متابعه موضوع من مشاركه 91
طبعا هذا الكود تستطيع أستخدامه لدائرتك او دائره مرفقه
http://up.top4top.net/downloadf-top4...7abe1-rar.html
طبعا أكيد تستخدم فوتوكبلر ولكن في محاكاه البروتيس لايستجيب مع فوتوكبلر
جرب وأعطنا النتيجه