Debian Codegraph @

extras/graphic_lcd/examples/sed1520/sed1520.asm

raw
1 ;
2 ; SED1520 Driver for the PIC 18F family.
3 ;
4 ; Copyright (C) 2005 T. Scott Dattalo
5 ;
6 ; This driver is designed to test gpsim. However, it is also usable
7 ; as a stand alone driver. You're free to use this driver as you
8 ; wish as long as the copyright is retained.
9 ;
10 ;
11 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 ;
13 ; The SED1520 driver supports graphic LCD displays that are based on the
14 ; S-MOS Systems SED1520 LCD graphics controller. The SED1520 is a
15 ; relatively primitive LCD graphics controller. It contains 320 bytes
16 ; of RAM which can be mapped to 2560 on/off pixels. It doesn't have
17 ; hardware support for fonts or drawing primitives.
18 ;
19 ; The primary target of this driver is a Varitronix 100X32 LCD display
20 ; which contains a pair of SED1520's. The upper half of the display
21 ; is supported by one SED1520 and the lower half by the other. Only a
22 ; portion of the SED1520 memory is used, but this driver doesn't take
23 ; advantage of the extra memory
24 ;
25 ;
26 ; !!! NOTE: The driver assumes all variables reside in Bank 0!. !!!
27 ;
28
29 list p=18f452,t=ON,c=132,n=80
30 radix dec
31
32
33
34 #include <p18f452.inc>
35
36 ; The defines in portdef.inc allow the LCD port definitions to be customized.
37
38 #include "portdef.inc"
39 #include "lcd100X32.inc"
40
41 ; Functions:
42
43 GLOBAL SED1520_Init
44 GLOBAL SED1520_WriteCmd
45 GLOBAL LCD_RefreshDisplay
46
47 EXTERN temp0, temp1, temp2, temp3
48 EXTERN DisplayBuffer
49
50
51
52 ;========================================================================
53 ;
54 ; SED1520 Driver
55 ;
56 ;
57 ; RAM Definitions
58
59 UDATA_ACS
60 ;--------------------
61 ; Mode
62 ;--------------------
63
64 SED1520_Mode RES 1
65 GLOBAL SED1520_Mode
66 ; xxxx_xxCM
67 ; |+--- Mode 0=Command 1=Data
68 ; +---- Chip 0=1st chip on Display, 1=2nd chip
69 bSED1520_MODE_CHIP EQU 1<<1
70
71
72 ;------------------------------------------------------------------------
73 ; Macros
74
75 ; SetMode
76 ; Selects between Command and Data mode
77 mSED1520_SetMode macro
78 BCF LATA, RA1
79 BTFSC SED1520_Mode,bSED1520_MODE_CMD
80 BSF LATA, RA1
81 endm
82
83 mSED1520_SelectChip macro
84 BTFSS SED1520_Mode,bSED1520_MODE_CHIP
85 BCF LATE, RE0
86 ; BTFSC SED1520_Mode,bSED1520_MODE_CHIP
87 ; BCF LATE, RE1
88 endm
89
90 mSED1520_deSelectChip macro
91 BTFSS SED1520_Mode,bSED1520_MODE_CHIP
92 BSF LATE, RE0
93 BTFSC SED1520_Mode,bSED1520_MODE_CHIP
94 BSF LATE, RE1
95 endm
96
97
98
99 SETA0 macro
100 BSF LCDA0_LAT,LCDA0_BIT
101 endm
102 CLRA0 macro
103 BCF LCDA0_LAT,LCDA0_BIT
104 endm
105
106 ;------------------------------------------------------------------------
107 ; SED1520 commands
108 ;
109 ; The SED1520 Commands are written to address 1 of the chip.
110 ; The data written for the command includes the command type and optional
111 ; parameters. The data bus is only 8-bits wide. The upper bits in general
112 ; describe the command while the lower are for data
113
114 SED1520_DisplayOn EQU 0xaf
115 SED1520_DisplayOff EQU 0xae
116 SED1520_DisplayStartLine EQU 0xc0
117 SED1520_SETPAGEADDRESS EQU 0xb8
118 SED1520_SetColumnAddress EQU 0x00
119 SED1520_SetDuty EQU 0xa8
120
121 ;------------------------------------------------------------------------
122 ;
123
124
125 SED1520_CODE CODE
126
127
128 SED1520_Init:
129
130 BCF TRISA, RA1
131 CLRF SED1520_TRIS
132
133 if LCDE1_TRIS == LCDE2_TRIS && LCDE1_TRIS == LCDRW_TRIS
134 CLRF TRISE
135 else
136 BCF LCDE1_TRIS, LCDE1_BIT
137 BCF LCDE2_TRIS, LCDE2_BIT
138 BCF LCDRW_TRIS, LCDRW_BIT
139 endif
140
141 ; Select the first chip and set the mode to command
142
143 CLRF SED1520_Mode
144 RCALL LSED1520_Init
145
146 BSF SED1520_Mode, bSED1520_MODE_CHIP
147
148 ; Fall through to initialize the second chip
149
150 LSED1520_Init:
151 MOVLW SED1520_DisplayStartLine
152 rcall SED1520_WriteCmd
153
154 MOVLW SED1520_SETPAGEADDRESS
155 rcall SED1520_WriteCmd
156
157 MOVLW SED1520_SetColumnAddress
158 rcall SED1520_WriteCmd
159
160 MOVLW SED1520_SetDuty|1
161 rcall SED1520_WriteCmd
162
163 MOVLW SED1520_DisplayOn
164 bra SED1520_WriteCmd
165
166 ;------------------------------------------------------------
167 ; Write either a command or data to the SED1520
168 ;
169 ; Inputs: WREG - byte to be written
170 ; Outputs:
171 ; Mem used: W
172 ;
173
174 SED1520_WriteCmd ;<--- Entry point to write a command.
175 BCF LATA, RA1
176
177 SED1520_Write: ;<--- Entry point to write data.
178
179
180 BCF LATE, RE2 ;SED1520 R/W' = write
181
182 rcall d2
183
184 MOVWF SED1520_LAT
185 rcall d2
186 BTFSS SED1520_Mode,bSED1520_MODE_CHIP
187 BSF LATE, RE0
188 BTFSC SED1520_Mode,bSED1520_MODE_CHIP
189 BSF LATE, RE1
190
191 rcall d2
192
193 BCF LATE, RE0
194 BCF LATE, RE1
195
196 BSF LATA, RA1
197
198 return
199 d2 rcall d3
200 d3 return
201
202
203
204 ;------------------------------------------------------------------------
205 ;LCD_RefreshDisplay - copy the RAM buffered display to the physical display
206 ;
207 ; Inputs: None
208 ; Outputs: None
209 ; MemUsed: temp0
210
211 LCD_RefreshDisplay:
212 LFSR 0, DisplayBuffer
213
214 RCALL SED1520_Init
215
216 CLRF SED1520_Mode
217
218 MOVLW LCD_nROWS/8
219 MOVWF temp0
220
221 SED_ref1:
222 BCF SED1520_Mode,bSED1520_MODE_CHIP
223 RCALL SED_ref2
224 BSF SED1520_Mode,bSED1520_MODE_CHIP
225 RCALL SED_ref2
226
227 DECFSZ temp0,F
228 bra SED_ref1
229 return
230
231 SED_ref2:
232 MOVLW SED1520_SetColumnAddress
233 rcall SED1520_WriteCmd
234
235 MOVF temp0,W
236 SUBLW LCD_nROWS/8
237
238 ANDLW 3
239 IORLW SED1520_SETPAGEADDRESS
240 rcall SED1520_WriteCmd
241
242 MOVLW 50
243 MOVWF temp1
244
245 SED_ref3:
246 MOVF POSTINC0,W
247 rcall SED1520_Write
248
249 DECFSZ temp1,F
250 bra SED_ref3
251
252 return
253
254 ;------------------------------------------------------------
255
256 end