;*************************************************************************** ; ; File Name :'PCD8544.asm" ; Title :Nokia 3310 LCD driver - PCD8544 ; Date :2006.06.28. ; Version :1.0.0 ; Support telephone :+36-70-333-4034, old: +36-30-9541-658 VFX ; Support fax : ; Support Email :info@vfx.hu ; Target MCU :AVR ; ;*************************************************************************** ; D E S C R I P T I O N ; ; driver for the Nokia 84x48 graphic LCD ; ; ; PCD8544 - http://www.myplace.nu/mp3/files/pcd8544.pdf ; ; http://www.amontec.com/lcd_nokia_3310.shtml ; http://www.myplace.nu/mp3/images/nokia_lcd_large.jpg ; http://sandiding.tripod.com/Bertys.html ; ; http://serdisplib.sourceforge.net/ser/pcd8544.html ; ;LPH7779, LPH7677: ; Pin Signal Description ; 1 VDD Power Input. Logic supply voltage range VDD to GND : 2.7 to 3.3 V ; 2 SCLK Serial clock. Input for the clock signal: 0.0 to 4.0 Mbits/s. ; 3 SDIN Serial data. Input for the data line. ; 4 D/C Mode Select. To select either command/address or data input. ; 5 SCE Chip enable input. The enable pin allows data to be clocked in. The signal is active LOW. ; 6 GND Ground ; 7 VOUT Ouptut voltage. Add external 1-10 uF electrolytic capacitor from VOUT to GND ; 8 RES External reset. This signal will reset the device and must be applied to properly initialize the chip. The signal is active LOW. ; ; ;LPH7366: ; 1 VDD ; 2 SCLK ; 3 SI ; 4 D/C ; 5 /CS ; 6 Osc ; 7 GND ; 8 Vout ; 9 /RES ; ; ; ; ; ;*************************************************************************** ; M O D I F I C A T I O N H I S T O R Y ; ; ; rev. date who why ; ---- ---------- --- ------------------------------------ ; 0.01 2006.06.28 VFX Creation ; ;*************************************************************************** ;Hardware ;*************************************************************************** ; pin definition: "hw.inc" ; .equ LCD_X_RES = 84 .equ LCD_Y_RES = 48 ;*************************************************************************** ;**** VARIABLES .DSEG ;*************************************************************************** .ESEG ;*************************************************************************** ;**** CODE SEG ;*************************************************************************** .CSEG ;**************************************************************************** ; PCD8544_Init ; ; Initialize port pins for use Nokia LCD and initializes the LCD ; ; PCD8544_Init: ;SPI port initilaized by Main.asm ;Init other LCD pins sbi LCD_CE_PORT,LCD_CE ;LCD inactive CD = 1 sbi LCD_CE_DIR,LCD_CE ;LCD Chip Enable output cbi LCD_DC_PORT,LCD_DC ;DC = 0 sbi LCD_DC_DIR,LCD_DC ;LCD Data/Command output sbi LCD_RES_PORT,LCD_RES ;RES = 1 sbi LCD_RES_DIR,LCD_RES ;LCD Reset , output ;HW Reset LCD cbi LCD_RES_PORT,LCD_RES ;LCD RESET = 0, active ldi R16,1 rcall Wait1ms sbi LCD_RES_PORT,LCD_RES ;LCD RESET = 1 ;SPI port abort cbi LCD_CE_PORT,LCD_CE ;CE=0 ldi R16,255 WL0: nop dec R16 brne WL0 sbi LCD_CE_PORT,LCD_CE ;CE=1, inactive bus ldi R16,255 WL1: nop dec R16 brne WL1 ;Setup LCD ldi R16,0x21 rcall LCD_WriteCommand ;LCD Extended Commands ldi R16,0x08 rcall LCD_WriteCommand ;Set LCD Vop (Contrast) ldi R16,0x06 rcall LCD_WriteCommand ;Set Temp coefficent ldi R16,0x13 rcall LCD_WriteCommand ;LCD bias mode 1:48 ldi R16,0x20 rcall LCD_WriteCommand ;LCD Standard Commands, Horizontal addressing mode ldi R16,0x0C rcall LCD_WriteCommand ;LCD in normal video mode rcall LCD_Clear ldi R16,0x0c ;LCD Standard Commands, Horizontal addressing mode rcall LCD_WriteCommand ret ;**************************************************************************** ; LCD_WriteCommand ; ; Write command to LCD ; ; In: R16 - Command ; ; Out: - ; LCD_WriteCommand: cbi LCD_DC_PORT,LCD_DC ;DC = 0 cbi LCD_CE_PORT,LCD_CE ;CE=0 rcall SPI_RW sbi LCD_CE_PORT,LCD_CE ;CE=1 ret ;**************************************************************************** ; LCD_WriteData ; ; Write data to LCD ; ; In: R16 - data ; ; Out: - ; LCD_WriteData: sbi LCD_DC_PORT,LCD_DC ;DC = 1 cbi LCD_CE_PORT,LCD_CE ;CE=0 rcall SPI_RW sbi LCD_CE_PORT,LCD_CE ;CE=1 ret ;**************************************************************************** ; LCD_Clear ; ; Clear LCD ; ; In: - ; ; Out: - ; LCD_Clear: ldi R16,0x0c rcall LCD_WriteCommand ldi R16,0x80 rcall LCD_WriteCommand ldi YL,low(504) ldi YH,high(504) LCD_C1: clr R16 rcall LCD_WriteData sbiw YL,1 brne LCD_C1 ret ;**************************************************************************** ; LCD_GotoXY ; ; Set Lcd X(Page) Y(Column) position ; ; In: R16 - X pos ; R17 - Y pos ; ; Out: - ; LCD_GotoXY: andi R16,0x7F ori R16,0x80 rcall LCD_WriteCommand ;Row, X axis mov R16,R17 andi R16,0x07 ori R16,0x40 rcall LCD_WriteCommand ;Column, Y axis ret ;**************************************************************************** ; LCD_Contrast ; ; Set display contrast ; change visible at ambient temperature ; ; In: R16 - contrast 0x00..0x7F ; ; Out: - ; ; Alt: R0 ; LCD_Contrast: mov R0,R16 ldi R16,0x21 ;LCD Extended Commands rcall LCD_WriteCommand mov R16,R0 ori R16,0x80 ;Set LCD Vop (Contrast) rcall LCD_WriteCommand ldi R16,0x20 ;LCD Standard Commands, horizontal addressing mode rcall LCD_WriteCommand ;************************************************************************* ; LCD_Text ; ; Write character to LCD ; ; In: R16 - ASCII code ; R17 - x pos (0.84) ; R18 - y pos (0..5) ; ; Out: c = 1 error ; LCD_Text: cpi R18,6 brcs lcd_text1 sec ;Wrong Y pos ret lcd_text1: rcall FetchASCII brcc lcd_text2 ret ;Wrong ASCII code lcd_text2: mov R16,R17 mov R17,R18 rcall LCD_GotoXY lpm R16,Z+ rcall LCD_WriteData lpm R16,Z+ rcall LCD_WriteData lpm R16,Z+ rcall LCD_WriteData lpm R16,Z+ rcall LCD_WriteData lpm R16,Z+ rcall LCD_WriteData clr R16 rcall LCD_WriteData ret ;************************************************************************* ;* Get character's pixel data from FLASH ; ; In: R16 - ASCII code ; ; Out: c = 0 , Z - points to Char's pixeldata ; c = 1 error ; FetchASCII: cpi R16,0x20 brcs Fe_01 subi R16,0x20 ldi ZL,6 mul R16,ZL ldi ZL,low(CharSet*2) ldi ZH,high(CharSet*2) add ZL,R0 adc ZH,R1 Fe_01: ret ;CharSet: .db 0x00,0x00,0x00,0x00,0x00,0x00 ; 20 space ; .db 0xff,0xff,0xff,0xff,0xff,0x00 ; 21 teli negyzet ; .db 0x46,0x49,0x49,0x49,0x31,0x00 ; 22 S ;***************************************************** ;** Wait1ms ;** ;** In: R16 - 16*1ms varakozas ;** ;** Out: - ;** ;** ;** Alt R16, XL,XH ;** ;** Description: wating for R16 * 1 ms ;* Wait1ms: ldi XL,low(SYSCLK/(5*1000)) ldi Xh,high(SYSCLK/(5*1000)) Waitx1: sbiw XL,1 ;[2] \ nop ;[1] - 5 cycles in loop brne Waitx1 ;[2] / dec R16 brne Wait1ms ret