Hi-Tech'te C18 Kütüphanesi

Başlatan mihri, 29 Temmuz 2009, 17:06:21

mihri

Hi-Tech Pic c 18 9.63 derleyicide HI-TECH Software\PICC-18\PRO\9.63\sources\plib klasöründe birçok uygulama için kütüphane var. Aynı kütüphaneler C18 3.15 derleyicide mcc18\src\pmc_common klasöründe de var. Hi-Tech'te bu kütüphaneler nasıl kullanılıyor bilen var mı?
"Eppur si muove!"

mihri

C18 için örnek kullanım aşağıda.
#include <p18C452.h>
#include <xlcd.h>
#include <delays.h>
#include <usart.h>
void DelayFor18TCY( void )
{
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
}
void DelayPORXLCD (void)
{
  Delay1KTCYx(60); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 16MHz) / 4
                   // Cycles = 60,000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(20); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 16MHz) / 4
                   // Cycles = 20,000
  return;
}
void main( void )
{
  char data;
  // configure external LCD
  OpenXLCD( EIGHT_BIT & LINES_5X7 );
  // configure USART
  OpenUSART( USART_TX_INT_OFF  & USART_RX_INT_OFF &
             USART_ASYNCH_MODE & USART_EIGHT_BIT  &
             USART_CONT_RX,
             25);
  while(1)
  {
    while(!DataRdyUSART());  //wait for data
    data = ReadUSART();      //read data
    WriteDataXLCD(data);     //write to LCD
    if(data=='Q')
      break;
  }
  CloseUSART();
}
"Eppur si muove!"

mihri

Hi-Tech için LCD kütüphanesi.

xlcd.h

#ifndef __XLCD_H
#define __XLCD_H

/* PIC18 XLCD peripheral routines.
 *
 *   Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
/* #define UPPER */

/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT      PORTB
#define TRIS_DATA_PORT TRISB

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
#define RW_PIN   RB6   /* PORT for RW */
//#define TRIS_RW  DDRBbits.RB6    /* TRIS for RW */
#define TRIS_RW  TRISB6    /* TRIS for RW */
#define RS_PIN   RB5   /* PORT for RS */
//#define TRIS_RS  DDRBbits.RB5    /* TRIS for RS */
#define TRIS_RS  TRISB5    /* TRIS for RS */
#define E_PIN    RB4   /* PORT for E  */
//#define TRIS_E   DDRBbits.RB4    /* TRIS for E  */
#define TRIS_E   TRISB4    /* TRIS for E  */

/* Display ON/OFF Control defines */
#define DON         0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off     */
#define CURSOR_ON   0b00001111  /* Cursor on       */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF   0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00010011  /* Cursor shifts to the left   */
#define SHIFT_CUR_RIGHT   0b00010111  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT   0b00011011  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00011111  /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT   0b00101111  /* 4-bit Interface               */
#define EIGHT_BIT  0b00111111  /* 8-bit Interface               */
#define LINE_5X7   0b00110011  /* 5x7 characters, single line   */
#define LINE_5X10  0b00110111  /* 5x10 characters               */
#define LINES_5X7  0b00111011  /* 5x7 characters, multiple line */


/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(unsigned char);

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(unsigned char);

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(char);


/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);


#endif


xlcd.c

#include "xlcd.h"

