test01 发表于 2012-9-26 15:00:58

贡献一个开源的“基于硬件SPI的LCD5110库”

本帖最后由 test01 于 2012-11-24 00:37 编辑

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <pins_arduino.h>
#include <SPI.h>

const bool LCD5110_MODE_COMMAND = LOW;
const bool LCD5110_MODE_DATA = HIGH;
const uint_fast8_t LCD5110_TRANSMISSION_UNIT_LENGTH_BITS = 8;

const uint_fast8_t LCD5110_RAM_WIDTH_BITS = 8;
const uint_fast8_t LCD5110_RAM_MAX_X = 84, LCD5110_RAM_MAX_Y = 6;//RAM X is 0-83, Y is 0-5
const uint_fast8_t LCD5110_MAX_ROW = 6, LCD5110_MAX_COLUMN = 12;
const uint_fast8_t LCD5110_MAXIMUM_CHARACTERS = LCD5110_MAX_ROW * LCD5110_MAX_COLUMN;
const uint_fast8_t ASCII_TOTAL_NUMBER = 128;
const uint_fast8_t ASCII_FONT_WIDTH = 7;
const unsigned char ASCII_BITMAP_FONT PROGMEM =//GCC 4.7.1 DEL PROGMEM
{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 00 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 01 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 02 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 03 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 04 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 05 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 06 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 07 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 08 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 09 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0a blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0b blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0c blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0d blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0e blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 0f blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 10 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 11 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 12 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 13 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 14 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 15 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 16 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 17 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 18 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 19 blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1a blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1b blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1c blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1d blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1e blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 1f blank
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00} // 21 !
,{0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00} // 22 "
,{0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14, 0x00} // 23 #
,{0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12, 0x00} // 24 $
,{0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00} // 25 %
,{0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00} // 26 &
,{0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00} // 27 '
,{0x00, 0x00, 0x1c, 0x22, 0x41, 0x00, 0x00} // 28 (
,{0x00, 0x00, 0x41, 0x22, 0x1c, 0x00, 0x00} // 29 )
,{0x00, 0x14, 0x08, 0x3e, 0x08, 0x14, 0x00} // 2a *
,{0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00} // 2b +
,{0x00, 0x00, 0x50, 0x30, 0x00, 0x00, 0x00} // 2c ,
,{0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00} // 2d -
,{0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00} // 2e .
,{0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00} // 2f /
,{0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00} // 30 0
,{0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00} // 31 1
,{0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00} // 32 2
,{0x00, 0x21, 0x41, 0x45, 0x4b, 0x31, 0x00} // 33 3
,{0x00, 0x18, 0x14, 0x12, 0x7f, 0x10, 0x00} // 34 4
,{0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00} // 35 5
,{0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30, 0x00} // 36 6
,{0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00} // 37 7
,{0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00} // 38 8
,{0x00, 0x06, 0x49, 0x49, 0x29, 0x1e, 0x00} // 39 9
,{0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00} // 3a :
,{0x00, 0x00, 0x56, 0x36, 0x00, 0x00, 0x00} // 3b ;
,{0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00} // 3c <
,{0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00} // 3d =
,{0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00} // 3e >
,{0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00} // 3f ?
,{0x00, 0x32, 0x49, 0x79, 0x41, 0x3e, 0x00} // 40 @
,{0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00} // 41 A
,{0x00, 0x7f, 0x49, 0x49, 0x49, 0x36, 0x00} // 42 B
,{0x00, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00} // 43 C
,{0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c, 0x00} // 44 D
,{0x00, 0x7f, 0x49, 0x49, 0x49, 0x41, 0x00} // 45 E
,{0x00, 0x7f, 0x09, 0x09, 0x09, 0x01, 0x00} // 46 F
,{0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a, 0x00} // 47 G
,{0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00} // 48 H
,{0x00, 0x00, 0x41, 0x7f, 0x41, 0x00, 0x00} // 49 I
,{0x00, 0x20, 0x40, 0x41, 0x3f, 0x01, 0x00} // 4a J
,{0x00, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x00} // 4b K
,{0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x00} // 4c L
,{0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x00} // 4d M
,{0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f, 0x00} // 4e N
,{0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00} // 4f O
,{0x00, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00} // 50 P
,{0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00} // 51 Q
,{0x00, 0x7f, 0x09, 0x19, 0x29, 0x46, 0x00} // 52 R
,{0x00, 0x46, 0x49, 0x49, 0x49, 0x31, 0x00} // 53 S
,{0x00, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x00} // 54 T
,{0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00} // 55 U
,{0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00} // 56 V
,{0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f, 0x00} // 57 W
,{0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00} // 58 X
,{0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00} // 59 Y
,{0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00} // 5a Z
,{0x00, 0x00, 0x7f, 0x41, 0x41, 0x00, 0x00} // 5b [
,{0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00} // 5c \
,{0x00, 0x00, 0x41, 0x41, 0x7f, 0x00, 0x00} // 5d ]
,{0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00} // 5e ^
,{0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00} // 5f _
,{0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00} // 60 `
,{0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00} // 61 a
,{0x00, 0x7f, 0x48, 0x44, 0x44, 0x38, 0x00} // 62 b
,{0x00, 0x38, 0x44, 0x44, 0x44, 0x20, 0x00} // 63 c
,{0x00, 0x38, 0x44, 0x44, 0x48, 0x7f, 0x00} // 64 d
,{0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00} // 65 e
,{0x00, 0x08, 0x7e, 0x09, 0x01, 0x02, 0x00} // 66 f
,{0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e, 0x00} // 67 g
,{0x00, 0x7f, 0x08, 0x04, 0x04, 0x78, 0x00} // 68 h
,{0x00, 0x00, 0x44, 0x7d, 0x40, 0x00, 0x00} // 69 i
,{0x00, 0x20, 0x40, 0x44, 0x3d, 0x00, 0x00} // 6a j
,{0x00, 0x7f, 0x10, 0x28, 0x44, 0x00, 0x00} // 6b k
,{0x00, 0x00, 0x41, 0x7f, 0x40, 0x00, 0x00} // 6c l
,{0x00, 0x7c, 0x04, 0x18, 0x04, 0x78, 0x00} // 6d m
,{0x00, 0x7c, 0x08, 0x04, 0x04, 0x78, 0x00} // 6e n
,{0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00} // 6f o
,{0x00, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00} // 70 p
,{0x00, 0x08, 0x14, 0x14, 0x18, 0x7c, 0x00} // 71 q
,{0x00, 0x7c, 0x08, 0x04, 0x04, 0x08, 0x00} // 72 r
,{0x00, 0x48, 0x54, 0x54, 0x54, 0x20, 0x00} // 73 s
,{0x00, 0x04, 0x3f, 0x44, 0x40, 0x20, 0x00} // 74 t
,{0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c, 0x00} // 75 u
,{0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00} // 76 v
,{0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c, 0x00} // 77 w
,{0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00} // 78 x
,{0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c, 0x00} // 79 y
,{0x00, 0x44, 0x64, 0x54, 0x4c, 0x44, 0x00} // 7a z
,{0x00, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00} // 7b {
,{0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00} // 7c |
,{0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x00} // 7d }
,{0x00, 0x10, 0x08, 0x08, 0x10, 0x08, 0x00} // 7e ~
,{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 7f blank
};
const uint_fast8_t LCD5110_MAXIMUM_PIXEL_X = 84, LCD5110_MAXIMUM_PIXEL_Y = 48;//LCD5110 max pixel X is 0-83, max pixel Y is 0-47
const bool LCD5110_PIXEL_DRAW = true, LCD5110_PIXEL_CLEAR = false;

