The serial communication of USART synchronous/asynchronous transmits display circuit and interrupt method
Technical field
The present invention relates to a kind of display circuit, relate in particular to a kind of USART synchronous/asynchronous serial communication and transmit display circuit and interrupt method.
Background technology
Generally in real-time system, display circuit all needs to monitor in real time according to the input of keyboard or operation, shows that according to the result who monitors the real-time monitoring of keyboard is all finished by continuous scanning, this exists a shortcoming, is exactly the significant wastage to cpu resource.Therefore, how effectively to economize on resources, the work efficiency that improves single-chip microcomputer is the problem that the present inventor is devoted to study.
Summary of the invention
The objective of the invention is to overcome the defective of prior art and provide a kind of USART synchronous/asynchronous serial communication to transmit display circuit and interrupt method, it can reach when monitoring in real time, effectively aim of saving.
The technical scheme that realizes above-mentioned purpose is:
A kind of USART synchronous/asynchronous serial communication of one of the present invention transmits display circuit, comprise two PIC single-chip microcomputers, every PIC single-chip microcomputer includes the RD port, the RB port, RC port and VSS port, wherein, described two PIC single-chip microcomputers are divided into PIC single-chip microcomputer main frame and PIC single-chip microcomputer slave, the RD port of these two PIC single-chip microcomputers is eight, be respectively the RD0 port to the RD7 port, each RD port all is in series with a LED light emitting diode, the RB port of two PIC single-chip microcomputers includes the RB4 port, the RB5 port, the RB6 port, the RB7 port, each RB port of PIC single-chip microcomputer main frame and PIC single-chip microcomputer slave all is connected with an independent key circuit, the RC port of described PIC single-chip microcomputer main frame and PIC single-chip microcomputer slave comprises RC7 port and RC6 port, wherein, the RC7 port of PIC single-chip microcomputer main frame links to each other with the RC6 port of PIC single-chip microcomputer slave, the RC6 port of PIC single-chip microcomputer main frame links to each other with the RC7 port of PIC single-chip microcomputer slave, the VSS port ground connection of two PIC single-chip microcomputers.
Above-mentioned USART synchronous/asynchronous serial communication transmits display circuit, and wherein, described RD0 port to RD7 port is all connected with described LED light emitting diode by a resistance R.
Above-mentioned USART synchronous/asynchronous serial communication transmits display circuit, and wherein, being set to respectively of described four RB ports: the RB4 port is counting automatically; The RB5 port is single two demonstration; The RB6 port is the height conversion; The RB7 port is that two lamps flow.
The present invention's two a kind of USART synchronous/asynchronous serial communication transmits the interrupt method of display circuit, described USART synchronous/asynchronous serial communication transmits display circuit and comprises continuous PIC single-chip microcomputer main frame and PIC single-chip microcomputer slave, four RB ports of each PIC single-chip microcomputer all are connected with an independent key circuit, and their RD port all is in series with the LED light emitting diode, wherein, the variation that the variation of instruction and cycle index realizes its show state is changeed in the display part of described PIC single-chip microcomputer main frame by loosing, the display message of PIC single-chip microcomputer slave is directly by USART communication the port content to be delivered to the slave port in real time by PIC single-chip microcomputer main frame to realize that its interrupt method comprises:
At first, during initialization, open 2 interrupt responses in the PIC single-chip microcomputer of 14 interrupt sources is arranged, i.e. USART synchronous/asynchronous serial communication receives the data interruption mode and RB port level changes interrupt mode;
When any one interrupt source generation interrupt request of master and slave PIC single-chip microcomputer, in the Interrupt Process process, at first must discern the identity of interrupt source, differentiate and interrupt the generation source;
After judging interrupt source, carry out corresponding break in service, if interrupt causing, then before the master routine that returns the PIC single-chip microcomputer, serial communication must be received the zero clearing of data interruption zone bit by USART communication.
Above-mentioned USART synchronous/asynchronous serial communication transmits the interrupt method of display circuit, wherein,
Described USART synchronous/asynchronous serial communication receives the reception in the data interruption mode and sends data and realizes by USART synchronous/asynchronous serial communication mode, utilize its interrupt request that receives generation that the PIC single-chip microcomputer is entered and interrupt receiving the data that the other side PIC single-chip microcomputer sends over, with the button variable COUNTER in the renewal PIC single-chip microcomputer and the data of PIC single-chip microcomputer slave port;
It is to change by level to interrupt the input of identification keyboard that described RB port level changes interrupt mode, adopt high 4 bit levels of RB port to change interrupt function, realization is to the real-time monitoring of independent key circuit, 4 kinds of display modes are defined into the independent key circuit that RB4, RB5, RB6, RB7 pin are connected respectively, when key was pressed, the PIC single-chip microcomputer caused that by button level changes response and interrupts.
Above-mentioned USART synchronous/asynchronous serial communication transmits the interrupt method of display circuit, wherein, change in the interrupt mode at described RB port level, the independent key circuit that detects 4 button RB4, RB5, RB6, RB7 correspondence successively has or not to be pressed, according to different button inputs button variable COUNTER is set and is respectively 0,1,2,3, before end interrupt is returned master routine, by USART synchronous/asynchronous serial communication mode, the numerical value of present button variable COUNTER is sent to another PIC single-chip microcomputer.
The invention has the beneficial effects as follows: the present invention is in order effectively to economize on resources, improve the work efficiency of single-chip microcomputer, satisfy the online detection requirement of response fast simultaneously, 4 distinctive level of 4 independent key circuits and RB port are changed interrupt function pin RB4~7 link to each other, the present invention ground connected mode constitutes two-shipper USART (universal synchronous/asynchronous serial reception/transmitter) synchronous/asynchronous serial communication.When pressing main or during from the independent key circuit that RB4, RB5, RB6, RB7 connected of single-chip microcomputer, host and slave processors RD port connects 8 LED light emitting diodes will show synchronously that certain key presses pairing display mode, interrupt pin by the PIC single-chip microcomputer has overcome original real time scan ground mode, has saved great resource.
Description of drawings
Fig. 1 is the circuit diagram that one of the present invention's USART synchronous/asynchronous serial communication transmits display circuit.
Embodiment
The invention will be further described below in conjunction with accompanying drawing.
See also Fig. 1, a kind of USART synchronous/asynchronous serial communication that there is shown one of the present invention transmits display circuit, comprise two PIC single-chip microcomputers, every PIC single-chip microcomputer includes the RD port, the RB port, RC port and VSS port, two PIC single-chip microcomputers are divided into PIC single-chip microcomputer main frame 1 and PIC single-chip microcomputer slave 2, the RD port of these two PIC single-chip microcomputers is eight, be respectively the RD0 port to the RD7 port, each RD port all is in series with a LED light emitting diode 4, the RB port of two PIC single-chip microcomputers includes the RB4 port, the RB5 port, the RB6 port, the RB7 port, each RB port of PIC single-chip microcomputer main frame 1 and PIC single-chip microcomputer slave 2 all is connected with an independent key circuit 3, the RC port of PIC single-chip microcomputer main frame 1 and PIC single-chip microcomputer slave 2 comprises RC7 port and RC6 port, wherein, the RC7 port of PIC single-chip microcomputer main frame 1 links to each other with the RC6 port of PIC single-chip microcomputer slave 2, the RC6 port of PIC single-chip microcomputer main frame 1 links to each other with the RC7 port of PIC single-chip microcomputer slave 2, the VSS port ground connection of two PIC single-chip microcomputers, RD0 port to RD7 port is all connected with LED light emitting diode 4 by a resistance R.
Being set to respectively of four RB ports:
RB4: count automatically;
RB5: single two demonstration;
RB6: height conversion;
RB7: two lamps flow.
Working method of the present invention: when pressing main or during from RB4, RB5, RB6, RB7 connected the independent key circuit 3 of single-chip microcomputer, the RD port of PIC single-chip microcomputer host and slave processors 1,2 connects 8 LED light emitting diodes 4 will show synchronously that certain key presses pairing display mode.
The present invention's two a kind of USART synchronous/asynchronous serial communication transmits the interrupt method of display circuit, the serial communication of USART synchronous/asynchronous transmits display circuit and comprises continuous PIC single-chip microcomputer main frame and PIC single-chip microcomputer slave, four RB ports of each PIC single-chip microcomputer all are connected with an independent key circuit, and their RD port all is in series with the LED light emitting diode, the variation that the variation of instruction and cycle index realizes its show state is changeed in the display part of PIC single-chip microcomputer main frame by loosing, introduced the master among the present invention, the notion of slave, the display message of PIC single-chip microcomputer slave is directly by USART communication the port content to be delivered to the slave port in real time by PIC single-chip microcomputer main frame to realize that its interrupt method comprises:
At first, during initialization, open 2 interrupt responses in the PIC single-chip microcomputer of 14 interrupt sources is arranged, i.e. USART synchronous/asynchronous serial communication receives the data interruption mode and RB port level changes interrupt mode;
When any one interrupt source generation interrupt request of master and slave PIC single-chip microcomputer, in the Interrupt Process process, at first must discern the identity of interrupt source, differentiate and interrupt the generation source;
After judging interrupt source, carry out corresponding break in service, if interrupt causing, then before the master routine that returns the PIC single-chip microcomputer, serial communication must be received the zero clearing of data interruption zone bit by USART communication.
Among the present invention, the serial communication of USART synchronous/asynchronous receives the reception in the data interruption mode and sends data and realizes by USART synchronous/asynchronous serial communication mode, utilize its interrupt request that receives generation that the PIC single-chip microcomputer is entered and interrupt receiving the data that the other side PIC single-chip microcomputer sends over, with the button variable COUNTER in the renewal PIC single-chip microcomputer and the data of PIC single-chip microcomputer slave port, because PIC single-chip microcomputer main frame can change PIC single-chip microcomputer slave COUNTER value, PIC single-chip microcomputer slave also can change PIC single-chip microcomputer host C OUNTER value, and the output video data of PIC single-chip microcomputer slave sends renewal in real time by PIC single-chip microcomputer main frame, so realized the synchro control and the demonstration of two PIC single-chip microcomputers;
It is to change by level to interrupt the input of identification keyboard that RB port level changes interrupt mode, adopt high 4 bit levels of RB port to change interrupt function, realization is to the real-time monitoring of independent key circuit, 4 kinds of display modes are defined into RB4 respectively, RB5, RB6, the independent key circuit that the RB7 pin is connected, when key is pressed, the PIC single-chip microcomputer causes that by button level changes response and interrupts, change in the interrupt mode at RB port level, detect 4 button RB4 successively, RB5, RB6, the independent key circuit of RB7 correspondence has or not to be pressed, according to different button inputs button variable COUNTER is set and is respectively 0,1,2,3, before end interrupt is returned master routine, by USART synchronous/asynchronous serial communication mode, the numerical value of present button variable COUNTER is sent to another PIC single-chip microcomputer.
Above embodiment is only for the usefulness that the present invention is described, but not limitation of the present invention, person skilled in the relevant technique, under the situation that does not break away from the spirit and scope of the present invention, can also make various conversion or modification, therefore all technical schemes that are equal to also should belong to category of the present invention, should be limited by each claim.