Debian Codegraph @

extras/graphic_lcd/examples/ssd0323/ssd0323.asm

raw
1 ;
2 ; SSD0323 Driver for the PIC 18F family.
3 ;
4 ; Copyright (C) 2007 T. Scott Dattalo
5 ;
6 ; This driver is designed to test gpsim. However, it is also usable
7 ; as a stand alone driver. You're free to use this driver as you
8 ; wish as long as the copyright is retained.
9 ;
10 ;
11 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 ;
13 ; The SSD0323 driver supports graphic LCD displays that are based on the
14 ; Solomon Systech SSD0323 OLED graphics controller. The SSD0323 is an
15 ; 128X80, 4-bit gray scale dot matrix controller.
16 ;
17 ;
18 ;
19 ; !!! NOTE: The driver assumes all variables reside in Bank 0!. !!!
20 ;
21
22 list p=18f452,t=ON,c=132,n=80
23 radix dec
24
25
26
27 #include <p18f452.inc>
28
29 ; The defines in portdef.inc allow the LCD port definitions to be customized.
30
31 #include "portdef.inc"
32 #include "osram128x64.inc"
33
34 ; Functions:
35
36 GLOBAL SSD0323_Init
37 GLOBAL SSD0323_WriteCmd
38 GLOBAL SSD0323_Write
39 GLOBAL LCD_RefreshDisplay
40 GLOBAL LCD_RefreshEntireDisplay
41 GLOBAL CommandLoop
42 GLOBAL CommandWaitForSPI
43
44 EXTERN temp0, temp1, temp2, temp3
45 EXTERN DisplayBuffer
46
47
48
49 ;========================================================================
50 ;
51 ; SSD0323 Driver
52 ;
53 ;
54 ; RAM Definitions
55
56 UDATA_ACS
57 ;--------------------
58 ; Mode
59 ;--------------------
60
61 SSD0323_Mode RES 1
62 GLOBAL SSD0323_Mode
63 ; xxxx_xxxM
64 ; +--- Mode 0=Command 1=Data
65
66
67 ;------------------------------------------------------------------------
68 ; Macros
69
70 ; SetMode
71 ; Selects between Command and Data mode
72 mSSD0323_SetMode macro
73 BCF LATA, RA1
74 BTFSC SSD0323_Mode,bSSD0323_MODE_CMD
75 BSF LATA, RA1
76 endm
77
78
79
80 SETA0 macro
81 BSF LCDA0_LAT,LCDA0_BIT
82 endm
83 CLRA0 macro
84 BCF LCDA0_LAT,LCDA0_BIT
85 endm
86
87 ;------------------------------------------------------------------------
88 ; SSD0323 commands
89 ;
90 ; The SSD0323 Commands are written to address 1 of the chip.
91 ; The data written for the command includes the command type and optional
92 ; parameters. The data bus is only 8-bits wide. The upper bits in general
93 ; describe the command while the lower are for data
94
95 SSD0323_DisplayOn EQU 0xaf
96 SSD0323_DisplayOff EQU 0xae
97 SSD0323_DisplayStartLine EQU 0xc0
98 SSD0323_SETPAGEADDRESS EQU 0xb8
99 SSD0323_SetColumnAddress EQU 0x00
100 SSD0323_SetDuty EQU 0xa8
101
102 ;------------------------------------------------------------------------
103 ;
104
105
106 SSD0323_CODE CODE
107
108
109 SSD0323_Init:
110
111 mInitLCD_PINS
112
113 ; de-select the chip
114 mSetLCDCS
115
116 ; Bring the chip out of reset:
117 RCALL delay
118 mSetLCDRES
119 RCALL delay
120
121 ; Select the chip
122 mClrLCDCS
123
124
125 CmdSetColumnAddress EQU 0x15
126 CmdGraphicAccleration EQU 0x23
127 CmdDrawRectangle EQU 0x24
128 CmdCopy EQU 0x25
129 CmdHorizontalScroll EQU 0x26
130 CmdStopMoving EQU 0x2E
131 CmdStartMoving EQU 0x2F
132
133 CmdSetRowAddress EQU 0x75
134 CmdSetContrast EQU 0x81
135 CmdSetQuarterCurrent EQU 0x84
136 CmdSetHalfCurrent EQU 0x85
137 CmdSetFullCurrent EQU 0x86
138
139 CmdSetRemap EQU 0xA0
140 CmdSetDisplayStartLine EQU 0xA1
141 CmdSetDisplayOffset EQU 0xA2
142 CmdSetNormalDisplay EQU 0xA4
143 CmdSetAllOn EQU 0xA5
144 CmdSetAllOff EQU 0xA6
145 CmdSetInverse EQU 0xA7
146 CmdSetMultiplexRatio EQU 0xA8
147 CmdSetMasterCfg EQU 0xAD
148 CmdSetDisplayOff EQU 0xAE
149 CmdSetDisplayOn EQU 0xAF
150
151 CmdSetPreChargeCompensationEnable EQU 0xB0
152 CmdSetPhaseLength EQU 0xB1
153 CmdSetRowPeriod EQU 0xB2
154 CmdSetClockDivide EQU 0xB3
155 CmdSetPreChargeCompensationLevel EQU 0xB4
156 CmdSetGrayScaleTable EQU 0xB8
157
158 CmdSetPreChargeVoltage EQU 0xBC
159 CmdSetVCOMH EQU 0xBE
160 CmdSetVSL EQU 0xBF
161 CmdNop EQU 0xE3
162
163 MOVLW LOW(CommandTable)
164 MOVWF TBLPTRL
165 MOVLW HIGH(CommandTable)
166 MOVWF TBLPTRH
167
168 MOVLW CommandTableEnd-CommandTable
169 MOVWF temp0
170
171 CommandLoop:
172 TBLRD *+
173 MOVF TABLAT,W
174 rcall SSD0323_WriteCmd
175 decfsz temp0,F
176 bra CommandLoop
177 if InterfaceMode == ModeSPI
178
179 ; In SPI mode, we need to wait for the command completes
180 ; before returning. The reason is that we may send data
181 ; just after this command. Sending data changes the DC
182 ; bit which in turn will screw up the command transfer.
183 CommandWaitForSPI:
184 MOVF SSPBUF,W
185 CommandSPIBusy:
186 BTFSS SSPSTAT,BF
187 bra CommandSPIBusy
188 endif
189 return
190
191 CommandTable:
192 db CmdSetColumnAddress, 0x00, 0x3f, CmdSetRowAddress, 0x00, 0x3f
193 db CmdSetContrast, 0x6d
194 db CmdSetFullCurrent, CmdSetRemap, 0x41, CmdSetDisplayStartLine
195 db 0x00, CmdSetDisplayOffset, 0x44, CmdSetNormalDisplay
196 db CmdSetMultiplexRatio, 0x3f
197 db CmdSetPhaseLength, 0x28
198 db CmdSetPreChargeCompensationLevel, 0x07
199 db CmdSetRowPeriod, 0x46
200 db CmdSetClockDivide, 0x91
201 db CmdSetVSL, 0x0d
202 db CmdSetVCOMH, 0x02
203 db CmdSetPreChargeVoltage, 0x10
204 db CmdSetGrayScaleTable, 0x01,0x11,0x22, 0x32, 0x43,0x54,0x65
205 db 0x76, CmdSetMasterCfg, 02, CmdSetDisplayOn
206 CommandTableEnd:
207
208
209 CommandSetCursorPosition:
210 db CmdSetColumnAddress, 0x00, 0x3f, CmdSetRowAddress, 0x00, 0x3f
211 CommandSetCursorPositionEnd:
212
213 ;------------------------------------------------------------
214 ; Write either a command or data to the SSD0323
215 ;
216 ; Inputs: WREG - byte to be written
217 ; Outputs:
218 ; Mem used: W
219 ;
220
221 if InterfaceMode == Mode8080
222
223 SSD0323_WriteCmd ;<--- Entry point to write a command.
224 BCF LCDDC_LAT, LCDDC_BIT
225
226 SSD0323_Write: ;<--- Entry point to write data.
227
228 BCF LCDRW_LAT, LCDRW_BIT ;SSD0323 WR#
229
230 MOVWF SSD0323_LAT
231
232 BSF LCDRW_LAT, LCDRW_BIT ;Rising edge writes the data
233 BSF LCDDC_LAT, LCDDC_BIT
234
235 return
236 endif
237
238 if InterfaceMode == Mode6800
239
240 SSD0323_WriteCmd ;<--- Entry point to write a command.
241 BCF LCDDC_LAT, LCDDC_BIT
242
243 SSD0323_Write: ;<--- Entry point to write data.
244
245 BCF LCDRW_LAT, LCDRW_BIT ;SSD0323 R/W line is low for writes
246
247 MOVWF SSD0323_LAT
248
249 BCF LCDE_LAT, LCDE_BIT ;Falling edge of E latches the data.
250 BRA $+2
251 BSF LCDE_LAT, LCDE_BIT ;Turn off the enable
252 BSF LCDDC_LAT, LCDDC_BIT
253
254 return
255 endif
256
257 if InterfaceMode == ModeSPI
258
259 SSD0323_WriteCmd ;<--- Entry point to write a command.
260 BCF LCDDC_LAT, LCDDC_BIT
261 BRA SSD0323_WriteSPI
262 SSD0323_Write: ;<--- Entry point to write data.
263
264 BSF LCDDC_LAT, LCDDC_BIT
265
266 SSD0323_WriteSPI:
267
268 MOVWF SSPBUF
269 btfss SSPCON1, WCOL
270 return
271
272 BCF SSPCON1, WCOL
273 bra SSD0323_WriteSPI
274
275 return
276 endif
277
278
279 d2 rcall d3
280 d3 return
281
282 delay: bra $+2
283 bra $+2
284 bra $+2
285 decfsz WREG,F
286 bra delay
287 return
288 ;------------------------------------------------------------------------
289 ;SSD_SetColumnRange - set the start and columns in the SSD0323
290 ; In addition, the width of the virtual display (in the PIC's ram)
291 ; is also initialized.
292 ;
293 ; Inputs: W - start column
294 ; temp0 - end column
295 ; Outputs: DisplaySizeX
296 ; MemUsed: None
297 ;
298 SSD_SetColumnRange:
299 GLOBAL SSD_SetColumnRange
300 MOVWF temp1
301 SUBWF temp0,W
302 ADDLW 1
303 MOVWF DisplaySizeX
304
305 CLRC
306 RRCF temp0,F
307 CLRC
308 RRCF temp1,F
309
310 MOVLW CmdSetColumnAddress
311 SSD_SetRowCol:
312 RCALL SSD0323_WriteCmd
313
314 MOVF temp1,W
315 RCALL SSD0323_WriteCmd
316
317 MOVF temp0,W
318 bra SSD0323_WriteCmd
319
320
321 SSD_SetRowRange:
322 GLOBAL SSD_SetRowRange
323 MOVWF temp1
324 SUBWF temp0,W
325 ADDLW 1
326 MOVWF DisplaySizeY
327
328 MOVLW CmdSetRowAddress
329
330 bra SSD_SetRowCol
331
332 ;------------------------------------------------------------------------
333 ;LCD_RefreshDisplay - copy the RAM buffered display to the physical display
334 ;
335 ; Inputs: None
336 ; Outputs: None
337 ; MemUsed: temp0
338 ;
339 ; The display buffer is organized differently than the physical display
340 ; Here is a graphical mapping:
341 ;
342 ; columns
343 ; 0 1 2 3 4 5 6 7 8
344 ; -----------------------------------
345 ; 0 | a0 b0 c0 d0 e0 f0 g0 h0 i0
346 ; 1 | a1 b1 c1 d1 e1 f1 g1 h1 i1
347 ; 2 | a2 b2 c2 d2 e2 f2 g2 h2 i2
348 ; R 3 | a3 b3 c3 d3 e3 f3 g3 h3 i3
349 ; O 4 | a4 b4 c4 d4 e4 f4 g4 h4 i4
350 ; W 5 | a5 b5 c5 d5 e5 f5 g5 h5 i5
351 ; S 6 | a6 b6 c6 d6 e6 f6 g6 h6 i6
352 ; 7 | a7 b7 c7 d7 e7 f7 g7 h7 i7
353 ; 8 | A0 B0 C0 D0 E0 F0 G0 H0 I0
354 ; 9 | A1 B1 C1 D1 E1 F1 G1 H1 I1
355 ;
356 ; The sequence of bytes in the PIC memory is:
357 ; a, b, c, and so on for the first 8 rows of pixels. The next 8 rows
358 ; begin with the A, B, C and so on bytes.
359 ;
360 ;
361
362 LCD_RefreshEntireDisplay:
363 MOVLW LOW(CommandSetCursorPosition)
364 MOVWF TBLPTRL
365 MOVLW HIGH(CommandSetCursorPosition)
366 MOVWF TBLPTRH
367
368 MOVLW CommandSetCursorPositionEnd-CommandSetCursorPosition
369 MOVWF temp0
370
371 call CommandLoop
372
373 LCD_RefreshDisplay:
374 LFSR 0, DisplayBuffer
375
376 MOVLW 0 ; row counter
377 MOVWF temp0
378
379 MOVLW 1
380 MOVWF temp2 ; bit mask
381
382 SSD_ref1:
383
384 ;row counter * number of columns
385 MOVF temp0,W
386 MULWF DisplaySizeX
387 ; MULLW LCD_nCOLS
388
389 LFSR 0, DisplayBuffer ;Get a pointer to the display
390 MOVF PRODL,W
391 ADDWF FSR0L,F
392 MOVF PRODH,W
393 ADDWFC FSR0H,F
394
395 ;MOVLW LCD_nCOLS/2 ; # of columns - 1 byte covers 2 columns
396 RRCF DisplaySizeX,W
397 ANDLW 0x7f
398 MOVWF temp1
399
400 SSD_ref2:
401 movf temp2,W ; Check a single pixel in the display
402 andwf POSTINC0,W ; buffer
403
404 movlw 0 ;Assume that the pixel is off
405 skpz ;
406 movlw 0xf0 ;Pixel was on- assign it the maximum color
407 movwf temp3 ;We now have the low order pixel.
408
409 movf temp2,W ;Check the pixel in the next column
410 andwf POSTINC0,W
411
412 movlw 0 ;Again, assume it's zero
413 skpz ;
414 movlw 0x0f ;Pixel is on
415 iorwf temp3,W ;We now have the high order pixel
416
417 rcall SSD0323_Write ;Write both pixels
418
419 DECFSZ temp1,F ;Have we gone through all of the columns?
420 bra SSD_ref2 ;... nope
421
422 ; next row
423 rlncf temp2,F ;Rotate the pixel mask
424 btfss temp2,0 ;Did we wrap around?
425 bra SSD_ref1 ;Nope,
426
427 incf temp0,F ;Display buffer row counter.
428
429 SWAPF temp0,W
430 RRNCF WREG,W
431 ADDLW 1
432 CPFSLT DisplaySizeY
433 bra SSD_ref1
434
435 return
436
437 ;------------------------------------------------------------
438
439 end