const uint_fast8_t LCD5110_NO_ERROR = 0;
const uint_fast8_t LCD5110_INPUT_TEXT_IS_NULL_ERROR = 1;
const uint_fast8_t LCD5110_TEXT_LEN_IS_ZERO_ERROR = 2;
const uint_fast8_t LCD5110_HAPPEN_BEYOND_SCREEN_RANGE_ERROR = 3;
const uint_fast8_t LCD5110_TEXT_OVERLENGTH_ERROR = 4;
const uint_fast8_t LCD5110_NON_ASCII_CHARACTERS_ERROR = 5;
const uint_fast8_t LCD5110_NOT_IS_GRAPH_CHARACTERS_ERROR = 6;

volatile static unsigned char display_ram ;//Automatic initialization display_ram[][] is 0
volatile static uint_fast8_t initial_write_ram_x, initial_write_ram_y;//Automatic initialization initial_write_ram_x and initial_write_ram_y is 0

static uint_fast8_t dc_pin = 4;//default pin 4 is DC

inline void lcd5110_spi_configuration (void)//Arduino with the statement
{
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
}

inline void lcd5110_start_write (void)//This is needed before lcd5110_spi_configuration. Arduino with the statement
{
SPI.begin();
digitalWrite(SS, LOW);//Low is CHIP enable
}

