📄 ks108.h
字号:
//************************************************************************
// KS108.H
// LowLevel Routinen f黵 LCD-Displays mit KS0108
//
//
// hk@holger-klabunde.de
// http://www.holger-klabunde.de
// 26.12.2007
//************************************************************************
// Compiler WinAVR 4.1.2
//************************************************************************
#ifndef KS108_H
#define KS108_H
#define NOP asm volatile ("nop" ::)
#define sbi(portn, bitn) ((portn)|=(1<<(bitn)))
#define cbi(portn, bitn) ((portn)&=~(1<<(bitn)))
// Da der Busy-Check bei mir nie klappt, hier feste Delay Werte f黵 E.
// Achtung ! Maximales Delay ist 768(us)/FCPU(MHZ)
// Bei 16MHz darf man maximal 48 angeben. Bei 20MHz maximal 38.
//Note: 1. F_CPU im makefile definieren, 2. Optimization ein ! Also wenigstens -O1
//#define KS108_E_DELAY 2 // Pollin Display TG12864B 596kHz FCLK
#define KS108_E_DELAY 4 // Displaytech 64240A 395kHz FCLK.
//#define KS108_E_DELAY 38 // Falls Schrott auf dem Display erscheint erst den probieren
// und dann langsam runter arbeiten.
// Only define ONE of these !!
//#define LCD_WIDTH_240 //Display Width for 240x64
#define LCD_WIDTH_128 //Display Width for 128x64
#define USE_BACKLIGHT // if you have a backlight !
// security check !
#if defined (LCD_WIDTH_240) && defined (LCD_WIDTH_128)
#error "Define LCD_WIDTH_240 or LCD_WIDTH_128 only in ks108.h, NOT both !"
#endif
// KS108 displays have one or more ks108 controllers.
// 240x64 has 4 controllers, 128x64 has 2 controllers
#ifdef LCD_WIDTH_240
#define LCD_WIDTH 240
#define MAX_CONTROLLERS 4
#endif
#ifdef LCD_WIDTH_128
#define LCD_WIDTH 128
#define MAX_CONTROLLERS 2
#endif
#define LCD_HEIGHT 64 //Display H鰄e
#if defined (__AVR_ATmega128__) || defined (__AVR_ATmega64__)
#define DATA_PORT PORTD
#define DATA_DDR DDRD
#define DATA_PIN PIND
#define RS_BIT 7 // D/I
#define RS_PORT PORTF
#define RS_DDR DDRF
#define RW_BIT 6
#define RW_PORT PORTF
#define RW_DDR DDRF
#define E_BIT 5
#define E_PORT PORTF
#define E_DDR DDRF
// F黵 Displays ohne RSTB (Reset) Pin folgende drei Zeilen einfach wegkommentieren.
#define RSTB_BIT 4
#define RSTB_PORT PORTF
#define RSTB_DDR DDRF
#define CS1_BIT 0
#define CS1_PORT PORTF
#define CS1_DDR DDRF
#define CS2_BIT 1
#define CS2_PORT PORTF
#define CS2_DDR DDRF
#if defined (LCD_WIDTH_240)
#define CS3_BIT 2
#define CS3_PORT PORTF
#define CS3_DDR DDRF
#define CS4_BIT 3
#define CS4_PORT PORTF
#define CS4_DDR DDRF
#endif
#ifdef USE_BACKLIGHT
#define BACKLIGHT_BIT 3
#define BACKLIGHT_PORT PORTF
#define BACKLIGHT_DDR DDRF
#endif
#elif defined (__AVR_ATmega32__)
#define DATA_PORT PORTC
#define DATA_DDR DDRC
#define DATA_PIN PINC
//#define DATA_PORT PORTB // Geht, aber ISP dann nicht mehr ! Display abziehen
//#define DATA_DDR DDRB
//#define DATA_PIN PINB
#define RS_BIT 7 //D/I
#define RS_PORT PORTA
#define RS_DDR DDRA
#define RW_BIT 6
#define RW_PORT PORTA
#define RW_DDR DDRA
#define E_BIT 5
#define E_PORT PORTA
#define E_DDR DDRA
// F黵 Displays ohne RSTB (Reset) Pin folgende drei Zeilen einfach wegkommentieren.
#define RSTB_BIT 4
#define RSTB_PORT PORTA
#define RSTB_DDR DDRA
#define CS1_BIT 0
#define CS1_PORT PORTA
#define CS1_DDR DDRA
#define CS2_BIT 1
#define CS2_PORT PORTA
#define CS2_DDR DDRA
#ifdef USE_BACKLIGHT
#define BACKLIGHT_BIT 3
#define BACKLIGHT_PORT PORTA
#define BACKLIGHT_DDR DDRA
#endif
#if defined (LCD_WIDTH_240) //Noch nicht probiert mit ATMega32
#define CS3_BIT 2
#define CS3_PORT PORTA
#define CS3_DDR DDRA
#define CS4_BIT 3
#define CS4_PORT PORTA
#define CS4_DDR DDRA
#endif
#else
# error "processor type not defined in ks108.h"
#endif
#define DATA_DIR_IN() { DATA_DDR=0x00; DATA_PORT=0xFF; } // set io-pins to inputs with pullups
#define DATA_DIR_OUT DATA_DDR=0xFF; // set io-pins to outputs
#define READ_DATA DATA_PIN // read PIN, ! NOT ! PORT
#define WRITE_DATA(a) DATA_PORT=(a); // write to data port
#ifdef USE_BACKLIGHT
#define BACKLIGHT_SET_DDR sbi(BACKLIGHT_DDR,BACKLIGHT_BIT);
#define BACKLIGHT_ON sbi(BACKLIGHT_PORT,BACKLIGHT_BIT);
#define BACKLIGHT_OFF cbi(BACKLIGHT_PORT,BACKLIGHT_BIT);
#endif
#define RS_SET_DDR sbi(RS_DDR,RS_BIT);
#define RS_ON sbi(RS_PORT,RS_BIT);
#define RS_OFF cbi(RS_PORT,RS_BIT);
#define RW_SET_DDR sbi(RW_DDR,RW_BIT);
#define RW_ON() { sbi(RW_PORT,RW_BIT); NOP; NOP; }
#define RW_OFF() { cbi(RW_PORT,RW_BIT); NOP; NOP; } //min 140ns
#define E_SET_DDR sbi(E_DDR,E_BIT);
#define E_ON() { sbi(E_PORT,E_BIT); Wait_for_E(); } //min 450ns
#define E_OFF() { cbi(E_PORT,E_BIT); Wait_for_E(); } //min 450ns
#define RSTB_SET_DDR sbi(RSTB_DDR,RSTB_BIT);
#define RSTB_ON sbi(RSTB_PORT,RSTB_BIT);
#define RSTB_OFF cbi(RSTB_PORT,RSTB_BIT);
#define CS1_SET_DDR sbi(CS1_DDR,CS1_BIT);
#define CS1_ON sbi(CS1_PORT,CS1_BIT);
#define CS1_OFF cbi(CS1_PORT,CS1_BIT);
#define CS2_SET_DDR sbi(CS2_DDR,CS2_BIT);
#define CS2_ON sbi(CS2_PORT,CS2_BIT);
#define CS2_OFF cbi(CS2_PORT,CS2_BIT);
#if defined (LCD_WIDTH_240)
#define CS3_SET_DDR sbi(CS3_DDR,CS3_BIT);
#define CS3_ON sbi(CS3_PORT,CS3_BIT);
#define CS3_OFF cbi(CS3_PORT,CS3_BIT);
#define CS4_SET_DDR sbi(CS4_DDR,CS4_BIT);
#define CS4_ON sbi(CS4_PORT,CS4_BIT);
#define CS4_OFF cbi(CS4_PORT,CS4_BIT);
#endif
#define DRAW_NORMAL 1
#define DRAW_INVERTED 2
extern unsigned char xtextcursor,ytextcursor;
extern unsigned char drawmode;
extern void SetDrawMode(unsigned char mode);
extern void SetTextCursor(unsigned char x, unsigned char y);
extern unsigned char ReadDisplay(void);
extern void WriteDisplay(unsigned char dat);
extern unsigned char SetPixel(unsigned char xpos, unsigned char ypos, unsigned char mode);
extern unsigned char GetPixel(unsigned char xpos, unsigned char ypos);
extern unsigned char GetChipNumber(unsigned char xpos);
extern void SetChipNumber(unsigned char num);
extern unsigned char GetPageNumber(unsigned char ypos);
extern unsigned char SetPageNumber(unsigned char num);
extern unsigned char SetRow(unsigned char xpos);
extern unsigned char SetPosition(unsigned char xpos, unsigned char ypos);
extern void DisplayOn(void);
extern void ClearScreen(void);
extern unsigned char CheckBusy(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -