Pic basic ile yazılmış kodu C diline çevirme

Başlatan mmtkr, 02 Şubat 2022, 16:20:28

mmtkr

Hocalarım öncelikle herkese iyi günler dilerim

ETE hocamın yaptığı https://etepic.com/index.php/topic,377.0.html
voltAmper projesini pic basic ile kodlanmış bu projenin c dilinde tekrardan yazmak istiyorum yardıma ihtiyacım var c dilini bilmiyorum programın c dilinde yazılmış hali bana lazım yardımcı olabilecek hocalarım  var mı şimdiden teşekkür ederim

mehmet

Selam,
şema çizin ve bir led uygulaması
yazın, yardım edeyim.
(Sadece XC8 ile)
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
http://www.mehmetbilgi.net.tr

mmtkr

Alıntı yapılan: mehmet - 03 Şubat 2022, 09:38:55Selam,
şema çizin ve bir led uygulaması
yazın, yardım edeyim.
(Sadece XC8 ile)
#include <xc.h>
#pragma config FOSC = EXTRC    // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF        // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON      // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON        // Low Voltage In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = ON  // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)
#define _XTAL_FREQ 4000000
void main(void) {
    TRISA=0b11111111;
    TRISB=0x00;
    while(1){
        if (RA0==1) PORTB=0b11111111;
    
    }
            
            
  
}
hocam zip dosyaı nasıl eklenir onu bulamadım


mehmet

Şimdilik yeterli sanırım.
Akım ve gerilim hesaplamasını da
yaparsınız artık.

Başucu kitabı olarak ilgili mcunun
belgelerini öneriyorum.

/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 04 Şubat 2022 Cuma, 22:32
 */

// PIC16F876 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>

#define _XTAL_FREQ      4000000

#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3

#define LED1            PORTBbits.RB0
#define LED2            PORTBbits.RB1

/*
 * MCU Hazırlığı
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    
    TRISA = 0b00001011;
    TRISB = 0b11111100;
    TRISC = 0b11111111;
}

/*
 * Analog girişleri Hazırla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1;      // Sağa yaslanık
    ADCON1bits.PCFG = 0b0100;   // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11;     // Frc
    ADCON0bits.ADON = 0b1;      // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {
        
    }
    
    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}

/*
 * Ana Döngü
 */
void main(void)
{
    uint16_t akim = 0;
    uint16_t gerilim = 0;

    adc_Hazirla();
    mcu_Hazirla();

    while(1)
    {
        akim = adc_Oku(AKIM_ADC);
        gerilim = adc_Oku(GERILIM_ADC);
        
        if(akim >= 511)
        {
            LED1 = 0b1;
        }
        else
        {
            LED1 = 0b0;
        }
        
        if(gerilim >= 511)
        {
            LED2 = 0b1;
        }
        else
        {
            LED2 = 0b0;
        }
        __delay_ms(500);
    }
}
//------------------------------------------------------------------------------
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
http://www.mehmetbilgi.net.tr

mmtkr

Alıntı yapılan: mehmet - 04 Şubat 2022, 23:14:35Şimdilik yeterli sanırım.
Akım ve gerilim hesaplamasını da
yaparsınız artık.

Başucu kitabı olarak ilgili mcunun
belgelerini öneriyorum.

/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 04 Şubat 2022 Cuma, 22:32
 */

// PIC16F876 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>

#define _XTAL_FREQ      4000000

#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3

#define LED1            PORTBbits.RB0
#define LED2            PORTBbits.RB1

/*
 * MCU Hazırlığı
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    
    TRISA = 0b00001011;
    TRISB = 0b11111100;
    TRISC = 0b11111111;
}

/*
 * Analog girişleri Hazırla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1;      // Sağa yaslanık
    ADCON1bits.PCFG = 0b0100;   // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11;     // Frc
    ADCON0bits.ADON = 0b1;      // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {
        
    }
    
    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}

/*
 * Ana Döngü
 */
void main(void)
{
    uint16_t akim = 0;
    uint16_t gerilim = 0;

    adc_Hazirla();
    mcu_Hazirla();

    while(1)
    {
        akim = adc_Oku(AKIM_ADC);
        gerilim = adc_Oku(GERILIM_ADC);
        
        if(akim >= 511)
        {
            LED1 = 0b1;
        }
        else
        {
            LED1 = 0b0;
        }
        
        if(gerilim >= 511)
        {
            LED2 = 0b1;
        }
        else
        {
            LED2 = 0b0;
        }
        __delay_ms(500);
    }
}
//------------------------------------------------------------------------------
Çök teşekkürler