/********************************************************************
*       Function Name:  BusyXLCD                                    *
*       Return Value:   char: busy status of LCD controller         *
*       Parameters:     void                                        *
*       Description:    This routine reads the busy status of the   *
*                       Hitachi HD44780 LCD controller.             *
********************************************************************/
unsigned char BusyXLCD(void)
{
        RW_PIN = 1;                     // Set the control bits for read
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock in the command
        DelayFor18TCY();


#ifndef BIT8
#ifdef UPPER                            // Upper nibble interface
        if(DATA_PORT&0x80){
#else                                   // Lower nibble interface
        if(DATA_PORT&0x08){
#endif
        E_PIN = 0;              // Reset clock line
        DelayFor18TCY();
        E_PIN = 1;              // Clock out other nibble
        DelayFor18TCY();

#else
	if(DATA_PORT&0x80){
#endif
        E_PIN = 0;              // Reset clock line
        RW_PIN = 0;             // Reset control line
		return 1;
	}
#ifndef BIT8
	E_PIN = 0;              // Reset clock line
	DelayFor18TCY();
	E_PIN = 1;              // Clock out other nibble
	DelayFor18TCY();
#endif
	E_PIN = 0;              // Reset clock line
	RW_PIN = 0;             // Reset control line
	return 0;
}
/********************************************************************
*       Function Name:  OpenXLCD                                    *
*       Return Value:   void                                        *
*       Parameters:     lcdtype: sets the type of LCD (lines)       *
*       Description:    This routine configures the LCD. Based on   *
*                       the Hitachi HD44780 LCD controller. The     *
*                       routine will configure the I/O pins of the  *
*                       microcontroller, setup the LCD for 4- or    *
*                       8-bit mode and clear the display. The user  *
*                       must provide three delay routines:          *
*                       DelayFor18TCY() provides a 18 Tcy delay     *
*                       DelayPORXLCD() provides at least 15ms delay *
*                       DelayXLCD() provides at least 5ms delay     *
********************************************************************/
void OpenXLCD(unsigned char lcdtype)
{
        // The data bits must be either a 8-bit port or the upper or
        // lower 4-bits of a port. These pins are made into inputs
#ifdef BIT8                             // 8-bit mode, use whole port
        DATA_PORT = 0;
        TRIS_DATA_PORT = 0xff;
#else                                   // 4-bit mode
#ifdef UPPER                            // Upper 4-bits of the port
        DATA_PORT &= 0x0f;
        TRIS_DATA_PORT |= 0xf0;
#else                                   // Lower 4-bits of the port
        DATA_PORT &= 0xf0;
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        TRIS_RW = 0;                    // All control signals made outputs
        TRIS_RS = 0;
        TRIS_E = 0;
        RW_PIN = 0;                     // R/W pin made low
        RS_PIN = 0;                     // Register select pin made low
        E_PIN = 0;                      // Clock pin made low

        // Delay for 15ms to allow for LCD Power on reset
        DelayPORXLCD();
        
        // Setup interface to LCD
#ifdef BIT8                             // 8-bit mode interface
        TRIS_DATA_PORT = 0;             // Data port output
        DATA_PORT = 0b00110000;         // Function set cmd(8-bit interface)
#else                                   // 4-bit mode interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= 0b00100000;        // Function set cmd(4-bit interface)
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= 0b00000010;        // Function set cmd(4-bit interface)
#endif
#endif
        E_PIN = 1;                      // Clock the cmd in
        DelayFor18TCY();
        E_PIN = 0;
        
        // Delay for at least 4.1ms
        DelayXLCD();

        // Setup interface to LCD
#ifdef BIT8                             // 8-bit interface
        DATA_PORT = 0b00110000;         // Function set cmd(8-bit interface)
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;              // Function set cmd(4-bit interface)
        DATA_PORT |= 0b00100000;
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;              // Function set cmd(4-bit interface)
        DATA_PORT |= 0b00000010;
#endif
#endif
        E_PIN = 1;                      // Clock the cmd in
        DelayFor18TCY();
        E_PIN = 0;

        // Delay for at least 100us
        DelayXLCD();

        // Setup interface to LCD
#ifdef BIT8                             // 8-bit interface
        DATA_PORT = 0b00110000;         // Function set cmd(8-bit interface)
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;              // Function set cmd(4-bit interface)
        DATA_PORT |= 0b00100000;
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;              // Function set cmd(4-bit interface)
        DATA_PORT |= 0b00000010;
#endif
#endif
        E_PIN = 1;                      // Clock cmd in
        DelayFor18TCY();
        E_PIN = 0;

#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0xff;          // Make data port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;         // Make data nibble input
#else                                   // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;         // Make data nibble input
#endif
#endif

        // Set data interface width, # lines, font
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(lcdtype);          // Function set cmd

        // Turn the display on then off
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);        // Display OFF/Blink OFF
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON);           // Display ON/Blink ON

        // Clear display
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(0x01);             // Clear display

        // Set entry mode inc, no shift
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(SHIFT_CUR_LEFT);   // Entry Mode

        // Set DD Ram address to 0
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(0x0);                // Set Display data ram address to 0

        return;
}


