Picproje Elektronik Sitesi

DERLEYİCİLER => Microchip XC Serisi => Konuyu başlatan: creastfallen - 24 Ocak 2016, 20:58:42

Başlık: 16F127 lcd çalışmıyor..
Gönderen: creastfallen - 24 Ocak 2016, 20:58:42
Merhaba arkadaşlar. 16F1827 entegre ile lcd'yi çalıştıramadım. Aşşağıda main, lcd.c ve lcd.h dosyalarını paylaştım.Yardım edermisiniz..


(http://s9.postimg.cc/3k4nzi67f/Screen_Hunter_247_Jan_24_13_55.jpg) (http://postimg.cc/image/3k4nzi67f/)


[main]

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

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

// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = ON          // Flash Program Memory Code Protection (Program memory code protection is enabled)
#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

#define _XTAL_FREQ 8000000L

void main(void)
{
      CM1CON0 = 0x00;
      CM2CON0 = 0x00;
      CM2CON1 = 0x00;
     
      ANSELA = 0x00;
      ANSELB = 0x00;
     
      OSCCONbits.SPLLEN  = 0b0;
      OSCCONbits.IRCF3   = 0b1;
      OSCCONbits.IRCF2   = 0b1;
      OSCCONbits.IRCF1   = 0b1;
      OSCCONbits.IRCF0   = 0b0;
      OSCCONbits.SCS0    = 0b0;
      OSCCONbits.SCS1    = 0b0;
     
      PORTA = 0x00;
      TRISA = 0x00;
     
      PORTB = 0x00;
      TRISB = 0x00;
     
    unsigned int sayi=12345;
    unsigned char text[6];

    lcd_init();
lcd_goto(0); // select first line
lcd_puts("LCD SAYI DENEME");
sprintf(text,"sayi= %u",sayi);
lcd_goto(0x40); // Select second line
    lcd_puts(text);


     
      while(1)
      {
         LATAbits.LATA6 = 0b1;
         __delay_ms(500);
         LATAbits.LATA6 = 0b0;
         __delay_ms(500);
      }
}



[code][lcd.c]

#include <p18cxxx.h>


#define _XTAL_FREQ 8000000L

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

#define LCD_RS RB1
#define LCD_EN RB0
#define LCD_DATA4 RB4
#define LCD_DATA5 RB5
#define LCD_DATA6 RB6
#define LCD_DATA7 RB7


#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

void lcd_write(unsigned char c)
{
__delay_us(40);
        unsigned char cv = (c>>4);
        LCD_DATA4 = (cv >> 0) & 0x01;
        LCD_DATA5 = (cv >> 1) & 0x01;
        LCD_DATA6 = (cv >> 2) & 0x01;
        LCD_DATA7 = (cv >> 3) & 0x01;
LCD_STROBE();
        LCD_DATA4 = (c >> 0) & 0x01;
        LCD_DATA5 = (c >> 1) & 0x01;
        LCD_DATA6 = (c >> 2) & 0x01;
        LCD_DATA7 = (c >> 3) & 0x01;
LCD_STROBE();
}

/*
* Clear and home the LCD
*/

void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */

void lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void lcd_putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}


/*
* Go to the specified position
*/

void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */
void lcd_init()
{
char init_value;

init_value = 0x3;
LCD_RS = 0;
LCD_EN = 0;

__delay_ms(15); // wait 15mSec after power applied,
        LCD_DATA4 = (init_value >> 0) & 0x01;
        LCD_DATA5 = (init_value >> 1) & 0x01;
        LCD_DATA6 = (init_value >> 2) & 0x01;
        LCD_DATA7 = (init_value >> 3) & 0x01;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
        LCD_DATA4 = 0;
        LCD_DATA5 = 1;
        LCD_DATA6 = 0;
        LCD_DATA7 = 0;
LCD_STROBE();

lcd_write(0x28); // Set interface length
lcd_write(0x0C); // Display On, Cursor Off, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}

[code][lcd.h]

#define _XTAL_FREQ 8000000L
/* write a byte to the LCD in 4 bit mode */

extern void lcd_write(unsigned char);

/* Clear and home the LCD */

extern void lcd_clear(void);

/* write a string of characters to the LCD */

extern void lcd_puts(const char * s);

/* Go to the specified position */

extern void lcd_goto(unsigned char pos);

/* intialize the LCD - call before anything else */

extern void lcd_init(void);

extern void lcd_putch(char);

/* Set the cursor position */

#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)



Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: dursuncemal - 25 Ocak 2016, 01:26:51
lcd nin rw ucunu kullanmiyor isen ( - ) ye vermelisin.bosta olmaz!!
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: creastfallen - 25 Ocak 2016, 10:14:07
Dursun bey devreyi elektronik bord üzerine kurdum ve rw ucunu (-) katota bağladım ama devre çalışmıyor. Kod yukarıda ki gibi...
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: dursuncemal - 25 Ocak 2016, 13:43:06
lcd init ten once uzun bir delay koy   lcd nin ust satirindaki kareler kayboluyomu diye bir gozle ? hangi derleyici ile calisiyorsun ona gore bi bakalim
Başlık: Ynt: 16F1827 lcd çalışmıyor..
Gönderen: creastfallen - 25 Ocak 2016, 14:02:10
uzun bir delay yapalim olacakmış.  derleyici mplabx xc8
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: dursuncemal - 25 Ocak 2016, 14:13:27
uzun delay calismasi icin degil  ilk satirdaki karecikler  kayboluyorsa gorebilmen icin  once onlarin kaybolmasi lazim.

mesaj birleştirme:: 25 Ocak 2016, 14:21:02

A6 yı da konrol et fonksiyonun calisiyomu?
Başlık: Ynt: 16F1827 lcd çalışmıyor..
Gönderen: creastfallen - 27 Ocak 2016, 20:20:59
A6 çalışıyor .Ekranda ilk satırda siyah kareler yok. Rwyi katota (-) ye bağladığımda similasyonda çalıştı ama bordun üzerinde çalışmıyor.
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: dursuncemal - 27 Ocak 2016, 23:13:53
siyah kareler once gelip sonra kayboluyomu? yoksa hic yok mu?
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: creastfallen - 29 Ocak 2016, 20:45:23
Siyah kare hiç yok. Simülasyon da çalışıyor bordun üzerinde çalışmıyor.
Başlık: Ynt: 16F127 lcd çalışmıyor..
Gönderen: dursuncemal - 29 Ocak 2016, 23:57:22
bordun ustunden islemciyi cıkart  sadece lcd kalsın. beslemeyi verince kontrast ayari yptıgın potansi cevirince ust satir komle karelerle dolmali. eger olmuyorsa kontrast potanisina bak yada lcd bozuk olabilir. semada pot dogru
ikinci asama islemciyi calistıtınca ilk etapta  kareler kaybolmali. kareler hala yerinde duruyorsa ya baglantintilarinda  yada  lcd_init fonksiyonunda bir sikinti vardir.  rw ucun - olacak.