mmtkr

#5
Alıntı yapılan: mehmet - 04 Şubat 2022, 23:14:35Şimdilik yeterli sanırım.
Akım ve gerilim hesaplamasını da
yaparsınız artık.

Başucu kitabı olarak ilgili mcunun
belgelerini öneriyorum.

/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 04 Şubat 2022 Cuma, 22:32
 */

// PIC16F876 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>

#define _XTAL_FREQ      4000000

#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3

#define LED1            PORTBbits.RB0
#define LED2            PORTBbits.RB1

/*
 * MCU Hazırlığı
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    
    TRISA = 0b00001011;
    TRISB = 0b11111100;
    TRISC = 0b11111111;
}

/*
 * Analog girişleri Hazırla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1;      // Sağa yaslanık
    ADCON1bits.PCFG = 0b0100;   // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11;     // Frc
    ADCON0bits.ADON = 0b1;      // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {
        
    }
    
    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}

/*
 * Ana Döngü
 */
void main(void)
{
    uint16_t akim = 0;
    uint16_t gerilim = 0;

    adc_Hazirla();
    mcu_Hazirla();

    while(1)
    {
        akim = adc_Oku(AKIM_ADC);
        gerilim = adc_Oku(GERILIM_ADC);
        
        if(akim >= 511)
        {
            LED1 = 0b1;
        }
        else
        {
            LED1 = 0b0;
        }
        
        if(gerilim >= 511)
        {
            LED2 = 0b1;
        }
        else
        {
            LED2 = 0b0;
        }
        __delay_ms(500);
    }
}
//------------------------------------------------------------------------------
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>
#include "lcd.h";
#include <stdio.h>



#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3






#define _XTAL_FREQ 8000000

#define RS RB1
#define RW RB2
#define EN RB3
#define D4 RB4
#define D5 RB5
#define D6 RB6
#define D7 RB7

/*
 * MCU Haz?rl???
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    
    TRISA = 0b00001011;
    TRISB = 0b11111100;
    TRISC = 0b11111111;
}

/*
 * Analog giri?leri Haz?rla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1;      // Sa?a yaslan?k
    ADCON1bits.PCFG = 0b0100;   // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11;     // Frc
    ADCON0bits.ADON = 0b1;      // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {
        
    }
    
    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}




void main(void)
{
    uint16_t akim = 0;
    uint16_t gerilim = 0;

    adc_Hazirla();
    mcu_Hazirla();
    
     unsigned int AMPER;
  
  Lcd_Init();

    while(1)
    {
        akim = adc_Oku(AKIM_ADC);
        gerilim = adc_Oku(GERILIM_ADC);
        float AMPER;
        AMPER = akim/125;
      
        Lcd_Clear();
    Lcd_Set_Cursor(1,1);
    Lcd_Write_String("A",AMPER);
    
     


    
        
    float volt;
    volt = gerilim/75; 
    
    Lcd_Set_Cursor(2,1);
    Lcd_Write_String("V",volt);
     }
}
hocam kolay gelsin burada kodun yazımı  ile ilgili hata va mı derleyiiici yok diyor ekrana çıktı vermedim hatam nerede olduğunu söeyyebilir misiiz onun üzerine araştırayım diyorum şimdiden teşekkürler

mehmet

"lcd.h" ve "lcd.c" dosyalarını görmek lazım.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
http://www.mehmetbilgi.net.tr

mmtkr

//LCD Functions Developed by electroSome


void Lcd_Port(char a)
{
   if(a & 1)
      D4 = 1;
   else
      D4 = 0;

   if(a & 2)
      D5 = 1;
   else
      D5 = 0;

   if(a & 4)
      D6 = 1;
   else
      D6 = 0;

   if(a & 8)
      D7 = 1;
   else
      D7 = 0;
}
void Lcd_Cmd(char a)
{
   RS = 0;             // => RS = 0
   Lcd_Port(a);
   EN  = 1;             // => E = 1
        __delay_ms(4);
        EN  = 0;             // => E = 0
}

Lcd_Clear()
{
   Lcd_Cmd(0);
   Lcd_Cmd(1);
}

void Lcd_Set_Cursor(char a, char b)
{
   char temp,z,y;
   if(a == 1)
   {
     temp = 0x80 + b - 1;
      z = temp>>4;
      y = temp & 0x0F;
      Lcd_Cmd(z);
      Lcd_Cmd(y);
   }
   else if(a == 2)
   {
      temp = 0xC0 + b - 1;
      z = temp>>4;
      y = temp & 0x0F;
      Lcd_Cmd(z);
      Lcd_Cmd(y);
   }
}

void Lcd_Init()
{
  Lcd_Port(0x00);
   __delay_ms(20);
  Lcd_Cmd(0x03);
   __delay_ms(5);
  Lcd_Cmd(0x03);
   __delay_ms(11);
  Lcd_Cmd(0x03);
  /////////////////////////////////////////////////////
  Lcd_Cmd(0x02);
  Lcd_Cmd(0x02);
  Lcd_Cmd(0x08);
  Lcd_Cmd(0x00);
  Lcd_Cmd(0x0C);
  Lcd_Cmd(0x00);
  Lcd_Cmd(0x06);
}

void Lcd_Write_Char(char a)
{
   char temp,y;
   temp = a&0x0F;
   y = a&0xF0;
   RS = 1;             // => RS = 1
   Lcd_Port(y>>4);             //Data transfer
   EN = 1;
   __delay_us(40);
   EN = 0;
   Lcd_Port(temp);
   EN = 1;
   __delay_us(40);
   EN = 0;
}

void Lcd_Write_String(char *a)
{
   int i;
   for(i=0;a[i]!='\0';i++)
      Lcd_Write_Char(a[i]);
}

void Lcd_Shift_Right()
{
   Lcd_Cmd(0x01);
   Lcd_Cmd(0x0C);
}

void Lcd_Shift_Left()
{
   Lcd_Cmd(0x01);
   Lcd_Cmd(0x08);
}
hocam dosyayı gönderemedim
lcd.h dosyası bu lcd.c dosyası yok

mehmet

#8
/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 04 Şubat 2022 Cuma, 22:32
 * 
 * Çay ısmarlama lisanslı
 * www.mehmetbilgi.net.tr
 */

#pragma warning disable 520     // Çağırılmayan fonsiyonlar hata iptal

// PIC16F876 Configuration Bit Settings
// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define _XTAL_FREQ      4000000

#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3

#define RS PORTBbits.RB1
#define RW PORTBbits.RB2
#define EN PORTBbits.RB3
#define D4 PORTBbits.RB4
#define D5 PORTBbits.RB5
#define D6 PORTBbits.RB6
#define D7 PORTBbits.RB7

//******************************************************************************
/*
 * LCD Fonksiyonları
 */
void Lcd_Port(char a)
{
    if(a & 1)
    {
        D4 = 1;
    }
    else
    {
        D4 = 0;
    }

    if(a & 2)
    {
        D5 = 1;
    }
    else
    {
        D5 = 0;
    }

    if(a & 4)
    {
        D6 = 1;
    }
    else
    {
        D6 = 0;
    }

    if(a & 8)
    {
        D7 = 1;
    }
    else
    {
        D7 = 0;
    }
}

void Lcd_Cmd(char a)
{
    RS = 0;             // => RS = 0
    Lcd_Port(a);
    EN  = 1;             // => E = 1
    __delay_ms(4);
    EN  = 0;             // => E = 0
}

void Lcd_Clear(void)
{
    Lcd_Cmd(0);
    Lcd_Cmd(1);
}

void Lcd_Set_Cursor(char a, char b)
{
   char temp,z,y;
   
   if(a == 1)
   {
        temp = (char)(0x80 + b - 1);
        z = (char)(temp>>4);
        y = (char)(temp & 0x0F);
        Lcd_Cmd(z);
        Lcd_Cmd(y);
   }
   else if(a == 2)
   {
        temp = (char)(0xC0 + b - 1);
        z = (char)(temp>>4);
        y = (char)(temp & 0x0F);
        Lcd_Cmd(z);
        Lcd_Cmd(y);
   }
}

void Lcd_Init(void)
{
    Lcd_Port(0x00);
     __delay_ms(20);
    Lcd_Cmd(0x03);
     __delay_ms(5);
    Lcd_Cmd(0x03);
     __delay_ms(11);
    Lcd_Cmd(0x03);
    /////////////////////////////////////////////////////
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x08);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x0C);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x06);
}

void Lcd_Write_Char(char a)
{
    char temp,y;
    temp = (char)(a&0x0F);
    y = (char)(a&0xF0);
    RS = 1;             // => RS = 1
    Lcd_Port((char)(y>>4));             //Data transfer
    EN = 1;
    __delay_us(40);
    EN = 0;
    Lcd_Port(temp);
    EN = 1;
    __delay_us(40);
    EN = 0;
}

void Lcd_Write_String(char *a)
{
   int i;
   for(i=0;a[i]!='\0';i++)
   {
        Lcd_Write_Char(a[i]);
   }
}

void Lcd_Shift_Right(void)
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x0C);
}

void Lcd_Shift_Left(void)
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x08);
}
//******************************************************************************

/*
 * MCU Hazırlığı
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;

    TRISA = 0b00001011;
    TRISB = 0b00000000;
    TRISC = 0b11111111;
}

/*
 * Analog girişleri Hazırla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1; // Sağa yaslanık
    ADCON1bits.PCFG = 0b0100; // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11; // Frc
    ADCON0bits.ADON = 0b1; // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {

    }

    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}

/*
 * Ana Döngü
 */
void main(void)
{
    uint8_t buf[10];
    uint8_t satir1[20];
    uint8_t satir2[20];
    
    uint16_t akim_Ham = 0;
    uint16_t gerilim_Ham = 0;

    uint16_t akim_Tam;
    uint16_t akim_Ondalik;

    uint16_t gerilim_Tam;
    uint16_t gerilim_Ondalik;

    adc_Hazirla();
    mcu_Hazirla();
    Lcd_Init();

    while(1)
    {        
        akim_Ham = adc_Oku(AKIM_ADC);
        gerilim_Ham = adc_Oku(GERILIM_ADC);

        akim_Tam = (uint16_t)(akim_Ham / 125.0);
        akim_Ondalik = (uint16_t)(((akim_Ham / 125.0) - akim_Tam) * 100); // İki hane ondalık

        gerilim_Tam = (uint16_t)(gerilim_Ham / 75.0);
        gerilim_Ondalik = (uint16_t)(((gerilim_Ham / 75.0) - gerilim_Tam) * 100); // İki hane ondalık
        
        satir1[0] = '\0';
        satir2[0] = '\0';
        
        strcpy(satir1, "AKIM    = "); 
        strcat(satir1, itoa(buf, akim_Tam, 10));
        strcat(satir1, ",");
        strcat(satir1, itoa(buf, akim_Ondalik, 10));
        strcat(satir1, "A");
        
        strcpy(satir2, "GERILIM = ");
        strcat(satir2, itoa(buf, gerilim_Tam, 10));
        strcat(satir2, ",");
        strcat(satir2, itoa(buf, gerilim_Ondalik, 10));
        strcat(satir2, "V");
        
        Lcd_Clear();
        Lcd_Set_Cursor(1, 1);
        Lcd_Write_String(satir1);
        
        Lcd_Set_Cursor(2, 1);
        Lcd_Write_String(satir2);

        __delay_ms(500);
    }
}
//------------------------------------------------------------------------------
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
http://www.mehmetbilgi.net.tr

mmtkr

https://s4.dosya.tc/server14/5jkx7j/testr.zip.html

hocam elinize sağlık

 olmadı çözeceğim inşallah denemek isterseniz bütün dosalar var

mmtkr

Alıntı yapılan: mehmet - 08 Şubat 2022, 16:25:32
/*
 * File:   main.c
 * Author: Mehmet
 *
 * Created on 04 Şubat 2022 Cuma, 22:32
 * 
 * Çay ısmarlama lisanslı
 * www.mehmetbilgi.net.tr
 */

#pragma warning disable 520     // Çağırılmayan fonsiyonlar hata iptal

// PIC16F876 Configuration Bit Settings
// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config CP = ALL         // FLASH Program Memory Code Protection bits (0000h to 1FFFh code protected)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = ON         // Data EE Memory Code Protection (Data EEPROM memory code-protected)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define _XTAL_FREQ      4000000

#define AKIM_ADC        0
#define GERILIM_ADC     1
#define YEDEK_ADC       3

#define RS PORTBbits.RB1
#define RW PORTBbits.RB2
#define EN PORTBbits.RB3
#define D4 PORTBbits.RB4
#define D5 PORTBbits.RB5
#define D6 PORTBbits.RB6
#define D7 PORTBbits.RB7

//******************************************************************************
/*
 * LCD Fonksiyonları
 */
void Lcd_Port(char a)
{
    if(a & 1)
    {
        D4 = 1;
    }
    else
    {
        D4 = 0;
    }

    if(a & 2)
    {
        D5 = 1;
    }
    else
    {
        D5 = 0;
    }

    if(a & 4)
    {
        D6 = 1;
    }
    else
    {
        D6 = 0;
    }

    if(a & 8)
    {
        D7 = 1;
    }
    else
    {
        D7 = 0;
    }
}

void Lcd_Cmd(char a)
{
    RS = 0;             // => RS = 0
    Lcd_Port(a);
    EN  = 1;             // => E = 1
    __delay_ms(4);
    EN  = 0;             // => E = 0
}

void Lcd_Clear(void)
{
    Lcd_Cmd(0);
    Lcd_Cmd(1);
}

void Lcd_Set_Cursor(char a, char b)
{
   char temp,z,y;
   
   if(a == 1)
   {
        temp = (char)(0x80 + b - 1);
        z = (char)(temp>>4);
        y = (char)(temp & 0x0F);
        Lcd_Cmd(z);
        Lcd_Cmd(y);
   }
   else if(a == 2)
   {
        temp = (char)(0xC0 + b - 1);
        z = (char)(temp>>4);
        y = (char)(temp & 0x0F);
        Lcd_Cmd(z);
        Lcd_Cmd(y);
   }
}

void Lcd_Init(void)
{
    Lcd_Port(0x00);
     __delay_ms(20);
    Lcd_Cmd(0x03);
     __delay_ms(5);
    Lcd_Cmd(0x03);
     __delay_ms(11);
    Lcd_Cmd(0x03);
    /////////////////////////////////////////////////////
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x08);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x0C);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x06);
}

void Lcd_Write_Char(char a)
{
    char temp,y;
    temp = (char)(a&0x0F);
    y = (char)(a&0xF0);
    RS = 1;             // => RS = 1
    Lcd_Port((char)(y>>4));             //Data transfer
    EN = 1;
    __delay_us(40);
    EN = 0;
    Lcd_Port(temp);
    EN = 1;
    __delay_us(40);
    EN = 0;
}

void Lcd_Write_String(char *a)
{
   int i;
   for(i=0;a[i]!='\0';i++)
   {
        Lcd_Write_Char(a[i]);
   }
}

void Lcd_Shift_Right(void)
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x0C);
}

void Lcd_Shift_Left(void)
{
    Lcd_Cmd(0x01);
    Lcd_Cmd(0x08);
}
//******************************************************************************

/*
 * MCU Hazırlığı
 */
void mcu_Hazirla(void)
{
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;

    TRISA = 0b00001011;
    TRISB = 0b00000000;
    TRISC = 0b11111111;
}

/*
 * Analog girişleri Hazırla
 */
void adc_Hazirla(void)
{
    ADCON1bits.ADFM = 0b1; // Sağa yaslanık
    ADCON1bits.PCFG = 0b0100; // Mecburen; AN0, AN1 ve AN3 analog
    ADCON0bits.ADCS = 0b11; // Frc
    ADCON0bits.ADON = 0b1; // ADC basla
}

/*
 * Analog kanal oku
 */
uint16_t adc_Oku(uint8_t kanal)
{
    ADCON0bits.CHS = kanal;
    __delay_us(20);
    ADCON0bits.GO_nDONE = 0b1;
    while(ADCON0bits.GO_nDONE)
    {

    }

    return(((uint16_t) (ADRESH << 8)) | ADRESL);
}

/*
 * Ana Döngü
 */