/********************************************************************
*       Function Name:  WriteDataXLCD                               *
*       Return Value:   void                                        *
*       Parameters:     data: data byte to be written to LCD        *
*       Description:    This routine writes a data byte to the      *
*                       Hitachi HD44780 LCD controller. The user    *
*                       must check to see if the LCD controller is  *
*                       busy before calling this routine. The data  *
*                       is written to the character generator RAM or*
*                       the display data RAM depending on what the  *
*                       previous SetxxRamAddr routine was called.   *
********************************************************************/
void WriteDataXLCD(char data)
{
#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0;             // Make port output
        DATA_PORT = data;               // Write data to port
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock data into LCD
        DelayFor18TCY();
        E_PIN = 0;
        RS_PIN = 0;                     // Reset control bits
        TRIS_DATA_PORT = 0xff;          // Make port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= data&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= ((data>>4)&0x0f);
#endif
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= ((data<<4)&0xf0);
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= (data&0x0f);
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        return;
}



/********************************************************************
*       Function Name:  WriteCmdXLCD                                *
*       Return Value:   void                                        *
*       Parameters:     cmd: command to send to LCD                 *
*       Description:    This routine writes a command to the Hitachi*
*                       HD44780 LCD controller. The user must check *
*                       to see if the LCD controller is busy before *
*                       calling this routine.                       *
********************************************************************/
void WriteCmdXLCD(unsigned char cmd)
{
#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0;             // Data port output
        DATA_PORT = cmd;                // Write command to data port
        RW_PIN = 0;                     // Set the control signals
        RS_PIN = 0;                     // for sending a command
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the command in
        DelayFor18TCY();
        E_PIN = 0;
        DelayFor18TCY();
        TRIS_DATA_PORT = 0xff;          // Data port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= cmd&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= (cmd>>4)&0x0f;
#endif
        RW_PIN = 0;                     // Set control signals for command
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= (cmd<<4)&0xf0;
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= cmd&0x0f;
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Make data nibble input
        TRIS_DATA_PORT |= 0xf0;
#else
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        return;
}




/********************************************************************
*       Function Name:  ReadDataXLCD                                *
*       Return Value:   char: data byte from LCD controller         *
*       Parameters:     void                                        *
*       Description:    This routine reads a data byte from the     *
*                       Hitachi HD44780 LCD controller. The user    *
*                       must check to see if the LCD controller is  *
*                       busy before calling this routine. The data  *
*                       is read from the character generator RAM or *
*                       the display data RAM depending on what the  *
*                       previous SetxxRamAddr routine was called.   *
********************************************************************/
char ReadDataXLCD(void)
{
        char data;

#ifdef BIT8                             // 8-bit interface
        RS_PIN = 1;                     // Set the control bits
        RW_PIN = 1;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the data out of the LCD
        DelayFor18TCY();
        data = DATA_PORT;               // Read the data
        E_PIN = 0;
        RS_PIN = 0;                     // Reset the control bits
        RW_PIN = 0;
#else                                   // 4-bit interface
        RW_PIN = 1;
        RS_PIN = 1;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the data out of the LCD
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data = DATA_PORT&0xf0;          // Read the upper nibble of data
#else                                   // Lower nibble interface
        data = (DATA_PORT<<4)&0xf0;     // read the upper nibble of data
#endif
        E_PIN = 0;                      // Reset the clock line
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the next nibble out of the LCD
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data |= (DATA_PORT>>4)&0x0f;    // Read the lower nibble of data
#else                                   // Lower nibble interface
        data |= DATA_PORT&0x0f;         // Read the lower nibble of data
#endif
        E_PIN = 0;                                      
        RS_PIN = 0;                     // Reset the control bits
        RW_PIN = 0;
#endif
        return(data);                   // Return the data byte
}


void DelayFor18TCY( void )
{
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
}