inline void lcd5110_finish_write (void)//Arduino with the statement
{
digitalWrite(SS, HIGH);//High is CHIP disable
SPI.end();
}

inline void lcd5110_write_byte (bool mode_select, unsigned char data)//This is needed before lcd5110_start_write(), then need to lcd5110_finish_write(). Arduino with the statement
{
digitalWrite(dc_pin, mode_select);
SPI.transfer(data);
}

void lcd5110_activate (void)//This is needed before lcd5110_initialise
{
{
    lcd5110_start_write();
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B100000);// Set(chip is in active; horizontal addressing; use basic instruction set)
    lcd5110_finish_write();
}
}

//The following is a public function: lcd5110_clear, lcd5110_initialise, lcd5110_display, lcd5110_blank, lcd5110_sleep, lcd5110_write_text, lcd5110_write_blink_character, lcd5110_put_pixel

void lcd5110_clear (void)//a public function. This is needed before lcd5110_spi_configuration.(In lcd5110_initialise has been running after)
{
{
    initial_write_ram_x = 0;
    initial_write_ram_y = 0;
}

for (int_fast8_t y_index = 0; y_index < LCD5110_RAM_MAX_Y; ++y_index)
{
    for (int_fast8_t x_index = 0; x_index < LCD5110_RAM_MAX_X; ++x_index)
    {
      display_ram = 0;
    }
}

{
    lcd5110_start_write();
    for (int_fast16_t index = 0; index < (uint_fast16_t)LCD5110_RAM_MAX_X * LCD5110_RAM_MAX_Y; ++index)
    {
      lcd5110_write_byte(LCD5110_MODE_DATA, 0x00);//To Lcd5110 RAM write data 0
    }
    lcd5110_finish_write();
}
}

void lcd5110_initialise (void)//a public function
{
{//del
const uint_fast8_t PIN_RESET = 6;
pinMode(PIN_RESET, OUTPUT);
digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_RESET, HIGH);
}

lcd5110_spi_configuration();
pinMode(dc_pin, OUTPUT);
lcd5110_clear();// The Lcd5110 RAM to clear
{
    lcd5110_start_write();
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B100101);// Set(chip is in Power-down mode; horizontal addressing; use extended instruction set)
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B11000011);// Set Vop value for 1000011
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B110);// Set Temp coefficent for TC2
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B10011);// Set Bias mode to 1:48
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B100100);// Set(chip is in Power-down mode; horizontal addressing; use basic instruction set)
    lcd5110_finish_write();
}
}

void lcd5110_display (void)// Set the display. a public function. This is needed before lcd5110_initialise.
{
{
    lcd5110_start_write();
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B1000000);// Setting the initial write LCD5110 RAM Y=0
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B10000000);// Setting the initial write LCD5110 RAM X=0
    for (int_fast8_t y_index = 0; y_index < LCD5110_RAM_MAX_Y; ++y_index)
    {
      for (int_fast8_t x_index = 0; x_index < LCD5110_RAM_MAX_X; ++x_index)
      {
      lcd5110_write_byte(LCD5110_MODE_DATA, display_ram);
      }
    }
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B1100);// Set the display mode to normal mode.
    lcd5110_finish_write();
}
}

void lcd5110_blank (void)// Set the display blank. a public function. This is needed before lcd5110_initialise.
{
{
    lcd5110_start_write();
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B1000);// Set the display blank.
    lcd5110_finish_write();
}
}

void lcd5110_sleep (void)//a public function. This is needed before lcd5110_initialise
{
lcd5110_clear();// The Lcd5110 RAM to clear
{
    lcd5110_start_write();
    lcd5110_write_byte(LCD5110_MODE_COMMAND, B100100);// Set(chip is in Power-down mode; horizontal addressing; use basic instruction set)
    lcd5110_finish_write();
}
}

void lcd5110_write_text (char input_text[], uint_fast8_t text_len, uint_fast8_t initial_row, uint_fast8_t initial_column, uint_fast8_t error_code)
/*a public function. This is needed before lcd5110_initialise.
text_len value must match the length of input_text[]!
input_text[] up to LCD5110_MAXIMUM_CHARACTERS characters, initial_row is 0 to LCD5110_MAX_ROW, initial_column is 0 to LCD5110_MAX_COLUMN.
initial_row if 0 remain initial_write_ram_y values, initial_column if 0 remain initial_write_ram_x values. */
{
char internal_text ;
int_fast8_t str_index = -1;

lcd5110_blank();

if (input_text == NULL)
{
    error_code = LCD5110_INPUT_TEXT_IS_NULL_ERROR;//"Pointer is empty error! "
    return;
}
if (text_len == 0)
{
    error_code = LCD5110_TEXT_LEN_IS_ZERO_ERROR;//"text_len = 0 error! "
    return;
}
if ((initial_row > LCD5110_MAX_ROW) or (initial_column > LCD5110_MAX_COLUMN))
{
    error_code = LCD5110_HAPPEN_BEYOND_SCREEN_RANGE_ERROR;//"Happen beyond screen range error! "
    return;
}
do
{
    ++str_index;
    if (str_index > LCD5110_MAXIMUM_CHARACTERS)
    {
      error_code = LCD5110_TEXT_OVERLENGTH_ERROR;//"Text overlength error! "
      return;
    }
    if (input_text < '\x0')
    {
      error_code = LCD5110_NON_ASCII_CHARACTERS_ERROR;//"Non-ASCII Characters error! "
      return;
    }
    internal_text = input_text;
}while(not(str_index == text_len) and not(internal_text == '\x0'));

if (initial_row > 0)
{
    initial_write_ram_y = initial_row - 1;
}
if (initial_column > 0)
{
    initial_write_ram_x = ASCII_FONT_WIDTH * (initial_column - 1);
}
uint_fast8_t y_index = initial_write_ram_y;
uint_fast8_t x_index = initial_write_ram_x;
uint_fast8_t character_code;
for (int_fast8_t n = 0; n < str_index; ++n)
{
    character_code = (uint_fast8_t)internal_text;
    for (int_fast8_t font_index = 0; font_index < ASCII_FONT_WIDTH; ++font_index)
    {
      display_ram = pgm_read_byte(&ASCII_BITMAP_FONT);//GCC 4.7.1 DEL pgm_read_byte(&)
      x_index = (x_index + 1) % LCD5110_RAM_MAX_X;
      if (x_index == 0)
      {
      y_index = (y_index + 1) % LCD5110_RAM_MAX_Y;
      }
    }
}

lcd5110_display();
lcd5110_activate();

error_code = LCD5110_NO_ERROR;
return;
}

void lcd5110_write_blink_character (char input_character, uint_fast8_t initial_row, uint_fast8_t initial_column, uint_fast8_t error_code)
/*a public function. This is needed before lcd5110_initialise.
initial_row is 0 to LCD5110_MAX_ROW, initial_column is 0 to LCD5110_MAX_COLUMN.
initial_row if 0 remain initial_write_ram_y values, initial_column if 0 remain initial_write_ram_x values. */
{
char internal_character_string [] = {'\x0', '\x0'};

internal_character_string = input_character;
if (internal_character_string < '\x0')
{
    error_code = LCD5110_NON_ASCII_CHARACTERS_ERROR;
    return;
}
if (not(isgraph(internal_character_string)))
{
    error_code =LCD5110_NOT_IS_GRAPH_CHARACTERS_ERROR;
    return;
}
if ((initial_row > LCD5110_MAX_ROW) or (initial_column > LCD5110_MAX_COLUMN))
{
    error_code = LCD5110_HAPPEN_BEYOND_SCREEN_RANGE_ERROR;
    return;
}
for (int_fast8_t n = 0; n < 3; ++n)
{
    uint_fast8_t lcd5110_write_text_of_error_code;
    lcd5110_write_text(internal_character_string, 2, initial_row, initial_column, lcd5110_write_text_of_error_code);
    delay(1000);
    lcd5110_write_text(" ", 2, initial_row, initial_column, lcd5110_write_text_of_error_code);
    delay(1000);
}
error_code = LCD5110_NO_ERROR;
return;
}

