Stm32F Discovery AxA LCD Lib Hk.

Başlatan burak54, 23 Eylül 2015, 15:54:44

burak54

Merhaba Arkadaşlar,
Arm işlemcilerde daha çok yeniyim.Stm32f4-discovery.com indirdigim HD44780 LCD kütüphanesi ile LCD yi çalıştırabildim ancak TM_GPIO diye kütüphane eklemişler kendi içine ben normal STD PERIPH te ki GPIO lib e cevirdim ne kadar dogru cevirdim bilmiyorum ama çalışıyor şu anda =) Sizin de incelemeniz ve takıldığım bir kaç soruyu sormak için kodları ekliyorum.


main.c Kodları Diğer LCD libten IO ayarlarını buraya taşıdım
/**
 *    Keil project example for HD44780 LCD driver
 *
 *    @author     Tilen Majerle
 *    @email        tilen@majerle.eu
 *    @website    http://stm32f4-discovery.com
 *    @ide        Keil uVision 5
 */
 #include "defines.h"

#include "stm32f4xx_gpio.h"
#include "tm_stm32f4_delay.h"
#include "tm_stm32f4_hd44780.h"

GPIO_InitTypeDef  GPIO_InitStructure;


int main(void) {
    //Rectangle for custom character
    //xxx means doesn't care, lower 5 bits are important for LCD
    
	
	uint8_t customChar[] = {
        0x1F,    // xxx 11111
        0x11,    // xxx 10001
        0x11,    // xxx 10001
        0x11,    // xxx 10001
        0x11,    // xxx 10001
        0x11,    // xxx 10001
        0x11,    // xxx 10001
        0x1F    // xxx 11111
		
		};
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // 

  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = HD44780_RS_PIN | HD44780_E_PIN| HD44780_D6_PIN| HD44780_D7_PIN ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);


RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); // 

  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = HD44780_D4_PIN | HD44780_D5_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
	
		  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); // PORT D ICIN CLOCK AKTIF HALE GELIYOR

  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);



	 GPIO_ResetBits(GPIOB, HD44780_RS_PIN | HD44780_E_PIN| HD44780_D6_PIN| HD44780_D7_PIN);
	
		 GPIO_ResetBits(GPIOC, HD44780_D4_PIN | HD44780_D5_PIN);
	

    //Initialize system
    SystemInit();
	
    
    //Initialize LCD 20 cols x 4 rows
    TM_HD44780_Init(16, 2);
    
    //Save custom character on location 0 in LCD
    TM_HD44780_CreateChar(0, &customChar[0]);
    
    //Put string to LCD
    TM_HD44780_Puts(0, 0, "STM32 BURAK");
    TM_HD44780_Puts(2, 1, "PICPROJE");
   
 
    //Wait a little
    Delayms(3000);
    
    //Clear LCD
    TM_HD44780_Clear();
    Delayms(3000);
    //Show cursor
    TM_HD44780_CursorOn();
    Delayms(3000);
    //Write new text
    TM_HD44780_Puts(6, 2, "CLEARED!");
    Delayms(3000);
    //Wait a little
    Delayms(1000);
    Delayms(3000);
    //Enable cursor blinking
    TM_HD44780_BlinkOn();
    Delayms(3000);
    //Show custom character at x = 1, y = 2 from RAM location 0
    TM_HD44780_PutCustom(1, 2, 0);

    while (1) {
			

	
  
		}
}



Değiştirdiğim tm_stm32f4_hd44780.c kodları
/**	
 * |----------------------------------------------------------------------
 * | Copyright (C) Tilen Majerle, 2014
 * | 
 * | This program is free software: you can redistribute it and/or modify
 * | it under the terms of the GNU General Public License as published by
 * | the Free Software Foundation, either version 3 of the License, or
 * | any later version.
 * |  
 * | This program is distributed in the hope that it will be useful,
 * | but WITHOUT ANY WARRANTY; without even the implied warranty of
 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * | GNU General Public License for more details.
 * | 
 * | You should have received a copy of the GNU General Public License
 * | along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * |----------------------------------------------------------------------
 */
#include "stm32f4xx_gpio.h"
#include "tm_stm32f4_hd44780.h"

/* Private HD44780 structure */
typedef struct {
	uint8_t DisplayControl;
	uint8_t DisplayFunction;
	uint8_t DisplayMode;
	uint8_t Rows;
	uint8_t Cols;
	uint8_t currentX;
	uint8_t currentY;
} HD44780_Options_t;

/* Private functions */
static void TM_HD44780_InitPins(void);
static void TM_HD44780_Cmd(uint8_t cmd);
static void TM_HD44780_Cmd4bit(uint8_t cmd);
static void TM_HD44780_Data(uint8_t data);
static void TM_HD44780_CursorSet(uint8_t col, uint8_t row);

/* Private variable */
static HD44780_Options_t HD44780_Opts;

/* Pin definitions */

#define HD44780_RS_LOW              GPIO_ResetBits(HD44780_RS_PORT, HD44780_RS_PIN)
#define HD44780_RS_HIGH             GPIO_SetBits(HD44780_RS_PORT, HD44780_RS_PIN)
#define HD44780_E_LOW               GPIO_ResetBits(HD44780_E_PORT, HD44780_E_PIN)
#define HD44780_E_HIGH              GPIO_SetBits(HD44780_E_PORT, HD44780_E_PIN)




//#define HD44780_RS_LOW              TM_GPIO_SetPinLow(HD44780_RS_PORT, HD44780_RS_PIN)
//#define HD44780_RS_HIGH             TM_GPIO_SetPinHigh(HD44780_RS_PORT, HD44780_RS_PIN)
//#define HD44780_E_LOW               TM_GPIO_SetPinLow(HD44780_E_PORT, HD44780_E_PIN)
//#define HD44780_E_HIGH              TM_GPIO_SetPinHigh(HD44780_E_PORT, HD44780_E_PIN)

#define HD44780_E_BLINK             HD44780_E_HIGH; HD44780_Delay(20); HD44780_E_LOW; HD44780_Delay(20)
#define HD44780_Delay(x)            Delay(x)

/* Commands*/
#define HD44780_CLEARDISPLAY        0x01
#define HD44780_RETURNHOME          0x02
#define HD44780_ENTRYMODESET        0x04
#define HD44780_DISPLAYCONTROL      0x08
#define HD44780_CURSORSHIFT         0x10
#define HD44780_FUNCTIONSET         0x20
#define HD44780_SETCGRAMADDR        0x40
#define HD44780_SETDDRAMADDR        0x80

/* Flags for display entry mode */
#define HD44780_ENTRYRIGHT          0x00
#define HD44780_ENTRYLEFT           0x02
#define HD44780_ENTRYSHIFTINCREMENT 0x01
#define HD44780_ENTRYSHIFTDECREMENT 0x00

/* Flags for display on/off control */
#define HD44780_DISPLAYON           0x04
#define HD44780_CURSORON            0x02
#define HD44780_BLINKON             0x01

/* Flags for display/cursor shift */
#define HD44780_DISPLAYMOVE         0x08
#define HD44780_CURSORMOVE          0x00
#define HD44780_MOVERIGHT           0x04
#define HD44780_MOVELEFT            0x00

/* Flags for function set */
#define HD44780_8BITMODE            0x10
#define HD44780_4BITMODE            0x00
#define HD44780_2LINE               0x08
#define HD44780_1LINE               0x00
#define HD44780_5x10DOTS            0x04
#define HD44780_5x8DOTS             0x00

void TM_HD44780_Init(uint8_t cols, uint8_t rows) {
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Init pinout */
	//TM_HD44780_InitPins();
	
	/* At least 40ms */
	HD44780_Delay(45000);
	
	/* Set LCD width and height */
	HD44780_Opts.Rows = rows;
	HD44780_Opts.Cols = cols;
	
	/* Set cursor pointer to beginning for LCD */
	HD44780_Opts.currentX = 0;
	HD44780_Opts.currentY = 0;
	
	HD44780_Opts.DisplayFunction = HD44780_4BITMODE | HD44780_5x8DOTS | HD44780_1LINE;
	if (rows > 1) {
		HD44780_Opts.DisplayFunction |= HD44780_2LINE;
	}
	
	/* Try to set 4bit mode */
	TM_HD44780_Cmd4bit(0x03);
	HD44780_Delay(4500);
	
	/* Second try */
	TM_HD44780_Cmd4bit(0x03);
	HD44780_Delay(4500);
	
	/* Third goo! */
	TM_HD44780_Cmd4bit(0x03);
	HD44780_Delay(4500);	
	
	/* Set 4-bit interface */
	TM_HD44780_Cmd4bit(0x02);
	HD44780_Delay(100);
	
	/* Set # lines, font size, etc. */
	TM_HD44780_Cmd(HD44780_FUNCTIONSET | HD44780_Opts.DisplayFunction);

	/* Turn the display on with no cursor or blinking default */
	HD44780_Opts.DisplayControl = HD44780_DISPLAYON;
	TM_HD44780_DisplayOn();

	/* Clear lcd */
	TM_HD44780_Clear();

	/* Default font directions */
	HD44780_Opts.DisplayMode = HD44780_ENTRYLEFT | HD44780_ENTRYSHIFTDECREMENT;
	TM_HD44780_Cmd(HD44780_ENTRYMODESET | HD44780_Opts.DisplayMode);

	/* Delay */
	HD44780_Delay(4500);
}

void TM_HD44780_Clear(void) {
	TM_HD44780_Cmd(HD44780_CLEARDISPLAY);
	HD44780_Delay(3000);
}

void TM_HD44780_Puts(uint8_t x, uint8_t y, char* str) {
	TM_HD44780_CursorSet(x, y);
	while (*str) {
		if (HD44780_Opts.currentX >= HD44780_Opts.Cols) {
			HD44780_Opts.currentX = 0;
			HD44780_Opts.currentY++;
			TM_HD44780_CursorSet(HD44780_Opts.currentX, HD44780_Opts.currentY);
		}
		if (*str == '\n') {
			HD44780_Opts.currentY++;
			TM_HD44780_CursorSet(HD44780_Opts.currentX, HD44780_Opts.currentY);
		} else if (*str == '\r') {
			TM_HD44780_CursorSet(0, HD44780_Opts.currentY);
		} else {
			TM_HD44780_Data(*str);
			HD44780_Opts.currentX++;
		}
		str++;
	}
}

void TM_HD44780_DisplayOn(void) {
	HD44780_Opts.DisplayControl |= HD44780_DISPLAYON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_DisplayOff(void) {
	HD44780_Opts.DisplayControl &= ~HD44780_DISPLAYON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_BlinkOn(void) {
	HD44780_Opts.DisplayControl |= HD44780_BLINKON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_BlinkOff(void) {
	HD44780_Opts.DisplayControl &= ~HD44780_BLINKON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_CursorOn(void) {
	HD44780_Opts.DisplayControl |= HD44780_CURSORON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_CursorOff(void) {
	HD44780_Opts.DisplayControl &= ~HD44780_CURSORON;
	TM_HD44780_Cmd(HD44780_DISPLAYCONTROL | HD44780_Opts.DisplayControl);
}

void TM_HD44780_ScrollLeft(void) {
	TM_HD44780_Cmd(HD44780_CURSORSHIFT | HD44780_DISPLAYMOVE | HD44780_MOVELEFT);
}

void TM_HD44780_ScrollRight(void) {
	TM_HD44780_Cmd(HD44780_CURSORSHIFT | HD44780_DISPLAYMOVE | HD44780_MOVERIGHT);
}

void TM_HD44780_CreateChar(uint8_t location, uint8_t *data) {
	uint8_t i;
	/* We have 8 locations available for custom characters */
	location &= 0x07;
	TM_HD44780_Cmd(HD44780_SETCGRAMADDR | (location << 3));
	
	for (i = 0; i < 8; i++) {
		TM_HD44780_Data(data[i]);
	}
}

void TM_HD44780_PutCustom(uint8_t x, uint8_t y, uint8_t location) {
	TM_HD44780_CursorSet(x, y);
	TM_HD44780_Data(location);
}

/* Private functions */
static void TM_HD44780_Cmd(uint8_t cmd) {
	/* Command mode */
	HD44780_RS_LOW;
	
	/* High nibble */
	TM_HD44780_Cmd4bit(cmd >> 4);
	/* Low nibble */
	TM_HD44780_Cmd4bit(cmd & 0x0F);
}

static void TM_HD44780_Data(uint8_t data) {
	/* Data mode */
	HD44780_RS_HIGH;
	
	/* High nibble */
	TM_HD44780_Cmd4bit(data >> 4);
	/* Low nibble */
	TM_HD44780_Cmd4bit(data & 0x0F);
}

static void TM_HD44780_Cmd4bit(uint8_t cmd) {
	/* Set output port */


	GPIO_WriteBit(HD44780_D7_PORT, HD44780_D7_PIN, (cmd & 0x08));
	GPIO_WriteBit(HD44780_D6_PORT, HD44780_D6_PIN, (cmd & 0x04));
GPIO_WriteBit(HD44780_D5_PORT, HD44780_D5_PIN, (cmd & 0x02));
	GPIO_WriteBit(HD44780_D4_PORT, HD44780_D4_PIN, (cmd & 0x01));

	
	
	//TM_GPIO_SetPinValue(HD44780_D7_PORT, HD44780_D7_PIN, (cmd & 0x08));
	//TM_GPIO_SetPinValue(HD44780_D6_PORT, HD44780_D6_PIN, (cmd & 0x04));
//	TM_GPIO_SetPinValue(HD44780_D5_PORT, HD44780_D5_PIN, (cmd & 0x02));
	//TM_GPIO_SetPinValue(HD44780_D4_PORT, HD44780_D4_PIN, (cmd & 0x01));
	HD44780_E_BLINK;
}

static void TM_HD44780_CursorSet(uint8_t col, uint8_t row) {
	uint8_t row_offsets[] = {0x00, 0x40, 0x14, 0x54};
	
	/* Go to beginning */
	if (row >= HD44780_Opts.Rows) {
		row = 0;
	}
	
	/* Set current column and row */
	HD44780_Opts.currentX = col;
	HD44780_Opts.currentY = row;
	
	/* Set location address */
	TM_HD44780_Cmd(HD44780_SETDDRAMADDR | (col + row_offsets[row]));
}

//GPIO_InitTypeDef  GPIO_InitStructure;

//static void TM_HD44780_InitPins(void) {
	/* Init all pins */
	

	
	
//	TM_GPIO_Init(HD44780_RS_PORT, HD44780_RS_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	//TM_GPIO_Init(HD44780_E_PORT, HD44780_E_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
//	TM_GPIO_Init(HD44780_D4_PORT, HD44780_D4_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	//TM_GPIO_Init(HD44780_D5_PORT, HD44780_D5_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	//TM_GPIO_Init(HD44780_D6_PORT, HD44780_D6_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	//TM_GPIO_Init(HD44780_D7_PORT, HD44780_D7_PIN, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Low);
	
	/* Set pins low */
	//TM_GPIO_SetPinLow(HD44780_RS_PORT, HD44780_RS_PIN);
	//TM_GPIO_SetPinLow(HD44780_E_PORT, HD44780_E_PIN);
	//TM_GPIO_SetPinLow(HD44780_D4_PORT, HD44780_D4_PIN);
	//TM_GPIO_SetPinLow(HD44780_D5_PORT, HD44780_D5_PIN);
	//TM_GPIO_SetPinLow(HD44780_D6_PORT, HD44780_D6_PIN);
	//TM_GPIO_SetPinLow(HD44780_D7_PORT, HD44780_D7_PIN); 
//}


Dediğim gibi bunu STD_GPIO ile değiştirdim çalıştı.Sadece GPIO_WriteBit(HD44780_D7_PORT, HD44780_D7_PIN, (cmd & 0x08)); de ki bit setleri için warning veriyor "enumerated type mixed with another type" şeklinde.

Asıl sorum bu kütüphanede direk Char yazmaya izin verilmiş anladıgım kadarı ile herhangi bir Float ya da Int değeri nasıl aktarabiliriz LCD ye.
Araştırmalarım sonucu Sprintf 'i gördüm ama tam anlayamadım. Bu konuda yardımcı olabilirseniz sevinirim.Teşekkürler.

eeburakdemir

bu Tm denilen kişiyi sürekli takip ediyorum bende, bu vatandaş ondalıklı değerleri  sprintf foksiyonu ile diziye aktarıp ekrana direk olarak diziyi bastırıp gösteriyor. Linkini veriyorum vatandaşın oradan diğer örneklere bakılıp görülebilir.
http://stm32f4-discovery.com/2014/05/all-stm32f429-libraries-at-one-place/
Asla pes etme...

Gökhan BEKEN

Özel mesaj okumuyorum, lütfen göndermeyin.

burak54

Merhaba,
  sprintf(adc_data,"ADC=%4d",ADC1ConvertedVoltage);
TM_HD44780_Clear(); 
TM_HD44780_Puts(0, 0,adc_data);
Delayms(1000);
ADC1ConvertedVoltage++;


Bu şekilde yazdırdım ben de ekrana değeri,
Değişkenler,
__IO uint32_t ADC1ConvertedVoltage = 0;
char adc_data[16];
son olarak sprinft fonsiyonunu kullanabilmek için #include <stdio.h>  eklemek gerek.

Teşekkürler arkadaşlar iyi çalışmalar.