Professional Documents
Culture Documents
MC LAB FÖY 2024 BHR
MC LAB FÖY 2024 BHR
Deney 2-a) Anahtar ile led yanıp-sönme Deney 2-b) Anahtar ile 220V lamba aç/kapa
hızını değiştirme denetimi
Deney 3-a) Buton Okuma, Led yak/söndür Deney 3-b) Button komutu ile buton okuma
Komut: Button( &Port, pin, süre(ms), aktif konum)
Deney 4-a). 7parçalı display sürme Deney 4-b) 2 buton ile ileri geri display
(Kontrolsüz 0-9 sayıcı ) saydırma
void main()
{
unsigned char sayac = 0;
unsigned char tablo[ ] = {0x3F, 0x06, 0x5B,
0x4F,0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
TRISB = 0;
TRISC=0xFF;
while(1)
{ if(tus1 == 0)
{ sayac++;
while(tus1==0); //Tuş bırakmayı bekle
}
Deney 5.a. Timer Interrupt ile kare dalga Deney 5-b. PWM İşareti Üretme
üretme
(fkare=500Hz , fosc=8MHz, önbölücü oranı=64)
OPTION REGISTER
RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0
0 0 0 0 0 1 1 0
INTCON REGISTER
GIE EEIE T0IE INTE RBIE T0IF INTF RBIF
1 x 1 1 x x x x
void ayarlar()
{ TRISB = 255;
TRISC = 0;
PWM1_Init(1000); // PWM1 frekansı set }
void main()
{ ayarlar();
Ton= 16; // ilk “Ton” değeri
PWM1_Start(); // PWM1 modül aktivasyon
PWM1_Set_Duty(Ton); // Set Ton değeri
while (1)
{
if(tus1 == 0)
{ Ton=Ton+16; // pwm oranını arttır
PWM1_Set_Duty(Ton);
while(tus1==0); // tus bırakmayı bekle
}
if(tus2 == 0)
{ Ton=Ton-16; // pwm oranını azalt
PWM1_Set_Duty(Ton);
Not: Doğru tasarım için MicroC ve ISIS ortamında seçilen while(tus2==0); // tus bırakmayı bekle
osc. frekansları (fosc) eşit seçilmelidir.. } } }
Gerekli düzenlemeleri yaparak, kare dalga
frekansını sırasıyla 1KHz, 2KHz, 10KHz olacak 1. 2KHz ve 4KHz için PWM frekansını değiştirerek
şekilde değiştiriniz. Osiloskop ile ölçerek deneyi tekrarlayınız.
doğrulayınız. (fosc=8MHz) 2. Her butona basışta toplam değerin 1/8’i değişim
fosc=4MHz seçerek 1KHz kare dalgayı tekrar için gerekli değişimi gerçekleştiriniz.
oluşturunuz. Not: Daha iyi gözlemlemek için while(tus1==0) yerine
delay_ms(50) kullanılabilir.
Delay_ms(2000);
//Kayan yazı …
{
// LCD modül bağlantılarını tanımlama… Lcd_Cmd(_LCD_SHIFT_RIGHT);
sbit LCD_RS at RB4_bit; bekle();
sbit LCD_EN at RB5_bit; }
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit; while(1)
sbit LCD_D6 at RB2_bit; {
sbit LCD_D7 at RB3_bit; for(i=0; i<8; i++) // 7kez sola…
sbit LCD_RS_Direction at TRISB4_bit; { Lcd_Cmd(_LCD_SHIFT_LEFT);
sbit LCD_EN_Direction at TRISB5_bit; bekle ();
sbit LCD_D4_Direction at TRISB0_bit; }
sbit LCD_D5_Direction at TRISB1_bit; for(i=0; i<8; i++) // 7kez sağa…
sbit LCD_D6_Direction at TRISB2_bit; { Lcd_Cmd(_LCD_SHIFT_RIGHT);
sbit LCD_D7_Direction at TRISB3_bit; bekle ();
// LCD_Init() için… }
}
char txt1[] = "Marmara "; }
char txt2[] = "Teknoloji ";
char txt3[] = "Lcd4bit";
char txt4[] = "Ornek Program";
char i;
1. Display’e 1. ve 2. satıra farklı mesajlar yazdırınız.
2. Kaydırma hızını değiştirerek tekrarlayınız.
void bekle()
{ // metin kaydırma hızı tek noktadan değiştirilir.
Delay_ms(300);
}
do
{
veri10bit = ADC_Read(3); // Analog veri oku
WordToStr(veri10bit, cevir);
Lcd_Out(1,1,"Data=");
Lcd_Out(1,6,cevir);
volt= veri10bit*5;
volt=volt/1024;
FloatToStr(volt, gerilim);
Lcd_Out(2,2,gerilim);
// LCD module bağlantı tanımları
Lcd_Out(2,12,"V");
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit; Delay_ms(200);
sbit LCD_D4 at RB0_bit; Lcd_Cmd(_LCD_CLEAR);
sbit LCD_D5 at RB1_bit;
}
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit; while(1);
sbit LCD_RS_Direction at TRISB4_bit; }
sbit LCD_EN_Direction at TRISB5_bit; -----------------------------------------------
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
İşlemler:
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit; 1. Potansiyometreden ölçülen 0-5V bilgisini,
0_100°C sıcaklık ölçen bir sensörden geldiğini kabul
void main()
{
ADCON1=0x80; //sağa yaslı veri formatı,
// tüm pinler analog, analog giriş: 0..+5V
TRISA = 0xFF; // PORTA giriş
TRISC = 0; // PORTC çıkış
Deney 7.
CAPTURE MODÜL İLE FREKANS ÖLÇME
do // Tuş basma- bırakma kontrol çevrimi Lcd_Chr(1, 12, tuskod); // Tuskodunu LCD'ye yaz
tuskod = Keypad_Key_Press(); // Tus algıla
byteToStr(tuskod, txt); // Sayıyı karakter
while (!tuskod); //tus bırakma kontrol
dizisine dönüştür
Lcd_Out(2, 12, txt); // LCD ye yaz
} while (1);
}