Лови. У меня там SPI аппаратный, все настройки по дефолту, Fsclk = 625 кГц. Код ассемблерный, для dsPIC - пришлось переписать для тебя на С, должОн работать // ST7036 based (DOGM162 etc.) character LCD display primitives
#define FCY 40000000UL // MCU instruction frequency, Hz
#include <xc.h> // Chip specific header file
#include <libpic30.h> // Delay macros defined here
// Character SPI LCD display control pins:
#define lcdrs LATBbits.LATB3 // R/S line
#define lcden LATBbits.LATB4 // EN line
#define lcdrw LATBbits.LATB5 // R/W line (not used, write only mode)
// Character SPI LCD display addresses for ST7036 display controller:
#define line_1 0x80 // Start of line 1
#define line_2 0x90 // Start of line 2
#define line_3 0xA0 // Start of line 3
// Character SPI LCD display contrast/booster amplifier setup values:
#define contrast 80 // LCD contrast value, 0..100%
#define follower 2 // Follower amplifier ratio, 0..7
// Character SPI LCD display control codes:
#define func_nib 0x22 // Function Set special case - force 4-bit interface
#define func_set 0x28 // Function Set - 4-bit interface, 2 lines
#define entry_set 0x06 // Entry Mode Set - address auto increment, no scroll
#define home_clr 0x01 // Return Home - display clear, cursor to home
#define cursor_off 0x0C // Display & Cursor Control - cursor off
#define cursor_on 0x0D // Display & Cursor Control - cursor on
#define highfont func_set+4 // Display & Cursor Control - double height font on
#define bias_set 0x1D // Bias Set: bias = 1/5, FX = 1
#define power_set 0x5C // Power/Icon/Contrast2MSB Set
#define contrast_set 0x70 // Contrast4LSB Set
#define follower_set 0x68 // Follower Control
#define hfont_line 0x18 // Double height font line position
// Character SPI LCD display initialization commands array:
const char init_ST7036[] = {
func_set+1, // Function Set: jump to ext. page 01
bias_set, // Bias Set: bias = 1/5, FX = 1
power_set+((contrast*63/100)>>4), // Power/Icon/Contrast Set: Icon off, booster on + contrast 2MSb
contrast_set+((contrast*63/100)&0x0F), // Contrast Set: contrast 4LSb
follower_set+follower, // Follower Control: follower on + set follower amplifier ratio
func_set+2, // Function Set: jump to ext. page 02
hfont_line, // Set double height font position to line 1
func_set, // Function Set: jump to ext. page 00
cursor_off, // Display ON/OFF: display on, cursor off
entry_set, // Entry Mode Set: incremental addressing, no display shift
home_clr, // Clear Display (takes 2 mS, thus must be the last command)
0 // Zero terminator (end of message)
};
//------------------------------------------------------------------------------
// Writes a byte to LCD
void putc_lcd (char lcd_data) {
SPI1BUF = lcd_data; // Write a byte to SPI1BUF
__delay_us(50); // Provide 50 uS delay instead of polling busy bit(s)
}
// Sets LCD cursor at desired position
void setcursor (char pos) {
lcden = 0; // Enable LCD data transfer
lcdrs = 0; // Set LCD command mode
putc_lcd (pos); // Set cursor position
lcdrs = 1; // Set LCD data mode
lcden = 1; // Disable LCD data transfer
}
// Writes a zero-terminated string to LCD
void puts_lcd (const char message[]) {
int i = 0;
lcden = 0; // Enable LCD data transfer
while (message[i]) { // Send message array to LCD until zero terminator is encountered
putc_lcd (message[i++]);
}
lcden = 1; // Disable LCD data transfer
}
void LCD_ST7036setup () {
__delay_ms(50); // Provide 50 mS delay after power on
lcdrs = 0; // Set LCD command mode
puts_lcd (init_ST7036); // Send the initialization array to LCD
lcdrs = 1; // Set LCD data mode
__delay_ms(2); // Provide 2 mS delay for HOME_CLR command to complete
}
//------------------------------------------------------------------------------
int main () {
// ports_setup(); // MCU specific, not included
// SPI_setup(); // MCU specific, not included - mode 0 as default, Fsclk = FCY/64
LCD_ST7036setup (); // Initialize LCD
setcursor (line_1 + 0); // Set cursor at the beginning of Line 1
puts_lcd ("Hello, Vova!"); // Print a message
while (1); // Stick here forever
}
-
- Большое человеческое спасибо! А если еще и заработает... :) - VL(28.06.2015 19:11, )