void DelayPORXLCD (void)
{
  DelayMs(15); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 16MHz) / 4
                   // Cycles = 60,000
  return;
}

void DelayXLCD (void)
{
 DelayMs(5); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 16MHz) / 4
                   // Cycles = 20,000
  return;
}


unsigned char lcd_line;

void lcd_gotoxy( unsigned char x, unsigned char y ) {
unsigned char address;
lcd_line=y;
switch(y) {
case 1 : address=0x80; break;
case 2 : address=0xC0; break;
case 3 : address=0x94; break;
case 4 : address=0xD4; break;
}
address+=x-1;

while( BusyXLCD() );
WriteCmdXLCD(0x80 | address);

}

#define LCD_DEGREE_CHAR 0x00
#define LCD_CLR_DISP 0x01



void lcd_puts(const char *c ) 
{
	while(*c)
	{
		switch(*c) 
		{
			case '\f' :  
			while(BusyXLCD());
			WriteCmdXLCD(LCD_CLR_DISP);
			lcd_line=1;
			break;
			
			case '\n' : 
			lcd_gotoxy(1,++lcd_line); 
			break;
			
			case '\1' : 
			while(BusyXLCD());
			WriteDataXLCD(LCD_DEGREE_CHAR); 
			break;
			
			default : 
			while(BusyXLCD());
			WriteDataXLCD(*c);
			break;
		}
		*c++;
	}
	
}


#define LCD_CGRAM_BASE_ADDR 0x40 // Set the CGRAM address

unsigned char const LCD_CUSTOM_CHARS[] = {
0x1C,0x14,0x1C,0x00,0x00,0x00,0x00,0x00, // DegC
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F }; // Not used

void lcd_init_custom_chars()
{
	unsigned char i;
	while(BusyXLCD());
	WriteCmdXLCD(LCD_CGRAM_BASE_ADDR);
	for (i=0;i<64;i++) 
	{
		while(BusyXLCD());
		WriteDataXLCD(LCD_CUSTOM_CHARS[i]);
	}
}

void LcdInit(void)
{
	// configure external LCD
  	OpenXLCD( FOUR_BIT & LINES_5X7 );
	while( BusyXLCD() );
	WriteCmdXLCD(CURSOR_OFF&BLINK_OFF);
	return;
}
"Eppur si muove!"

kenan_re

Bu kullanımda LCD data portlarını değiştirirken nasıl yapıldığını gösterebilir misinz?

M_B

Alıntı yapılan: kenan_re - 13 Haziran 2013, 22:13:49
Bu kullanımda LCD data portlarını değiştirirken nasıl yapıldığını gösterebilir misinz?

xlcd.h dosyasında değişiklik yaparak.
Değişiklik yapılacak kısım altta

/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT      PORTB
#define TRIS_DATA_PORT TRISB

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
#define RW_PIN   RB6   /* PORT for RW */
//#define TRIS_RW  DDRBbits.RB6    /* TRIS for RW */
#define TRIS_RW  TRISB6    /* TRIS for RW */
#define RS_PIN   RB5   /* PORT for RS */
//#define TRIS_RS  DDRBbits.RB5    /* TRIS for RS */
#define TRIS_RS  TRISB5    /* TRIS for RS */
#define E_PIN    RB4   /* PORT for E  */
//#define TRIS_E   DDRBbits.RB4    /* TRIS for E  */
#define TRIS_E   TRISB4    /* TRIS for E  */

İmkanın sınırlarını görmek için imkansızı denemek lazım.                                                             Fatih Sultan Mehmet

kenan_re

onları yaptım ama sorun data pinlerinde RB4-D4.....RB7-D7 ama pinler tam tersi RB7-D4.....RB4-D7 şeklinde birde zamanlama sorunu olduğunu düşünüyrum. PLL ile 48 mhz hızındayım gecikme rutinlerinde  void

DelayPORXLCD (void) {Delay100TCYx(187); // Delay of 15ms }
DelayXLCD (void){Delay100TCYx(62); // Delay of 5ms }

Sizce bu zamanlamalar doğru mu ?

kenan_re


Mr.Java

Sorun net anlaşılmıyor.Açık ve net birşekilde yazın ki bizde anlayıp cevaplayalım..Ben şu şekilde anladım yukarıda lcd için data pin tanımlamasını nasıl yapacağım demişsiniz.
#define	rs RC0
#define	rw RC1
#define e  RC2
#define lcd_port  PORTD


şeklinde istediğiniz porta yönlendirebilirsiniz.Delay fonksyonunda ise;
//DELAY.H
#ifndef	XTAL_FREQ
#define	XTAL_FREQ	20MHZ		/* Crystal frekansı buraya girilecek */
#endif

#define	MHZ	*1000L			
#define	KHZ	*1			

#if	XTAL_FREQ >= 12MHZ

#define	DelayUs(x)	{ unsigned char _dcnt; \
			  _dcnt = (x)*((XTAL_FREQ)/(12MHZ)); \
			  while(--_dcnt != 0) \
				  continue; }
#else

#define	DelayUs(x)	{ unsigned char _dcnt; \
			  _dcnt = (x)/((12MHZ)/(XTAL_FREQ))|1; \
			  while(--_dcnt != 0) \
				  continue; }
#endif

extern void DelayMs(unsigned char);

//DELAY.c
#include	"delay.h"

void
DelayMs(unsigned char cnt)
{
#if	XTAL_FREQ <= 2MHZ
	do {
		DelayUs(996);
	} while(--cnt);
#endif

#if    XTAL_FREQ > 2MHZ	
	unsigned char	i;
	do {
		i = 4;
		do {
			DelayUs(250);
		} while(--i);
	} while(--cnt);
#endif
}

kullanabilirsiniz.


kenan_re

Hi-tec C18 içindeki xlcd.h kütüphanesi ile 2X16 LCD sürmek istiyorum.
xlcd.h içindeki tanımlamaları kendi şemama göre tanımladım. Aşağıda belirttiğim gibi...
Yalnız bu kütüphanede LCD data pinlerinin dizilimi nasıl. İçinde UPPER seçeneği var fakat nasıl bi sırayla var(RB4 - D4 şeklinde bir sırayla mı gidiyor yoksa RB4-D7 ile mi?) Bu sıralamayı istediğim gibi nasıl sıralarım ?

