📄 lcd.asm
字号:
/* ***********************************************************************
**
** Copyright (C) 2002 Romuald Bialy (MIS) <romek_b@o2.pl>.
**
**
** Yampp-7/USB - low level support library.
** Nokia 6610 Color LCD driver
**
*************************************************************************
**
** This file is part of the yampp system by Jesper Hansen
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*************************************************************************
**
** Revision History
**
** when what who why
**
** 2004-01-01 2.00 MIS initial public release for colour LCD
** 2004-01-07 2.01 MIS fixed support for national characters displaying
** 2005-09-14 2.02 Sebi added support for new epson displays based on
** S1D15G17 controllers
** comments / bugs welcome at sebi@justmail.de
**
*********************************************************************** */
#define __ASSEMBLER__ 1
#define __SFR_OFFSET 0
#include <avr/io.h>
#define LCD_ASM
#include "lcd.h"
#define __tmp_reg__ r0
#define __zero_reg__ r1
.comm lcd_x,1
.comm lcd_y,1
.comm bkg_color,1
.comm text_color,1
.comm setcolmark,1
.text
.extern vs1001_init_io
.extern delay10
;************************************************
wrtab1: clr r24
wrl1: rcall lcd_wrdata
subi r24,lo8(-2)
cpi r24,8
brne wril2
inc r24
wril2: cpi r24,0x11
brne wrl1
ret
;************************************************
;LCD control routine
;void lcd_init(u08 mode)
.global lcd_init
lcd_init:
clr r24
sts bkg_color,r24
dec r24
sts text_color,r24
sbi PORTB,LCD_CS ;deselect Display
sbi DDRB,LCD_CS ;
call vs1001_init_io ;init SPI
; According to the datasheet for S1D15G17 controllers CS must go high between command & data bytes
; so LCD_CS handling has been moved to SPI routines. If the Philips / other Epson controller doesn`t work
; with this setting, remove comment marks and drop me a mail at sebi@justmail.de
;
; cbi PORTB,LCD_CS ;select Display
#ifdef EPSON_LCD
ldi r24,LCD_CMD_PWRCTRL ;Power Control
rcall lcd_wrcmd
ldi r24,0x0F ;On all internal boosters and other power stages
rcall lcd_wrdata
#else
ldi r24,LCD_CMD_SWRESET ;Reset
rcall lcd_wrcmd
#endif
#ifdef EPSON_NEW_LCD
call delay10
ldi r24,LCD_CMD_DISPCTL ; Display control
rcall lcd_wrcmd
ldi r24,0x7f ; default values according to datasheet
rcall lcd_wrdata ; these values set N line inversion, bias rate,
ldi r24,0x84 ; no. of lines (arg. 5) and some other parameters
rcall lcd_wrdata
ldi r24,0x8c
rcall lcd_wrdata
ldi r24,0x86
rcall lcd_wrdata
ldi r24,0x84
; the gamma table is initialized after hardware reset; if that isn`t reliable,
; uncomment these lines although I had no problems
; values are defaults from datasheet
;
; ldi r24,LCD_CMD_GRAYSCALE ;gray scale table
; rcall lcd_wrcmd
; ldi r24,0x01
; rcall lcd_wrdata
; ldi r24,10
; rcall lcd_wrdata
; ldi r24,18
; rcall lcd_wrdata
; ldi r24,26
; rcall lcd_wrdata
; ldi r24,35
; rcall lcd_wrdata
; ldi r24,43
; rcall lcd_wrdata
; ldi r24,51
; rcall lcd_wrdata
; ldi r24,60
; rcall lcd_wrdata
; ldi r24,68
; rcall lcd_wrdata
; ldi r24,76
; rcall lcd_wrdata
; ldi r24,85
; rcall lcd_wrdata
; ldi r24,93
; rcall lcd_wrdata
; ldi r24,101
; rcall lcd_wrdata
; ldi r24,110
; rcall lcd_wrdata
; ldi r24,118
; rcall lcd_wrdata
; ldi r24,126
; rcall lcd_wrdata
ldi r24,LCD_CMD_DRVPOS ; behaviour of MADCTL values
rcall lcd_wrcmd
ldi r24,0 ; set to standard mode (no inversion)
rcall lcd_wrdata
ldi r24,LCD_CMD_PWRCTRL ;power control
rcall lcd_wrcmd
ldi r24,0x54 ;boosting circuit freq., high output capacity for Vcout
rcall lcd_wrdata
ldi r24,0x02
rcall lcd_wrdata
ldi r24,LCD_CMD_VOLCTRL ;voltage control
rcall lcd_wrcmd
ldi r24,0x60 ;voltage for full mode
rcall lcd_wrdata
ldi r24,0x02 ;voltage for partial mode
rcall lcd_wrdata
ldi r24,63
rcall lcd_contrast
ldi r24,0xb7 // temperature gradient set
rcall lcd_wrcmd
clr r22
clr r24
tempset: rcall lcd_wrdata
inc r22
cpi r22,0x0f
brne tempset
ldi r24,LCD_CMD_INVOFF ; Non Invert mode
rcall lcd_wrcmd
ldi r24,LCD_CMD_NORMAL ; normal mode
rcall lcd_wrcmd
#else
call delay100
ldi r24,LCD_CMD_SLEEPOUT ;Sleep_out
rcall lcd_wrcmd
ldi r24,LCD_CMD_DISPON ;display on
rcall lcd_wrcmd
ldi r24,LCD_CMD_BSTRON ;booster on
rcall lcd_wrcmd
call delay100
#endif
ldi r24,LCD_CMD_MADCTL ;Memory data acces control
rcall lcd_wrcmd
ldi r24,MADCTL_HORIZ ;X Mirror and BGR format (needed)
rcall lcd_wrdata
#ifdef EPSON_LCD
ldi r24,0x02 ;Colour mode (second data for MADCTRL)
rcall lcd_wrdata
ldi r24,0x01 ;Colour mode (second data for MADCTRL)
rcall lcd_wrdata
ldi r24,0xBB ;Display setup
rcall lcd_wrcmd
ldi r24,0x01 ;Normal mode
rcall lcd_wrdata
#else
ldi r24,LCD_CMD_COLMOD ;Colour mode
rcall lcd_wrcmd
ldi r24,0x02 ;256 colour mode select
rcall lcd_wrdata
#endif
; I`m getting random colors when writing the LUT. The LUT is initialized during hard resed
; and it works well without writing the LUT
#ifndef EPSON_NEW_LCD
ldi r24,LCD_CMD_INVOFF ;Non Invert mode
rcall lcd_wrcmd
ldi r24,LCD_CMD_RGBSET ;LUT write
rcall lcd_wrcmd
rcall wrtab1
rcall wrtab1
ldi r24,0x00
rcall lcd_wrdata
ldi r24,0x07
rcall lcd_wrdata
ldi r24,0x0B
rcall lcd_wrdata
ldi r24,0x0F
rcall lcd_wrdata
ldi r24,45
rcall lcd_contrast
#endif
; the new epson controller is very picky about too early sleepout / dispon commands!
; display works, but has way too high contrast setting and random colors
#ifdef EPSON_NEW_LCD
ldi r24,LCD_CMD_SLEEPOUT ;Sleep_out
rcall lcd_wrcmd
call delay100
ldi r24,LCD_CMD_DISPON ;display on
rcall lcd_wrcmd
#endif
;fall trough
;************************************************
;clear LCD
;void lcd_clrscr(void)
.global lcd_clrscr
lcd_clrscr: cli
sts lcd_x,__zero_reg__
sts lcd_y,__zero_reg__
; cbi PORTB,LCD_CS ;select Display
ser r24
ser r22
ldi r20,0x80
mov r18,r20
rcall lcd_window1
ldi r24,LCD_CMD_RAMWR ;write memory
rcall lcd_wrcmd
ldi r31, 0x42
ldi r30, 0x04
lds r24,bkg_color
LCD_CLEAR_1: rcall lcd_wrdata
sbiw r30,1
brne LCD_CLEAR_1
; sbi PORTB,LCD_CS ;deselect Display
sei
ret
;************************************************
;void lcd_off(void)
.global lcd_off
lcd_off: rcall lcd_clrscr
; cbi PORTB,LCD_CS ;select Display
ldi r24,LCD_CMD_SLEEPIN ;Sleep_IN
rcall lcd_wrcmd
; sbi PORTB,LCD_CS ;deselect Display
ret
;************************************************
;void lcd_color(u08 bkg, u08 text)
.global lcd_color
lcd_color: sts bkg_color,r24
sts text_color,r22
ret
;************************************************
; r24
;void lcd_contrast(u08 cont)
.global lcd_contrast
lcd_contrast: mov r25,r24
; cbi PORTB,LCD_CS ;select Display
ldi r24,LCD_CMD_SETCON ;set contrast cmd.
rcall lcd_wrcmd
mov r24,r25 ;contrast value
subi r24,lo8(-10)
rcall lcd_wrdata
#ifdef EPSON_LCD
ldi r24,0x03 ;bias
rcall lcd_wrdata
#endif
; sbi PORTB,LCD_CS ;deselect Display
ret
;************************************************
;display a bar
;Lenght(on display) is in r25 and value(how much is filled) in r24
;
; r25 r24 r23 r22
;void lcd_bar(u16 len:val, u16 bkgcol:fillcol)
.global lcd_bar
lcd_bar: mov r21,r24
; cbi PORTB,LCD_CS ;select Display
ldi r24,LCD_CMD_MADCTL ;Memory data acces control
rcall lcd_wrcmd
ldi r24,MADCTL_VERT ;X Mirror + vertical addresing mode
rcall lcd_wrdata
#ifdef EPSON_LCD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -