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

Processing explanation for Console 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_c:This is the area which stores category data.

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.

disp_p :This is the area which stores a display position data for the LED.

key_p:This is the area which stores a scan position for the switch.

key_data:This is the area which stores the push condition of the switch.

key_flag:This is the flag storage area which prevents repeat processing by the continuously push of the switch.

tx_p:This is the area which stores a sending position for the LED.

rc4 designates the bit position (4) of the RC4 port. This designation isn't included in p16f873.inc.
seg7_b from seg7_0 are the designations of the lighting-up segment data of the 7 segment LED. Compatible in the bit and the segment must be adjusted to the circuit of the hardware. At the circuit this time, the 0th bit from the right corresponds to the segment "g" and the 6th bit corresponds to the segment "a". 0 is lighting-up and 1 is going-out. It makes the 7th bit 0. This bit is used for the identifying of start data when sending data to the display unit.
seg7_a is for the displaying in abnormally processing and the displaying is "E". seg7_b is the data to erase all the segments of the LED.

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 the port which specifies an LED control position. All ports are set to the digital mode(ADCON1) and the output mode. (TRISA)
B port is for the segment control of the LED. All ports are set to the output mode. (TRSIB)
RC0-RC3 of the C port are for the switch position control. These ports are set to the output mode.
RC4 is for the detection of the switch condition. This port is set to the input mode. (TRSIC)

Initialization of the LED lighting-up control and the timer for the switch detection scan

The lighting-up control of the LED and the detection control of the switch condition are done at the the same period. Timer 0 is used for a periodic control and the designation of the period in the 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

A port is made the position of the category LED.
B port is made a going-out condition for LED.
C port is made the position of SW1.

Initialization of the workarea

Initialization of the various workarea 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. Interrupting of doing transmission complete is made possible. This interruption indicates that the contents of the transmit data setting register(TXREG) were sent to the transmission buffer(TSR) and that the setting register became a empty condition. It is not that the data transmission was complete.
In the USART initialization processing, the function of the transmission doesn't make operate yet. TXEN bit of TXSTA = 0.

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 transmit data setting buffer(TXREG) becomes empty.
The interruption of TMR0 is identified by the T0IF bit of the INTCON register and transmission buffer interruption is identified by the TXIF 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. 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 transmission 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 confirming whether or not sending key processing is executed when pushing a sending key, you put "goto illegal" in the 702nd line. Because "E" is displayed when pushing a sending key, 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.

LED control

As for the LED control, 1 digit is processed every time it does 2 milliseconds interruption. Because there are four kinds of LEDs(Category, 100th, 10th, 1st), it takes a 8 milliseconds to control all LEDs. So, each digit does the operation which lights up only in the 2 milliseconds every 8 milliseconds. When controlling at this speed, at the eyes of the human being, it seems to light up continuously with the afterimage. The control of the LED is done in order of Category -> 100th -> 10th -> 1st.

Key scan process
;******************  Key scan Process  ******************
The key scan processing is continuously done by the LED control.

Key scan position

The condition of one key is checked every time it interrupts. The order of the checking is from SW1.
Because there are 15 keys in all, they need in the 30 milliseconds to check all keys. If being this time, there is not a sense of incongruity of the key operation.

Prevention of the wrong detection

It is detecting key ON twice because of the sure key operation. It only stores the key number which was detected in the 1st ON detection in key_data and the processing of a key push isn't done. Then, it is making scan from SW1. It makes SW1 a top priority key by returning to the scan from SW1 and the wrong detection when more than one key is pushed at the same time is prevented.
A key is recognized to have been pushed when detecting the ON condition of the same key continuously twice and the processing which corresponds to the key is executed. key_flag is set at the same time and a processed record is done. By this, the repeat processing when a key is continuously pushed is prevented.
All scan logic of each key is the same. This processing can be made a subroutine, too. However, I am not doing to the subroutine for the following reason. There are a lot of memories. The input/output management of the subroutine becomes complicated. Because I made have priority over that it was easy to see, the number of the processing steps increased.

Figure key

SW10 from SW1 are the key for the figure input. When a figure key is pushed, the displaying of a 7 segment LED is shifted on the 1 digit left. Then, the figure which corresponds to the key is displayed in 1st position. That is, 10th -> 100th, 1st -> 10th, and a new figure is set to the 1st.

Category key

SW13 from SW11 are the key for the category input. Only the LED which corresponds to the pushed category is lit up.

Send key

SW14 is a key for data sending. TXEN bit of the TXSTA register is made "1" when this key is pushed and the function of the transmission works. The transmission interruption gets to occur with this. Actual data transmission operation is done in the interruption process.

Clear key

SW15 is a key for display clear. All LEDs are turned off when this key is pushed.

Data send process
;*****************  Data send Process  ******************
A data transmission to the display is done by this process. This process is started by the transmission buffer interruption by the TXIF bit of the PIR1 register. The TXIF bit indicates the empty condition of the TXREG register which sets a transmit data. It is different from the other interruption bit and to clear by the software isn't necessary. The interruption occurs when the data of TXREG is transferred to the TSR register. Also, the interruption occurs when making TXEN bit of the TXSTA register "1". The TSR register is the register which is used with the hardware. It isn't possible to control by the software.

Start data

Start data "10000000" is sent out before the sending-out of category data and number data. The identifying information of the data isn't put to the category and the number data which is transmitted from the console unit. The receiver identifies the kind of the data in the order of the arriving data. So, it has made a mistake in the kind of the data when not understanding data at the head. This data is sent to identify the head of the data.

Data sending

Category, 100th, 10th and 1st data are sent following the start data in the order. While the data of the TSR register is sent, the data which is sent next is set to the TXREG register. By this, the transmission of the following data is immediately done when the data of the TSR register is sent. This operation is called "back to back" operation.

End of sending

The interruption which occurs after 1st data is set to the TXREG register means that the 1st data was transferred to the TSR register from the TXREG register. When this interruption occurs, 1st data is not to do transmission complete yet. That the transmission complete of the 1st data is done can be confirmed by TRMT bit of TXSTA register becoming "1". In the change of the TRMT bit, the interruption doesn't occur. So, the transmission complete of 1st data is detected by checking this bit repeatedly by the software. After confirming to do transmission complete, it makes the TXEN bit of the TXSTA register "0" and the function of the transmission is stopped.

    Each data is composed of 8 bits. A start and a stop bit are added to each of the data. So, one piece of data is composed of 10 bits. Because there are five pieces of data including the start data, the whole is 50 bits. The line speed of the circuit this time is 9600bps(bit par second). So, in the time to take to transmit all data, it is 50bit / 9600bps = 5.2 milliseconds.

End of coding
;          END of signboard control processing

At the end of coding, END directive is used.