PIC12F683 Yardım

Başlatan equilibrium61, 13 Aralık 2023, 18:51:26

equilibrium61

Merhabalar değerli üyeler... Bir kod ve bir simülasyon ile ilgili değerli görüşleriniz ve yardımınıza başvurmak istiyorum. PIC12F683 kullanarak DHT11 sensöründen aldığım değerlere göre bir mosfet tetiklemek istiyorum. 35 derece altına düştüğünde mosfeti iletime sokacak, 40 derece üstüne çıktığında iletimden çıkaracak. Seçtiğim MOSFET IRFZ44N(ChatGPT tavsiyesidir.

Yine biraz ChatGPT desteği, birkaç forum ve datasheet okuyarak aşağıdaki kodu yazabildim. Hatasız derliyor fakat çalışıp çalışmadığını anlamak için Proteus 8 Pro'da simüle etmeye çalıştığımda MOSFET'i tetikleyemiyorum. Ya kod problemli ya da Proteus'ta devreyi düzgün kuramadım. Forumda yeniyim pek de zamanım yok eğer yanlış yere konu açtıysam lütfen doğru yere yönlendiriniz...

Ek olarak kod Proteus'ta simülasyon hatası vermiyor...

KOD:

/*
 * File:   test.c
 */

#include <xc.h>
#include <pic12f683.h>

// PIC12F683 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown Out Detect (BOR enabled)
#pragma config IESO = ON        // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 4000000 // Assuming 4MHz oscillator frequency
#define DHT11_PIN GP0      // Pin connected to DHT11 sensor
#define LED_GREEN GP1      // Green LED pin
#define LED_RED GP2        // Red LED pin
#define HEATING_ELEMENT GP5 // Pin connected to heating element
#define TEMP_LOWER_LIMIT 35
#define TEMP_UPPER_LIMIT 40
// Function prototypes
void dht11_start();
uint8_t dht11_read();
void readDHT11(uint8_t *temp, uint8_t *hum);
void controlHeating(uint8_t temperature);


void main(void) {
    
    uint8_t temperature, humidity;
    
    TRISIO = 0x01; // Set GP0 as input (Temperature Sensor Data), others as output
    GPIO = 0x00; // All output pins low initially
    
    while (1) {
        readDHT11(&temperature, &humidity);
        controlHeating(temperature);
        // Implement LED control logic here based on temperature if needed
    }
}
void dht11_start() {
    TRISIO &= ~(1 << DHT11_PIN); // Set DHT11_PIN as output
    GPIO &= ~(1 << DHT11_PIN); // Pull the data line low
    __delay_ms(18); // Hold the line low for at least 18ms
    GPIO |= (1 << DHT11_PIN); // Release the line
    __delay_us(30); // Wait for DHT11 response
    TRISIO |= (1 << DHT11_PIN); // Set DHT11_PIN as input to read sensor response
}

uint8_t dht11_read() {
    uint8_t data = 0;
    for (int i = 0; i < 8; i++) {
        while (!(GPIO & (1 << DHT11_PIN))); // Wait for the data line to go high (start of data)
        __delay_us(30); // Wait for 30us to ensure it's a valid bit
        if (!(GPIO & (1 << DHT11_PIN))) {
            // If the line is still low after waiting, it's a '0' bit
            data <<= 1; // Shift left by 1 bit
        } else {
            // If the line is high, it's a '1' bit
            data |= 0x01; // OR operation with 0x01
            data <<= 1; // Shift left by 1 bit
            while (GPIO & (1 << DHT11_PIN)); // Wait for the line to go low (end of data)
        }
    }
    return data;
}

void readDHT11(uint8_t *temp, uint8_t *hum) {
    dht11_start(); // Initialize communication
    if (!(GPIO & (1 << DHT11_PIN))) {
        __delay_us(80);
        if (GPIO & (1 << DHT11_PIN)) {
            __delay_us(80);
            *hum = dht11_read(); // Read humidity
            *temp = dht11_read(); // Read temperature
            uint8_t checksum = dht11_read(); // Read checksum
            if (checksum != (*hum + *temp)) {
                // Checksum doesn't match data
                // Handle error or retry reading
            }
        }
    }
}


void controlHeating(uint8_t temperature) {
    if (temperature < TEMP_LOWER_LIMIT) {
        // Turn on heating element
        GPIO |= (1 << HEATING_ELEMENT);
    } else if (temperature > TEMP_UPPER_LIMIT) {
        // Turn off heating element
        GPIO &= ~(1 << HEATING_ELEMENT);
    }
}

Proteus proje dosyasını da ekledim.


mehmet

#1
Npn bir transistör ile mosfeti sürmelisiniz.
Bu şekilde sürünce, lojik kısım terslenmeli.

Ayrıca, sıcaklık testi için sabit değer
verin veya zamanla artsın-eksilsin.
Bu kısmı hallettikten sonra DHT11 ile
denersiniz.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

equilibrium61

İlginiz için teşekkür ederim. Nasıl yapılacağı ile ilgili biraz tüyo verebilir misiniz?  ::op

mehmet

Alttaki şekilde yapmanız mümkün...

http://tinyurl.com/ymrrml55

Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr