Tarama ile 12 adet displayin sürülmesi (74HC595+ULN2803) ÇÖZÜLDÜ.

Başlatan Faruk53, 17 Nisan 2016, 21:51:49

Faruk53

Merhaba arkadaşlar. CCS C ile yazdığım programı XC8'e çevirmek için uğraşıyorum. Fakat bir türlü çalıştıramadım. Hiçbir türlü displaylerde herhangi birşey görünmüyor. Program 12 adet displayi sürmek için. CCS C de çalıştırmıştım herhangi bir problem yaşamamıştım. Ek olarak 32mhz pll yapmaya çalıştım. Orada mı hatam var yoksa giriş çıkış tanımlamalarımda mı ne yaptıysam olmadı. Yardımlarınız için şimdiden teşekkür ederim. İyi çalışmalar..

config3x25mm.h dosyası

// PIC18F4520 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

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

// CONFIG1H
#pragma config OSC = INTIO67     // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3         // Brown Out Reset Voltage bits (Minimum setting)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC   // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)

// CONFIG4L
#pragma config STVREN = OFF     // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)


#define _XTAL_FREQ 32000000L


3x25mm.c dosyası

#include <stdio.h>
#include <stdlib.h>
#include "config3x25mm.h"

//*********************************74hc595 pinleri****************************//
#define SH_CP LATDbits.LATD2
#define DATA  LATDbits.LATD0
#define ST_CP LATDbits.LATD1
//____________________________________________________________________________//

//*************************Display bacaklarının bağlantısı********************//
#define hbirler LATDbits.LATD4
#define honlar LATDbits.LATD7
#define hyuzler LATDbits.LATD6
#define hbinler LATDbits.LATD5

#define gbirler LATAbits.LATA4
#define gonlar LATAbits.LATA5
#define gyuzler LATAbits.LATA6
#define gbinler LATCbits.LATC0

#define fbirler LATBbits.LATB4
#define fonlar LATBbits.LATB3
#define fyuzler LATBbits.LATB2
#define fbinler LATBbits.LATB1
//____________________________________________________________________________//

unsigned char segmentler[10]={0x7D,0x44,0x7A,0x6E,0x47,0x2F,0x3F,0x64,0x7F,0x6f};

int a=0,b=0,c=0;

unsigned int gdata[4];
unsigned int fdata[4];
unsigned int Hdata[4];

unsigned long gsayi=1233; 
unsigned long fsayi;
unsigned long Hsayi=6544;

//*********************Yazılan Kütüphanelerin Başlık Dosylaları****************//
void mcu_init();
void pll_init();
void hc595_yaz(unsigned char veri);
void int_to_seg(unsigned long sayi,int DP);
void int_to_fseg(unsigned long sayi,int DP);
void int_to_Hseg(unsigned long sayi,int DP);
void sayac();
void hedef();
void fark();
void baslangic_sifirla();
//____________________________________________________________________________//

//************************HC595 veri basma************************************//
void hc595_yaz(unsigned char veri)
{
   unsigned  char i;
   for(i=0x80;i>0;i>>=1)
   {
      if(i&veri)     
      {
          DATA=1;
      }
      else      
      {
          DATA=0;
      }

      SH_CP=1;
      SH_CP=0;
      __delay_us(1);
      ST_CP=1;
      ST_CP=1;
      
   } 
   }
//____________________________________________________________________________//

//**********************************G. sayı için çevirme******************//
void int_to_seg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; gdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; gdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; gdata[1]=segmentler[c];
 sayi/=10 ; gdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//

//**********************************F. sayı için çevirme********************//
void int_to_fseg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; fdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; fdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; fdata[1]=segmentler[c];
 sayi/=10 ; fdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//


//**********************************h. sayı için çevirme********************//
void int_to_Hseg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; Hdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; Hdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; Hdata[1]=segmentler[c];
 sayi/=10 ; Hdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//

//********************G. HANESİNE SAYI YAZDIRMA***************************//
void sayac()
{

   hc595_yaz(gdata[3]);
   gbirler=1;
   __delay_ms(4);
   gbirler=0;


   hc595_yaz(gdata[2]);
   gonlar=1;
   __delay_ms(4);
   gonlar=0;

   hc595_yaz(gdata[1]);
  gyuzler=1;
   __delay_ms(4);
   gyuzler=0;

   hc595_yaz(gdata[0]);
   gbinler=1;
   __delay_ms(4);
   gbinler=0;
}
//____________________________________________________________________________//


//************************************F. HANESİ YAZDIRILIYOR******************//
void fark()
{
   //int_to_fseg(fsayi,0);

   fsayi==((Hsayi-gsayi)-1);
   
   hc595_yaz(fdata[3]);
   fbirler=1;
   __delay_ms(4);
   fbirler=0;

   hc595_yaz(fdata[2]);
   fonlar=1;
   __delay_ms(4);
   fonlar=0;

   hc595_yaz(fdata[1]);
   fyuzler=1;
   __delay_ms(4); 
   fyuzler=0;

   hc595_yaz(fdata[0]);
   fbinler=1;
   __delay_ms(4);
   fbinler=0;
}
//____________________________________________________________________________//


//*************************H. HANESİ YAZDIRILIYOR**************************//
void hedef()
{
  
   hc595_yaz(Hdata[3]);
   hbirler=1;
   __delay_ms(4);
   hbirler=0;


   hc595_yaz(Hdata[2]);
   honlar=1;
   __delay_ms(4);
   honlar=0;

   hc595_yaz(Hdata[1]);
   hyuzler=1;
   __delay_ms(4);
   hyuzler=0;

   hc595_yaz(Hdata[0]);
   hbinler=1;
   __delay_ms(4);
   hbinler=0;
}
//____________________________________________________________________________//

//***********Ekran Taraması başlatılıyor sayılar çevrime dallanıyor***********//
void yaz_tara()
{
int_to_seg(gsayi,0);
__delay_ms(4);
int_to_Hseg(Hsayi,0);
__delay_ms(4);
int_to_fseg(fsayi,0);
__delay_ms(4);
}
//____________________________________________________________________________//

//***********İLK AÇILIŞTA BÜTÜN ÇIKIŞLARI SIFIRLAMAK İÇİN YAZILDI*************//
void baslangic_sifirla()
{
       gbirler=0;gonlar=0;gyuzler=0;gbinler=0;
       hbirler=0;honlar=0; hyuzler=0; hbinler=0;
       fbirler=0;fonlar=0; fyuzler=0;fbinler=0;

}
//____________________________________________________________________________//
void pll_init()
{
    OSCTUNEbits.PLLEN = 0b1; // PLL AKTİFLİĞİ SYF=27
    OSCCONbits.SCS = 0b10; // DAHİLİ OSİLATÖR BLOĞU SEÇİLDİ. SYF=30
    OSCCONbits.IRCF = 0b111; //DAHİLİ 8MHZ SEÇİLDİ. SYF=30
     // OSCCON = 0x76;
}
void mcu_init()
{
    ADCON1bits.PCFG = 0b1111; //Bütün analog girişler dijitale çevrildi. SYF = 224
    
    TRISA = 0;
    TRISB = 0;
    TRISD = 0;
    TRISC0 =0;

    PORTA = 0x00;
    PORTB = 0x00;
    PORTD = 0x00;
}

void main()
{
    mcu_init();
    pll_init();
    baslangic_sifirla();

while(1)
{
   yaz_tara();
   fark();
   sayac();
   hedef();
   
}
}

Faruk53

Arkadaşlar sorunu çözdüm. Sorun 74hc595 in yaz fonksiyonlarını tanımlarken  ST_CP ucunu low konumuna çekmemem. uykusuzluk başa bela işte :) Birde delay ayarlarını birazdaha kısmam gerekiyordu. kodlar aşağıdadır. belki birilerinin işine yarar. kolay gelsin.

config3x25mm.h dosyası

// PIC18F4520 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

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

// CONFIG1H
#pragma config OSC = INTIO67     // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3         // Brown Out Reset Voltage bits (Minimum setting)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC   // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)

// CONFIG4L
#pragma config STVREN = OFF     // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)


#define _XTAL_FREQ 8000000


3x25mm.c dosyası

#include <stdio.h>
#include <stdlib.h>
#include "config3x25mm.h"


//*********************************74hc595 pinleri****************************//
#define SH_CP LATDbits.LATD2
#define DATA  LATDbits.LATD0
#define ST_CP LATDbits.LATD1
//____________________________________________________________________________//

//*************************Display bacaklarının bağlantısı********************//
#define hbirler LATDbits.LATD4
#define honlar LATDbits.LATD7
#define hyuzler LATDbits.LATD6
#define hbinler LATDbits.LATD5

#define gbirler LATAbits.LATA4
#define gonlar LATAbits.LATA5
#define gyuzler LATAbits.LATA6
#define gbinler LATCbits.LATC0

#define fbirler LATBbits.LATB4
#define fonlar LATBbits.LATB3
#define fyuzler LATBbits.LATB2
#define fbinler LATBbits.LATB1
//____________________________________________________________________________//

unsigned char segmentler[10]={0x7D,0x44,0x7A,0x6E,0x47,0x2F,0x3F,0x64,0x7F,0x6f};

int a=0,b=0,c=0;

unsigned char gdata[4];
unsigned char fdata[4];
unsigned char Hdata[4];

unsigned long gsayi=1233; //g.sayı
unsigned long fsayi;
unsigned long Hsayi=6544;

//*********************Yazılan Kütüphanelerin Başlık Dosylaları****************//
void mcu_init();
void osc_init();
void hc595_yaz(unsigned char veri);
void int_to_seg(unsigned long sayi,int DP);
void int_to_fseg(unsigned long sayi,int DP);
void int_to_Hseg(unsigned long sayi,int DP);
void sayac();
void hedef();
void fark();
void baslangic_sifirla();
//____________________________________________________________________________//