İlginiz için teşekkür ederim  :-[

#define UPPER

/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT      		PORTB
 #define TRIS_DATA_PORT 		TRISB

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   LATBbits.LATB1   		/* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISB1    	/* TRIS for RW */

 #define RS_PIN   LATBbits.LATB2   		/* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISB2    	/* TRIS for RS */

 #define E_PIN    LATBbits.LATB3  		/* PORT for D  */
 #define TRIS_E   TRISBbits.TRISB3    	/* TRIS for E  */

Mr.Java

Aslında C temeliniz var ise kendi kütüphanenizi yazabilirsiniz.Gelin beraber yazalım..

Aşağıdaki kodları MPLAB X'te kopyalayıp yapıştırın ve main fonksyonu içerisinde kullanıp sonuçları paylaşın lütfen.İlgili port bacaklarını define ile tanımladık istediğiniz gibi değiştirebilirsiniz.LCD 4,5,6,7 bacakları portb'nin 4,5,6,7 bacaklarına gelecek.RS,RW ve E ise RB0 RB1 ve RB2 olacak..

/* 
 * File:   LCD Kütüphanemiz.c
 * Author: Fatih ASLAN
 *
 * Created on 14 Haziran 2013 Cuma, 16:14
 */

#include <stdio.h>
#include <stdlib.h>
#include "delay.h"
#include <xc.h>

#define	rs RB0				//Pin tanımlamaları
#define	rw RB1
#define     e  RB2
#define lcd_port  PORTB
#define uchar unsigned char

void lcd_beklet(void)
{
    DelayUs(500);
}

void Lcd_komut(uchar komut)
{
    rw = 0; // LCD'ye yazma yapılacak
    rs = 0; // LCD'ye komut gönderilecek
    e = 1;
    lcd_port = (komut & 0xF0); // İlk önce yüksek değerlikli bitler gönderiliyor
    e = 0;
    lcd_beklet();
    e = 1; //
    lcd_port = ((komut & 0x0F) << 4); // Düşük değerlikli bitler gönderiliyor
    e = 0;
    lcd_beklet(); // Belirli bir süre bekleniyor
}

void lcd_putch(unsigned char _data)
{
    rw = 0;
    rs = 1;
    e = 1;
    lcd_port = (_data & 0xF0);
    e = 0;
    lcd_beklet();
    e = 1;
    lcd_port = ((_data & 0x0F) << 4);
    e = 0;
    lcd_beklet();
}

void lcd_clear(uchar i)
{

    Lcd_komut(0x01);
    for (i = 0; i < 4; i++)
    {
        lcd_beklet();
        if (i == 3)break;
    }
}

void lcd_yaz(const char * s)	// LCD'ye string ifade gönderiliyor
{
	lcd_beklet();
	while(*s)
		lcd_putch(*s++);
}
void lcd_state(unsigned char x,unsigned char y)	// LCD'nin konumu
{
	if(x==1)
		lcd_putch(0x80+((y-1)%16));
	else
		lcd_putch(0xC0+((y-1)%16));
}
void lcd_init()		// LCD ilk yükleme ayarları yapılıyor
{
	rs = 0;
	e = 0;
	rw = 0;

	DelayMs(15);
	e=1;
	Lcd_komut(0x02);
	DelayMs(2);

	Lcd_komut(0x40);
	Lcd_komut(0x06);
	Lcd_komut(0x12);
	lcd_beklet();
	Lcd_komut(0x128);
}

void main(void)
{
    lcd_init();
}

kenan_re

16f için yazdığım vardı 18f serisine yeni geçtim bu nedenle öncelikle kendi kütüphanesiyle bi başlayım sonra ilerlerim diye düşündüm ama olmadı :)

İşlemci OSC ayarlarını zor yaptım (-ki hala işlemci hızından emin değilim, PLL ile 48 MHZ olduğunu düşünüyorum.) Sizden ricam öncelikle OSC den emin olup daha sonra bu adıma geçebilir miyiz?

Mr.Java

İşlemci nedir ? Neden PLL kullanıyorsunuz ? Yapacağınız uygulama nedir ?

kenan_re

18f4550 triyak sürme, Rs-232, Adc, ve LCD uygulamasının olduğu bir yapı kurmaya çalışacağım. Bu esnada 18F serisini öğrenmek istiyorum. PLL yapısını meraktan kurcaladım :) 48Mhz fena olmaz hani !

Siğortaları şu şekilde ayarladım.
   // CONFIG1H
      #pragma config FOSC = HSPLL_HS  //INTOSCIO_HS Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL))

      #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 BOR = 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)

      #pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)


   // CONFIG2H
      #pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))

      #pragma config WDTPS = 128    // Watchdog Timer Postscale Select bits (1:32768)


   // CONFIG3H
      #pragma config CCP2MX = ON      // 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 = ON    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)

      #pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)


// CONFIG1L
      #pragma config PLLDIV = 5       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))

      #pragma config CPUDIV = 1       // System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])

      #pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)


   // CONFIG4L
      #pragma config STVREN = OFF      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)

      #pragma config LVP = OFF         //RB5     Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)

      #pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)

      #pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

Mr.Java

Şimdi orada dur !
- Yüksek hızlarda seri iletişimde hatalar olabilmesi muhtemel.Başıma geldi daha önce.O işlemci 20Mhzde SPBGR=129'da 0.16lık bir hata ihtimali var.Baudrate ve işlemci hızında bu oran artar.
- ADC fonksyonu kolaydır.Halledemezseniz beraber yaparız.
- LCD kütüphanesini denediniz mi ?Yazmak biraz zamanımı aldı merak ettim çünkü :P
- Neden Triyak ? Proje tam nedir net açıklayın ki tam yardımcı olalım.

kenan_re

Akım sabitleyici bi cihaz yapmaya çalışıyorum. Şimdi çayımı aldım EasyPic3 kart ile deneyeceğim. :)