Picproje Elektronik Sitesi

DERLEYİCİLER => Microchip XC Serisi => Microchip XC8 => Konuyu başlatan: tomi - 05 Nisan 2021, 20:41:53

Başlık: MİLFORD 4x20-BKP tek hat SERİ LCD KÜTÜPHANESİ
Gönderen: tomi - 05 Nisan 2021, 20:41:53
Arkadaşlar merhaba,
Proteusta her zaman hoşuma giden ve basic ile kod yazarken severek kullandığım seri LCD nin c kodlarını 18F4520 işlemci kullanarak  xc8 de derledim.Kısaca bilgi vermek isterim.seri LCD tek portla çalışır, bu port istediğiniz bir işlemcinin herhangi bir portu olabilir.
     Proteusta simulasyonu nu yaparken seri LCD yi üzerine tıklayarak hız ayarını yapınız(9600/2400 baud).
   Yine seri lcd yi hangi hıza ayarladınız ise program içinde -->baud_kur(baud)<<-- programında hızı 9600/2400 olarak giriniz.
Tüm ayarlar bu kadar.

//ANA PROGRAM BASI------------------------
/*
 * File:   seriLCD.c
 * Author: SAİT ERCAN
 *
 * Created on 05 Nisan 2021 Pazartesi, 17:11
*18f4520 MİLFORD 4x20-BKP tek hat SERİ LCD
 * 04.04.2021
 * NOT: SERİ LCD HANGİ HIZDA ÇALIŞACAK İSE
 * PROGRAM İÇİNDE   baud_kur(2400); ŞEKLİNDE 9600/2400
 * OLARAK İLETİŞİM HIZI BELİRTİLMELİDİR.
 */
#include <xc.h>
#include <stdint.h>
#include <stdio.h>              // printf için gerekli c standart giriş
//çıkış kütüphanesi

#include "LCD1_lib.h"
#include "LCD1_lib.c"

#include "sLCD1_lib.h"
#include "sLCD1_lib.c"

#define _XTAL_FREQ 4000000


    void main(void)
{
       
    ADCON1=0x0F; // hepsi dijital çıkış oldu
   
                TRISA=0b00000000;   TRISC=0b00000000;
            TRISB=0b00000000;            TRISD=0b00000000;
        TRISEbits.RE0=0;                    TRISEbits.RE2=0;
    TRISEbits.RE1=0;
       
        PORTB=0x00; PORTC=0x00; PORTD=0x00;
    PORTA=0x00;                     PORTE=0x00;         

         __delay_ms(200);
         
         
          lcd_kur();
          slcd_kur();
         
         
          while(1)
       {     
             slcd_gotoxy(1,1);           
                slcd_veri_gon(50);       
                    slcd_gotoxy(1,1);
                    slcd_yaz("->>BILGI PAYLASIM<<-"); 
                        slcd_gotoxy(2,1);
                            slcd_yaz("       SITESI     ");
                                slcd_gotoxy(3,1);
                            slcd_yaz("     PIC PROJE    ");
                        slcd_gotoxy(4,1);
                slcd_yaz("  ELEKTRONIK SITESI  "); 
        for(;;);
             
          }         
         
 }     
 //ANA PROGRAM SONU------------------------   
   

// "sLCD1_lib.c"  DOSYASI BASI----------------


   

//------------------------------------------------------ 
        unsigned int baud_kur(unsigned int baud)
        {
         if  (baud==9600)  {veri=0x02;hiz=9600;}
         if  (baud==2400)  {veri=0x01;hiz=2400;}
            return hiz;
        }
//------------------------------------------------------ 
void slcd_veri_gon(unsigned char veri)
           
