Beginning of this page
Jump to main content

Please note that JavaScript and style sheet are used in this website,
Due to unadaptability of the style sheet with the browser used in your computer, pages may not look as original.
Even in such a case, however, the contents can be used safely.


Worldwide > Japan日本語

Programming





Processing to be executed first [common to 78K]

FAQ-ID : 78prog-0101Last Updated : 2006/04

Q-1
I want to use the 78K0 develop a program in C for the first time, but I don't understand well the flow of processing from starting by reset to executing the process (main function) that I want the program to do.
A-1
The processing in question is performed by a start-up routine.

An application program of a microcontroller is ultimately written to internal ROM (mask ROM or flash memory) and is embedded into an application system.
In addition, the initial settings of the internal peripheral I/O functions of the microcontroller must be set in advance.
Moreover, setting to use the standard functions and run-time library of C must be made.
To perform this processing, the start-up routine is executed immediately after the system is started after reset.
The start-up routine performs the following processing.

(1) Preprocessing
Performs processing necessary for using the standard library.
(2) Initial setting of hardware
Set the Initial settings of the internal peripheral I/O functions of the microcontroller.
Define the actual processing as a hdwinit function.
(3) ROMization processing
Copies the default value with a default value from ROM to an actual variable area (RAM).
(4) Starting main function
Calls the main function and executes the actual program.

Of the above processing, the hdwinit function must be actually created for initial settings of hardware in (2) above.
Describe the setting in accordance with the internal peripheral I/O to be used to the hdwinit function.

Is this information useful for you ?

Q-2
Initial settings of internal peripheral I/O are described to the hdwinit function. Can't it be described elsewhere?
A-2
Basically, initial settings of the internal peripheral I/O may be described anywhere as long as they are described before the internal peripheral I/O is actually used.

If initial settings of a port that is to be set in the output mode are late, the influence of noise may increase.
In addition, the operating clock operates at a low frequency in the default status.
Completing initial settings as soon as possible is recommended, taking the relationship between the supply voltage and operating clock frequency into consideration.
Moreover, manipulating the setting of the watchdog timer after the execution program has been started is not recommended.

Is this information useful for you ?

Q-3
What points should be noted concerning the sequence of initial settings to be described to the hdwinit function?
A-3
The point to be noted first is the relationship between the supply voltage, operable clock cycle time, and operable internal peripheral I/O.
Many recent products have an internal power-on clear (POC) circuit.
These products are activated at a low voltage after power has been turned on and the products have been reset by POC.
In addition, the recent microcontrollers that start in a short time after the reset signal has been released start operating by using an internal oscillator before the system clock oscillation is stabilized.
In such a case, initial settings must be performed with the rise time of the supply voltage taken into consideration.

The second point to be noted is that the entry of signals must be set first and sequentially along with the flow of the signals.
Otherwise, an abnormal output may be produced and malfunctioning may occur.
In addition, a serial clock, for example, must be set in a sequence in which a pulse is not output during initial setting.

Is this information useful for you ?


Sample arithmetic operation program for CPUs that do not have a decimal adjust instruction

FAQ-ID : 78prog-0001Last Updated : 2002/07

Q-1
The uPD789415 does not have a decimal adjust instruction, so decimal operations are a little complicated.
Is there a sample program for decimal operations such as addition, subtraction, multiplication and division?
A-1
Please refer to the following sample.

ADJBA is a decimal adjust instruction for addition defined by a macro. Decimal adjust is performed by placing the ADJBA macro instruction after the addition.
ADJBS is decimal adjust instruction for subtraction defined by a macro. Decimal adjust is performed by placing the ADJBS macro instruction after the subtraction.
;
;       definition of macro
;
ADJBA   MACRO
        CALLT   [ADJBAT]
ENDM
        ADJBS   MACRO
CALLT   [ADJBST]
ENDM
;
;       definition of CALT table
;
CALTTBL CSEG    AT 40H
ADJBAT: DW      ADJBAS
;
;       decimal adjust for addtion
;
ADJBAS: PUSH    BC
        MOV     C,#0
        BNC     $NEXT0          ; IF C=1 ADJUST 60H
        MOV     C,#0B0H
NEXT0:  BT      PSW.4,$NEXT1    ; JUMP IF AC=1
        MOV     B,A             ; SAVE DATA
        AND     A,#0FH          ; MASK UPPER NIBBLE
        CMP     A,#0AH
        MOV     A,B             ; RESTORE DATA
        BC      $NEXT3          ; JUMP IF NOT ADJUST
NEXT1:  ADD     A,#6            ; ADJUST
        MOV     B,A             ; SAVE DATA
NEXT2:  BNC     $NEXT3
        MOV     C,#0B0H
NEXT3:  CMP     A,#0A0H
        BC      $NEXT4
        MOV     C,#0B0H
NEXT4:  ADD     A,C
        ADD     A,C
        POP     BC
        RET
;
;       decimal adjust for subtraction
;
ADJBSS: PUSH    BC
        MOV     C,#0
        BNC     $NEXT5
        MOV     C,#0D0H
NEXT5:  BF      PSW.4,$NEXT6
        SUB     A,#6
NEXT6:  BNC     $NEXT7
        MOV     C,#0D0H
NEXT7:  ADD     A,C
        ADD     A,C
        POP     BC
        RET

Is this information useful for you ?


Safety measures when unused interrupt occurs

FAQ-ID : 78prog-0002

Q-1
If an interrupt that is not used occurs due to a bug or a CPU hardware failure, what does the CPU do?
A-1
It is impossible to positively state what operation will result when an unused interrupt is received, because when the CPU acknowledges an interrupt, it reads the branch destination address (vector) from the vector table data determined for each interrupt, and branches to that address.
Then the CPU executes the code written at that address as an instruction.
So the type of operation performed depends on the code that is read.

Is this information useful for you ?

Q-2
When an unused interrupt occurs, I want the operation to jump to @cstart.
So what should I do?
A-2
Simply define the interrupt function in the C source and make that processing function name @cstart.
For example, to use INTP0 in this way, write a declaration such as

#pragma interrupt INTP0 noint rb1

so that all unused interrupts are processed with noint.
In this way, all unused interrupt vectors become noint.
Here, define the following function as noint.
    Void noint()
    {
      #asm
        ; Initialization of interrupt-related flag
        movw ax!0
        br ax
      #endasm
    }
Since the actual processing must be assembler-programmed, use an assembler with #asm expanded inline.

Is this information useful for you ?


Approach to register bank allocation

FAQ-ID : 78prog-0003

Q-1
When there are three or fewer interrupt functions, I think that it is all right to assign each interrupt to register banks RB1 to 3, respectively; but what should I do when supporting 4 or 5 different interrupts? (Register save, etc.)
A-1
There is no need to allocate all the interrupts to a different register bank.
The approach differs depending on whether or not you want to use multiple interrupts (nesting).

Even if you plan on using several interrupts, as long as you will not use multiple interrupts, it is sufficient to use one register bank for the main processing, and one register bank for the interrupt servicing.
(Since no interrupt will be serviced while another interrupt is being serviced, the same register bank can be shared for different interrupts.)

If, using multiple interrupts, it is necessary to acknowledge an interrupt during the servicing of another interrupt, different register banks must be used for these interrupts.

In this case, allocate the register banks for that interrupt combination so that there is no conflict.
If there are many nested levels and they cannot be handled by the register banks, do not use the register banks for the lower priority interrupts, and instead save the registers to the stack area.

This processing is automatically performed by not describing register bank specification (and not specifying NOBANK) when using the #pragma interrupt command for interrupt definition.

For details, refer to the explanation in section
"(10) Interrupt function qualifier" in "11.5 How to Use Extended Functions" in CHAPTER 11 EXTENDED FUNCTIONS in the CC78K0 (Language) manual.

Is this information useful for you ?


LCD display RAM bit set/reset

FAQ-ID : 78prog-0004

Q-1
In the uPD789488, can the LCD display RAM be set/reset bitwise?
A-1
Bitwise set/reset using the assembler should be avoided.
The reason for this is that a bit manipulation instruction is executed using the read-modify-write method.

As LCD display RAM does not have the 4 higher bits, the data becomes undefined during readout, so these higher 4 bits must be filled with 0s.
(Refer to the caution of Fig.13-6 in "13.5 LCD Display Data Memory" in "CHAPTER 13 LCD CONTROLLER/DRIVER" in the User's Manual.)

When using C language, description should be possible by setting the bit field to 4 bits and using the bitwise AND operator.
Please create the program referring to the C language manual.

Is this information useful for you ?


Port bit clearing

FAQ-ID : 78prog-0005

Q-1
How should I clear P2.0 of the uPD789012 ?
I thought I could use "AND P2,#11111110B", but the AND instruction could not be applied to SFRs.
A-1
When using alternate functions, save the data of each port in RAM.
When you want to change the port contents, modify the value in the RAM (in this case, clear bit 0) and output the new value to P2 while also writing it back to RAM.
Please use this method for holding the value of other bits.

Is this information useful for you ?


Instruction for substituting a value for the stack pointer [78K/0S]

FAQ-ID : 78prog-0007

Q-1
The uPD789415's User's Manual makes no mention of an instruction for setting values directly to the SP.
Can the
        MOV     SP,#0FEFFH
instruction be used?
A-1
Since it is not possible to set values directly to the SP, please set a value to the AX register and then transfer it to the SP.
        MOVW    AX,#0FEFFH
        MOVW    SP,AX

Is this information useful for you ?


Is there a need to differentiate between uppercase and lowercase for the CC78K0 ?

FAQ-ID : 78prog-0008

Q-1
Until now, I have used the option "Don't differentiate between uppercase and lowercase" in the CC78K0, but this option is no longer available in the upgraded version.
A-1
The CC78K0 started differentiating between uppercase and lowercase from V3.10.
As distinction between uppercase and lowercase has become common, this option has been eliminated.

Is this information useful for you ?


What cautions apply when programming beyond 10000H ? [78K/4]

FAQ-ID : 78prog-0009

Q-1
The uPD784038 has internally a 60 KB area (00000H to 0EDFFH) and a 64KB area (10000H to 1FFFFH).
Are there any cautions I should observe or items I should set when programming the area beyond 10000H ?
A-1
The only caution is that the program must be split.
Therefore, if using this memory configuration, you must change the name of the part from 10000H to 1FFFH in the link directive file to something like ROM1, name the program segment to be placed in this area, and place the segment in ROM1.

For details, refer to the "6.4 Link Directives" in "CHAPTER 6 LINKER" in the RA78K4 Operation Manual.
However, rather than using such a memory configuration, it is recommended to place the internal RAM 1MB further back using LOCATION 0FH and use the continuous space from 0 to 1FFFFH for the program.

Is this information useful for you ?


Can setting-type registers be rewritten using a fixed cycle?

FAQ-ID : 78prog-0010Last Updated : 2002/02

Q-1
In the uPD789022, I want to refresh the following registers at a fixed cycle.
Is this a problem?

PM0 / PM1 / PM2 / PM3 / PM4 / PM5 / PUO / TCL2 / WDTM / TMC20 / CR20 / IF0 / MK0 / IF1 / MK1
A-1
Yes, there are some problems with this.
CR20 should not be set during timer operation because it could cause an interrupt to occur at that time.

Moreover, re-setting IF0 and IF1 may cause the interrupt that occurs at that time to disappear.
It is therefore important to be aware of all consequences when carrying out register manipulations.

Basically, it is not recommended to re-set registers when this is not required.

Is this information useful for you ?


Table access in 16-bit space

FAQ-ID : 78prog-0011Last Updated : 2006/04

Q-1
What kind of programming should be used for table access in the 16-bit space?
A-1
The parameter for accessing the table is an 8-bit parameter (in register A), and the result can be read from register A as shown in the example below.
    MOV   X,A           ; X=Input data(offset)
    SUB   A,X           ; A=0
    ADDW  AX,#table     ; get Table Address
    MOVW  HL,AX
    MOV   A,[HL]        ; Get data from Table

Is this information useful for you ?


The read value differs from the one set to the stack point. [78K0/Kx1, 78K0S]

FAQ-ID : 78prog-0012Last Updated : 2006/04

Q-1
To reserve a stack for the uPD78F9116, I set 0FF00H, but when I read to confirm the returned value was 0FB00H. What happened?
A-1
Stack pointers can be set only to the high-speed RAM area, and only the lower 10 bits can be actually set.
0FF00H is in the SFR area, not the high-speed RAM area, so it was converted to 0FB00H that is in the high-speed RAM area.
When the value is actually pushed onto the stack, 1 is subtracted from 0FB00H to become 0FAFFH, but that value is not in the high-speed RAM area, so it is converted to 0FEFFH, which is the same value as when 0FF00H is set to the stack pointer.

Is this information useful for you ?

Q-2
When I set 5555H to the stack pointer for a 78K0/KC1 product and read the result, 0D555H was returned.
What happened?
A-2
In 78K0/Kx1 products, the stack pointer can only be set to the high-speed RAM area.
5555H is not in the high-speed RAM area, so its upper 6 bits are converted by hardware for the high-speed RAM area, and the result is 0D555H.

Is this information useful for you ?























End of this page.
Top of this page