Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //******************************************************************************
- // THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY.
- // AUTHOR SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
- // OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- // FROM USE OF THIS SOFTWARE.
- //
- // PROGRAM ZAWARTY W TYM PLIKU PRZEZNACZONY JEST WYLACZNIE
- // DO CELOW SZKOLENIOWYCH. AUTOR NIE PONOSI ODPOWIEDZIALNOSCI
- // ZA ZADNE EWENTUALNE, BEZPOSREDNIE I POSREDNIE SZKODY
- // WYNIKLE Z JEGO WYKORZYSTANIA.
- //******************************************************************************
- #include "lcd.h"
- #include "stm32f10x_gpio.h"
- GPIO_InitTypeDef GPIO_InitStructure;
- void wait(int us);
- // wyslij pólbajt na linie danych wyswietlacza
- void LCD_WriteNibble(unsigned char nibble)
- {
- volatile unsigned int delayCnt = 0;
- GPIO_WriteBit(LCD_GPIO, LCD_D4, (nibble & 0x01)); // ustaw bity na liniach
- GPIO_WriteBit(LCD_GPIO, LCD_D5, (nibble & 0x02)); // D4 – D7
- GPIO_WriteBit(LCD_GPIO, LCD_D6, (nibble & 0x04));
- GPIO_WriteBit(LCD_GPIO, LCD_D7, (nibble & 0x08));
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_SET); // ustaw wysoki poziom E
- for(delayCnt = 0; delayCnt < 16; delayCnt++); // poczekaj troche…
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_RESET); // ustaw niski poziom E
- }
- // wyslij komende do wyswietlacza
- void LCD_WriteCommand(unsigned char commandToWrite)
- {
- volatile unsigned int delayCnt = 0;
- GPIO_WriteBit(LCD_GPIO, LCD_RS, Bit_RESET); // RS = 0 - komenda
- LCD_WriteNibble(commandToWrite >> 4); // wyslij starszy pólbajt
- LCD_WriteNibble(commandToWrite & 0x0F); // wyslij mlodszy pólbajt
- if (commandToWrite > 3) // w zaleznosci od komendy dobierz opóznienie
- for(delayCnt = 0; delayCnt < 3000; delayCnt++);
- else
- for(delayCnt = 0; delayCnt < 150000; delayCnt++);
- }
- // wyslij znak do wyswietlenia
- void LCD_WriteData(unsigned char dataToWrite)
- {
- // uzupelnij samodzielnie
- GPIO_WriteBit(LCD_GPIO, LCD_RS, 1);
- GPIO_WriteBit(LCD_GPIO, LCD_D4, dataToWrite & 0x10);
- GPIO_WriteBit(LCD_GPIO, LCD_D5, dataToWrite & 0x20);
- GPIO_WriteBit(LCD_GPIO, LCD_D6, dataToWrite & 0x40);
- GPIO_WriteBit(LCD_GPIO, LCD_D7, dataToWrite & 0x80);
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_SET); // ustaw wysoki poziom E
- wait(300);
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_RESET); // ustaw niski poziom E
- GPIO_WriteBit(LCD_GPIO, LCD_D4, dataToWrite & 0x01);
- GPIO_WriteBit(LCD_GPIO, LCD_D5, dataToWrite & 0x02);
- GPIO_WriteBit(LCD_GPIO, LCD_D6, dataToWrite & 0x04);
- GPIO_WriteBit(LCD_GPIO, LCD_D7, dataToWrite & 0x08);
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_SET); // ustaw wysoki poziom E
- wait(300);
- GPIO_WriteBit(LCD_GPIO, LCD_E, Bit_RESET); // ustaw niski poziom E
- GPIO_WriteBit(LCD_GPIO, LCD_RS, 0);
- wait(300);
- }
- // inicjalizacja wyswietlacza
- void LCD_Initialize(void)
- {
- GPIO_InitStructure.GPIO_Pin = LCD_D4|LCD_D5|LCD_D6|LCD_D7|LCD_RS|LCD_E;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(LCD_GPIO, &GPIO_InitStructure);
- // uzupelnij samodzielnie
- wait(150000);
- LCD_WriteNibble(0x03);
- wait(3000000);
- LCD_WriteNibble(0x03);
- wait(6000);
- LCD_WriteNibble(0x03);
- wait(6000);
- LCD_WriteNibble(0x02);
- wait(6000);
- LCD_WriteCommand(LCD_FUNCTION_SET | LCD_FONT8 | LCD_TWO_LINE);
- wait(6000);
- LCD_WriteCommand(LCD_DISPLAY_ONOFF | LCD_DISPLAY_OFF);
- wait(6000);
- LCD_WriteCommand(LCD_CLEAR);
- wait(600000);
- LCD_WriteCommand(LCD_ENTRY_MODE | LCD_EM_INCREMENT | LCD_EM_SHIFT_CURSOR);
- wait(6000);
- LCD_WriteCommand(LCD_DISPLAY_ONOFF | LCD_DISPLAY_ON);
- }
- void wait(int us) {
- unsigned int i = 0;
- for (; i< us; i++);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement