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