0
|
1 ;=============================================================================
|
|
2 ;
|
|
3 ; File tft.asm
|
|
4 ;
|
|
5 ; Managing the TFT screen
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code.
|
|
11
|
|
12 #include "ostc3.inc"
|
|
13 #include "wait.inc"
|
|
14 #include "varargs.inc"
|
|
15 #include "external_flash.inc"
|
|
16 #include "tft_outputs.inc"
|
|
17 #include "eeprom_rs232.inc"
|
|
18
|
|
19 ;=============================================================================
|
|
20 ; TFT_frame needs to backup coordinates.
|
|
21 CBLOCK tmp
|
|
22 save_top
|
|
23 save_height
|
|
24 save_left
|
|
25 save_width
|
|
26 ds_line ; Current line (0..239).
|
|
27 ds_column ; Current columnx2 (0..159)
|
|
28 ds_pixel:2 ; Current pixel color.
|
|
29 ds_count ; Repetition count.
|
|
30 ENDC
|
|
31
|
|
32 ;=============================================================================
|
|
33 ; Basic bit-level macros
|
|
34
|
|
35 RD_H macro
|
|
36 bsf tft_rd,0
|
|
37 endm
|
|
38
|
|
39 RD_L macro
|
|
40 bcf tft_rd,0
|
|
41 endm
|
|
42
|
|
43 RS_H macro
|
|
44 bsf tft_rs,0
|
|
45 endm
|
|
46
|
|
47 RS_L macro
|
|
48 bcf tft_rs,0
|
|
49 endm
|
|
50
|
|
51 NCS_H macro
|
|
52 bsf tft_cs,0
|
|
53 endm
|
|
54
|
|
55 NCS_L macro
|
|
56 bcf tft_cs,0
|
|
57 endm
|
|
58
|
|
59 WR_H macro
|
|
60 bsf tft_nwr,0
|
|
61 endm
|
|
62
|
|
63 WR_L macro
|
|
64 bcf tft_nwr,0
|
|
65 endm
|
|
66
|
|
67 ;=============================================================================
|
|
68 ; Byte-leve macros
|
|
69 ;
|
|
70 Index_out macro low_b
|
|
71 movlw low_b
|
|
72 rcall TFT_CmdWrite
|
|
73 endm
|
|
74
|
|
75 Parameter_out macro high_b, low_b
|
|
76 movlw high_b
|
|
77 movwf PORTA ; Upper
|
|
78 movlw low_b
|
|
79 rcall TFT_DataWrite
|
|
80 endm
|
|
81
|
|
82
|
|
83 basic CODE
|
|
84
|
|
85
|
|
86 ;=============================================================================
|
|
87 ; TFT_write_flash_image
|
|
88 ;
|
|
89 ; Inputs: FSR2 = EEPROM address / 256
|
|
90 ; win_left, win_top : imagte CENTER position
|
|
91 ; Outputs: win_height, win_width.
|
|
92 ; image copyed on screen.
|
|
93 ; Trashed: PROD, hi, lo
|
|
94 ;
|
|
95 global TFT_write_flash_image
|
|
96 TFT_write_flash_image:
|
|
97 ; Get back the full 24bit EEPROM address
|
|
98 clrf ext_flash_address+0
|
|
99 movff FSR2L,ext_flash_address+1
|
|
100 movf FSR2H,W
|
|
101 iorlw 0x30
|
|
102 movwf ext_flash_address+2
|
|
103
|
|
104 ; Read header: width and height
|
|
105 global TFT_write_flash_image_addr
|
|
106 TFT_write_flash_image_addr:
|
|
107 call ext_flash_read_block_start
|
|
108 movff SSP2BUF,win_width+0
|
|
109 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
110 btfss SSP2STAT, BF ; Next byte ready ?
|
|
111 bra $-2 ; NO: wait...
|
|
112 movff SSP2BUF,win_width+1
|
|
113 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
114 btfss SSP2STAT, BF ; Next byte ready ?
|
|
115 bra $-2 ; NO: wait...
|
|
116 movff SSP2BUF,win_height
|
|
117 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
118 btfss SSP2STAT, BF ; Next byte ready ?
|
|
119 bra $-2 ; NO: wait...
|
|
120 movff SSP2BUF,WREG ; drop 4th byte.
|
|
121 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
122 btfss SSP2STAT, BF ; Next byte ready ?
|
|
123 bra $-2 ; NO: wait...
|
|
124
|
|
125 ; Sanity check on header to avoid badly uploaded images.
|
|
126 iorwf WREG ; Check height < 256
|
|
127 bnz TFT_write_flash_image_failed
|
|
128 movf win_width+1,W ; Check width < 512
|
|
129 andlw 0xFE
|
|
130 bnz TFT_write_flash_image_failed
|
|
131
|
|
132 ; Center image on win_top, win_left values
|
|
133 bcf STATUS,C ; Clear carry
|
|
134 rrcf win_height,W ; And get height/2
|
|
135 subwf win_top,F ; top -= height/2
|
|
136 rrcf win_width+1,W ; Get 9th bit into carry
|
|
137 rrcf win_width+0,W ; Get width/2 (in 0..320 range)
|
|
138 bcf STATUS,C
|
|
139 rrcf WREG,W ; Get width/2 in 0..160 range
|
|
140 subwf win_leftx2,F ; left -= width/2
|
|
141
|
|
142 rcall TFT_box_write ; Inputs : win_top, win_leftx2, win_height, win_width(in 1..320 range)
|
|
143
|
|
144 ; Compute number of pixels to move (result on 17 bits !)
|
|
145 clrf TBLPTRU
|
|
146 movf win_width+0,W
|
|
147 mulwf win_height ; Result in PRODL:H
|
|
148 movf win_width+1,W
|
|
149 bz TFT_write_flash_image_1 ; width > 8bits ?
|
|
150 movf win_height,W ; YES: add extra
|
|
151 addwf PRODH,F
|
|
152 rlcf TBLPTRU ; And carry into upper register.
|
|
153 TFT_write_flash_image_1:
|
|
154 incf PRODH,F ; Pre-condition nested loops
|
|
155 incf TBLPTRU,F
|
|
156
|
|
157 ; Write pixels
|
|
158 Index_out 0x22 ; Frame Memory Data Write start
|
|
159 RS_H ; Data
|
|
160
|
|
161 TFT_write_flash_image_loop:
|
|
162 btfss SSP2STAT, BF ; Buffer full?
|
|
163 bra $-2 ; NO: wait...
|
|
164 movff SSP2BUF,PORTH ; Read lo
|
|
165 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
166
|
|
167 btfss SSP2STAT, BF ; Buffer full?
|
|
168 bra $-2 ; NO: wait...
|
|
169 movff SSP2BUF,PORTA ; And read hi
|
|
170 movwf SSP2BUF ; Write to buffer to initiate new read
|
|
171 WR_L
|
|
172 WR_H ; Write 1 Pixel
|
|
173
|
|
174 decfsz PRODL,F
|
|
175 bra TFT_write_flash_image_loop
|
|
176 decfsz PRODH,F
|
|
177 bra TFT_write_flash_image_loop
|
|
178 decfsz TBLPTRU,F
|
|
179 bra TFT_write_flash_image_loop
|
|
180
|
|
181 btfss SSP2STAT, BF ; Buffer full?
|
|
182 bra $-2 ; No, wait
|
|
183 movf SSP2BUF,W ; Read dummy byte
|
|
184
|
|
185 bsf flash_ncs ; CS=1
|
|
186 movlw 0x00 ; NOP, to stop window mode
|
|
187 bra TFT_CmdWrite ; This routine "returns"
|
|
188
|
|
189 ;---- Draw a 4x4 red square in place of missing images...
|
|
190 TFT_write_flash_image_failed:
|
|
191 movlw -1
|
|
192 addwf win_leftx2,F
|
|
193 movlw -2
|
|
194 addwf win_top,F
|
|
195 movlw 2
|
|
196 movwf win_width+0
|
|
197 clrf win_width+1
|
|
198 movlw 4
|
|
199 movwf win_height
|
|
200 movlw color_red
|
|
201 rcall TFT_set_color
|
|
202 goto TFT_box
|
|
203
|
|
204 ;=============================================================================
|
|
205 ;
|
|
206
|
|
207 global TFT_CmdWrite
|
|
208 TFT_CmdWrite:
|
|
209 RS_L ; Command
|
|
210 clrf PORTA ; Upper
|
|
211 movwf PORTH ; Lower
|
|
212 WR_L
|
|
213 WR_H ; Tick
|
|
214 return;
|
|
215
|
|
216 global TFT_DataWrite
|
|
217 TFT_DataWrite:
|
|
218 RS_H ; Data
|
|
219 movwf PORTH ; Lower
|
|
220 WR_L
|
|
221 WR_H ; Tick
|
|
222 return
|
|
223
|
|
224 ;=============================================================================
|
|
225 ;
|
|
226 global TFT_ClearScreen
|
|
227 TFT_ClearScreen:
|
|
228 Index_out 0x50 ; Window Horizontal Start Address
|
|
229 Parameter_out 0x00, 0x00 ; 0-239
|
|
230 Index_out 0x51 ; Window Horizontal End Address
|
|
231 Parameter_out 0x00, 0xEF ; 0-239
|
|
232 Index_out 0x52 ; Window Vertical Start Address
|
|
233 Parameter_out 0x00, 0x00 ; 0-319
|
|
234 Index_out 0x53 ; Window Vertical End Address
|
|
235 Parameter_out 0x01, 0x3F ; 0-319
|
|
236 Index_out 0x20 ; Frame Memory Horizontal Address
|
|
237 Parameter_out 0x00, 0x00 ; 0-239
|
|
238 Index_out 0x21 ; Frame Memory Vertical Address
|
|
239 Parameter_out 0x01, 0x3F ; 0-319
|
|
240
|
|
241 Index_out 0x22 ; Frame Memory Data Write start
|
|
242
|
|
243 RD_H ; Not Read
|
|
244 RS_H ; Data
|
|
245 NCS_L ; Not CS
|
|
246 clrf PORTA ; Data Upper
|
|
247 clrf PORTH ; Data Lower
|
|
248
|
|
249 movlw d'10'
|
|
250 movwf tft_temp3
|
|
251 TFT_ClearScreen2:
|
|
252 movlw d'30'
|
|
253 movwf tft_temp2
|
|
254 TFT_ClearScreen3:
|
|
255 clrf tft_temp1 ; 30*10*256=76800 Pixels -> Clear complete 240*320
|
|
256 TFT_ClearScreen4:
|
|
257 WR_L
|
|
258 WR_H ; Tick
|
|
259 decfsz tft_temp1,F
|
|
260 bra TFT_ClearScreen4
|
|
261 decfsz tft_temp2,F
|
|
262 bra TFT_ClearScreen3
|
|
263 decfsz tft_temp3,F
|
|
264 bra TFT_ClearScreen2
|
|
265 return
|
|
266
|
|
267 ;=============================================================================
|
|
268 ;
|
|
269 global TFT_DisplayOff
|
|
270 TFT_DisplayOff:
|
|
271 clrf CCPR1L ; PWM OFF
|
|
272 clrf PORTA
|
|
273 clrf PORTH
|
|
274 RD_L ; LOW
|
|
275 nop
|
|
276 RS_L ; LOW
|
|
277 bcf tft_nwr
|
|
278 nop
|
|
279 bcf tft_cs
|
|
280 nop
|
|
281 bcf tft_nreset
|
|
282 WAITMS d'1'
|
|
283 bsf tft_power ; inverted...
|
|
284 bcf lightsen_power ; power-down light sensor
|
|
285 return
|
|
286
|
|
287 ; -----------------------------
|
|
288 ; TFT boot
|
|
289 ; -----------------------------
|
|
290 global TFT_boot
|
|
291 TFT_boot:
|
|
292 clrf PORTA
|
|
293 clrf PORTH
|
|
294 RD_L ; LOW
|
|
295 bcf tft_nwr
|
|
296 nop
|
|
297 bcf tft_cs
|
|
298 nop
|
|
299 bcf tft_nreset
|
|
300 WAITMS d'1'
|
|
301 bcf tft_power ; inverted...
|
|
302 WAITMS d'1'
|
|
303
|
|
304 RD_H ; Keep high
|
|
305 WR_H ;
|
|
306 NCS_L ; Not CS
|
|
307
|
|
308 WAITMS d'2'
|
|
309 bsf tft_nreset
|
|
310 WAITMS d'150'
|
|
311 bsf lightsen_power ; Supply power to light sensor
|
|
312
|
|
313 ; Data Transfer Synchronization
|
|
314 Parameter_out 0x00, 0x00
|
|
315 Parameter_out 0x00, 0x00
|
|
316
|
|
317 ; Init through config table...
|
|
318 movlw LOW display0_config_table
|
|
319 movwf TBLPTRL
|
|
320 movlw HIGH display0_config_table
|
|
321 movwf TBLPTRH
|
|
322 movlw UPPER display0_config_table
|
|
323 movwf TBLPTRU
|
|
324 rcall display0_init_loop
|
|
325
|
|
326 Index_out 0x22
|
|
327 ; WAITMS d'81' ; 46
|
|
328 call TFT_ClearScreen
|
|
329 Index_out 0x07
|
|
330 Parameter_out 0x01, 0x00
|
|
331 return
|
|
332
|
|
333
|
|
334 display0_config_table:
|
|
335 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end
|
|
336 db 0xA4,0x00,0x01,0xFF,.002,0x00
|
|
337 db 0x09,0x00,0x01,0x92,0x04,0x00
|
|
338 db 0x93,0x04,0x02,0x94,0x00,0x02
|
|
339 db 0x07,0x00,0x00,0x10,0x04,0x30
|
|
340 db 0x11,0x02,0x37,0x12,0x11,0x8D
|
|
341 db 0x13,0x11,0x00,0x01,0x01,0x00
|
|
342 db 0x02,0x02,0x00,0x03,0x50,0x20
|
|
343 db 0x0A,0x00,0x08,0x0D,0x00,0x00
|
|
344 db 0x0E,0x00,0x30,0xFF,.151,0x00
|
|
345 db 0x12,0x11,0xBD,0x20,0x00,0x00
|
|
346 db 0x21,0x00,0x00,0x30,0x06,0x02
|
|
347 db 0x31,0x56,0x0D,0x32,0x05,0x07
|
|
348 db 0x33,0x06,0x09,0x34,0x00,0x00
|
|
349 db 0x35,0x09,0x06,0x36,0x57,0x05
|
|
350 db 0x37,0x0D,0x06,0x38,0x02,0x06
|
|
351 db 0x39,0x00,0x00,0xFF,0x00,0x00
|
|
352
|
|
353 display0_init_loop:
|
|
354 TBLRD*+
|
|
355 movlw 0xFF
|
|
356 cpfseq TABLAT
|
|
357 bra display0_config_write ; Write Config pair to Display
|
|
358 ; Delay ms or quit (return)
|
|
359 TBLRD*+
|
|
360 tstfsz TABLAT ; End of config?
|
|
361 bra $+4 ; No
|
|
362 return ; Done.
|
|
363 movf TABLAT,W
|
|
364 call WAITMSX ; Wait WREG milliseconds
|
|
365 TBLRD*+ ; Dummy read (Third byte of delay command)
|
|
366 bra display0_init_loop ; Loop
|
|
367
|
|
368 display0_config_write: ; With command in WREG
|
|
369 movf TABLAT,W
|
|
370 rcall TFT_CmdWrite ; Write command
|
|
371 TBLRD*+ ; Get config0
|
|
372 movff TABLAT,PORTA
|
|
373 TBLRD*+ ; Get config1
|
|
374 movf TABLAT,W
|
|
375 rcall TFT_DataWrite ; Write config
|
|
376 bra display0_init_loop ; Loop
|
|
377
|
|
378
|
|
379 ;=============================================================================
|
|
380 ; Smooth lighting-up of the display:
|
|
381 ;
|
|
382 ; Trashes: WREG, PRODL
|
|
383 ; Typical usage:
|
|
384 ; clrf CCPR1L ; Backlight off
|
|
385 ; [draw splash screen]
|
|
386 ; call TFT_DisplayFadeIn
|
|
387 ;
|
|
388 global TFT_Display_FadeIn
|
|
389 TFT_Display_FadeIn:
|
|
390 movlw CCP1CON_VALUE ; See ostc3.inc
|
|
391 movwf CCP1CON
|
|
392 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor!
|
|
393 clrf CCPR1L ; Backlight off - to be sure
|
|
394 movff max_CCPR1L,PRODL
|
|
395 TFT_Display_FadeIn_0:
|
|
396 incf CCPR1L,F ; Duty cycle
|
|
397 WAITMS d'2'
|
|
398 decfsz PRODL,F
|
|
399 bra TFT_Display_FadeIn_0
|
|
400 bcf tft_is_dimming ; dimming done.
|
|
401 return
|
|
402
|
|
403 ;=============================================================================
|
|
404 ; Smooth lighting-off of the display:
|
|
405 ; Trashes: WREG, PRODL
|
|
406 global TFT_Display_FadeOut
|
|
407 TFT_Display_FadeOut:
|
|
408 movff max_CCPR1L,PRODL
|
|
409 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor!
|
|
410 TFT_Display_FadeOut_0:
|
|
411 movff PRODL,CCPR1L ; Duty cycle
|
|
412 WAITMS d'1'
|
|
413 decfsz PRODL,F
|
|
414 bra TFT_Display_FadeOut_0
|
|
415 clrf CCPR1L
|
|
416 return
|
|
417
|
|
418 ;=============================================================================
|
|
419
|
|
420 global box_std_block, box_black_block, box_color_block
|
|
421
|
|
422 box_std_block: ; Use white color
|
|
423 setf WREG
|
|
424 bra box_common
|
|
425 box_black_block: ; Use black color
|
|
426 clrf WREG
|
|
427 box_common:
|
|
428 box_color_block:
|
|
429 rcall TFT_set_color
|
|
430 VARARGS_BEGIN
|
|
431 VARARGS_GET8 win_top
|
|
432 VARARGS_GET8 win_height
|
|
433 VARARGS_GET8 win_leftx2
|
|
434 VARARGS_GET8 win_width
|
|
435 VARARGS_END
|
|
436 bra TFT_box
|
|
437
|
|
438 ;-----------------------------------------------------------------------------
|
|
439
|
|
440 global box_frame_std, box_frame_common, box_frame_color, box_frame_color16
|
|
441
|
|
442 box_frame_std:
|
|
443 setf WREG
|
|
444 rcall TFT_set_color
|
|
445
|
|
446 box_frame_common:
|
|
447 VARARGS_BEGIN
|
|
448 VARARGS_GET8 win_top
|
|
449 VARARGS_GET8 win_height
|
|
450 VARARGS_GET8 win_leftx2
|
|
451 VARARGS_GET8 win_width
|
|
452 VARARGS_END
|
|
453 bra TFT_frame
|
|
454
|
|
455 box_frame_color:
|
|
456 rcall TFT_set_color
|
|
457 box_frame_color16:
|
|
458 bra box_frame_common
|
|
459
|
|
460 ;=============================================================================
|
|
461 ; Init for half_pixel_write
|
|
462 ; Set column register on TFT device, and current color.
|
|
463 ; Inputs: win_leftx2
|
|
464 ; Outputs: win_color:2
|
|
465 ; Trashed: WREG, PROD
|
|
466 global init_pixel_write
|
|
467 init_pixel_write:
|
|
468 movff win_leftx2,WREG
|
|
469 mullw 2
|
|
470 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
471 setf WREG
|
|
472 bra TFT_set_color
|
|
473
|
|
474 ;-----------------------------------------------------------------------------
|
|
475 ; Writes two half-pixels at position (win_top,win_leftx2)
|
|
476 ; Inputs: win_leftx2, win_top, win_color:2
|
|
477 ; Trashed: WREG, PROD
|
|
478 global pixel_write
|
|
479 pixel_write:
|
|
480 movff win_leftx2,WREG
|
|
481 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL
|
|
482 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
483 rcall half_pixel_write ; Write this half-one.
|
|
484
|
|
485 movff win_leftx2,WREG ; Address of next one
|
|
486 mullw 2
|
|
487 infsnz PRODL ; +1
|
|
488 incf PRODH
|
|
489 rcall pixel_write_col320
|
|
490 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because
|
|
491 ; of the autoincrement going vertical
|
|
492
|
|
493 global pixel_write_col320
|
|
494 pixel_write_col320:
|
|
495 Index_out 0x21 ; Frame Memory Vertical Address
|
|
496 bra TFT_DataWrite_PROD
|
|
497
|
|
498 ;-----------------------------------------------------------------------------
|
|
499 ; Writes one half-pixel at position (win_top,win_leftx2).
|
|
500 ; Inputs: win_leftx2, win_top, win_color:2
|
|
501 ; Trashed: WREG, PROD
|
|
502 global half_pixel_write
|
|
503 half_pixel_write:
|
|
504 movff win_top,WREG ; d'0' ... d'239'
|
|
505 ; Variant with Y position in WREG.
|
|
506 half_pixel_write_1:
|
|
507 sublw .239 ; 239-Y --> Y
|
|
508
|
|
509 mullw 1 ; Copy row to PRODH:L
|
|
510 Index_out 0x20 ; Frame Memory Horizontal Address
|
|
511 rcall TFT_DataWrite_PROD
|
|
512
|
|
513 Index_out 0x22 ; Frame Memory Data Write start
|
|
514 RS_H ; Data
|
|
515 movff win_color1,PORTA ; Upper
|
|
516 movff win_color2,PORTH ; Lower
|
|
517 WR_L
|
|
518 WR_H ; Tick
|
|
519 return
|
|
520
|
|
521 ;-----------------------------------------------------------------------------
|
|
522 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height).
|
|
523 ; Inputs: win_leftx2, win_top, win_height, win_color:2
|
|
524 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
|
|
525 global half_vertical_line
|
|
526 half_vertical_line:
|
|
527 clrf TABLAT ; Loop index.
|
|
528
|
|
529 half_vertical_line_loop:
|
|
530 movff win_leftx2,WREG ; Init X position.
|
|
531 mullw 2
|
|
532 movf TABLAT,W ; Get loop index
|
|
533 andlw 1 ; Just low bit
|
|
534 xorwf PRODL,F ; And use it to jitter current X position
|
|
535 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
536
|
|
537 movff win_height,WREG ; Index reached height (Bank0 read) ?
|
|
538 xorwf TABLAT,W
|
|
539 btfsc STATUS,Z ; Equals ?
|
|
540 return ; Yes: done.
|
|
541 movff win_top,WREG ; Y = top + index (Bank0 read)
|
|
542 addwf TABLAT,W
|
|
543 rcall half_pixel_write_1
|
|
544 incf TABLAT,F ; index++
|
|
545 bra half_vertical_line_loop
|
|
546
|
|
547 ;-----------------------------------------------------------------------------
|
|
548 ; Writes a horizontal line of half-pixel at position (win_top,win_leftx2,win_width).
|
|
549 ; Inputs: win_leftx2, win_top, win_width, win_color:2
|
|
550 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
|
|
551 global half_horizontal_line
|
|
552 half_horizontal_line:
|
|
553 clrf TABLAT ; Loop index.
|
|
554
|
|
555 half_horizontal_line_loop:
|
|
556 movff win_leftx2,WREG ; Init X position.
|
|
557 mullw 2
|
|
558 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
559 movff win_width,WREG ; Index reached height (Bank0 read) ?
|
|
560 xorwf TABLAT,W
|
|
561 btfsc STATUS,Z ; Equals ?
|
|
562 return ; Yes: done.
|
|
563 movff win_top,WREG ; Y = top + index (Bank0 read)
|
|
564 addwf TABLAT,W
|
|
565 rcall half_pixel_write_1
|
|
566 incf TABLAT,F ; index++
|
|
567 bra half_horizontal_line_loop
|
|
568
|
|
569
|
|
570 ;-----------------------------------------------------------------------------
|
|
571 ; TFT Data Cmd via W
|
|
572 ;
|
|
573 global TFT_DataWrite_PROD
|
|
574 TFT_DataWrite_PROD:
|
|
575 ; RD_H ; Keep high
|
|
576 RS_H ; Data
|
|
577 movff PRODH,PORTA ; Move high byte to PORTA
|
|
578 movff PRODL,PORTH ; Move low byte to PORTH
|
|
579 WR_L
|
|
580 WR_H ; Tick
|
|
581 return
|
|
582
|
|
583 TFT_DataRead_PROD:
|
|
584 Index_out 0x22 ; Frame Memory Data Read start
|
|
585 setf TRISA ; PortA as input.
|
|
586 setf TRISH ; PortH as input.
|
|
587 RS_H ; Data
|
|
588 WR_H ; Not write
|
|
589 RD_L ; Read!
|
|
590 nop
|
|
591 nop
|
|
592 nop
|
|
593 RD_H ; Tick
|
|
594 nop
|
|
595 RD_L ; Read!
|
|
596 nop
|
|
597 nop
|
|
598 nop
|
|
599 movff PORTA,PRODH
|
|
600 movff PORTH,PRODL
|
|
601 RD_H ; Tick
|
|
602 nop
|
|
603 clrf TRISA ; PortA as output
|
|
604 clrf TRISH ; PortH as output
|
|
605 return
|
|
606
|
|
607
|
|
608
|
|
609 ;=============================================================================
|
|
610 ; Output TFT Window Address commands.
|
|
611 ; Inputs : win_top, win_leftx2, win_height, win_width.
|
|
612 ; Output : PortA/PortH commands.
|
|
613 ; Trashed: PROD
|
|
614 ;
|
|
615 global TFT_box_write
|
|
616 TFT_box_write:
|
|
617 movff win_leftx2,WREG ; Compute left = 2*leftx2 --> PROD
|
|
618 mullw 2
|
|
619
|
83
|
620 global TFT_box_write_16bit_win_left
|
|
621 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH
|
0
|
622 ;---- Normal horizontal window ---------------------------------------
|
|
623 ; Output 0x35 left,
|
|
624 ; 0x36 right == left + width - 1.
|
|
625
|
|
626 Index_out 0x52 ; Window Vertical Start Address
|
|
627 rcall TFT_DataWrite_PROD ; Output left
|
|
628 Index_out 0x21 ; Frame Memory Vertical Address
|
|
629 rcall TFT_DataWrite_PROD ; Output left
|
|
630
|
|
631 movff win_width+0,WREG ; right = left + width - 1
|
|
632 addwf PRODL,F
|
|
633 movff win_width+1,WREG
|
|
634 addwfc PRODH,F
|
|
635 decf PRODL,F ; decrement result
|
|
636 btfss STATUS,C
|
|
637 decf PRODH,F
|
|
638
|
|
639 Index_out 0x53 ; Window Vertical End Address
|
|
640 rcall TFT_DataWrite_PROD
|
|
641
|
|
642 ;---- Flipped vertical window ----------------------------------------
|
|
643 ; Output 0x37 flipped(bottom) = 239-bottom = 240 - top - height
|
|
644 ; flipped(top) = 239-top
|
|
645 TFT_box_flip_V:
|
|
646 movff win_top,PRODL
|
|
647 movff win_height,WREG
|
|
648 addwf PRODL,W
|
|
649 sublw .240 ; 240 - top - height
|
|
650 movwf PRODH ; First byte
|
|
651
|
|
652 movf PRODL,W
|
|
653 sublw .239 ; 249-top
|
|
654 movwf PRODL ; --> second byte.
|
|
655
|
|
656 Index_out 0x50 ; Window Horizontal Start Address
|
|
657 clrf PORTA ; Upper
|
|
658 movf PRODH,W
|
|
659 rcall TFT_DataWrite ; Lower (and tick)
|
|
660
|
|
661 Index_out 0x51 ; Window Horizontal End Address
|
|
662 clrf PORTA ; Upper
|
|
663 movf PRODL,W
|
|
664 rcall TFT_DataWrite ; Lower (and tick)
|
|
665
|
|
666 Index_out 0x20 ; Frame Memory Horizontal Address
|
|
667 clrf PORTA ; Upper
|
|
668 movf PRODL,W
|
|
669 rcall TFT_DataWrite ; Lower (and tick)
|
|
670 return
|
|
671
|
|
672
|
|
673 ;=============================================================================
|
|
674 ; TFT_frame : draw a frame around current box with current color.
|
|
675 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
|
|
676 ; Outputs: (none)
|
|
677 ; Trashed: WREG, PROD, aa_start:2, aa_end:2
|
|
678 global TFT_frame
|
|
679 TFT_frame:
|
|
680 movff win_top,save_top ; Backup everything.
|
|
681 movff win_height,save_height
|
|
682 movff win_leftx2,save_left
|
|
683 movff win_width,save_width
|
|
684
|
|
685 ;---- TOP line -----------------------------------------------------------
|
|
686 movlw 1 ; row ~ height=1
|
|
687 movff WREG,win_height
|
|
688 rcall TFT_box
|
|
689
|
|
690 ;---- BOTTOM line --------------------------------------------------------
|
|
691 movff save_top,PRODL ; Get back top,
|
|
692 movff save_height,WREG ; and height
|
|
693 addwf PRODL,W ; top+height
|
|
694 decf WREG ; top+height-1
|
|
695 movff WREG,win_top ; top+height-1 --> top
|
|
696 rcall TFT_box
|
|
697
|
|
698 ;---- LEFT column --------------------------------------------------------
|
|
699 movff save_top,win_top ; Restore top/height.
|
|
700 movff save_height,win_height
|
|
701 movlw 1 ; column ~ width=1
|
|
702 movff WREG,win_width
|
|
703 rcall TFT_box
|
|
704
|
|
705 ;---- RIGHT column -------------------------------------------------------
|
|
706 movff save_left,WREG
|
|
707 movff save_width,PRODL
|
|
708 addwf PRODL,W
|
|
709 decf WREG
|
|
710 movff WREG,win_leftx2
|
|
711 rcall TFT_box
|
|
712
|
|
713 ;---- Restore everything -------------------------------------------------
|
|
714 movff save_left,win_leftx2
|
|
715 movff save_width,win_width
|
|
716 return
|
|
717
|
|
718 ;=============================================================================
|
|
719 ; TFT_box : fills current box with current color.
|
|
720 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
|
|
721 ; Outputs: (none)
|
|
722 ; Trashed: WREG, PROD
|
|
723 global TFT_box
|
|
724
|
|
725 TFT_box:
|
|
726 ;---- Define Window ------------------------------------------------------
|
|
727 movf win_width,W
|
|
728 bcf STATUS,C
|
|
729 rlcf WREG
|
|
730 movwf win_width+0
|
|
731 movlw 0
|
|
732 rlcf WREG
|
|
733 movwf win_width+1
|
83
|
734 rcall TFT_box_write ; Setup box
|
0
|
735
|
83
|
736 global TFT_box_16bit_win_left
|
|
737 TFT_box_16bit_win_left:
|
0
|
738 rrcf win_width+1,W ; width /= 2
|
|
739 rrcf win_width+0,W
|
|
740 movwf win_width
|
|
741
|
|
742 ;---- Fill Window --------------------------------------------------------
|
|
743 Index_out 0x22 ; Frame Memory Data Write start
|
|
744
|
|
745 clrf PRODH ; Column counter.
|
|
746 RS_H ; Data
|
|
747
|
|
748 TFT_box2: ; Loop height times
|
|
749 movff win_height,PRODL
|
|
750
|
|
751 TFT_box3: ; loop width times
|
|
752 movff win_color1,PORTA ; Upper
|
|
753 movff win_color2,PORTH ; Lower
|
|
754 WR_L
|
|
755 WR_H ; Tick
|
|
756
|
|
757 movff win_color1,PORTA ; Upper
|
|
758 movff win_color2,PORTH ; Lower
|
|
759 WR_L
|
|
760 WR_H ; Tick
|
|
761
|
|
762 decfsz PRODL,F ; row loop finished ?
|
|
763 bra TFT_box3 ; No: continue.
|
|
764
|
|
765 incf PRODH,F ; column count ++
|
|
766
|
|
767 movff win_bargraph,WREG ; current column == bargraph ?
|
|
768 cpfseq PRODH
|
|
769 bra TFT_box4 ; No: just loop.
|
|
770
|
|
771 clrf WREG ; Yes: switch to black
|
|
772 movff WREG,win_color1
|
|
773 movff WREG,win_color2
|
|
774 TFT_box4:
|
|
775
|
|
776 movff win_width+0,WREG ; compare ?
|
|
777 xorwf PRODH,W
|
|
778 bnz TFT_box2 ; Loop not finished.
|
|
779
|
|
780 movlw 0x00 ; NOP, to stop window mode
|
|
781 rcall TFT_CmdWrite
|
|
782
|
|
783 setf WREG ; Reset bargraph mode...
|
|
784 movff WREG,win_bargraph
|
|
785
|
|
786 return
|
|
787
|
|
788 ;=============================================================================
|
|
789 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB'
|
|
790 global TFT_set_color
|
|
791
|
|
792 TFT_set_color:
|
|
793 movwf tft_temp1 ; Get 8Bit RGB b'RRRGGGBB'
|
|
794 movwf tft_temp2 ; Copy
|
|
795
|
|
796 ; Mask Bit 7,6,5,4,3,2
|
|
797 movlw b'00000011'
|
|
798 andwf tft_temp2,F
|
|
799
|
|
800 movlw b'00000000'
|
|
801 dcfsnz tft_temp2,F
|
|
802 movlw b'01010000'
|
|
803 dcfsnz tft_temp2,F
|
|
804 movlw b'10100000'
|
|
805 dcfsnz tft_temp2,F
|
|
806 movlw b'11111000'
|
|
807 movwf tft_temp3 ; Blue done.
|
|
808
|
|
809 movff tft_temp1, tft_temp2 ; Copy
|
|
810 ; Mask Bit 7,6,5,1,0
|
|
811 movlw b'00011100'
|
|
812 andwf tft_temp2,F
|
|
813 rrncf tft_temp2,F
|
|
814 rrncf tft_temp2,F
|
|
815
|
|
816 movlw b'00000000'
|
|
817 dcfsnz tft_temp2,F
|
|
818 movlw b'00000100'
|
|
819 dcfsnz tft_temp2,F
|
|
820 movlw b'00001000'
|
|
821 dcfsnz tft_temp2,F
|
|
822 movlw b'00001100'
|
|
823 dcfsnz tft_temp2,F
|
|
824 movlw b'00010000'
|
|
825 dcfsnz tft_temp2,F
|
|
826 movlw b'00010100'
|
|
827 dcfsnz tft_temp2,F
|
|
828 movlw b'00100000'
|
|
829 dcfsnz tft_temp2,F
|
|
830 movlw b'00111111'
|
|
831 movwf tft_temp4
|
|
832
|
|
833 rrcf tft_temp4,F
|
|
834 rrcf tft_temp3,F
|
|
835
|
|
836 rrcf tft_temp4,F
|
|
837 rrcf tft_temp3,F
|
|
838
|
|
839 rrcf tft_temp4,F
|
|
840 rrcf tft_temp3,F ; tft_temp3 (b'GGGBBBBB') done.
|
|
841
|
|
842 movff tft_temp1, tft_temp2 ; Copy
|
|
843 clrf tft_temp1
|
|
844
|
|
845 rrcf tft_temp4,F
|
|
846 rrcf tft_temp1,F
|
|
847
|
|
848 rrcf tft_temp4,F
|
|
849 rrcf tft_temp1,F
|
|
850
|
|
851 rrcf tft_temp4,F
|
|
852 rrcf tft_temp1,F ; Green done.
|
|
853
|
|
854 ; Mask Bit 4,3,2,1,0
|
|
855 movlw b'11100000'
|
|
856 andwf tft_temp2,F
|
|
857
|
|
858 rrncf tft_temp2,F
|
|
859 rrncf tft_temp2,F
|
|
860 rrncf tft_temp2,F
|
|
861 rrncf tft_temp2,F
|
|
862 rrncf tft_temp2,F
|
|
863
|
|
864 movlw b'00000000'
|
|
865 dcfsnz tft_temp2,F
|
|
866 movlw b'00000100'
|
|
867 dcfsnz tft_temp2,F
|
|
868 movlw b'00001000'
|
|
869 dcfsnz tft_temp2,F
|
|
870 movlw b'00001100'
|
|
871 dcfsnz tft_temp2,F
|
|
872 movlw b'00010000'
|
|
873 dcfsnz tft_temp2,F
|
|
874 movlw b'00010100'
|
|
875 dcfsnz tft_temp2,F
|
|
876 movlw b'00100000'
|
|
877 dcfsnz tft_temp2,F
|
|
878 movlw b'00111111'
|
|
879 movwf tft_temp4
|
|
880
|
|
881 rrcf tft_temp4,F
|
|
882 rrcf tft_temp1,F
|
|
883
|
|
884 rrcf tft_temp4,F
|
|
885 rrcf tft_temp1,F
|
|
886
|
|
887 rrcf tft_temp4,F
|
|
888 rrcf tft_temp1,F
|
|
889
|
|
890 rrcf tft_temp4,F
|
|
891 rrcf tft_temp1,F
|
|
892
|
|
893 rrcf tft_temp4,F
|
|
894 rrcf tft_temp1,F ; Red done.
|
|
895
|
|
896 movff tft_temp1,win_color1
|
|
897 movff tft_temp3,win_color2 ; Set Bank0 Color registers...
|
|
898 return
|
|
899
|
|
900 ;=============================================================================
|
|
901 ; Dump screen contents to the UART
|
|
902
|
|
903 global TFT_dump_screen
|
|
904 TFT_dump_screen:
|
|
905 bsf no_sensor_int
|
|
906 movlw 'l'
|
|
907 movwf TXREG ; Send command echo.
|
|
908 call rs232_wait_tx ; wait for UART
|
|
909 ;---- Send DISPLAY box command for the full screen window -------------------
|
|
910 Index_out 0x50 ; Window Horizontal Start Address
|
|
911 Parameter_out 0x00, 0x00 ; 0-239
|
|
912 Index_out 0x51 ; Window Horizontal End Address
|
|
913 Parameter_out 0x00, 0xEF ; 0-239
|
|
914 Index_out 0x52 ; Window Vertical Start Address
|
|
915 Parameter_out 0x00, 0x00 ; 0-319
|
|
916 Index_out 0x53 ; Window Vertical End Address
|
|
917 Parameter_out 0x01, 0x3F ; 0-319
|
|
918
|
|
919 clrf ds_column
|
|
920 rcall dump_screen_pixel_reset
|
|
921 dump_screen_1:
|
|
922 btg LEDr ; LED activity toggle
|
|
923 ; Dump even column
|
|
924 movlw .240 ; 240 lines, once.
|
|
925 movwf ds_line
|
|
926 dump_screen_2:
|
|
927 Index_out 0x20 ; Frame Memory Horizontal Address
|
|
928 movff ds_line,WREG ; d'0' ... d'239'
|
|
929 mullw 1 ; Copy row to PRODH:L
|
|
930 rcall TFT_DataWrite_PROD
|
|
931
|
|
932 movff ds_column,WREG ; Init X position.
|
|
933 mullw 2
|
|
934 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
935
|
|
936 rcall TFT_DataRead_PROD ; read pixel
|
|
937 rcall dump_screen_pixel
|
|
938
|
|
939 decfsz ds_line,F
|
|
940 bra dump_screen_2
|
|
941 rcall dump_screen_pixel_flush
|
|
942
|
|
943 ; Dump odd column
|
|
944 movlw .240 ; 240 lines, twice.
|
|
945 movwf ds_line
|
|
946 dump_screen_3:
|
|
947 Index_out 0x20 ; Frame Memory Horizontal Address
|
|
948 movff ds_line,WREG ; d'0' ... d'239'
|
|
949 mullw 1 ; Copy row to PRODH:L
|
|
950 rcall TFT_DataWrite_PROD
|
|
951
|
|
952 movff ds_column,WREG ; Init X position.
|
|
953 mullw 2
|
|
954 movlw .1
|
|
955 addwf PRODL,F
|
|
956 movlw 0
|
|
957 addwfc PRODH,F ; +1
|
|
958 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319)
|
|
959
|
|
960 rcall TFT_DataRead_PROD ; read pixel
|
|
961 rcall dump_screen_pixel
|
|
962
|
|
963 decfsz ds_line,F
|
|
964 bra dump_screen_3
|
|
965 rcall dump_screen_pixel_flush
|
|
966
|
|
967 incf ds_column,F
|
|
968 movlw .160
|
|
969 cpfseq ds_column
|
|
970 bra dump_screen_1
|
|
971
|
|
972 bcf no_sensor_int
|
|
973 clrf RCREG1 ; Clear receive buffer
|
|
974 bcf RCSTA1,CREN ; Clear receiver status
|
|
975 bsf RCSTA1,CREN
|
|
976 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
|
|
977 return
|
|
978
|
|
979
|
|
980 ;=============================================================================
|
|
981 ; Pixel compression
|
|
982 ;
|
|
983 ; Input: PRODH:L = pixel.
|
|
984 ; Output: Compressed stream on output.
|
|
985 ; Compressed format:
|
|
986 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128).
|
|
987 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1..64).
|
|
988 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1..64).
|
|
989 ;
|
|
990 dump_screen_pixel:
|
|
991 movf PRODH,W ; Compare pixel-high
|
|
992 xorwf ds_pixel+1,W
|
|
993 bnz dump_screen_pixel_1 ; Different -> dump.
|
|
994
|
|
995 movf PRODL,W ; Compare pixel-low
|
|
996 xorwf ds_pixel+0,W
|
|
997 bnz dump_screen_pixel_1 ; Different -> dump.
|
|
998
|
|
999 incf ds_count,F ; Same color: just increment.
|
|
1000 return
|
|
1001
|
|
1002 dump_screen_pixel_1: ; Send (pixel,count) tuple
|
|
1003 movf ds_count,W ; Is count zero ?
|
|
1004 bz dump_screen_pixel_2 ; Yes: skip sending.
|
|
1005
|
|
1006 movf ds_pixel+1,W ; This is a BLACK pixel ?
|
|
1007 iorwf ds_pixel+0,W
|
|
1008 bz dump_screen_pix_black ; YES.
|
|
1009
|
|
1010 movf ds_pixel+1,W ; This is a white pixel ?
|
|
1011 andwf ds_pixel+0,W
|
|
1012 incf WREG
|
|
1013 bz dump_screen_pix_white ; YES.
|
|
1014
|
|
1015 ; No: write the pixel itself...
|
|
1016 movlw .64 ; Max color pixel on a single byte.
|
|
1017 cpfsgt ds_count ; Skip if count > 64
|
|
1018 movf ds_count,W ; W <- min(64,count)
|
|
1019 subwf ds_count,F ; ds_count <- ds_count-W
|
|
1020 decf WREG ; Save as 0..63
|
|
1021 iorlw b'10000000' ; MARK as a color pixel.
|
|
1022
|
|
1023 movwf TXREG
|
|
1024 call rs232_wait_tx ; wait for UART
|
|
1025 movff ds_pixel+1,TXREG
|
|
1026 call rs232_wait_tx ; wait for UART
|
|
1027 movff ds_pixel+0,TXREG
|
|
1028 call rs232_wait_tx ; wait for UART
|
|
1029 bra dump_screen_pixel_1
|
|
1030
|
|
1031 dump_screen_pixel_2:
|
|
1032 movff PRODH,ds_pixel+1 ; Save new pixel color
|
|
1033 movff PRODL,ds_pixel+0
|
|
1034 movlw 1
|
|
1035 movwf ds_count ; And set count=1.
|
|
1036 return
|
|
1037
|
|
1038 dump_screen_pix_black:
|
|
1039 movlw .128 ; Max black pixel on a single byte.
|
|
1040 cpfsgt ds_count ; Skip if count > 128
|
|
1041 movf ds_count,W ; W <- min(128,count)
|
|
1042 subwf ds_count,F ; ds_count <- ds_count-W
|
|
1043 decf WREG ; Save as 0..127
|
|
1044 dump_screen_pix_3:
|
|
1045 movwf TXREG
|
|
1046 call rs232_wait_tx
|
|
1047 bra dump_screen_pixel_1 ; More to dump ?
|
|
1048
|
|
1049 dump_screen_pix_white:
|
|
1050 movlw .64 ; Max white pixel on a single byte.
|
|
1051 cpfsgt ds_count ; Skip if count > 64
|
|
1052 movf ds_count,W ; W <- min(64,count)
|
|
1053 subwf ds_count,F ; ds_count <- ds_count-W
|
|
1054 decf WREG ; Save as 0..63
|
|
1055 iorlw b'11000000' ; MARK as a compressed white.
|
|
1056 bra dump_screen_pix_3
|
|
1057
|
|
1058 dump_screen_pixel_flush:
|
|
1059 clrf PRODH
|
|
1060 clrf PRODL
|
|
1061 rcall dump_screen_pixel_1 ; Send it
|
|
1062 dump_screen_pixel_reset:
|
|
1063 clrf ds_count ; But clear count.
|
|
1064 return
|
|
1065
|
|
1066 end |