[Menu]>[Circuits Gallery]>[Remote display]

Processing explanation for Display unit

System requirements setting

Label definition
;****************  Label Definition  ********************
        cblock  h'20'
The data area is automatically assigned from 20h by CBLOCK directive. ENDC is used for the ending of assignment.
The purpose of each data area is shown below.


data_h:This is the area which stores 100th data.

data_t:This is the area which stores 10th data.

data_u:This is the area which stores 1st data.

cdisp_p :This is the area which stores a category display scan position.

ddisp_p:This is the area which stores a 7 segment LED display scan position.

rcv_p:This is the area which ccounts a received data.

r_category:This is the workarea to use for the change of the received category data.

Program start
;****************  Program Start  ***********************
Instruction is executed from Zero addresses of the program memory when making the power ON of the PIC. When there is interruption processing, processing is begun from the addresse 4. It makes each processing jump with the GOTO instruction.

Initialization process
;****************  Initial Process  *********************
The following process is done as the initialization process after the turning on.

Initialization of the mode of ports A , B and C

A port is used for the category specification and the display digit specification for the 7 segment LED. It is completely made digital mode (ADCON1) and it is made output mode (TRISA).
All B ports are used for the segment control of the 7 segment LED and are made an output mode. (TRSIB)
RC0-RC3 of the C port is used for the scan of the category display and is set to the output mode.
RC7 is made an input mode to be used for the receiving of data. (TRSIC)

Initialization of the LED lighting-up scan

Timer 0 is used for the lighting-up scan of the LED. The period is 2 milliseconds. Because the prescaler is made 1:8, when making a timer value 6, the period becomes in the 2 milliseconds. Time-out interrupting is generated at the 256th count by the addition method. (255 -> 0)
( 256 - 6 ) x 8 = 2000 microseconds

Initialization for the port

Only A port is executed in the initialization. As for each port, when not doing initialization, the original value is "1". Even if the B port and C port don't do initialization at this point, there is no problem on the operation. By the A port, the specification of the category is done. The specification of the category is done in making either of RA3, RA4, RA5 "1". When not doing the initialization of the A port, it is in the condition that all of RA3, 4, 5 are "1". Therefore, the character which doesn't have a meaning is displayed.

Initialization of the workarea

The initialization of the LED display data, the LED scan position data, the data receiving area is done.

Initialization of the USART

Because most of the registers about the setting of a USART are in bank 1, it is necessary to be careful of the bank designation.
The designation of the asynchronous serial communication with 9600bps transmission speed is done. This receiving interrupting occurs when data is received in the receiving buffer.
Receiving operation is immediately done when the initialization of the USART ends.

Initialization of interruption

GIE, PEIE and T0IF are set. To use the interruption of transmission complete, PEIE must be set.

The initialization processing ended above. After this, it waits for the interruption only. As the main processing, it repeats the execution of the same address. '$' with operand means its address.

Interruption process
;***************  Interruption Process  *****************
In the software this time, two kinds of interruption are used. They are interruption by the time-out of TMR0 and the interruption when the data is received.
The interruption of TMR0 is identified by the T0IF bit of the INTCON register and the data receive interruption is identified by the RCIF bit of the PIR1 register.

Illegal interruption process
;********  Illegal interruption (For debugging)  ********
I made display the letter of "E" in the 1st digit of the LED when the interruption which doesn't correspond to two kinds of above-mentioned interruption occurred. Usually this processing is hardly executed. This logic is for the debugging of software. The almost software operation confirmation can be confirmed using the debugging function of MPLAB. However, the operation such as the communication function and the data input can not be confirmed. Their operation must be confirmed using actual PIC. However, it doesn't understand an operating state from outside. In the case, you put "goto illegal" on the logic to want to check. For example, when you want to confirm the interruption of data receive, you put "goto illegal" in the 159th line. Because "E" is displayed when the data is received, you find that the processing was executed. But, it displays "E" and the processing stops. So, the original logic must be returned after the operation confirmation.

Interruption ending process
;************  END of Interruption Process **************
The RETFIE instruction is executed at end of the interruption processing. With this, it becomes the interruption possible condition. Because it isn't saving registers in case of interruption, there is no need to resave.

LED control process
;**************** LED control Process *****************
Clearing of interruption flag

The interruption occurs every 2 milliseconds with TRM0. The interruption flag of T0IF should be cleared first. When not clearing this, the following interruption occurs without waiting desired time. Also, the setting of the timer value of TMR0 is needed too.

Category display LED scan

As for the control of the category display LED, one row is done every time it interrupts in the 2 milliseconds. Because of 11 rows, the display of a category character is done in the 22 milliseconds. The specification of the row is done by the RC port. 0 shows the 1st row and 1 shows the 2nd row. So, as the value which specifies a scan position, the value which is added every scans is used. Usually, a subtraction method is used for the ending judgement of the repeat processing. It is because there are few execute steps of the ending judgement in this one. This time, I used the same value for the value of the ending judgement and the value of the scan position. A judgement is done every time each processing ends.

