comparison code_part1/OSTC_code_asm_part1/oled_samsung.asm @ 142:8b75ba28d641

Screen-flipping custom function. - Fix bank safe addressings.
author JeanDo
date Fri, 07 Jan 2011 03:01:02 +0100
parents d721b49b8934
children c09b0be2e1e6
comparison
equal deleted inserted replaced
141:622da16b768f 142:8b75ba28d641
16 16
17 17
18 ; hardware routines for S6E6D6 Samsung OLED Driver IC 18 ; hardware routines for S6E6D6 Samsung OLED Driver IC
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com 19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
20 ; written: 090801 20 ; written: 090801
21 ; last updated: 090830 21 ; History:
22 ; known bugs: 22 ; 2009-08-30: [MH] last updated.
23 ; ToDo: Optimise PLED_box calls 23 ; 2011-01-07: [jDG] Added flip_screen option
24 ; known bugs: pixel-write (loogbok curves) not done yet...
25 ; ToDo:
24 26
25 WIN_FONT macro win_font_input 27 WIN_FONT macro win_font_input
26 movlw win_font_input 28 movlw win_font_input
27 movff WREG,win_font 29 movff WREG,win_font
28 endm 30 endm
44 46
45 WIN_COLOR macro win_color_input 47 WIN_COLOR macro win_color_input
46 movlw win_color_input 48 movlw win_color_input
47 call PLED_set_color 49 call PLED_set_color
48 endm 50 endm
49 51
52 ;=============================================================================
53
50 word_processor: ; word_processor: 54 word_processor: ; word_processor:
51 clrf POSTINC2 ; Required, to mark end of string. 55 clrf POSTINC2 ; Required, to mark end of string.
52 call aa_wordprocessor 56 call aa_wordprocessor
53 movlb b'00000001' ; Back to Rambank1 57 movlb b'00000001' ; Back to Rambank1
54 return 58 return
55 59
56 ; ----------------------------- 60 ;=============================================================================
57 ; PLED_SetColumnPixel: 61 ; PLED_SetColumnPixel:
58 ; ----------------------------- 62 ;
59 PLED_SetColumnPixel: 63 PLED_SetColumnPixel:
60 movff WREG,win_leftx2 ; d'0' ... d'159' 64 movff WREG,win_leftx2 ; d'0' ... d'159'
61 mullw 2 ; Copy to PROD, times 2. 65 mullw 2 ; Copy to PROD, times 2.
62 66
63 movlw 0x21 ; Start Address Vertical (.0 - .319) 67 movlw 0x21 ; Start Address Vertical (.0 - .319)
64 rcall PLED_CmdWrite 68 rcall PLED_CmdWrite
65 bra PLED_DataWrite_PROD 69 bra PLED_DataWrite_PROD
66 70
67 ; ----------------------------- 71 ;=============================================================================
68 ; PLED_SetRow: 72 ; PLED_SetRow:
69 ; Backup WREG --> win_top, for the next write pixel. 73 ; Backup WREG --> win_top, for the next write pixel.
70 ; Setup OLED pixel horizontal address. 74 ; Setup OLED pixel horizontal address.
71 ; ----------------------------- 75 ;
72 PLED_SetRow: 76 PLED_SetRow:
73 movff WREG,win_top ; d'0' ... d'239' 77 movff WREG,win_top ; d'0' ... d'239'
74 mullw 1 ; Copy row to PRODH:L 78 mullw 1 ; Copy row to PRODH:L
75 movlw 0x20 ; Horizontal Address START:END 79 movlw 0x20 ; Horizontal Address START:END
76 rcall PLED_CmdWrite 80 rcall PLED_CmdWrite
77 bra PLED_DataWrite_PROD 81 bra PLED_DataWrite_PROD
78 82
79 ; ----------------------------- 83 ;=============================================================================
80 ; PLED Write Two Pixel 84 ; PLED Write Two Pixel
81 ; ----------------------------- 85 ;
82 86
83 PLED_PxlWrite: 87 PLED_PxlWrite:
84 rcall PLED_PxlWrite_Single ; Write first pixel. 88 rcall PLED_PxlWrite_Single ; Write first pixel.
85 89
86 ; Write 2nd Pixel on same row but one column to the right 90 ; Write 2nd Pixel on same row but one column to the right
123 bcf oled_rw 127 bcf oled_rw
124 bcf oled_nreset 128 bcf oled_nreset
125 return 129 return
126 130
127 ;============================================================================= 131 ;=============================================================================
132 ; Fast macros to write to OLED display.
133 ; Adding a call/return adds 3 words and a pipeline flush, hence make it
134 ; nearly twice slower...
135 ;
136 ; Input : commande as macro parameter.
137 ; Output : NONE
138 ; Trash : WREG
139 ;
140 AA_CMD_WRITE macro cmd
141 movlw cmd
142 rcall PLED_CmdWrite
143 ; bcf oled_rs ; Cmd mode
144 ; movwf PORTD,A
145 ; bcf oled_rw ; Tick the clock
146 ; bsf oled_rw
147 endm
148 ;
149 ; Input : PRODH:L as 16bits data.
150 ; Output : NONE
151 ; Trash : NONE
152 ;
153 AA_DATA_WRITE_PROD macro
154 rcall PLED_DataWrite_PROD
155 ; bsf oled_rs ; Data mode
156 ; movff PRODH,PORTD ; NOTE: OLED is BIGENDIAN!
157 ; bcf oled_rw ; Tick the clock
158 ; bsf oled_rw
159 ; movff PRODL,PORTD
160 ; bcf oled_rw ; Tick the clock
161 ; bsf oled_rw
162 endm
163
164 ;=============================================================================
165 ; Output OLED Window Address commands.
166 ; Inputs : win_top, win_leftx2, win_height, aa_width.
167 ; Output : PortD commands.
168 ; Trashed: PROD
169 ;
170 PLED_box_write:
171 movff win_leftx2,WREG ; Compute left = 2*leftx2 --> PROD
172 mullw 2
173
174 movff win_flags,WREG ; BEWARE: bank0 bit-test
175 btfsc WREG,0 ; 180° rotation ?
176 bra PLED_box_flip_H ; YES:
177
178 ;---- Normal horizontal window ---------------------------------------
179 ; Output 0x35 left,
180 ; 0x36 right == left + width - 1.
181 AA_CMD_WRITE 0x35 ; this is the left border
182 AA_DATA_WRITE_PROD ; Output left
183 AA_CMD_WRITE 0x21 ; Also the horizontal first pix coord.
184 AA_DATA_WRITE_PROD
185
186 movf aa_width+0,W,ACCESS ; right = left + width - 1
187 addwf PRODL,F
188 movf aa_width+1,W,ACCESS
189 addwfc PRODH,F
190 decf PRODL,F,A ; decrement result
191 btfss STATUS,C
192 decf PRODH,F,A
193
194 AA_CMD_WRITE 0x36 ; Write and the right border
195 AA_DATA_WRITE_PROD
196
197 bra PLED_box_noflip_H
198
199 ;---- Flipped horizontal window --------------------------------------
200 PLED_box_flip_H:
201 ; Output 0x36 flipped(left) = 319-left
202 ; 0x35 flipped(right) = 319-right = 320 - left - width
203 movf PRODL,W ; 16bits 319 - PROD --> PROD
204 sublw LOW(.319) ; 319-W --> W
205 movwf PRODL
206 movf PRODH,W
207 btfss STATUS,C ; Borrow = /CARRY
208 incf WREG
209 sublw HIGH(.319)
210 movwf PRODH
211 AA_CMD_WRITE 0x36 ; this is the left border
212 AA_DATA_WRITE_PROD ; Output left
213 AA_CMD_WRITE 0x21
214 AA_DATA_WRITE_PROD
215
216 movf aa_width+0,W ; 16bits PROD - width --> PROD
217 subwf PRODL,F ; PRODL - WREG --> PRODL
218 movf aa_width+1,W
219 subwfb PRODH,F
220 infsnz PRODL ; PROD+1 --> PROD
221 incf PRODH
222 AA_CMD_WRITE 0x35 ; this is the left border
223 AA_DATA_WRITE_PROD ; Output left
224
225 PLED_box_noflip_H:
226 movff win_flags,WREG ; BEWARE: bank0 bit-test
227 btfsc WREG,0 ; 180° rotation ?
228 bra PLED_box_flip_V
229
230 ;---- Normal vertical window -----------------------------------------
231 ; Output 0x37 (top) (bottom)
232 movff win_top,PRODH ; top --> PRODH (first byte)
233 movff win_height,WREG
234 addwf PRODH,W
235 decf WREG
236 movwf PRODL ; top+height-1 --> PRODL (second byte)
237
238 AA_CMD_WRITE 0x37
239 AA_DATA_WRITE_PROD
240
241 movff PRODH,PRODL
242 clrf PRODH ; Start pixel V coord == top.
243 AA_CMD_WRITE 0x20
244 AA_DATA_WRITE_PROD
245
246 return
247
248 ;---- Flipped vertical window ----------------------------------------
249 ; Output 0x37 flipped(bottom) = 239-bottom = 240 - top - height
250 ; flipped(top) = 239-top
251 PLED_box_flip_V:
252 movff win_top,PRODL
253 movff win_height,WREG
254 addwf PRODL,W
255 sublw .240 ; 240 - top - height
256 movwf PRODH ; First byte
257
258 movf PRODL,W
259 sublw .239 ; 249-top
260 movwf PRODL ; --> second byte.
261
262 AA_CMD_WRITE 0x37
263 AA_DATA_WRITE_PROD
264
265 clrf PRODH ; Start pixel V coord.
266 AA_CMD_WRITE 0x20
267 AA_DATA_WRITE_PROD
268
269 return
270
271 ;=============================================================================
128 ; PLED_frame : draw a frame around current box with current color. 272 ; PLED_frame : draw a frame around current box with current color.
129 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 273 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
130 ; Outputs: (none) 274 ; Outputs: (none)
131 ; Trashed: WREG, PROD, aa_start:2, aa_end:2, win_leftx2, win_width:1 275 ; Trashed: WREG, PROD, aa_start:2, aa_end:2, win_leftx2, win_width:1
132 276
133 PLED_frame: 277 PLED_frame:
134 movff win_top,aa_start+0 ; Backup everything. 278 movff win_top,aa_start+0 ; Backup everything.
135 movff win_height,aa_start+1 279 movff win_height,aa_start+1
136 movff win_leftx2,aa_end+0 280 movff win_leftx2,aa_end+0
137 movff win_width,aa_end+1 281 movff win_width,aa_end+1
138 282
139 ;---- TOP line ----------------------------------------------------------- 283 ;---- TOP line -----------------------------------------------------------
140 movlw 1 ; row ~ height=1 284 movlw 1 ; row ~ height=1
141 movff WREG,win_height 285 movff WREG,win_height
142 rcall PLED_box 286 rcall PLED_box
143 287
144 ;---- BOTTOM line -------------------------------------------------------- 288 ;---- BOTTOM line --------------------------------------------------------
145 movff aa_start+0,PRODL ; Get back top, 289 movff aa_start+0,PRODL ; Get back top,
146 movff aa_start+1,WREG ; and height 290 movff aa_start+1,WREG ; and height
147 addwf PRODL,W ; top+height 291 addwf PRODL,W ; top+height
148 decf WREG ; top+height-1 292 decf WREG ; top+height-1
149 movff WREG,win_top ; top+height-1 --> top 293 movff WREG,win_top ; top+height-1 --> top
150 rcall PLED_box 294 rcall PLED_box
151 295
152 ;---- LEFT column -------------------------------------------------------- 296 ;---- LEFT column --------------------------------------------------------
153 movff aa_start+0,win_top ; Restore top/height. 297 movff aa_start+0,win_top ; Restore top/height.
154 movff aa_start+1,win_height 298 movff aa_start+1,win_height
170 ; Outputs: (none) 314 ; Outputs: (none)
171 ; Trashed: WREG, PROD 315 ; Trashed: WREG, PROD
172 316
173 PLED_box: 317 PLED_box:
174 ;---- Define Window ------------------------------------------------------ 318 ;---- Define Window ------------------------------------------------------
175 movlw 0x35 ; VerticalStartAddress HIGH:LOW 319 movff win_width,WREG
176 rcall PLED_CmdWrite 320 bcf STATUS,C
177 movff win_leftx2,WREG 321 rlcf WREG
178 mullw 2 322 movwf aa_width
179 rcall PLED_DataWrite_PROD 323 movlw 0
180 324 rlcf WREG
181 movlw 0x36 ; VerticalEndAddress HIGH:LOW 325 movwf aa_width+1
182 rcall PLED_CmdWrite 326 rcall PLED_box_write
183 movff win_width,PRODL ; Bank-safe addressing
184 movff win_leftx2,WREG
185 addwf PRODL,W ; left+width
186 decf WREG ; left+width-1
187 mullw 2 ; times 2 --> rightx2
188 rcall PLED_DataWrite_PROD
189
190 movlw 0x37 ; HorizontalAddress START:END
191 rcall PLED_CmdWrite
192 movff win_top,PRODH ; Start row.
193 movff win_height,PRODL ; height
194 movf PRODH,W
195 addwf PRODL,F ; top + height
196 decf PRODL,F ; top + height - 1 --> bottom.
197 rcall PLED_DataWrite_PROD
198
199 ;---- Start pointer ------------------------------------------------------
200 movlw 0x20 ; Start Address Horizontal (.0 - .239)
201 rcall PLED_CmdWrite
202 movff win_top,WREG
203 mullw 1
204 rcall PLED_DataWrite_PROD
205
206 movlw 0x21 ; Start Address Vertical (.0 - .319)
207 rcall PLED_CmdWrite
208 movff win_leftx2,WREG
209 mullw 2
210 rcall PLED_DataWrite_PROD
211 327
212 ;---- Fill Window -------------------------------------------------------- 328 ;---- Fill Window --------------------------------------------------------
213 movlw 0x22 ; Start Writing Data to GRAM 329 movlw 0x22 ; Start Writing Data to GRAM
214 rcall PLED_CmdWrite 330 rcall PLED_CmdWrite
215 331
216 movff win_height,PRODH 332 movff win_width,PRODH
217 bsf oled_rs ; Data! 333 bsf oled_rs ; Data!
218 334
219 PLED_box2: ; Loop height times 335 PLED_box2: ; Loop height times
220 movff win_width,PRODL 336 movff win_height,PRODL
221 PLED_box3: ; loop width times 337 PLED_box3: ; loop width times
222 movff win_color1,PORTD 338 movff win_color1,PORTD
223 bcf oled_rw 339 bcf oled_rw
224 bsf oled_rw ; Upper 340 bsf oled_rw ; Upper
225 movff win_color2,PORTD 341 movff win_color2,PORTD
226 bcf oled_rw 342 bcf oled_rw
227 bsf oled_rw ; Lower 343 bsf oled_rw ; Lower
228 344
229 movff win_color1,PORTD 345 movff win_color1,PORTD
230 bcf oled_rw 346 bcf oled_rw
231 bsf oled_rw ; Upper 347 bsf oled_rw ; Upper
232 movff win_color2,PORTD 348 movff win_color2,PORTD
233 bcf oled_rw 349 bcf oled_rw
234 bsf oled_rw ; Lower 350 bsf oled_rw ; Lower
235 351
236 decfsz PRODL,F 352 decfsz PRODL,F
237 bra PLED_box3 353 bra PLED_box3
238 decfsz PRODH,F 354 decfsz PRODH,F
239 bra PLED_box2 355 bra PLED_box2
240 356
241 movlw 0x00 ; NOP, to stop Address Update Counter 357 movlw 0x00 ; NOP, to stop Address Update Counter
242 bra PLED_CmdWrite ; Returns... 358 bra PLED_CmdWrite ; returns...
243 359
244 ;============================================================================= 360 ;=============================================================================
245 ; PLED_ClearScreen: An optimized version of PLEX_box, for full screen black. 361 ; PLED_ClearScreen: An optimized version of PLEX_box, for full screen black.
246 ; Trashed: WREG, PROD 362 ; Trashed: WREG, PROD
247 363
373 movlw 0x00 ; DM X RIM1 RIM0 VSPL HSPL EPL DPL 489 movlw 0x00 ; DM X RIM1 RIM0 VSPL HSPL EPL DPL
374 rcall PLED_DataWrite ; System Interface: RIM is ignored, Internal Clock 490 rcall PLED_DataWrite ; System Interface: RIM is ignored, Internal Clock
375 491
376 movlw 0x03 ; Entry Mode (S6E63D6 Datasheet page 46) 492 movlw 0x03 ; Entry Mode (S6E63D6 Datasheet page 46)
377 rcall PLED_CmdWrite 493 rcall PLED_CmdWrite
378 movlw 0x00 ; =b'00000000' CLS MDT1 MDT0 BGR X X X SS 65k Color 494 movlw 0x00 ; CLS MDT1 MDT0 BGR X X X SS 65k Color
379 rcall PLED_DataWrite 495 rcall PLED_DataWrite
380 movlw b'00110000' ; =b'00110000' X X I/D1 I/D0 X X X AM 496
497 ; Change direction for block-writes of pixels
498 lfsr FSR0,win_flags
499 btfss INDF0,0 ; BANK-SAFE bit test.
500 movlw b'00110000' ; [normal] X X I/D1 I/D0 X X X AM
501 btfsc INDF0,0
502 movlw b'00000000' ; [flipped] X X I/D1 I/D0 X X X AM
381 rcall PLED_DataWrite 503 rcall PLED_DataWrite
382 504
383 movlw 0x18 505 movlw 0x18
384 rcall PLED_CmdWrite 506 rcall PLED_CmdWrite
385 movlw 0x00 507 movlw 0x00