[Menu]>[Circuits Gallery]>[Signboard]


Processing explanation of signboard



Title


;********************************************************
;
;             The signboard control processing
;
;                                 Author : Seiichi Inoue
;********************************************************

    I wrote the title of the program using the comment( ; ).



LIST and INCLUDE directive

 
        list            p=pic16f84a
        include         p16f84a.inc
    Processor type is set by LIST directive.

    The standard label definition of PIC16F84A is read by the INCLUDE directive.
    When using the standard definition of the Microchip Inc., a warning message about TRISA and TRISB is displayed. So, I modified the definition file.
    Definition files are generally installed in the place below.

    c:\Program Files\Mplab\p16f84a.inc
      ( The drive name depends on your PC. )

    The change parts of the contents of p16f84a.inc are hereinafter.
; P16F84A.INC  Standard Header File, Version 2.00'(modify)

TRISA      EQU     H'0085'    ->     H'0005'
TRISB      EQU     H'0086'    ->     H'0006'



Configuration Word
    Configuration Word is specified using CONFIG directive.
        __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
    Configuration Word can be set when writing a program by programmer. However, it is automatically established when using CONFIG directive. Two under bars in front of CONFIG are written.
    When using a label for the operand of this command, the constant of the label must be defined beforehand.

    The labels which were specified this time are defined as follows at the standard label.
_CP_OFF        EQU     H'3FFF'
_PWRTE_ON      EQU     H'3FF7'
_WDT_OFF       EQU     H'3FFB'
_HS_OSC        EQU     H'3FFE'
    Because these label definitions are AND(&)ed at the operand, the set value of CONFIG is as follows.
_CP_OFF0011 1111 1111 1111(3FFFh)
AND
_PWRTE_ON0011 1111 1111 0111(3FF7h)
AND
_WDT_OFF0011 1111 1111 1011(3FFBh)
AND
_HS_OSC0011 1111 1111 1110(3FFEh)

Result0011 1111 1111 0010(3FF2h)

    The CONFIG directive can be written as follows, too.
        __config    h'3ff2'
    The setting contents are as follows.

    ItemContentsField nameBit(s)
    Code ProtectionOFFCP1111111111
    Power-up TimerONPWRTE(inv)0
    Watchdog TimerOFFWDTE0
    Oscillator SelectionHSFOSC1 and FOSC010




Label definition

;****************  Label Definition  ********************

    The definition of the label constant to use by the processing is done. The standard label of PIC16F84A is read in INCLUDE directive.

    There are a definition of the memory address and a definition of the data value in the label definition. They are defined using either of the EQU directive. In the list this time, I divided the EQU of the address and the EQU of the data setting to easiness understanding.
;************************
;*     Time adjust      *
;************************
;This data decides a scroll speed. Basic rate is 26msec.
tm_adj  equ     0c              ;Time adjust(26msec x 12)


;************************
;*   EEPROM data size   *
;************************
;If the data size is 30 bytes, then simply set d'30'.
e_size  equ    d'32'            ;EEPROM data size



Setting of EEPROM data

;***************  EEPROM Data Definition  ***************
        org     h'2100'
        de      b'11111111'

    I used an EEPROM for the memory which holds the contents of the message to display.
    The data of the EEPROM specifies a memory address from h'2100'.
    Address h'2100' is h'00' at the EEPROM memory. The specification of the address is done by the ORG directive.
    Each bit means that the LED lights up in '0' and means that the LED goes out in '1'.



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.



Initial process

;****************  Initial Process  *********************

    The following processing is done as the initialization processing after the turning on.
    It sets all ports A and B to the output port.
    It sets the condition of the timer interrupt.
    It uses an internal clock for the timer.TOCS = 0

    It uses the prescaler for TMR0.PSA = 0

    The prescaler value = 256PS2 = 1


    PS1 = 1


    PS0 = 1

    The timer value = 0 ( 256 counts )TMR0 = 0

    The number of the time-out skipsTM_ADJ = TM_CNT



    It sets the condition of the EEPROM.

    The initialization of the EEPROM address

    The setting of an EEPROM data size
    It sets interruption function starting.

    Enables the TMR0 interruptT0IE = 1

    Enables all un-masked interruptsGIE = 1




Screen Load Process

;**************  Screen Load Process  *******************

    Because a message is displayed on the LEDs of 128 (8 x 16), I am calling it a screen.
    The blink condition of 128 LEDs is controlled in 16 bytes of the RAM file memory.
    Because it is possible to do only the blink control of eight LEDs at the same time in PIC, the blink control of eight units is at high speed done. At the eyes of the person, it seems to be controlling 128 LEDs at the same time. The control begins with eight LEDs at the end of being rightmost and one row is shifted.
    If changing the contents of the RAM file memory, the lighting-up situation of the LED can be changed.
    The blink condition of eight LEDs is output to port B and a row control binary signal is output to 4 bits of port A(RA3-RA0).

    One of the points of this processing is to be using an indirect memory address.
    In case of the indirect memory address, contents are displayed at the INDF register when writing the address of the memory to want to access in the FSR register.
    As for the instruction in PIC, basically, a direct address is adopted. In this case, the address to want to access is directly written in the instruction code. Because it is, to change an access address, the instruction code must be prepared beforehand every address. It is necessary a lot of program memories.
    When using an indirect addressing, the address can be decided by the calculation and the memory can be accessed in the order. The program quantity can be made little.

     bcf     intcon,gie      ;Interrupt disable
    
     bsf     intcon,gie      ;Interrupt enable
    Another point is the point which prohibits interruption processing in change of the screen data.
    When the interruption processing occurs, the processing to be executing at that time is interrupted and interruption processing is executed. When a memory is changed into the way of the screen data update, the display of the screen has shifted.
    The interruption is possible only among 4 steps which prepare the update of the next screen. When the time-out occurs during screen update, the interruption becomes a wait state.

    In the rewriting processing of screen data, it has the processing to turn off an LED first. The LED of the following row has lit up by the data of the row in front when changing an LED to the following row without turning off it.




