Debian Codegraph @

extras/graphic_lcd/examples/ssd0323/osram128x64.asm

raw
1 ;
2 ; osram128x64.asm - Driver for 128x64 pixel graphics LCD based on
3 ; SSD0323 controllers
4 ;
5 ;
6 ; From a high level point of view, this driver supports basic graphing
7 ; and text functions (that the SED1320 lacks). The graphing functions
8 ; include points and lines, while the text function allows 5X7 fonts
9 ; to be written to the display.
10 ;
11 ; !!! NOTE: The driver assumes all variables reside in Bank 0!. !!!
12
13 include "processor.inc"
14 include "ssd0323.inc"
15
16
17 ; GLOBAL DisplayBuffer
18 EXTERN DisplayBuffer
19 GLOBAL LCD_ClearScreen
20 GLOBAL SSD0323_Test
21 GLOBAL LCD_Line
22 GLOBAL LCD_putBitMap
23 GLOBAL LCD_ResetCursor
24 GLOBAL LCD_MoveCursor
25
26 EXTERN temp0, temp1, temp2, temp3
27
28 UDATA_ACS
29
30
31 LCD_WritePtrLo RES 1
32 LCD_WritePtrHi RES 1
33 PixelX RES 1
34 PixelY RES 1
35 TempX RES 1
36 TempY RES 1
37 global TempY, PixelX, PixelY
38
39 ; The virtual display (rendered in the PIC's ram) size is defined here:
40 DisplaySizeX RES 1
41 DisplaySizeY RES 1
42
43 global DisplaySizeX,DisplaySizeY
44
45 ;----------------------------------------
46 ; Private RAM area for temporary variables.
47
48 TempRam udata_ovr 0x78
49 LCD_Temporaries RES 6
50
51
52 TempRam udata_ovr 0x78
53
54 LCD_x2 RES 1
55 LCD_y2 RES 1
56 slope RES 1
57 dx RES 1
58 dy RES 1
59 dir RES 1
60
61 global LCD_x2, LCD_y2
62
63 ;------------------------------------------------------------------------
64 ; Display buffer
65 ;
66 ;GPR_ARRAYS UDATA 400
67 ;DisplayBuffer RES 100*4
68
69 ;------------------------------------------------------------------------
70 ;
71
72 LCD_CODE CODE
73
74
75 SSD0323_Test:
76
77
78 MOVLW 20
79 MOVWF PixelX
80 CLRF PixelY
81
82 MOVLW 2
83 RCALL LCD_putBitMap
84
85 CLRF PixelX
86 CLRF PixelY
87 MOVLW 93
88 MOVWF LCD_x2
89 CLRF LCD_y2
90
91 RCALL LCD_Line
92
93 MOVLW 31
94 MOVWF LCD_x2
95 MOVWF LCD_y2
96
97 RCALL LCD_Line
98
99 CLRF PixelX
100 CLRF PixelY
101 RCALL LCD_Line
102
103
104 bra LCD_RefreshDisplay
105
106
107
108 ;------------------------------------------------------------------------
109 ;LCD_ClearScreen
110
111 LCD_ClearScreen:
112
113 LFSR 0, DisplayBuffer ;Get a pointer to the display
114 SWAPF DisplaySizeY,W ;Y/16
115 RLNCF WREG,W ;Y/8
116 ANDLW 0x1f
117 MULWF DisplaySizeX
118 MOVFF PRODL,temp0
119 MOVF PRODH,W
120
121 cs1 CLRF POSTINC0
122 decfsz temp0,F
123 bra cs1
124 andlw 0xff
125 BZ LCS1
126 decfsz WREG,F
127 bra cs1
128 LCS1: return
129
130
131 ;------------------------------------------------------------------------
132 ; LCD_putBitMap
133 ;
134 ; Input: x1, y1 - Where the upper left hand corner of the bitmap will be placed
135 ; WREG - Bitmap # (i.e. index into the BitMapTable array)
136 ; Output
137 ; MemUsed: temp0 - used as a counter
138 ; PRODL,PRODH
139 ; TBLPTRL,TBLPTRH
140 ;
141 ; Calls: LCD_putByte
142
143 LCD_putBitMap:
144
145 ; Point to BitMapTable entry that contains the pointer
146 ; to the desired bitmap.
147
148 RLNCF WREG,W
149 ADDLW LOW(BitMapTable)
150 MOVWF TBLPTRL
151 MOVLW HIGH(BitMapTable)
152 SKPNC
153 ADDLW 1
154 MOVWF TBLPTRH
155
156 ; Get the pointer to the bitmap
157
158 TBLRD *+
159 MOVF TABLAT,W
160 TBLRD *+
161 MOVWF TBLPTRL
162 MOVF TABLAT,W
163 MOVWF TBLPTRH
164
165 ; The first byte of the bitmap is the width and the second is the height
166
167 TBLRD *+
168 MOVF TABLAT,W
169 MOVWF LCD_y2
170 TBLRD *+
171 MOVF TABLAT,W
172 MOVWF LCD_x2
173
174 ; At this point, the TBLPTR points to the bitmap data. Now we need
175 ; to fetch this data and copy it to the display.
176
177 movf PixelX,W
178 movwf temp1
179 rrncf PixelY,W
180 rrncf WREG,W
181 rrncf WREG,W
182 RCALL LCD_MoveCursor
183
184 pbm1:
185 MOVF LCD_y2,W
186 MOVWF temp0
187 pbm2:
188 TBLRD *+
189 MOVF TABLAT,W
190 RCALL LCD_PutByte
191 DECFSZ temp0,F
192 bra pbm2
193
194 MOVF LCD_y2,W
195 SUBLW 128
196 ADDWF LCD_WritePtrLo,F
197 CLRW
198 ADDWFC LCD_WritePtrHi,F
199
200 DECFSZ LCD_x2,F
201 bra pbm1
202
203 aret: RETURN
204 ;------------------------------------------------------------------------
205 ; LCD_putc
206 ;
207 ; Write a single character to the LCD display buffer. The input is the ASCII
208 ; code of the character to write. This is used as an index into the LCD font
209 ; table. The 5 7-bit bytes that comprise this character are then written to
210 ; the LCD display buffer. In addition, a 6th byte containing 0 is written so
211 ; that there will be a little space between characters. Note, the character
212 ; will be written at the current location of the cursor. No attempt is made
213 ; to prevent line wrapping.
214 ;
215 ; Input: WREG - ASCII value of character
216 ; Output: None
217 ; Mem used: temp0 - used as a counter
218 ;
219 LCD_putc:
220 global LCD_putc
221
222 BTFSC WREG,7 ;The max character is 127
223 return ;leave if we're beyond this.
224
225 ADDLW -' ' ;The first character in the table is a Space
226 BNC aret ;leave if the ascii code is smaller than this
227
228 MULLW 5 ;Each character is comprised of 5 bytes.
229 ;The offset into the table is the product
230 ;of the ASCII code and the size of each character
231 CLRF TBLPTRU ;Get a pointer to the
232 MOVF PRODL,W ;start of this character's font
233 ADDLW LOW(ASCII_5X7Table) ;
234 MOVWF TBLPTRL ;
235
236 MOVLW HIGH(ASCII_5X7Table) ;
237 ADDWFC PRODH,W
238 MOVWF TBLPTRH ;
239 ;
240 MOVLW 5 ; Now loop through and get all 5 bytes
241 MOVWF temp0
242 LCD_ASCII_L1
243 TBLRD *+ ;Get one byte
244 MOVF TABLAT,W ;
245 rcall LCD_PutByte ;Write the byte to the display buffer
246 decfsz temp0,F
247 bra LCD_ASCII_L1
248
249 MOVLW 0
250
251 ;;
252 ;; !!!! Intentionally fall through to write a zero to the display
253 ;;
254
255 ;------------------------------------------------------------------------
256 ; LCD_PutByte - write a byte of data to the LCD display buffer
257 ;
258 ; Write the byte contained in W to the display buffer. The byte is written
259 ; at the current cursor position. Also, the cursor position is incremented
260 ; after the write.
261 ;
262 ; INPUT: WREG
263 ; OUTPUT:
264 ; Mem Used: temp1
265 ; LCD_WritePtrLo/Hi
266 ; FSR0L/H
267
268 LCD_PutByte:
269
270 MOVWF temp1 ;Save the byte to write
271
272 LFSR 0, DisplayBuffer ;Get a pointer to the display
273 MOVF LCD_WritePtrLo,W ;Now point to the location
274 ADDWF FSR0L,F ;of the cursor.
275 MOVF LCD_WritePtrHi,W
276 ADDWFC FSR0H,F
277
278 MOVFF temp1, INDF0 ;Write the byte to the display
279
280 INFSNZ LCD_WritePtrLo,F ;Increment the cursor position
281 INCF LCD_WritePtrHi,F
282
283 MOVLW HIGH(128*64/8) ;The Display buffer is only 400
284 CPFSGT LCD_WritePtrHi ;bytes. If we didn't increment
285 return ;then we're okay.
286
287 ;;; Fall Through...
288
289 LCD_ResetCursor:
290 CLRF LCD_WritePtrHi ;oops - we've rolled over
291 CLRF LCD_WritePtrLo
292 return
293
294 ;------------------------------------------------------------------------
295 ; LCD_MoveCursor - re-position the cursor. The cursor marks where the next
296 ; byte will be written
297 ;
298 ; INPUT: WREG - row
299 ; temp1 - column
300 ; OUTPUT
301 ; MemUsed: LCD_WritePtrLo/HI
302 ; PRODL/H
303
304 LCD_MoveCursor:
305 ANDLW 7
306 MULLW 128
307 MOVF PRODL,W
308 MOVWF LCD_WritePtrLo
309 MOVF PRODH,W
310 MOVWF LCD_WritePtrHi
311
312 MOVF temp1,W
313 ADDWF LCD_WritePtrLo,F
314 CLRW
315 ADDWFC LCD_WritePtrHi,F
316 RETURN
317
318 ;------------------------------------------------------------------------
319 ; LCD_GetPixelPtr - convert the current (PixelX,PixelY) coordinates into
320 ; a pointer into the display buffer. This pointer is returned in FSR0
321 ; and the bit offset within the byte of the display buffer is returned
322 ; is returned as bit mask in temp0.
323 ;
324 ; {
325 ; temp0 = 1<<(PixelY & 7);
326 ;
327 ; int offset = (PixelY>>3) * nLCD_COLUMNS + PixelX
328 ; FSR0 = &DisplayBuffer[offset];
329 ; return(temp0);
330 ; }
331 ;
332 ; Input: PixelX = X location of the pixel
333 ; PixelY = Y location of the pixel
334 ; Output: FSR0L:FSR0H -- will point to the byte offset in the display buffer
335 ; temp0 -- 2^n where n is the position within the byte.
336 ;
337
338 LCD_GetPixelPtr:
339 RRCF PixelY,W ;Put the LSB of the current Y pixel into C.
340
341 CLRF temp0 ;
342 BSF temp0,0 ; 1<<0 -- assumes Y is even
343 SKPNC ;
344 RLNCF temp0,F ; 1<<1 -- Y is actually odd
345
346 RRCF WREG,W ;Put bit 1 of the current Y pixel into C
347 BNC pp1 ;
348 RLNCF temp0,F ; bit 1 is set, so we need to shift the
349 RLNCF temp0,F ; mask two positions
350
351 pp1: RRCF WREG,W ;Put bit 2 of the current Y pixel into C
352 SKPNC ;If it is set
353 SWAPF temp0,F ; then shift the mask left 4 positions.
354
355 ANDLW 7 ;The lower two bits of W are the 3rd and 4th
356 ;bit of the current Y pixel.
357 MULLW 128 ;Multiply by number of columns in a row
358 ;to obtain the byte offset into the buffer.
359
360 LFSR 0, DisplayBuffer ;Get a pointer to the display
361 MOVF PRODL,W
362 ADDWF FSR0L,F
363 MOVF PRODH,W
364 ADDWFC FSR0H,F
365
366 MOVF PixelX,W
367 ADDWF FSR0L,F
368 MOVLW 0
369 ADDWFC FSR0H,F
370 ret1:
371 return
372
373 ;------------------------------------------------------------------------
374 ; LCD_Line - Draw a line
375 ;
376 ; Inputs: PixelX, PixelY - start coordinates
377 ; LCD_x2, LCD_y2 - end coordinates
378 ;
379 ; Outputs: PixelX and PixelY will equal LCD_x2 and LCD_y2
380 ;
381 ; Algorithm:
382 ;
383 ; int dx = abs(x2-x1);
384 ; int dy = abs(y2-y1);
385 ;
386 ; int bRight = 1;
387 ; int bUp = 1;
388 ;
389 ; if (dx<0) {
390 ; bRight = 0;
391 ; dx = -dx;
392 ; }
393 ; if (dy<0) {
394 ; bUp = 0 ;
395 ; dy = -dY;
396 ; }
397 ;
398 ; int slope = dx - dy;
399 ;
400 ; do {
401 ;
402 ; SetPixel(x,y);
403 ;
404 ; if ( slope < 0) {
405 ; y++;
406 ; slope += dx;
407 ; } else {
408 ; x++;
409 ; slope -= dy;
410 ; }
411 ; } while (x!=x2 && y!=y2);
412 ;
413 ;
414 ; MEM Used:
415 ; dx
416 ; dy
417 ; slope
418 ; temp1
419 ; Calls:
420 ; LCD_SetPixel
421 ;
422 LCD_Line:
423
424
425 MOVF PixelX,W ;x1
426 SUBWF LCD_x2,W ;W=x2-x1
427 MOVWF dx ;dx=x2-x1
428 RLCF dir,F ;Pick up carry
429 BTFSS dir,0 ;if x2<x1
430 NEGF dx ; dx = x1-x2
431
432 MOVF PixelY,W ;y1
433 SUBWF LCD_y2,W ;W=y2-y1
434 MOVWF dy ;dy=y2-y1
435 RLCF dir,F ;Pick up carry
436 BTFSS dir,0 ;if y2<y1
437 NEGF dy ; dy = y1-y2
438
439 ; Initialize the slope accumulator to
440 ; slope = (dx-dy)/2
441 movf dy,W
442 subwf dx,w
443 rrcf WREG,F
444 xorlw 0x80
445 movwf slope
446
447
448 btfsc slope,7
449 bra LVertical
450 LHorizontal:
451 RCALL LCD_SetPixel ;Turn on (PixelX,PixelY)
452
453 movf PixelX,W
454 xorwf LCD_x2,W
455 bz aret
456 tstfsz slope
457 btfsc slope,7
458 rcall LVertStep
459 rcall LHoriStep
460 bra LHorizontal
461
462 LVertical:
463 RCALL LCD_SetPixel ;Turn on (PixelX,PixelY)
464 ; rcall LCD_RefreshDisplay
465 movf PixelY,W
466 xorwf LCD_y2,W
467 bz aret
468 btfss slope,7
469 rcall LHoriStep
470 rcall LVertStep
471 bra LVertical
472
473
474 LHoriStep:
475 movf dy,W
476 subwf slope,F
477 btfsc dir,1
478 incf PixelX,F
479 btfss dir,1
480 decf PixelX,F
481 return
482
483 LVertStep:
484 movf dx,W
485 addwf slope,F
486 btfsc dir,0
487 incf PixelY,F
488 btfss dir,0
489 decf PixelY,F
490 return
491
492 ;
493 ;------------------------------------------------------------------------
494 ; LCD_SetPixel - turn on a single Pixel
495 ;
496 ; Inputs:
497 ; PixelX - X coordinate
498 ; PixelY - Y coordinate
499 ;
500 ; Outputs
501 ; Mem Used:
502 ; temp0
503 ; Calls
504 ; LCD_GetPixelPtr
505 LCD_SetPixel:
506 RCALL LCD_GetPixelPtr
507 MOVF temp0,W
508 IORWF INDF0,F
509 return
510
511 ;------------------------------------------------------------------------
512 ; LCD_ClearPixel - turn off a single Pixel
513
514 LCD_ClearPixel:
515 RCALL LCD_GetPixelPtr
516 COMF temp0,W
517 ANDWF INDF0,F
518 return
519
520 ;========================================================================
521 LCD_TABLES CODE 0x3000
522
523 ;------------------------------------------------------------------------
524 ; This ASCII table contains the 5X7 font for characters 32-127. It was
525 ; created from a modified version of the perl script that is distributed
526 ; with gpsim's LCD module.
527 ASCII_5X7Table:
528 db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00 ; 32, 33
529 db 0x00, 0x07, 0x00, 0x07, 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 ; 34, 35
530 db 0x24, 0x2a, 0x7f, 0x2a, 0x12, 0x23, 0x13, 0x08, 0x64, 0x62 ; 36, 37
531 db 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x05, 0x03, 0x00, 0x00 ; 38, 39
532 db 0x00, 0x1c, 0x22, 0x41, 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 ; 40, 41
533 db 0x14, 0x08, 0x3e, 0x08, 0x14, 0x08, 0x08, 0x3e, 0x08, 0x08 ; 42, 43
534 db 0x00, 0x50, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 ; 44, 45
535 db 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 ; 46, 47
536 db 0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, 0x42, 0x7f, 0x40, 0x00 ; 48, 49
537 db 0x42, 0x61, 0x51, 0x49, 0x46, 0x21, 0x41, 0x45, 0x4b, 0x31 ; 50, 51
538 db 0x18, 0x14, 0x12, 0x7f, 0x10, 0x27, 0x45, 0x45, 0x45, 0x39 ; 52, 53
539 db 0x3c, 0x4a, 0x49, 0x49, 0x30, 0x01, 0x71, 0x09, 0x05, 0x03 ; 54, 55
540 db 0x36, 0x49, 0x49, 0x49, 0x36, 0x06, 0x49, 0x49, 0x29, 0x1e ; 56, 57
541 db 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 ; 58, 59
542 db 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 ; 60, 61
543 db 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 ; 62, 63
544 db 0x32, 0x49, 0x79, 0x41, 0x3e, 0x7e, 0x11, 0x11, 0x11, 0x7e ; 64, 65
545 db 0x7f, 0x49, 0x49, 0x49, 0x36, 0x3e, 0x41, 0x41, 0x41, 0x22 ; 66, 67
546 db 0x7f, 0x41, 0x41, 0x41, 0x3e, 0x7f, 0x49, 0x49, 0x49, 0x41 ; 68, 69
547 db 0x7f, 0x09, 0x09, 0x09, 0x01, 0x3e, 0x41, 0x49, 0x49, 0x7a ; 70, 71
548 db 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x41, 0x7f, 0x41, 0x00 ; 72, 73
549 db 0x20, 0x40, 0x41, 0x3f, 0x01, 0x7f, 0x08, 0x14, 0x22, 0x41 ; 74, 75
550 db 0x7f, 0x40, 0x40, 0x40, 0x40, 0x7f, 0x01, 0x02, 0x01, 0x7f ; 76, 77
551 db 0x7f, 0x04, 0x08, 0x10, 0x7f, 0x3e, 0x41, 0x41, 0x41, 0x3e ; 78, 79
552 db 0x7f, 0x09, 0x09, 0x09, 0x06, 0x3e, 0x41, 0x51, 0x21, 0x5e ; 80, 81
553 db 0x7f, 0x09, 0x19, 0x29, 0x46, 0x46, 0x49, 0x49, 0x49, 0x31 ; 82, 83
554 db 0x01, 0x01, 0x7f, 0x01, 0x01, 0x3f, 0x40, 0x40, 0x40, 0x3f ; 84, 85
555 db 0x1f, 0x20, 0x40, 0x20, 0x1f, 0x3f, 0x40, 0x38, 0x40, 0x3f ; 86, 87
556 db 0x63, 0x14, 0x08, 0x14, 0x63, 0x07, 0x08, 0x70, 0x08, 0x07 ; 88, 89
557 db 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x7f, 0x41, 0x41, 0x00 ; 90, 91
558 db 0x15, 0x16, 0x7c, 0x16, 0x15, 0x00, 0x41, 0x41, 0x7f, 0x00 ; 92, 93
559 db 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40 ; 94, 95
560 db 0x00, 0x01, 0x02, 0x04, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 ; 96, 97
561 db 0x7f, 0x48, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x20 ; 98, 99
562 db 0x38, 0x44, 0x44, 0x48, 0x7f, 0x38, 0x54, 0x54, 0x54, 0x18 ; 100, 101
563 db 0x08, 0x7e, 0x09, 0x01, 0x02, 0x06, 0x49, 0x49, 0x49, 0x3f ; 102, 103
564 db 0x7f, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7d, 0x40, 0x00 ; 104, 105
565 db 0x20, 0x40, 0x42, 0x3f, 0x00, 0x7f, 0x10, 0x28, 0x44, 0x00 ; 106, 107
566 db 0x00, 0x41, 0x7f, 0x40, 0x00, 0x7c, 0x04, 0x18, 0x04, 0x78 ; 108, 109
567 db 0x7c, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38 ; 110, 111
568 db 0x7c, 0x14, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, 0x18, 0x7c ; 112, 113
569 db 0x7c, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24 ; 114, 115
570 db 0x02, 0x3f, 0x42, 0x40, 0x20, 0x3c, 0x40, 0x40, 0x20, 0x7c ; 116, 117
571 db 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x3c, 0x40, 0x30, 0x40, 0x3c ; 118, 119
572 db 0x44, 0x28, 0x10, 0x28, 0x44, 0x0c, 0x50, 0x50, 0x50, 0x3c ; 120, 121
573 db 0x44, 0x64, 0x54, 0x4c, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00 ; 122, 123
574 db 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00 ; 124, 125
575 db 0x08, 0x08, 0x2a, 0x1c, 0x08, 0x08, 0x1c, 0x2a, 0x08, 0x08 ; 126, 127
576
577
578 ; Include the bitmaps.
579
580 include "bitmaps.asm"
581
582 end