//************************HC595 veri basma************************************//
void hc595_yaz(unsigned char veri)
{
   unsigned  char i;
   for(i=0x80;i>0;i>>=1)
   {
      if(i&veri)DATA=1;
      
      else DATA=0;
      
      SH_CP=1;
      SH_CP=0;
      __delay_us(1);
      ST_CP=1;
      ST_CP=0;
   } 
   }
//____________________________________________________________________________//

//**********************************G. sayı için çevirme******************//
void int_to_seg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; gdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; gdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; gdata[1]=segmentler[c];
 sayi/=10 ; gdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//

//**********************************F.sayı için çevirme********************//
void int_to_fseg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; fdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; fdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; fdata[1]=segmentler[c];
 sayi/=10 ; fdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//


//**********************************F. sayı için çevirme********************//
void int_to_Hseg(unsigned long sayi,int DP)//Dot Point.
{
 a=sayi%10; Hdata[3]=segmentler[a]+DP;
 sayi/=10;
 b=sayi%10; Hdata[2]=segmentler[b];
 sayi/=10;
 c=sayi%10; Hdata[1]=segmentler[c];
 sayi/=10 ; Hdata[0]=segmentler[sayi];
}
//____________________________________________________________________________//

//********************G. HANESİNE SAYI YAZDIRMA***************************//
void sayac()
{

   hc595_yaz(gdata[3]);
   gbirler=1;
  __delay_us(750);
   gbirler=0;


   hc595_yaz(gdata[2]);
   gonlar=1;
  __delay_us(750);
   gonlar=0;

   hc595_yaz(gdata[1]);
  gyuzler=1;
  __delay_us(750);
   gyuzler=0;

   hc595_yaz(gdata[0]);
   gbinler=1;
   __delay_us(750);
   gbinler=0;
}
//____________________________________________________________________________//


//************************************F.HANESİ YAZDIRILIYOR******************//
void fark()
{
   //int_to_fseg(fsayi,0);

   fsayi=((Hsayi-gsayi));
   
   hc595_yaz(fdata[3]);
   fbirler=1;
  __delay_us(750);
   fbirler=0;

   hc595_yaz(fdata[2]);
   fonlar=1;
  __delay_us(750);
   fonlar=0;

   hc595_yaz(fdata[1]);
   fyuzler=1;
 __delay_us(750);
   fyuzler=0;

   hc595_yaz(fdata[0]);
   fbinler=1;
   __delay_us(750);
   fbinler=0;
}
//____________________________________________________________________________//


//*************************H. HANESİ YAZDIRILIYOR**************************//
void hedef()
{
  
   hc595_yaz(Hdata[3]);
   hbirler=1;
   __delay_us(750);
   hbirler=0;


   hc595_yaz(Hdata[2]);
   honlar=1;
  __delay_us(750);
   honlar=0;

   hc595_yaz(Hdata[1]);
   hyuzler=1;
   __delay_us(750);
   hyuzler=0;

   hc595_yaz(Hdata[0]);
   hbinler=1;
   __delay_us(750);
   hbinler=0;
}
//____________________________________________________________________________//

//***********Ekran Taraması başlatılıyor sayılar çevrime dallanıyor***********//
void yaz_tara()
{
int_to_seg(gsayi,0);
__delay_us(750);
int_to_Hseg(Hsayi,0);
__delay_us(750);
int_to_fseg(fsayi,0);
__delay_us(750);
}
//____________________________________________________________________________//

//***********İLK AÇILIŞTA BÜTÜN ÇIKIŞLARI SIFIRLAMAK İÇİN YAZILDI*************//
void baslangic_sifirla()
{
       gbirler=0;gonlar=0;gyuzler=0;gbinler=0;
       hbirler=0;honlar=0; hyuzler=0; hbinler=0;
       fbirler=0;fonlar=0; fyuzler=0;fbinler=0;

}
//____________________________________________________________________________//
void osc_init()
{
   // OSCTUNEbits.PLLEN = 0b1; // PLL AKTİFLİĞİ SYF=27
   // OSCCONbits.SCS = 0b10; // DAHİLİ OSİLATÖR BLOĞU SEÇİLDİ. SYF=30
    OSCCONbits.IRCF = 0b111; //DAHİLİ 8MHZ SEÇİLDİ. SYF=30
     
}
void mcu_init()
{
    ADCON1bits.PCFG = 0b1111; //Bütün analog girişler dijitale çevrildi. SYF = 224
    
    TRISA = 0;
    TRISB = 0;
    TRISD = 0;
    TRISE = 0;
    TRISC0 =0;

    PORTA = 0x00;
    PORTB = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;
}
void main()
{
    mcu_init();
    osc_init();
    baslangic_sifirla();
   
    
while(1)
{
   yaz_tara();
   fark();
   sayac();
   hedef();   
}
}