Interruption process

;************  Begin Interruption Process  **************

    The interruption occurs when the hardware timer does in the time-out. As for the interruption, the execution address of the program becomes h'0004' compulsorily at the same time as the T0IF bit of the INTCON register becomes '1'. Also, the return address of the interrupted program is recorded to the stack. Because it is, when using interruption processing, don't use all stacks by the subroutine call. The stack aria of doing one minimum must be vacated.
    The GIE bit of the INTCON register is automatically made '0' so as not for the double interruption to occur in the interruption processing and interruption is prohibited.

    To do first at the interruption processing is the saving processing of registers. This time, it is saving W register and STATUS register. In some cases, it sometimes saves the other register, too.
    First, it saves W register. This is because the contents of the W register are broken with the W register having to be used to save STATUS register. Even if it saves W register, the contents of the STATUS register don't change.

    Next, it checks the kind of the interruption. This time, because it generates only time-out interruption, the checking is unnecessary. I am checking time-out bit (T0IF) for processing practice. When there is not a time-out bit and the interruption occurs, it is making jump to initialization processing.




Interruption ending process

;************  END of Interruption Process **************
    When the interruption processing ends, it returns the original program processing.
    The STATUS register is recovered first and the W register is recovered next. Because, the W register is used for recover process for the STATUS register.
    To do the W register in the recover, it is necessary the technique. The contents of the STATUS register have changed when setting W register simply using the MOVF instruction. So, the W register should be recovered using the SWAPF instruction. In this way, the contents of the STATUS register don't change. For recovering the W register the SWAPF instruction should be used twice.
    Lastly, it returns to the original processing by the RETFIE instruction. This instruction checks the contents of the stack and returns to the original program. Also, it makes the GIE bit of the INTCON register to '1' and it makes an interruptible state.





Time-out interruption process

;***********  Time-out interruption Process  ************
    The time which can be counted with the hardware timer is a maximum of about 26 milliseconds even if it uses prescaler.(In case of the 10-MHz clock) In the processing this time, a message is being shifted by the interruption processing of hardware timer. When using 26 milliseconds just as it is, the movement speed of the message is 16 x 26 = 416 milliseconds from the right end to the left end. At this speed, it is too fast. Therefore, it counts the number of times of the interruption and it makes the integral multiple of 26 milliseconds. This count value is changed at the set value of the label definition. The setting this time is '6', so, the message is 16 x 26 x 6 = 2,496 milliseconds(About 2.5 seconds) in the time from the right end to the left end.
    The T0IF bit of the INTCON register is set in '1' when the time-out interruption occurs. The following interruption doesn't occur when this bit isn't erased by the software. Also, the timer count value must be set once more.

    TMR0 is a count up timer. It is in the time-out condition when the timer value becomes 00h from FFh. So, the value which subtracted the timer value to want from 256 is a set value. It does a time-out at 1 count when setting 255(FFh).
    When using a 10-MHz clock, because it is 4 cycles in the 1 count time, it is 0.4-µsec. When setting the prescaler to 256, in the interval of the pulse with input to TMR0, it is 256 x 0.4 = 102.4 µsec.
    To have TMR0 in the time-out within about 20 milliseconds, it is necessary to do 20/0.1024 = about 195 counts. The TMR0 set value to make do in the time-out at 195 counts is 256-195 = 61(3Dh).
    This time, because I want to set maximum time, I make the set value of TMR0 = 0.







Screen scroll process

;************  Screen data shift Process  ***************
    When the time-out interruption occurs, LED display shift process is executed.
    By this process, it shifts the message to be displaying to the left for one row and displays new messages in the row on the rightmost side.
    First, it shifts 2dn row messages to left. And 3rd row to 2dn row and reprepeats shifting 15 times in amount. Indirect addressing is used for this process. The content of the memory which corresponds to the address which was set to the FSR register is stored in the INDF register. If changing the contents of the INDF register in this condition, the contents of the RAM memory can be changed.






EEPROM data reading process

;**************  New data write Process  ****************
    After the screen scroll processing ends, it writes data from the EEPROM in one row of the rightmost.

    The special process step is necessary to the reading of the EEPROM. EEADR register, EECON1 register and EEDATA register are used.
    First, the address of the EEPROM memory to want to read is set to the EEADR register. The address to use here is 64 bytes from h'00' to h'3f'. It is not the value of h'2100' which was specified on source code.
    Next, the RD bit of the EECON1 register should be '1'. This process is the instruction of the reading beginning. When the reading of the EEPROM data completes, the RD bit becomes '0' automatically. To confirm that it became '0' is unnecessary.
    Read data is stored in the EEDATA register.

      movwf   eeadr           ;Set EEPROM address
      bsf     status,rp0      ;Change to Bank1
      bsf     eecon1,rd       ;Start EEPROM reading
      bcf     status,rp0      ;Change to Bank0
      movf    eedata,w        ;Read EEPROM data

    The read data is set to the row on the rightmost side of the LED display.
    By the above process, the display of the LED is shifted one row to the left.

    After reading the last data which was written in the EEPROM is done, it returns to the head data.
    By this processing is repeatedly done, the data of the EEPROM is displayed to flow on the LED screen.




End of coding

;********************************************************
;          END of signboard control processing
;********************************************************

        end
    At the end of coding, END directive is used.