
Environment setting
Various environment setting is done at the line number
008-011 of the list.
008 |
list |
It is defining the name of PIC to
use. |
009 |
include |
The file (p16f84a.inc) that a various
standard label is defined is taken in. |
010 |
__config |
The contents of Configuration Word are
designated. |
 |
_hs_osc |
 |
Type of the oscillator |
: HS |
_wdt_off |
Watch-dog timer |
: It isn't used. |
_pwrte_on |
Power up timer |
: It is used. |
_cp_off |
Code protector |
: It isn't
used. | |
The value of Configuration Word by
above-mentioned specification is H'3FF2'. |

|
|
|
011 |
errorlevel |
It makes not show bank switching
warning message [302]. At the RAM file
register of PIC16F84A, a bank method is adopted. For example, both
memory addresses of TMR0 and OPTION_REG is 01. However, TMR0 is at
bank 0 and OPTION_REG is at bank 1. In the definition file which
is read by INCLUDE, it defines the address of OPTION_REG as being
H'0081'. Bank information is written. The bank must be designated
with RP0 bit of the STATUS register by the actual processing. In
case of MPLAB, to prevent mistake in the bank processing, warning
message "Message[302]" is shown in the processing of the register
of bank 1. "Register in operand not in bank
0. Ensure that bank bits are correct." Even
if specifying a bank normally, this message is
shown. To make not display this message, there is a way of
changing a definition file designation. That is, the message
becomes not displayed when changing the address of OPTION_REG into
H'0001'. Or, there is a way of stopping the display of 302
messages using the ERRORLEVEL directive to be using this
time. |
Label definition
;**************** Label Definition ********************
CBLOCK and ENDC are used for the block definition of
the RAM register file. The area of the label among these commands is
automatically set in the order from the address which is specified by
CBLOCK. This time, it is the same as specifying as
follows.
tx_status equ h'000c'
tx_substatus equ h'000d'
pattern equ h'000e'
ptn1 and ptn2 are the label which specifies control
code data. If changing the value to specify here, the control code to
transmit can be changed. In the case, the side of the receiver must be
changed too. ra4 is the label which specifies the
position of port A. "4" can be designated to direct by the instruction
even if it doesn't use ra4, too.

Program start
;**************** Program Start ***********************
The program memory address 0 is the program starting
address when turning on or reset occurs. Also, the program memory
address 4 is a start address when interruption occurs. These addresses
are decided with the hardware of PIC16F series.

Initialization process
;**************** Initial Process *********************
Port initialization
First, the initialization of the port is done. RA0
and RA1 are set to the input mode and the other RA ports which contain
RA4 are set to the output mode.
Timer setting
This circuit controls the data to transmit in the
10-millisecond interval. Timer 0 is used to make 10-millisecond time.
TOCS and PSA of OPTION_REG are set to "0" to use an internal clock and
prescaler for timer 0. It makes prescaler value "101"(1:64). Because
it is using 4 MHz for the oscillator of PIC, the clock is one
microsecond. TMR0 is increased every 64 microseconds when combining
with prescaler. The timer interrupt generates TMR0 when count value
(TMR0) becomes 0 from 255(H'FF'). So, the value to set to TMR0 for the
10-millisecond timer is 256-(10000/64)=100. The other value can be
used for the prescaler value. In case of 1:128, the timer increases
every 128 microseconds. In the case, the set value of TMR0 is
256-(10000/128)=178. In case of 1:256, it is 256-(10000/256)=217. When
the prescaler value is small, the timer value by TMR0 can be set,
being detailed. However, in case of 1:32, it becomes 10000/32=312.5.
The value more than 255 can not be set to TMR0.
Initialization of the register
When turning on the power of PIC, the initialization
for various register is executed with hardware. I am doing
initialization to make those original values
certainty.
Confirmation of the transmission
pattern
It checks the condition of RA0 and RA1 and it
confirms a transmission pattern. RA0 becomes an H level when SW1 is
pushed and RA1 becomes an H level when SW2 is pushed. By the condition
of the pushed switch, a control code pattern is set to the PATTERN
register. When SW1 and SW2 are pushed at the same time, SW1 is judged
to have been pushed.
Timer interrupt wait
After above processing, it waits for the interruption
of the timer only. It specifies $ (its address) by the GOTO
instruction, and it repeats the processing of the same address and it
waits for the interruption.

Timer interrupt process
;********* Begin Timer Interruption Process ***********
In the processing this time, the interruption has only
a timer time-out. So, it assumes that all interruption is a timer
interrupt. When using the other interruption (the RB port change
interruption, and so on), judgment processing of the interruption factor
is needed. First, it clears a timer interrupt
flag. When not clearing this, the timer interrupt occurs again
immediately after executing interruption ending instruction
(RETFIE).

Preamble data sending-out process
;************ Preamble data send Process **************
When transmission status (TX_STATUS) is "0", it sends
out a preamble signal. It transmits ON and OFF three times alternately
and making do continuously ON in twice in case of transmission ending.
After transmitting the end mark, it makes an electric wave OFF and it
ends in the sending-out of a preamble signal and it makes transmission
status "1".

Control code data sending-out process
;************ Control data send Process ***************
When the transmission status is "1", the sending-out
processing of a control code is done. It sends ON signal in front of
each bit of the control code and it sends OFF signal back. The condition
of the sending-out bit is managed by sub status (TX_SUBSTATUS). I think
that it is possible for more few processing steps to realize if devising
processing. However, I made the processing of each signal to be
independent. The quantity consumed of the program memory increases but
can make an execution time little. It is because there are not judgement
processing and so on too much. This time, because the program is small,
the memory is enough. Also, in this way, the understanding of processing
is easy and there is little possibility to make bug (the mistake of the
software). It makes transmission status "2" when the sending-out of a
control code ends.

Ending data sending-out process
;************** End data send Process *****************
When the transmission status is "2", the sending-out
processing of an ending code is done. The ending code continues ON
condition three times and makes it OFF condition last. By making transmission status "0" after finishing transmitting an
ending code, the transmission of the preamble is again
done.

Timer interrupt ending process
;*********** Substatus Increment Process **************
;******** End of Timer Interruption Process ***********
A timer interrupt is done every 10 milliseconds and
code transmission processing is done by the contents of the transmission
status and the transmission sub status. When the
timer interrupt processing ends, it sets 10 milliseconds to timer value
(TMR0) and it sets a timer interrupt condition for next time. Depending
on the condition of the status, sub status is sometimes increased. The
interruption processing ends using the RETFIE instruction. With this
instruction, the GIE bit of the INTCON register becomes "1" and the
interruption becomes
possible.
|