7 segment LED scan

A 3-digit figure is displayed by the 7 segment LED. 1 digit is controlled every 2 milliseconds about these LEDs, too. As for the management of the display digit, an increment style is used like the category display. There is no problem in the decrement style.
The digit specification of 7 segments is done by RA0, RA1 and RA2. However, the bit (RA3,RA4,RA5) of the higher rank is used for the category display specification. So, in case of specification of 7 segments, RA0-2 must be rewritten while saving this value. Therefore, it makes data "0" except the category specification by the AND. As for the AND, the result becomes "1" only when both data is "1". So, as for the bit that the fixing value in the instruction is "1", the contents don't change just as it is and the bit that the fixing value is "0" always becomes "0".
Next, the digit specification data of the 7 segment LED is set to RA0-2. This time, the calculation of the OR is used. As for the OR, when either of the data is "1", the result becomes "1". That is, the contents of the bit that the fixing value in the instruction is "0" don't change just as it is and the bit that the fixing value is "1" always becomes "1". Because it is, it makes only the bit of the digit to want to control out of RA0-2 "1" and it makes the others "0".
The digit specification ended above. Next, the segment data to display is written in the RB port. It reads content in the received data area of each of the digits and writes in the RB port. It makes writing processing to the RB port common and a processing step is reduced.

Data receive process
;***************  Data receive Process  *****************
Data receiving from the console unit is done by this processing. This process is started by the data receive interruption by the RCIF bit of the PIR1 register. It is different from the other interruption display bit and to clear RCIF bit by the software isn't necessary. It is cleared by the hardware in reading the data which was received to RCRGE.

Overrun check

It becomes an overrun condition in case of being behind in the receiving process and receiving buffer's becoming full. Because the receiving buffer is a double buffer, in the process this time, the overrun doesn't occur. This processing is made for the safety. When the overrun occurs, it stops the receiver and it must be started once again. Above thing must be always done when the overrun occurs.
This time, it clears all display data after that to find that the overrun occurred in the process.

Frame error check

The frame is from the start bit to the stop bit. When a stop bit isn't detected after detecting a start bit, the frame error occurs. After that, if a normal frame is received, the error passes away. This time, when the frame error occurs, it clears display only.

Start data receive process

As for the data which is sent from the console unit, the category, 100th, 10th and 1st data is sent sequentially. The information which shows the kind of the data isn't included in each data. The kind of the data is decided in the order to receive. So, the console unit sends start data first and it transmits category, 100th, 10th and 1st data continuously in the order. In the receiving process, it waits for the start data first. When the data except the start data comes in the start data receiving position, data is canceled and the incrementation of the receiving position isn't done. When start data is received, being normal, a receiving position is incremented.

Category data receiv process

Category data is received following the start data. The category data which is sent from the console unit is sent in the form to use in the console unit. So, in the display unit, it isn't possible to use just as it is. The reason is the difference of the bit configuration and the bit contents. In the received data, bit 4-6 is the data which shows a category. Bit 6 indicates "SEI", bit 5 indicates "TEN" and bit 4 indicates "PU". And, "0" indicates lighting-up and "1" indicates going-out. As for the display unit, bit 3-5 indicates a category. Bit 3 corresponds to "SEI", bit 4 corresponds to "TEN" and bit 5 corresponds to "PU". And, "0" indicates going-out and "1" indicates lighting-up. This difference is due to the difference of the hardware of each unit. Therefore, it judges above difference by the software and the data to use in the display unit is made.

Number data receive process

100th, 10th and 1st data are received in the order following the category data. The form of the console unit and the form of the display unit are different about these data, too. The bit position is the same and the meaning is opposite to "0" and "1". In the console unit, "0" is lighting-up, "1" is going-out, but in the display unit, "0" means going-out and "1" means lighting-up. Exclusive OR is used to reverse "0" and "1". In case of Exclusive OR, "0" is output if being a value with the same data and "1" is output when the value is different. So, the result reverses when calculating in Exclusive OR with "1". For example, when the received data is '01001111', the result of execution of Exclusive OR with '11111111' is '10110000'. This is the value which reversed "0" and "1" of the received data. A translated value is written in the storage area which corresponds to each of the digits.

    Actually, this processing isn't perfect. When the data receiving stops in the condition that the frame could be received, being normal, the receiving processing has the possibility to make a mistake in the kind of the data. For example, It supposes that the communication stopped when receiving in the 100th, being normal. After that, when receiving start data from the console unit, in the receiving process, it receives start data as 10th data and category data as 1st data. Because it becomes start data waiting condition when 1st data is received, the 100th, 10th and 1st data are canceled. After that, normal receiving is done.
    There is no process about this in the process this time. There are few occurring frequencies. When occurring, it gets back to normal with retry. So, I didn't make process about this with above reason.

End of coding
;          END of signboard control processing

At the end of coding, END directive is used.