[Menu]>[Circuits Gallery]>[Radio Controlled Clock with Large-Sized Display]>[Process explanation]


Processing explanation of RCC (Display week)

Day-of-the-week display program

Configuration Bits

012
013
014
015
016
017
018
        __config        h'3F10' ;OSC is Int 4MHz
                                ;RA5,RA6,RA7,RB4 are I/O
                                ;Power-up timer ON
                                ;Code protection OFF
                                ;Data code protection OFF
                                ;Brown-out detection OFF
                                ;Watchdog timer OFF
The 4Hz built-in oscillator is used like the display scan.

General Purpose Register (GPR)

021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
;****************  Label Definition  ********************
        cblock  h'20'
disp1                           ;1st line data
disp2                           ;2nd line data
disp3                           ;3rd line data
disp4                           ;4th line data
disp5                           ;5th line data
disp6                           ;6th line data
disp7                           ;7th line data
disp8                           ;8th line data
line_indexr                     ;Index for display
line_indexw                     ;Index for set
input_data                      ;Input data save area
line_data                       ;Data save area
        endc
Workarea (disp1-disp8) for the dot matrix LED display data is placed in the general memory. A program scans the data of this area and performs lighting control of LED.
line_indexr is the counter which specifies the display control line of an LED matrix. A character is displayed on an LED matrix by changing the value of this counter.
line_indexw is the counter which specifies the line when rewriting a character pattern. Display to LED and rewriting of a work area are not performed simultaneously. Therefore, it is possible to share with line_indexr. I set aside in order to make it easy to understand.
input_data is the input save area used by character pattern rewriting processing.
line_data is the area which saves the data read by character pattern rewriting processing.

Character pattern

045
046
047
048
049
050
051
052
053
054
;******************** Dispaly data **********************
monday
        retlw   b'10000011'     ;1st line data
        retlw   b'10111011'     ;2nd line data
        retlw   b'10000011'     ;3rd line data
        retlw   b'10111011'     ;4th line data
        retlw   b'10000011'     ;5th line data
        retlw   b'10111011'     ;6th line data
        retlw   b'10111011'     ;7th line data
        retlw   b'10111101'     ;8th line data
In this processing, the character pattern to display is stored in the program memory. The capacity of GPR does not refuse storing of a character pattern. I tried the method of data reading by "retlw" instruction.
There are eight kinds of patterns of each day of the week and putting out lights. "Reading processing of display data" describes this processing system. When the contents of data are "0", LED lights up.

Initialization processing of various registers

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
;******************* Initial Process ********************
init
;*** Set Port mode
        bsf     status,rp0      ;Change to Bank1
        movlw   b'00111000'     ;RA2-0:OUT RA3-5:IN mode
        movwf   trisa           ;Set TRISA reg
        movlw   b'00000000'     ;RB7-0:OUT mode
        movwf   trisb           ;Set TRISB reg

;*** Set Option reg
        movlw   b'00000100'     ;PS=1:32
        movwf   option_reg      ;Set OPTION_REG

;*** Set PIE1 reg
        movlw   b'00000000'     ;TMR1IE=OFF
        movwf   pie1            ;Set PIE1 reg
        bcf     status,rp0      ;Change to Bank0

;*** Set CMCON reg
        movlw   b'00000111'     ;RA port to digital
        movwf   cmcon           ;Set CMCON reg

;*** Set TMR0 reg
        movlw   d'225'          ;256-1000us/32us=225
        movwf   tmr0            ;Set TMR0
Day of the week information from CPLD is inputted to bit 5 from the bit 3 of PORTA in the binary form. All other ports are set to the output mode.
The prescaler of TMR0 is set to 1:32. Therefore, the count-up cycle of a count is 32 microseconds. Interruption by TMR0 is a 1@millisecond like a display scan. Therefore, it is good even if it is same as the display scan. The original interruption cycle was 5 milliseconds. However, since flickering occurred in a display, it changed at the 1 millisecond. The set value of the prescaler is as the first.
The one with the smaller value of prescaler is better for the precision with interrupting period. However, the circuit this time is doing to being just as it is because the precision isn't so important.

Initialization processing of work areas

152
153
154
155
156
157
158
159
160
161
162
163
164
165
;*** Other registers and work area initialization
        clrf    porta           ;Clear PORTA
        clrf    portb           ;Clear PORTB
        clrf    line_indexr     ;Clear index for dip
        clrf    line_indexw     ;Clear index for set
        movlw   b'11111111'     ;Set light out data
        movwf   disp1           ;Set 1st line
        movwf   disp2           ;Set 2nd line
        movwf   disp3           ;Set 3rd line
        movwf   disp4           ;Set 4th line
        movwf   disp5           ;Set 5th line
        movwf   disp6           ;Set 6th line
        movwf   disp7           ;Set 7th line
        movwf   disp8           ;Set 8th line
