31-12-2015, 02:11
Witam, nie wiem czy to jest odpowiedni dział. Jeśli nie to proszę o przeniesienie. Wracając do tematu chciał bym prosić o pomoc przy stworzeniu biblioteki dla wyświetlaczy z Kasy Fiskalnej Novitus Soleo. Udało mi się znaleźć kod do obsługi tych wyświetlaczy, ale napisany dla samych µC a nie dla Arduino. Nie potrafię się w tym odnaleźć, jestem dopiero początkującym z arduino i za bardzo nie wiem jak za to się zabrać. Kod z biblotek wklejam poniżej.
NOVITUS_graphic_display_library.h
NOVITUS_graphic_display_library.c
Kod odnaleziony na forum Pana Mirosława Kardasia (forum Atnel), stworzone przez użytkownika 1bobik1
Pozdrawiam Łukasz
NOVITUS_graphic_display_library.h
Kod:
/*
* NOVITUS_graphic_display_library.h
* 132x64 or 132x32 resolution
*/
#define Y_resolution 64 // 32 or 64
#define X_resolution 132
#if Y_resolution == 32
#define Y0_address 0x42
#endif
#if Y_resolution == 64
#define Y0_address 0x47
#endif
// *** PORT
#define PORT(x) SPORT(x)
#define SPORT(x) (PORT##x)
// *** DDR
#define DDR(x) SDDR(x)
#define SDDR(x) (DDR##x)
// LCD PINS LCD Pin name LCD Pin nr. SPI pin name
#define DC_PIN PB6 // D/C 4
#define CS_PIN PB2 // /CS 7 SS chip select
#define MOSI_PIN PB3 // MOSI 3 MOSI
#define RES_PIN PB0 // RST 6 RESET
#define SCLK_PIN PB5 // SCLK 5 SCK
#define LCD_PORT B
#define SET_DC_PIN PORT(LCD_PORT) |= (1<<DC_PIN)
#define CLEAR_DC_PIN PORT(LCD_PORT) &= ~(1<<DC_PIN)
#define SET_CS_PIN PORT(LCD_PORT) |= (1<<CS_PIN)
#define CLEAR_CS_PIN PORT(LCD_PORT) &= ~(1<<CS_PIN)
#define SET_RES_PIN PORT(LCD_PORT) |= (1<<RES_PIN)
#define CLEAR_RES_PIN PORT(LCD_PORT) |= (1<<RES_PIN)
void LCD_SPI_init(void);
void LCD_init ( void );
void LCD_writeCommand ( uint8_t command );
void LCD_writeData ( uint8_t Data);
void LCD_clear ( void );
void LCD_gotoX0Y0 ( void );
void LCD_writeChar (unsigned char ch);
void LCD_writeString_F ( const unsigned char *string);
void LCD_gotoXY ( unsigned char x, unsigned char y );
void LCD_LoadBMP(unsigned char *bitmap);
/*--------------------------------------------------------------------------------------------------
5x7 size character generator
--------------------------------------------------------------------------------------------------*/
static const unsigned char smallFont[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, // sp
0x00, 0x00, 0x2f, 0x00, 0x00, // !
0x00, 0x07, 0x00, 0x07, 0x00, // "
0x14, 0x7f, 0x14, 0x7f, 0x14, // #
0x24, 0x2a, 0x7f, 0x2a, 0x12, // $
0xc4, 0xc8, 0x10, 0x26, 0x46, // %
0x36, 0x49, 0x55, 0x22, 0x50, // &
0x00, 0x05, 0x03, 0x00, 0x00, // '
0x00, 0x1c, 0x22, 0x41, 0x00, // (
0x00, 0x41, 0x22, 0x1c, 0x00, // )
0x14, 0x08, 0x3E, 0x08, 0x14, // *
0x08, 0x08, 0x3E, 0x08, 0x08, // +
0x00, 0x00, 0x50, 0x30, 0x00, // ,
0x10, 0x10, 0x10, 0x10, 0x10, // -
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x20, 0x10, 0x08, 0x04, 0x02, // /
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
0x00, 0x42, 0x7F, 0x40, 0x00, // 1
0x42, 0x61, 0x51, 0x49, 0x46, // 2
0x21, 0x41, 0x45, 0x4B, 0x31, // 3
0x18, 0x14, 0x12, 0x7F, 0x10, // 4
0x27, 0x45, 0x45, 0x45, 0x39, // 5
0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
0x01, 0x71, 0x09, 0x05, 0x03, // 7
0x36, 0x49, 0x49, 0x49, 0x36, // 8
0x06, 0x49, 0x49, 0x29, 0x1E, // 9
0x00, 0x36, 0x36, 0x00, 0x00, // :
0x00, 0x56, 0x36, 0x00, 0x00, // ;
0x08, 0x14, 0x22, 0x41, 0x00, // <
0x14, 0x14, 0x14, 0x14, 0x14, // =
0x00, 0x41, 0x22, 0x14, 0x08, // >
0x02, 0x01, 0x51, 0x09, 0x06, // ?
0x32, 0x49, 0x59, 0x51, 0x3E, // @
0x7E, 0x11, 0x11, 0x11, 0x7E, // A
0x7F, 0x49, 0x49, 0x49, 0x36, // B
0x3E, 0x41, 0x41, 0x41, 0x22, // C
0x7F, 0x41, 0x41, 0x22, 0x1C, // D
0x7F, 0x49, 0x49, 0x49, 0x41, // E
0x7F, 0x09, 0x09, 0x09, 0x01, // F
0x3E, 0x41, 0x49, 0x49, 0x7A, // G
0x7F, 0x08, 0x08, 0x08, 0x7F, // H
0x00, 0x41, 0x7F, 0x41, 0x00, // I
0x20, 0x40, 0x41, 0x3F, 0x01, // J
0x7F, 0x08, 0x14, 0x22, 0x41, // K
0x7F, 0x40, 0x40, 0x40, 0x40, // L
0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
0x7F, 0x04, 0x08, 0x10, 0x7F, // N
0x3E, 0x41, 0x41, 0x41, 0x3E, // O
0x7F, 0x09, 0x09, 0x09, 0x06, // P
0x3E, 0x41, 0x51, 0x21, 0x5E, // Q
0x7F, 0x09, 0x19, 0x29, 0x46, // R
0x46, 0x49, 0x49, 0x49, 0x31, // S
0x01, 0x01, 0x7F, 0x01, 0x01, // T
0x3F, 0x40, 0x40, 0x40, 0x3F, // U
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
0x3F, 0x40, 0x38, 0x40, 0x3F, // W
0x63, 0x14, 0x08, 0x14, 0x63, // X
0x07, 0x08, 0x70, 0x08, 0x07, // Y
0x61, 0x51, 0x49, 0x45, 0x43, // Z
0x00, 0x7F, 0x41, 0x41, 0x00, // [
0x55, 0x2A, 0x55, 0x2A, 0x55, // 55
0x00, 0x41, 0x41, 0x7F, 0x00, // ]
0x04, 0x02, 0x01, 0x02, 0x04, // ^
0x40, 0x40, 0x40, 0x40, 0x40, // _
0x00, 0x01, 0x02, 0x04, 0x00, // '
0x20, 0x54, 0x54, 0x54, 0x78, // a
0x7F, 0x48, 0x44, 0x44, 0x38, // b
0x38, 0x44, 0x44, 0x44, 0x20, // c
0x38, 0x44, 0x44, 0x48, 0x7F, // d
0x38, 0x54, 0x54, 0x54, 0x18, // e
0x08, 0x7E, 0x09, 0x01, 0x02, // f
0x0C, 0x52, 0x52, 0x52, 0x3E, // g
0x7F, 0x08, 0x04, 0x04, 0x78, // h
0x00, 0x44, 0x7D, 0x40, 0x00, // i
0x20, 0x40, 0x44, 0x3D, 0x00, // j
0x7F, 0x10, 0x28, 0x44, 0x00, // k
0x00, 0x41, 0x7F, 0x40, 0x00, // l
0x7C, 0x04, 0x18, 0x04, 0x78, // m
0x7C, 0x08, 0x04, 0x04, 0x78, // n
0x38, 0x44, 0x44, 0x44, 0x38, // o
0x7C, 0x14, 0x14, 0x14, 0x08, // p
0x08, 0x14, 0x14, 0x18, 0x7C, // q
0x7C, 0x08, 0x04, 0x04, 0x08, // r
0x48, 0x54, 0x54, 0x54, 0x20, // s
0x04, 0x3F, 0x44, 0x40, 0x20, // t
0x3C, 0x40, 0x40, 0x20, 0x7C, // u
0x1C, 0x20, 0x40, 0x20, 0x1C, // v
0x3C, 0x40, 0x30, 0x40, 0x3C, // w
0x44, 0x28, 0x10, 0x28, 0x44, // x
0x0C, 0x50, 0x50, 0x50, 0x3C, // y
0x44, 0x64, 0x54, 0x4C, 0x44, // z
0x00, 0x06, 0x09, 0x09, 0x06 // ş
};
NOVITUS_graphic_display_library.c
Kod:
/*
* NOVITUS_graphic_display_library.c
*/
#include <avr/io.h>
#include <inttypes.h>
#include <stdlib.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "NOVITUS_graphic_display_library.h"
void LCD_SPI_init(void)
{
SPCR = (1<<SPE)|(1<<MSTR);
SPSR = (1<<SPI2X);
}
void LCD_init ( void )
{
PORT(LCD_PORT) |= ((1<<DC_PIN) | (1<<CS_PIN) | (1<<MOSI_PIN) | (1<<RES_PIN) | (1<<SCLK_PIN));
DDR(LCD_PORT) |= ((1<<DC_PIN) | (1<<CS_PIN) | (1<<MOSI_PIN) | (1<<RES_PIN) | (1<<SCLK_PIN));
_delay_ms(100);
CLEAR_CS_PIN; //Enable LCD
CLEAR_RES_PIN; //reset LCD
_delay_ms(1);
SET_RES_PIN;
LCD_SPI_init(); // Ustawienia SPI
LCD_writeCommand( 0x23 );
LCD_writeCommand( 0x03 );
LCD_writeCommand( 0x20 );
LCD_writeCommand( 0x04 );
LCD_writeCommand( 0x21 );
LCD_writeCommand( 0x15 ); // KONTRAST
LCD_writeCommand( 0xe6 ); // KONTRAST
LCD_writeCommand( 0x22 );
LCD_writeCommand( 0xB8 );
LCD_writeCommand( 0x23 );
LCD_writeCommand( 0x09 );
LCD_writeCommand( 0xB4 );
LCD_writeCommand( 0x38 );
LCD_writeCommand( 0x0C );
LCD_clear();
}
void LCD_writeCommand ( uint8_t command )
{
CLEAR_CS_PIN; //enable LCD
CLEAR_DC_PIN; //set LCD in command mode
// Send data to display controller.
SPDR = command;
// Wait until Tx register empty.
while ( !(SPSR & 0x80) );
SET_CS_PIN; //disable LCD
}
void LCD_writeData ( uint8_t Data)
{
CLEAR_CS_PIN; //enable LCD
SET_DC_PIN; //set LCD in Data mode
// Send data to display controller.
SPDR = Data;
// Wait until Tx register empty.
while ( !(SPSR & 0x80) );
SET_CS_PIN; //disable LCD
}
void LCD_clear ( void )
{
LCD_gotoXY(0,0);
for(uint8_t i=0; i< Y_resolution / 8; i++)
for(uint8_t j=0; j< X_resolution; j++)
LCD_writeData( 0x00);
}
void LCD_writeChar (unsigned char ch)
{
unsigned char j;
for(j=0; j<5; j++)
LCD_writeData(smallFont [(ch-32)*5 + j]);
LCD_writeData(0x00);
}
void LCD_writeString_F ( const unsigned char *string)
{
while ( *string )
LCD_writeChar( *string++);
}
void LCD_gotoXY ( uint8_t x, uint8_t y )
{
#if Y_resolution == 32
LCD_writeCommand (Y0_address + y);
#endif
#if Y_resolution == 64
if(y){
LCD_writeCommand (0x3f + y );
}
else{
LCD_writeCommand (0x47);
}
#endif
LCD_writeCommand (0xF0 | (x >> 4) );
LCD_writeCommand (0xE0 | (x & 0x0F));
}
void LCD_LoadBMP(unsigned char *bitmap)
{
uint8_t by;
for(uint16_t i=0; i<1056;i++){
by=pgm_read_byte(bitmap++);
LCD_writeData(by);
}
}
Pozdrawiam Łukasz