{
              veri_yar=0b00000001;              //...veri içindeki değişkenleri sececek olan yardımcı degişken
              sdata=0;
           if (hiz==9600)  __delay_us(104);    //.104..start biti  hatta bekleme süresi
        if (hiz==2400)  __delay_us(380);       //..start biti  hatta bekleme süresi
 //------------------------------------------------------ 
       
              for (i=0;i<8;i++)                 // 8 bitlik veri döngüsü
              {
                    if ((veri&veri_yar)==veri_yar)                                       
                                {
                                    veri_yar=veri_yar<<1;
                                    sdata=1;
                                    if (hiz==9600)  __delay_us(60); //150...veri biti  hatta bekleme süresi
                                    if (hiz==2400)__delay_us(380); //.70..veri biti  hatta bekleme süresi
                             //       __delay_us(70);
                                }
                       else         
                                {
                                    veri_yar=veri_yar<<1;
                                    sdata=0;
                                    if (hiz==9600)  __delay_us(60); //150...veri biti  hatta bekleme süresi
                                    if (hiz==2400)__delay_us(380);  //.70..veri biti  hatta bekleme süresi
                             //       __delay_us(70);
                                }
              }
         
              sdata=1;
                if (hiz==9600)  __delay_us(150);        //150...stop biti  hatta bekleme süresi
              if (hiz==2400)__delay_us(380);            //...stop biti  hatta bekleme süresi
}
 //---------------------------------------------------------------- 
     
void slcd_sil(void)
{
        slcd_veri_gon(0xFE);
            slcd_veri_gon(0x01);
}
//----------------------------------------------------------------     
    int j=0;
void slcd_yaz( const char *text)

   for (j=0;text[j];j++)
    slcd_veri_gon(text[j]);
}
//---------------------------------------------------------------- 
void slcd_gotoxy(unsigned char x,unsigned char y)
{
        if(x==1) slcd_veri_gon(0xFE);
    if(x==1) slcd_veri_gon(128+((y-1)%16));
   
        if(x==2) slcd_veri_gon(0xFE);
    if(x==2) slcd_veri_gon(192+((y-1)%16));
       
        if(x==3) slcd_veri_gon(0xFE);
    if(x==3) slcd_veri_gon(148+((y-1)%16));
       
        if(x==4) slcd_veri_gon(0xFE);
    if(x==4) slcd_veri_gon(212+((y-1)%16));   
}
//---------------------------------------------------------------- 

void slcd_binlerhane_gon(unsigned int k)
{     
    slcd_veri_gon(((k%10000)/1000)+48);

void slcd_yuzlerhane_gon(unsigned int k)
{
    slcd_veri_gon(((k%1000)/100)+48);
}
void slcd_onlarhane_gon(unsigned int k)
{
    slcd_veri_gon(((k%100)/10)+48);
}
void slcd_birlerhane_gon(unsigned int k)
{
    slcd_veri_gon((k%10)+48);   
}   
//----------------------------------------------------------------
 
   void slcd_kur(void)
   {
         lcd_sil();
          baud_kur(9600); //BURADA HIZ SEÇİLMELİDİR 9600/2400 OLARAK
         if  (hiz==9600)  veri=0x02;
         if  (hiz==2400)  veri=0x01;
         slcd_veri_gon(veri);
                slcd_veri_gon(0xFE);
                    slcd_veri_gon(128);                           
                        slcd_veri_gon(0xFE);
                            slcd_veri_gon(13);  // kursörü flash yaptırıR                     
   }
//----------------------------------------------------------------
// "sLCD1_lib.c"  DOSYASI SONU----------------


//     "sLCD_lib.h"  DOSYASI BASI----------------
/*
 * File:   sLCD_lib.h
 * Author: User
 *
 * Created on 04.04 2021, 5:29 PM
 */

#include <xc.h>

// PIC18F4520 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1H
#pragma config OSC = XT         // Oscillator Selection bits (XT oscillator)
#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 = ON        // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#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 (MCLR pin enabled; RE3 input pin 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)

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

#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif

#define sdata PORTCbits.RC4     //seri lcd için TEK HAT port .


unsigned char veri=0,veri_yar,x,y;
unsigned int i,baud,hiz,k;


extern unsigned int baud_kur(unsigned int baud);
extern void slcd_veri_gon(unsigned char veri);
extern void slcd_sil(void);
extern void slcd_yaz( const char *text);
extern void slcd_gotoxy(unsigned char x,unsigned char y);
extern void slcd_kur(void);
extern void slcd_binlerhane_gon(unsigned int k);
extern void slcd_yuzlerhane_gon(unsigned int k);
extern void slcd_onlarhane_gon(unsigned int k);
extern void slcd_birlerhane_gon(unsigned int k);


//     "sLCD_lib.h"  DOSYASI SONU----------------

   
(https://i.ibb.co/TgH3Y2r/20210405-215540.jpg) (https://ibb.co/TgH3Y2r)