void main(void)
{
    uint8_t buf[10];
    uint8_t satir1[20];
    uint8_t satir2[20];
    
    uint16_t akim_Ham = 0;
    uint16_t gerilim_Ham = 0;

    uint16_t akim_Tam;
    uint16_t akim_Ondalik;

    uint16_t gerilim_Tam;
    uint16_t gerilim_Ondalik;

    adc_Hazirla();
    mcu_Hazirla();
    Lcd_Init();

    while(1)
    {        
        akim_Ham = adc_Oku(AKIM_ADC);
        gerilim_Ham = adc_Oku(GERILIM_ADC);

        akim_Tam = (uint16_t)(akim_Ham / 125.0);
        akim_Ondalik = (uint16_t)(((akim_Ham / 125.0) - akim_Tam) * 100); // İki hane ondalık

        gerilim_Tam = (uint16_t)(gerilim_Ham / 75.0);
        gerilim_Ondalik = (uint16_t)(((gerilim_Ham / 75.0) - gerilim_Tam) * 100); // İki hane ondalık
        
        satir1[0] = '\0';
        satir2[0] = '\0';
        
        strcpy(satir1, "AKIM    = "); 
        strcat(satir1, itoa(buf, akim_Tam, 10));
        strcat(satir1, ",");
        strcat(satir1, itoa(buf, akim_Ondalik, 10));
        strcat(satir1, "A");
        
        strcpy(satir2, "GERILIM = ");
        strcat(satir2, itoa(buf, gerilim_Tam, 10));
        strcat(satir2, ",");
        strcat(satir2, itoa(buf, gerilim_Ondalik, 10));
        strcat(satir2, "V");
        
        Lcd_Clear();
        Lcd_Set_Cursor(1, 1);
        Lcd_Write_String(satir1);
        
        Lcd_Set_Cursor(2, 1);
        Lcd_Write_String(satir2);

        __delay_ms(500);
    }
}
//------------------------------------------------------------------------------


HOCAM evet çalışıyor teşekkürler benim hatam varmış

mehmet

Okumaların sağlıklı olması için
low-pass filtre kullanmak uygun
olacaktır. Ben altta linkini verdiğim
kodu kullanıyorum. Buna göre yeniden
düzenleme yapılabilir.

https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
http://www.mehmetbilgi.net.tr

mmtkr

hocam benim alt yapım yok önce araştırıyorum sonra yazmaya çalışıyorum teşekkürler linki inceleeceğim birde bir sorum var  pic basic prooda */ operatörünün  C dilindeki karşılığı nedir

ete

Basic de (A*/B) operatörünün yaptığı iş şu. A ile B yi çarpıp sonucu 256 ya bölerek vermek.
Bunu kullanmamızın sebebi ise Basic de ondalıklı sayılarla çalışamıyor olmamızdır.
C dilinde direk ondalıklı (FLOAT) sayılarla çalışıldığı için bu karşılığı aramana da gerek yok.
AMa çok istiyor isen (A*B)/256 şeklinde uygulayabilirsin.

Ete

ete

#14
Analog okumalarda okunan ilgiye LOW-PASS_FILTRE uygulamak isteyenlere örnek vereym istedim.
İşin Genel Formülü;
y[i] := ß * x[i] + (1-ß) * y[i-1]
şeklinde.
Bu formülde yer alan bileşenlere bakacak olursak ;
-Y[i]=filtrelenmiş okuma değeri
-ß (Beta) = filtre parametresi 
-X[i] = ADC den okunan değer
-y[i-1]= bir önceki hesaplanmış filtrelenmiş okuma değeri

Burada önemli kriter Beta değeri oluyor bizim açımızdan zira genelde 1 den küçük bir değer kullanılıyor.
Bu durumda bizim ondalıklı sistemden çıkıp tam sayı sistemi ile bu hesabı yapmamız gerekecek.
Örnek linkte verilen Beta değeri 0,025 olarak verilmiş. Bu değeri kullanmak için;
0,025 * 256=6,4 bulunur. Bunu 10 ile çarparak kullanabileceğiz. Yani değerimiz 64 olacak.
Formülde birde (1-Beta) değeri var. Buda 1-0,025=0,975 eder bunuda 256 ile çarparsak 249,6 ve 10 ile çarpılmış halide 2496 olarak kullanılacak demektir.
Şimdi formülümüzü yazabiliriz.
ADC den okunan değerimiz RAW olsun Filtreden geçirilmiş haline de HAM diyelim.
İlk defa bu işe başlıyor isek önceki filtrelenmiş değeri yeni okunan değer olarak kabul edebiliriz. Yani EskiHAM=RAW diye işe başlayabiliriz.
HAM=((64*/RAW) + (2496*/EskiHAM))/10
EskiHAM=HAM

hepsi bu kadar. Umarım anlaşılmıştır.

Ete

Powered by EzPortal