Abstract:
A security circuit for protecting data stored in an internal memory of a microcomputer has a first memory for storing an externally applied security code and a latch circuit for latching a key code in order to read data stored in the internal memory. A comparator determines whether or not the security code in the first memory and the key code in the latch circuit are in agreement and outputs comparison results for storage in a second memory. A read control circuit uses the comparison results stored in the second memory as the basis for prohibiting reading of data in the internal memory when the security code and the key code are not in agreement, and for using an externally applied output control signal as the basis to control reading of data stored in the internal memory when there is agreement.

Description:
The present invention relates to a security circuit which protects data that is written in a read only memory (ROM) internal to a microcomputer, and which is used in single-chip microcomputers. 
     The problem of security of data written to ROM that are internal to single-chip microcomputers has been under investigation for a long time and methods such as prohibiting the reading of data in ROM have been thought of. In the conventional technology, a writing by the user of &#34;0&#34; or &#34;1&#34; in an electrically programmable ROM (EPROM) that stores the (1 bit) security code performs a security operation to operate a security circuit and prohibit the reading of data (programs) inside a ROM. 
     In this conventional technology, once the security circuit has operated, it is not possible for the data that are stored in the ROM to be read by the user for the purpose of maintenance and management. 
     SUMMARY OF THE INVENTION 
     In the light of this problem, the present invention has as an object the provision of a security circuit that enables the user who applied the security, to read data such as programs and the like that are stored in the memory, and that disables reading by other users. 
     The present invention is a security circuit for the protection of data that is stored in a memory internal to a microcomputer. The security circuit is provided with a first memory to store and input a security code, a latch circuit to latch a key code that is input in order to read the data that is stored in the internal memory, and a comparator circuit to compare whether or not the security code that is stored in the first memory and the key code that is latched by the latch circuit are in agreement. The security circuit according to the invention also has a second memory to store the comparison results compared by the comparator circuit, and a read control circuit that uses the results of comparison stored in the second memory as the basis to prohibit the reading of data stored in the internal memory when the security code and the key code are not in agreement and that uses an externally input output control signal when there is agreement as the basis for controlling the reading of data that is stored in the internal memory. 
     According to a security circuit of the present invention having the configuration described above, inputting a security code causes that security code to be stored in a non-volatile first memory, for example. Then, the key code to read the data that is stored in the internal memory is input and this key code is latched by the latch circuit. Also, this latched key code is compared in a comparator circuit with a security code which is stored in a non-volatile first memory. The results of this comparison are stored in a non-volatile second memory. 
     Then, the results of the comparison which are stored in the second memory, are used as the basis to prohibit the reading of data stored in the internal memory when the security code and the key code are not in agreement, and when there is agreement an externally applied output control signal is used as the basis to control the reading of data that are stored in the internal memory. In this way, for as long as the correct key code is not inputted, it is not possible to read that data from the internal memory, and it is possible for the user who has applied the key code to read that data of the program and the like that are stored in the internal memory, but it is not possible for this to be read by other users. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     In the appended drawings, 
     FIG. 1 is a block diagram showing the configuration of a security circuit according to an embodiment of the present invention; and 
     FIG. 2 is a flow chart for describing the operation of the security circuit shown in FIG. 1. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     FIG. 1 is a block diagram showing the configuration of a security circuit according to an embodiment of the present invention. The security circuit of this embodiment is provided with a first memory 2, a latch circuit 4, a comparator circuit 6, an AND circuit 7, a flip-flop 8, a NOT circuit 9, a NAND circuit 10, a second memory 12 and a read control circuit 20. The data that are stored in an internal memory such as an EPROM (not indicated in the figure) that is internal to the microcomputer or the like, is protected. The first memory 2 is for example, a non-volatile memory comprising an EPROM and stores the security code that is inputted from external. The latch circuit 4 latches the key code that is input, in order to read the data that are stored in the memory internal to the microcomputer or the like. The comparator circuit 6 compares the key code that is latched to the latch circuit 4, with the security code that is stored in the first memory 2. The second memory 12 is a non-volatile memory comparing a 1-bit EPROM for example, and stores the comparison results that were compared by the comparator circuit 6. The read control circuit 20 has an AND circuit 21, an OR circuit 22, a NOT circuit 23 and an AND circuit 24, and controls the reading of data that is stored in the memory (EPROM) internal to the microcomputer not indicated in the figure. Numeral 15 shows a NOT circuit that supplies to a reset terminal R of the flip-flop 8 a reset signal RESEThaving a negative level, and numeral 30 indicates an address decoder for decoding coded address data. 
     The following is a description of the configuration and operation of the present embodiment, with reference to FIG. 1 and FIG. 2. 
     First, when security has not been applied, that is, when the security code has been inputted, the step ST1 in FIG. 2 becomes NO, and the signal S 3  that is sent from the first memory 2 to the OR circuit 22 of the read control circuit 20 becomes the &#34;1&#34; status (refer to step ST2). At this time, the signal S 13  (shown in FIG. 1) that controls the reading of the data stored in the internal memory (EPROM) not indicated in the figure, is output in accordance with the externally applied output control signal OE (step ST3 and step ST4). More specifically, when the signal OE is &#34;1&#34;, the output of the NOT circuit 23 becomes &#34;0&#34; and accordingly, the signal S 13  that is the output of the AND circuit 23 becomes &#34;0&#34; and reading of data from the internal memory (EPROM) not indicated in the figure is performed. Also, when the signal OE is &#34;0&#34;, the output of the NOT circuit 23 becomes &#34;1&#34; and so the read enable signal which is the output of the AND circuit 24 becomes &#34;1&#34; (step ST6) and it is possible to read the data from the memory not indicated in the figure (step ST7). 
     The following is a description of the case when security is applied i.e., when a security code has been entered. When the security code and the address of the memory 2 are input (YES for step ST1), the signal S 1  sent from the address decoder 30 to the first memory 2 becomes &#34;0&#34; and the first memory 2 enters the status where data writing is possible. The security code is sent to the first memory 2 via the data bus and stored. When this occurs, the signal S 3  sent from the memory 2 to the OR circuit 22 of the read control circuit 20 becomes &#34;0&#34; (step ST8). 
     After the security code has been input in this manner, and the data that are stored in the memory (not indicated in the figure) internal to the microcomputer or the like are to be read, it is necessary to input the security code and the address of the latch circuit 4. Accordingly, this is judged in step ST9. When the key code and the address of the latch circuit 4 are input, the signal S 2  is sent from the address decoder 30 to the first memory 2, the latch circuit 4, and the flip-flop 8. The first memory 2 enters the read mode, the flip-flop 8 enters the set status and the key code is latched to the latch circuit 4 (step ST10). 
     Then, the security code that is stored in the memory 2 and the key code that is latched to the latch circuit 4 are compared in the comparator circuit 6 (step ST11) and if they are in agreement, the signal S 4  that is sent from the comparator circuit 6 to the AND circuit 7 becomes &#34;1&#34; (step ST12) and &#34;0&#34; (step ST20) if they are not in agreement. The signal S 5  that is sent on the external write voltage line to the AND circuit 7 becomes &#34;1&#34; when the write voltage V pp  is impressed (step ST14 ) and becomes &#34;0&#34; when the write voltage V pp  is not impressed (step ST19). Accordingly, in step ST13, the write voltage V pp  is determined as to whether or not it is impressed. 
     The following will consider the case when the signal S 5  is &#34;1&#34; and the security code and the key code are in agreement, that is, the case for when the signal S 4  is &#34;1&#34;. When this occurs, the output signal S 6  of the AND circuit 7 becomes &#34;1&#34; (step ST15) and the output signal S 7  of the NOT circuit 9 becomes &#34;0&#34;. By this, the output signal S 9  of the NAND circuit 10 becomes &#34;1&#34; and writing to the second memory 12 is performed. Moreover, the output signal S 8  of the flip-flop 8 is in the set status and is therefore &#34;1&#34;. The signal S 10  sent from the memory 12 to the AND circuit 21 of the read control circuit 20 is &#34;1&#34; and so the signal S 11  sent from the AND circuit 21 to the OR circuit 22 becomes &#34;1&#34;. Accordingly, the read enable signal S 13  which is the output of the read control circuit 20 is in accordance with the output control signal OE that is externally applied. Judging step ST16 is the same as step ST13, so that the external input signal OE is judged whether or not it is in the read. Namely, when the signal OE is not &#34;1&#34;, the signal S 13  becomes &#34;1&#34; (step ST6), and it is possible to read the data that stored in the memory (EPROM) not indicated in the figure (step ST7). Moreover, when step ST16is determined to be YES the signal S 13  becomes &#34;0&#34; (step ST7), and it is impossible to read the data after this. 
     On the other hand, when there is not agreement between the key code and the security code when the two are compared by the comparator circuit 6 (NO for step ST11), the signal S 4  becomes &#34;0&#34;, (step ST20), an output signal S 6  of the AND circuit 7 becomes &#34;0&#34; (step ST21). Then, an output signal S 7  of the NOT circuit 9 becomes &#34;1&#34;. Also, since the signal S 8  becomes &#34;1&#34;, an output signal S 9  of the NAND circuit 10 becomes &#34;0&#34; and is written to the second memory 12. When there is a write to the memory 12, the signal S 10  becomes &#34;0&#34; and so the output signal S 11  of the AND circuit 21 becomes &#34;0&#34;. Also, the security code is stored in the first memory 2 and so the signal S 3  also becomes &#34;0&#34; and so the output signal S 12  of the OR circuit 22 also becomes &#34;0&#34;. Accordingly, the read enable signal S 13  that is the output of the read control circuit 20 is always &#34;0&#34; and reading of the data that is stored in the memory (EPROM) internal to the microcomputer or the like is not possible for as long as the data in the memory 12 is not erased (step ST18). Moreover, if the data in the memory 12 is erased, then the memory for which reading was prohibited, that is, the data in the memory internal the microcomputer or the like is also erased at the same time and security is ensured. 
     As has been described above, according to the present embodiment, it is possible for the user who has applied security to read the data that is stored in the memory but it is not possible for this data to be read by other users. Normal reading is also not possible when an erroneous security code has been input. 
     Accordingly, with the present invention, it is possible for the user who has applied security to read the data that is stored in the memory but it is not possible for this data to be read by other users. Also, normal reading is not possible after an erroneous security code has been input.