After initializing the port registers and an index counter, putting-out-lights "1" data is set to the work area of the data displayed on a dot matrix LED. Since it is operation only immediately after switching on a power supply, even if it does not perform this setup, there is no problem substantially.

Interruption setup and waiting processing for interruption

167
168
169
170
171
;*** Set interrupt condition
        movlw   b'10100000'     ;GIE,TOIE=1
        movwf   intcon          ;Interruption enable

        goto    $               ;Wait interruption
All initialization is completed and interruption is made possible.
Display control is performed by interruption processing after that.

Interruption processing

Interruption initialization

173
174
175
176
177
int
;***** TMR0 Interruption ( 1 millisecond interval) ******
        bcf     intcon,t0if     ;Clear timer int flag
        movlw   d'225'          ;Set 1 millisecond
        movwf   tmr0            ;Set TMR0
In the beginning of interruption processing, clearance of the interrupting flag and initialization of a timer value are performed.

LED display processing

179
180
181
182
183
184
185
186
187
188
189
190
191
192
        movfw   line_indexr     ;Read index
        movwf   porta           ;Set display index
        
        movlw   disp            ;Read disp table head adr
        addwf   line_indexr,w   ;RA table head + index
        movwf   fsr             ;Set table address
        movfw   indf            ;Read display data
        movwf   portb           ;Set data to PORTB
        incf    line_indexr,f   ;Index + 1
        movfw   line_indexr     ;Read index
        sublw   d'7'            ;Check upper limit
        btfsc   status,c        ;Over ?
        goto    int_end         ;No. Jump to end
        clrf    line_indexr     ;Yes. Clear index
The information on a screen line is set to PORTA. This information is an input to a decoder. Although the bit 3 to the bit 5 of PORTA is an input port, even if it rewrites all the bits of PORTA, input does not change.
Next, an index value is added to the head address of the work area for a dot-matrix LED display set as GPR, and the data to display is read. LED of the line which corresponds by setting the value to PORTB lights up. The light is switched on in order for every 1 millisecond from the upper line. Only one line is turned on simultaneously. However, since it is high-speed, it seems to have switched on the light simultaneously.

Input data reading processing

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
        movlw   b'00111000'     ;Set input data mask
        andwf   porta,w         ;Read input data
        movwf   input_data      ;Save input data
        rrf     input_data,f    ;Rotate Right
        rrf     input_data,f    ;Rotate Right
        rrf     input_data,f    ;Rotate Right
        movlw   b'00000111'     ;Set pick up mask
        andwf   input_data,f    ;Pick up input data

        movfw   input_data      ;Read input data
        btfss   status,z        ;Input data = 0 ?
        goto    p002            ;No. Next

;*** Light out
p001
        movlw   light_out       ;Read data address
        call    data_set        ;Data set
        btfsc   status,c        ;Over ?
        goto    p001            ;Next line
        goto    p_end           ;Jump to end
When the display from the 1st line to the 8th line of LED is completed, reading processing of input is performed. Input goes into the bit 3, the bit 4 and the bit 5 of PORTA.
This input is taken out and the contents are checked.
0:Turning-off, 1:Sunday, 2:Monday, 3:Tuesday, 4:Wednesday, 5:Thursday, 6:Friday, 7:Saturday.
The head address of the data which is on a program memory according to the contents of input is stored in W register and it jumps to "data_set" subroutine.

Reading processing of display data

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
data_set
        call    data_read       ;Read data
        movwf   line_data       ;Save data
        movlw   disp            ;Read display table HA
        addwf   line_indexw,w   ;Table HA + index
        movwf   fsr             ;Set table address
        movfw   line_data       ;Read data
        movwf   indf            ;Write data
        incf    line_indexw,f   ;Index + 1
        movfw   line_indexw     ;Read index
        sublw   d'7'            ;Check upper limit
        return

data_read
        addwf   line_indexw,w   ;DATA HA + Index
        movwf   pcl             ;Read data
In "deta_set" subroutine, "data_read" subroutine is called first.
"Data_read" subroutine adds the index value for data writing to the data head address stored in W register, and calculates the program memory address where the data to display is written. If the value is written in a PCL register, the execution address of a program will change. The "retlw" instruction with display data is written there. If "retlw" is executed, it will return to the next address of the address which called "data_read". It moves to the 312nd line of a left list. At this time, the value which is written with "retlw" is stored in the W register. It is data displayed on LED.
However, cautions are required when using this method. Since PCL is a 8-bit register, it is manageable only to 255. That is, it can specify from the address 0 to 255. When making it jump to the address after it, it is required to rewrite a PCLATH register. When the added result overflows, it is required to add 1 to PCLATH. In this time, since a data table is put on less than address 255, such processing is not performed.
"Data_set" subroutine writes this value in the work area for a display.
The data for eight lines is written in a work area with 1 time of a cycle.