void lcd5110_put_pixel (uint_fast8_t pixel_x, uint_fast8_t pixel_y, bool pixel_mode)//a public function. This is needed before lcd5110_initialise. pixel_x is 0 to LCD5110_MAXIMUM_PIXEL_X-1, pixel_y is 0 to LCD5110_MAXIMUM_PIXEL_X-1.
{
if ((pixel_x < LCD5110_MAXIMUM_PIXEL_X) and (pixel_y < LCD5110_MAXIMUM_PIXEL_Y))
{
    div_t pixel_y_position = div(pixel_y, LCD5110_TRANSMISSION_UNIT_LENGTH_BITS);
    if (pixel_mode == LCD5110_PIXEL_DRAW)
    {
      display_ram = (unsigned char)write_bit(display_ram, LCD5110_RAM_WIDTH_BITS, pixel_y_position.rem, 1);
    }
    else
    {
      display_ram = (unsigned char)write_bit(display_ram, LCD5110_RAM_WIDTH_BITS, pixel_y_position.rem, 0);
    }
}
else
{//Beyond the scope of the screen doing nothing
}
}
==============================
此库特点除了硬件SPI,还有在RAM开了一个显存缓冲,再有查屏幕上有什么的时候就好办了
初始化重启屏幕用的PIN 6,建议只调试时候用,实际应用可做硬件重启,去掉相关段
库内有注释,还有应用问题就发帖吧

Randy 发表于 2012-9-26 15:36:18

硬件SPI操作,可做硬件重启这点都差不多吧?我记得很多NOKIA 5110都是SPI控制的,沙发,顶你一个!

test01 发表于 2012-9-26 16:20:17

Randy 发表于 2012-9-26 15:36 static/image/common/back.gif
硬件SPI操作,可做硬件重启这点都差不多吧?我记得很多NOKIA 5110都是SPI控制的,沙发,顶你一个!

:lol
现有的5110库都未用spi.h,都是软件编程用任意io模拟spi协议的

Randy 发表于 2012-9-26 16:37:09

test01 发表于 2012-9-26 16:20 static/image/common/back.gif
现有的5110库都未用spi.h,都是软件编程用任意io模拟spi协议的

是的,哈哈,是软件模拟的!

test01 发表于 2012-10-13 02:43:50

为更方便大家应用,变更了开源许可证

test01 发表于 2012-10-20 00:27:42

有人反映说看不懂
好吧,我用中文解释下
这个库的公共函数有:
lcd5110_clear      清空显存
lcd5110_initialise   屏上电后要首先调用下这个,初始化
lcd5110_display    让屏显示出显存里的字
lcd5110_blank      让屏全屏空白,但不影响显存内容
lcd5110_sleep      让屏休眠
lcd5110_write_text   往屏上输出字串
lcd5110_write_blink_character往屏上输出闪烁的单字母
lcd5110_put_pixel   往屏上画点

xpaul 发表于 2012-10-20 20:33:59

:$如何制成库文件调用,还是加到程序中。

test01 发表于 2012-10-20 23:14:18

xpaul 发表于 2012-10-20 20:33 static/image/common/back.gif
如何制成库文件调用,还是加到程序中。

可以直接复制到自己的程序里
也可以按精华区那篇做库的方法做成库调用

Pizzro 发表于 2012-10-21 21:52:53

https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/blob/master/Adafruit_PCD8544.h

test01 发表于 2012-11-24 00:45:40

lcd5110_write_text和 lcd5110_write_blink_character 函数的调用参数有改变

shenhaiyu 发表于 2012-11-24 17:48:34

这代码长度。。。看来我是用不了,现在板子里空间寸土寸金的……

zjhyhky 发表于 2013-1-23 12:11:17

'write_bit' was not declared in this scope
找不到write_bit函数

ttyp 发表于 2013-1-23 13:16:29

貌似

mark一下
貌似没有太多作图的功能

test01 发表于 2013-1-24 12:43:20

本帖最后由 test01 于 2013-1-24 12:48 编辑

ttyp 发表于 2013-1-23 13:16 static/image/common/back.gif
mark一下
貌似没有太多作图的功能
:lol 有基础的画点函数,更高级的画直线曲线填充可以调用画点函数编写

test01 发表于 2013-1-24 12:47:24

zjhyhky 发表于 2013-1-23 12:11 static/image/common/back.gif
'write_bit' was not declared in this scope
找不到write_bit函数

这个函数在另一个帖子里
http://www.geek-workshop.com/thread-1988-1-1.html
当然你也可以用Arduino里自带的写bit宏替换
页: [1] 2
查看完整版本: 贡献一个开源的“基于硬件SPI的LCD5110库”