StartHTML:0000000105
EndHTML:0000009599
StartFragment:0000001197
EndFragment:0000009583
#include <REGX51.H>
void bekle()
{
unsigned int i;
for (i=0;i<7600;i++)
{
;
}
}
void Hizi_Arttir() interrupt 0
{
while(!TI);
SBUF=0xF1; // Hizi arttir butonuna basilinca aliciya F1H gonder
bekle();
}
void Hizi_Azalt() interrupt 2
{
while(!TI);
SBUF=0xF2; // Hizi azalt butonuna basilinca aliciya F2H gonder
bekle();
}
void main()
{
SCON=0x40; // 8 bit uart modu
TMOD=0x20; // Z/S 1 icin 8 bit otomatik yukleme modu
TH1=0xE8; // yaklasik 1200 bit/s (11.059 Mhz kristal icin)
TR1=1; // Z/S'i calistir
TI=1;
EX0=1; // INT0'in yetkilendirilmesi
EX1=1; // INT1'in yetkilendirilmesi
IT0=1; // INT0 dusen kenarda tetiklensin
IT1=1; // INT1 dusen kenarda tetiklensin
EA=1; // Butun kesmelerin yetkilendirilmesi
P3=0xFF; //Butonlar giris icin ayarlandi
while(1)
{
;
}
}
PWM sinyali ile DC Motor kontrolü (Visual Basic)
Public Enable As Integer, Phase As Integer, duty_cycle As Integer, a As Integer
Const PortA = &H378 'Paralel Port adresi
Sub delay(delay_time As Double)
'Gecikmeyi sağlayan fonksiyon
temp_timer = Timer
Do
Loop While (Timer - temp_timer) < delay_time
End Sub
Sub pwm(total_time As Double, duty_cycle As Integer)
Dim OnTime As Double
Dim OffTime As Double
OnTime = total_time * duty_cycle / 100
OffTime = total_time - OnTime
Enable = 1
Out PortA, Enable + Phase
delay OnTime
Enable = 0
Out PortA, Enable + Phase
delay OffTime
Label1.Caption = duty_cycle
Label1.Refresh
End Sub
Private Sub Command1_Click()
If duty_cycle < 100 Then
duty_cycle = duty_cycle + 5
Enable = 1
Label1.Caption = duty_cycle
Label1.Refresh
End If
End Sub
Private Sub Command2_Click()
a = 0
Do
DoEvents
If a = 1 Then Exit Do
pwm 0.1, duty_cycle
Loop
End Sub
Private Sub Command3_Click()
If duty_cycle > 5 Then
duty_cycle = duty_cycle - 5
Enable = 1
Label1.Caption = duty_cycle
Label1.Refresh
End If
End Sub
Private Sub Command4_Click()
'Ters yönde çalıştırma rutini
Enable = 1
If Phase = 0 Then
Phase = 2
Else
Phase = 0
End If
End Sub
Private Sub Command5_Click()
'Durdurma ve Do-Loop tan çıkış
a = 1
Out PortA, 0
End Sub
Private Sub Form_Load()
duty_cycle = 50
Phase = 0
End Sub
Hiç yorum yok:
Yorum Gönder