Using the Serial Peripheral Interface to Communicate
Transcript
Using the Serial Peripheral Interface to Communicate
Freescale Semiconductor Application Note AN991/D Rev. 1, 1/2002 Freescale Semiconductor, Inc... Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers General Description As the complexity of user applications increases, many designers find themselves needing multiple microprocessors to provide necessary functionality in a circuit. Communication between multiple processors can often be difficult, especially when differing processors are used. A possible solution to this problem is usage of the serial peripheral interface (SPI), an interface intended for communication between integrated circuits on the same printed wire board. The MC68HC05C4 is one of the first single-chip microcomputers to incorporate SPI into hardware. One advantage of the SPI is that it can be provided in software, allowing communication between two microcomputers where one has SPI hardware and one does not. Special interfacing is necessary when using the hardware SPI to communicate with a microcomputer that does not include SPI hardware. This interface can be illustrated with a circuit used to display either temperature or time, that incorporates both a MC68HC05C4 and a MC68705R3. The MC68HC05C4 monitors inputs from a keypad and controls the SPI data exchange, while the MC68705R3 determines temperature by performing an analog-to-digital conversion on inputs from a temperature sensor and controls the LED display. Communication between the microcomputers is handled via SPI, with the MC68HC05C4 handling exchanges in hardware, and the MC68705R3 handling them in software. Usage of software SPI can be expanded to include circuits where the singlechip implementing the SPI in software controls the data exchange, and those in which neither single-chip has hardware SPI capability. Minor modifications to the SPI code are necessary when data exchanges are controlled by software. Debugging designs including multiple processors can often be confusing. Some of the confusion can be alleviated by careful planning of both the physical debugging environment and the order in which software is checked. © Freescale Semiconductor, Inc., 2004. All rights reserved. © Motorola, Inc., 1994, 2002 For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. AN991/D Freescale Semiconductor, Inc... Serial Peripheral Interface Communication between the two processors is handled via the serial peripheral interface (SPI). Every SPI system consists of one master and one or more slaves, where a master is defined as the microcomputer that provides the SPI clock, and a slave is any integrated circuit that receives the SPI clock from the master. It is possible to have a system where more than one IC can be master, but there can only be one master at any given time. In this design, the MC68HC05C4 is the master and the MC68705R3 is the slave. Four basic signals, master-out/slave-in (MOSI), master-in/slave-out (MISO), serial clock (SCK), and slave select (SS), are needed for an SPI. These four signals are provided on the MC68HC05C4 on port D, pins 2–5. Signals The MOSI pin is configured as a data output on the master and a data input on the slave. This pin is used to transfer data serially from the master to a slave, in this case the MC68HC05C4 to the MC68705R3. Data is transferred most significant bit first. Data transfer from slave to master is carried out across the MISO, master-in/slave-out, line. The MISO pin is configured as an input on the master device and an output on the slave device. As with data transfers across the MOSI line, data is transmitted most significant bit first. All data transfers are synchronized by the serial clock. One bit of data is transferred every clock pulse, and one byte can be exchanged in eight clock cycles. Since the serial clock is generated by the master, it is an input on the slave. The serial clock is derived from the master’s internal processor clock, and clock rate is selected by setting bits 0 and 1 of the serial peripheral control register to choose one of the four divide-by values. Values for the MCUs crystal oscillators and the SPI divide-by must be chosen so that the SPI clock is no faster than the internal processor clock on the slave. The last of the four SPI signals is the slave select (SS). Slave select is an active low signal, and the SS pin is a fixed input which is used to enable a slave to receive data. A master will become a slave when it detects a low level on its SS line. In this design, the MC68HC05C4 is always the master, so its SS line is tied to VDD through a pull-up resistor. 2 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. AN991/D Serial Peripheral Interface Registers Three registers unique to the serial peripheral interface provide control, status, and data storage. The Serial Peripheral Control Register (SPCR), shown in Figure 1, provides control for the SPI. Address: $000A Freescale Semiconductor, Inc... Reset: Bit 7 6 5 4 3 2 1 Bit 0 SPIE SPE — MSTR CPOL CPHA SPR1 SPR0 0 0 0 0 0 1 U U U = Unaffected Figure 1. Serial Peripheral Control Register (SPCR) SPIE — Serial Peripheral Interrupt Enable 0 = SPIF interrupts disabled 1 = SPI interrupt if SPIF = 1 SPE — Serial Peripheral System Enable 0 = SPI system off 1 = SPI system on MSTR — Master Mode Select 0 = Slave mode 1 = Master mode CPOL — Clock Polarity When the clock polarity bit is cleared and data is not being transferred, a steady state low value is produced at the SCK pin on the master device. Conversely, if this bit is set, the SCK pin will idle high. This bit is also used in conjunction with the clock phase control bit to produce the desired clockdata relationship between master and salve. See Figure 2. CPHA — Clock Phase The clock phase bit, in conjunction with the CPOL bit, controls the clock-data relationship between master and slave. The CPOL bit can be thought of as simply inserting an inverter in series with the SCK line. The CPHA bit selects one of two fundamentally different clocking protocols. When CPHA = 0, the shift clock is the OR of SCK with SS. As soon as SS goes low the transaction begins and the first edge of SCK involves the first data sample. When CPHA = 1, the SS pin may be thought of as a simple output enable control. Refer to Figure 2. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 3 Freescale Semiconductor, Inc. AN991/D SS SCK (CPOL = 0, CPHA = 0) SCK (CPOL = 0, CPHA = 1) SCK Freescale Semiconductor, Inc... (CPOL = 1, CPHA = 0) SCK (CPOL = 1, CPHA = 1) MISO/MOSI MSB 6 5 4 3 2 1 LSB INTERNAL STROBE FOR DATA CAPTURE (ALL MODES) Figure 2. Data Clock Timing SPR1 and SPR0 — SPI Clock Rate Selects These two serial peripheral rate bits select one of four baud rates (Table 1) to be used as SCK if the device is a master; however, they have no effect in the slave mode. Table 1. Serial Peripheral Rate Selection SPR1 SPR0 Internal Processor Clock Divide By 0 0 2 0 1 4 1 0 16 1 1 32 Data for the SPI is transmitted and received via the Serial Peripheral Data Register (SPDR). A data transfer is initiated by the master writing to its SPDR. If the master is sending data to a slave, it first loads the data into the SPDR and then transfers it to the slave. When reading data, the data bits are gathered in the SPDR and then the complete byte can be accessed by reading the SPDR. 4 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. AN991/D Demonstration Board Description Freescale Semiconductor, Inc... Demonstration Board Description A keypad input from the user is used to choose the output display function. The MC68HC05C4 monitors the keypad, decodes any valid inputs, and sends the data to the MC68705R3. If the user has requested a temperature display, the MC68705R3 sends a binary value of temperature in degrees farenheit to the MC68HC05C4, where the value is converted to a celcius binary coded decimal value and returned to the MC68705R3 to be displayed. The LEDs are common anode display and are driven directly off of port B of the MC68705R3. If the user desires the circuit to function as a real-time clock, a starting time must be entered and transmitted from the MC68HC05C4 to the MC68705R3. Once the clock has been initialized, the MC68705R3 updates the clock every minute. Clock values are stored in memory, and when the circuit is functioning as a thermometer, the values in memory are updated as required to maintain clock accuracy. Using the A/D Converter to Monitor Temperature Temperature monitoring is performed by the Freescale MTS102 silicon temperature sensor and the LM358 Dual Low-Power Operational Amplifier, as shown in the schematic in Figure 3. Variations in the base-emitter voltage of the Freescale MTS102 silicon temperature sensor are monitored by the MC68705R3, which converts these analog inputs to equivalent digital values in degrees farenheit. The sensor voltage is buffered, inverted, and amplified by a dual differential amplifier before entering the A/D converter. An amplifier gain of 16 is used, resulting in 20-millivolt steps per degree farenheit. Using a VCC of 5 volts, the maximum differential amplifier output is 3.8 volts, resulting in a temperature sensing range of –40 degrees to +140 degrees farenheit. The output from the differential amplifier is connected to the A/D converter on the MC68705R3. A block diagram of the successive approximation A/D converter is shown in Figure 4. Provision is made for four separate external inputs and four internal analog channels. Two different registers associated with the converter control channel selection, initiate a conversion, and store the result of a completed conversion. Both the external and the internal input channels are chosen by setting the lower 3 bits of the A/D Control Register (ACR). The internal input channels are connected to the VRH/VRL resistor chain and may be used for calibration purposes. The converter operates continuously, requiring 30 machine cycles per conversion. Upon completion of a conversion, the digital value of the analog input is placed in the A/D result register (ARR) and the conversion complete flag, bit 7 of the ACR is set. Another sample of the selected input is taken, and a new conversion is started. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 5 6 24 pF VCC 1 µF 4.7 k VCC 4.7 k 39 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 24 8 3 6 1 20 19 OSC2 OSC1 AN0 TMR INT XTAL VSS VRL VRH 4.7 k 1 µF 40 4 5 6 7 8 9 10 11 34 33 32 31 0.01 µF 7 2 VPP RESET 15 C6 14 C5 13 C4 12 C3 11 C2 10 C1 9 C0 25 B0 26 B1 27 B2 28 B3 29 B4 30 B5 31 B6 VSS 20 VDD PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 SS SCK MOSI MISO VCC VDD 4 7 10 12 8 5 9 6 R2 240 k 1% 7 11 4 R1 6 14 15k 100 k R3 15 k 1% VCC 1 11 2 7 8 12 13 1 G F E D C B A VCC 50 k 10 TURN 6 – + 5 VCC 100 MANB1 LED DISPLAYS COMMON ANODE 2N2907 10 12 7 4 15 k 5 15 k 8 14 2 – + 3 G F E D C B A VCC 15k U2 LM358 9 14 MTS102 0.001 µF 47 k VCC G F E D C B A VCC VSS Figure 3. Serial Peripheral Interface Demonstration Schematic 4 VCC VCC 2 IRQ 28 PC0 10 M 3.579 MHz VCC TO PIN 16, PC7 30 pF 1 MHz 30 pF MC68HC05C4 Freescale Semiconductor, Inc... 14 G F E D C B A VCC Freescale Semiconductor, Inc. AN991/D Freescale Semiconductor, Inc. AN991/D Using the A/D Converter to Monitor Temperature 8 D/A 15 kΩ (TYP) 8 1-OF-8 SELECT MULTIPLEXERS ACR1 0 ACR2 7 A/D CONTROL REGISTER 7 ACR0 PD0/AN0 PD1/AN1 PD2/AN2 PD3/AN3 COUNT VRH/2 VRH/4 ACR7 Freescale Semiconductor, Inc... VRH VRL CONTROL LOGIC COMP 0 A/D RESULT REGISTER Figure 4. A/D Block Diagram Conversions are performed internally in hardware by a simple bisection algorithm. The D/A converter (DAC) is initially set to $80, the midpoint of the available conversion range. This value is compared with the input value and, if the input value is larger, $80 becomes the new minimum conversion value and the DAC is once again set to the midpoint of the conversion range, which is now $C0. If the input value is less than $80, $80 becomes the maximum conversion value and the DAC is set to the midpoint of the new conversion range, in this case $40. This process is repeated until all eight bits of the conversion are determined. Quantizing errors are reduced to +1/2 LSB, rather than +0, –1 LSB, through usage of a built-in 1/2 LSB offset. Ignoring errors, the transition between 00 and 01 will occur at 1/2 LSB above the voltage reference low, and the transition between $FE and $FF will occur 1-1/2 LSBs below voltage reference high. The A/D converter returns a value of $30 when given an input of zero degrees farenheit, so $30 must be subtracted from the result before converting to celcius. This offset must also be considered when calibrating the sensor. Calibration of the temperature sensor can be performed by adjusting the variable resistor to produce a display of $00 after a piece of ice has been placed on the temperature sensor for approximately one minute. A 00 display results from a value of $50 in the ARR, so the variable resistor should be adjusted until this value is reached. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 7 Freescale Semiconductor, Inc. AN991/D Communication Considerations In this application, an SPI read or write is initiated via an interrupt from the MCU desiring to write data. When any of the three function keys, display temperature, set time, or display time, are pressed, the MC68HC05C4, as master, sends the MC68705R3 an interrupt on the MC68705R3’s INT pin. The MC68HC05C4 writes the key value to its serial peripheral data register, thereby initiating the SPI. It then waits for the SPIF bit to go high and returns to scanning the keypad. Freescale Semiconductor, Inc... At the same time the MC68HC05C4 is writing to its SPDR, the MC68705R3 sets a bit counter to eight and waits for the first SCK from the MC68HC05C4. After each clock pulse, the MC68705R3 checks the status of the data bit, sets the carry bit equal to the data bit, and rotates the carry bit left into a result register. The bit counter is decremented, compared to zero, and if not zero, the MC68705R3 waits for the next clock pulse and repeats the cycle. To ensure proper data transfers, the internal processor clock of the MC68705R3 must be sufficiently faster than the SPI clock of the MC68HC05C4 to allow the MC68705R3 time to complete this routine before the MC68HC05C4 can send another bit. This requires the user to first write the code to handle the software SPI, count machine cycles, and then choose MCU oscillator values that allow the additional machine cycles required in a software SPI to be completed before the master can send another clock pulse to the slave. For example, consider the following piece of code for the MC68705R3, a slave receiving data from the master. DATA IN SCK Cycles 2 5 10 10 6 6 4 -43 PORTC pin 5 PORTC pin 4 NXT STR LDA STA BRSET BRSET ROL DEC BNE Instruction #$08 BITCT 4,PORTC,* 5,PORTC,STR RESULT BITCT NXT Set bit counter Wait for clock transition Check data status Store in result Check for end of byte Get next bit Execution of this code requires 43 machine cycles. The maximum oscillator speed for an MC68705R3 is 1 MHz, requiring an SPI clock no greater than 1/43 MHz. One way of obtaining this rate for the SPI clock is to run the MC68HC05C4 at 0.5 MHz and choose a divide-by 32 to generate the SPI clock. 8 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. AN991/D Additional Uses of SPI Freescale Semiconductor, Inc... If the user has selected a temperature display, it is necessary for the MC68705R3, as a slave, to send data to the MC68HC05C4 master. When the MC68705R3 is ready to send data, it interrupts the MC68HC05C4 via the MC68HC05C4’s IRQ line. The MC68HC05C4 then writes to its serial peripheral data register to initiate the transfer and shifts in data bits sent from the MC68705R3 until the SPIF bit goes high. While the MC68HC05C4 is writing to its SPDR, the MC68705R3 program is setting a bit counter to 8. When it detects a clock pulse on the SCK pin, the data register is rotated left one bit, placing the MSB in the carry. The MOSI pin is then set equal to the carry bit, the bit counter is decremented and, if it is greater than zero, the process is repeated. Additional Uses of SPI Many variations of this usage of the SPI are possible. The three possibilities are: • Hardware SPI at both master and slave • Software SPI at the master and hardware at the slave • Software SPI at both master and slave Table 1 shows the various MCUs that have SPI implemented in hardware. SPI is fairly straightforward in a circuit where both master and slave have hardware SPI capability. In this case, the MCUs are connected as shown in Figure 5 and Figure 6. Figure 5 illustrates a single master system, and Figure 6 shows a system where either MCU can be system master. When both master and slave have SPI capability in hardware, data transfers can be handled full duplex. For a single master system, both master and slave write the data to be transferred to their respective serial peripheral data registers. A data transfer is initiated when the master writes to its serial peripheral data register. A slave device can shift data at a maximum rate equal to the CPU clock, so clock values must be chosen that allow the slave to transfer data at a rate equal to the master’s transfer rate. In a multiple master system, the master must pull the slave’s SS line low prior to writing to its serial peripheral data register and initiating the transfer. Programming a Master for Software SPI When the master in an SPI system does not have hardware SPI capabilities, the resulting system is quite different. An SPI system with a master providing the SPI in software is shown in Figure 7. This system only requires two lines between the microcomputers; data and clock. A slave select line can be added for use with multiple slaves. If operated with one data line, the SPI will function half-duplex only. Data is stored in a register, rotated left one bit at a time, and a port pin is set equal to the data bit. The master then provides the serial clock by toggling a different port pin. A bit counter must also be used to count the eight bits in the byte. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 9 Freescale Semiconductor, Inc. AN991/D CLOCK DATA OUT SPI MC68HC05C4 SPI MASTER SPI OUTPUT PERIPHERAL IC DATA IN SLAVE SELECT 1 PORT SLAVE SELECT 2 SPI INPUT PERIPHERAL IC Freescale Semiconductor, Inc... SLAVE SELECT 3 ANOTHER MCU SPI SLAVE SLAVE PERIPHERAL PROCESSOR MAY BE ANOTHER MC68HC05C4, OR PERHAPS AN M6804 FAMILY SINGLE-CHIP MCU Figure 5. Single Master SPI CLOCK DATA DATA SPI MC68HC05C4 SPI MASTER/SLAVE SPI SLAVE SEL SLAVE SEL PORT MC68HC05C4 SPI MASTER/SLAVE PORT SYNC SPI SLAVE SEL OTHER PROCESSORS MAY BE USED, SOME FORTHCOMING M6801,M6805, AND M6804 FAMILY VERSIONS HAVE SPI FACILITIES. Figure 6. Multiple Master SPI 10 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com MC68HC05C4 SPI MASTER/SLAVE PORT Freescale Semiconductor, Inc. AN991/D Additional Uses of SPI CLOCK SPI MASTER MCU DATA SPI SLAVE MCU Freescale Semiconductor, Inc... Figure 7. Software SPI Bit manipulation instructions are very useful for implementing SPI in software. One possible software implementation for a write from the master to the slave is shown below. DATA OUT SCK PORTC pin 0 PORTC pin 1 LDX #$08 LDA DATA RPT ROLA BCS SET BCLR 0,PORTC CLK BSET 1,PORTC BCLR 1,PORTC DECX BNE RPT SET BSET 0,PORTC BRA CLK Bit counter Put data in register A Shift a data bit into carry Check for a 1 Set data out line to 0 Toggle clock pin Check for end of byte It not, repeat Set data out line to 1 Go to clock Full-duplex operation requires a second data line. One port pin is then devoted to data-out and one to data-in. Data transfer from slave to master is accomplished immediately before the SCK pin is toggled. The state of the datain pin is tested, and the carry is then set equal to the data-in pin. This value is then rotated into a result register. The modified code is shown below. DATA OUT SCK DATA IN PORTC pin 0 PORTC pin 1 PORTC pin 2 LDX #$08 LDA DATA BCLR 1,PORTC RPT ROLA BCS SET BCLR 0,PORTC BSET 1,PORTC DIN BRCLR3,PORTC,CLK CLK ROL DATAIN DECX BNE RPT SET BSET 0,PORTC BRA DIN Bit counter Put data in register A Clear clock pin Shift a data bit into carry Check for a 1 Set data out line to 0 Set clock pin Check state of data Rotate input data one bit Check for end of byte If not, repeat Set data out line to 1 Go to data input Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 11 Freescale Semiconductor, Inc. AN991/D Freescale Semiconductor, Inc... Programming a Slave for Software SPI If the slave in the system is a MCU with hardware SPI capability, the data transfer will happen automatically, one bit per clock pulse. If the slave is a MCU that does not have SPI implemented in hardware, a read requires the following actions. A bit counter is set to eight, the slave polls its SCK pin waiting for a clock transition, once it perceives a clock it checks its data-in pin, sets the carry equal to the data and rotates the carry into a results register. One possible code implementation is shown in the previous timing example. Converting this to full duplex operation requires the addition of a write from slave to master. The slave rolls a data register to place the data bit to be sent into the carry, and the data-out pin is set equal to the carry. These actions occur prior to the read of data from the master. With these modifications, the code looks as shown below. DATA OUT DATA IN SCK AGN STR PORTC pin 6 PORTC pin 5 PORTC pin 4 LDA #$08 STA BITCT BRSET 4,PORTC,* ROL RES1 BCS SET1 BCLR 6,PORTC BRCLR 4,PORTC,* BRSET 5,PORTC,STR ROL RESULT DEC BITCT BNE AGN Set bit counter Wait for clock Shift data to send Check data status If 0, clear data out Wait for clock transition Check input data status Store in result Check for end of byte Debugging Tips Debugging a circuit containing two microcomputers presents various problems not evident when working with a single microcomputer circuit. The first problem is simultaneously providing emulation for both microcomputers. Once emulation capability is arranged, the designer needs to keep track of the progress of each single-chip, and monitor how the actions of one affects the actions of the other. One of the easiest methods to debug a circuit of this type is to use two emulator stations, complete with separate terminals. Any emulators can be used, but user confusion is reduced if the emulators have similar commands and syntax. Physical separation also helps reduce confusion.It is somewhat easier to keep track of the concurrent operations if one side of the prototype board is devoted to each single-chip and the majority of peripherals they each must interface with, and the emulator for that microcomputer is placed to that side of the printed circuit board. 12 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. AN991/D Conclusion Freescale Semiconductor, Inc... Before starting simultaneous debugging, it is best to individually debug the code for each microcomputer wherever possible. Once it becomes necessary for the microcomputers to communicate with one another, halt one of the microcomputers anytime they are not actually talking and work with the remaining microcomputer. As the debugging progresses, keep in mind that an error in the function of one single-chip does not necessarily indicate an error in the corresponding code for that single-chip, but rather, the error may have been caused by an incorrect or unintended transmission from the other single-chip. Although the aforementioned suggestions reduce debugging problems, some will remain. Long periods of debug can result in an obscuring of the separation of the functions of the two programs. It helps to take periodic breaks to get away from the system and clear the thought processes. Expect to occasionally be confused, be willing to retrace sections of code multiple numbers of times, and the debugging will proceed fairly smoothly. Conclusion The Serial Peripheral Interface can be used as a tool to interconnect to MCU with various other MCUs or peripherals, and can be used with any microcomputer. A special case occurs when one, or more, of the MCUs in a circuit do not have SPI capability in hardware. In this case, a simple software routine can be written to perform the SPI. Used in this manner, the SPI eliminates the need for costly, inconvenient parallel expansion buses and Universal ‘Asynchronous Receiver/Transmitters (UARTs) and simplifies the design effort. Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 13 Freescale Semiconductor, Inc. AN991/D Freescale Semiconductor, Inc... Code Listings 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 0050 0051 0052 0053 0054 0055 14 nam spicnt ************ REGISTER ADDRESS DEFINITION ************ 0000 0002 0003 0004 0006 000A 000B 000C 0012 porta portc portd ddra ddrc spcr spsr spdr tcr 00B0 00B0 00B1 00B2 00B3 00B4 00B8 00B9 rwno tmpa dctr ct1 base lsb msb 0020 equ equ equ equ equ equ equ equ equ 0 2 3 4 6 $0a $0b $0c $12 org $b0 rmb rmb rmb rmb rmb rmb rmb 1 1 1 1 4 1 1 org $20 ************ KEYPAD LOOUP TABLE ************ 0020 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F kypd 07 04 01 00 08 05 02 0A 09 06 03 0E 0D 0C 0F 0B 0100 0100 0101 0103 0105 9C 3F 12 AE 7B BF 02 start equ * fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb $07 $04 $01 $00 $08 $05 $02 $0a $09 $06 $03 $0e $0d $0c $0f $0b org $100 program start rsp clr ldx stx tcr #$7b portc mask timer interrupts disp. temp. set time am pm disp. time blank initialize port c Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0056 0057 0058 0059 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111 0112 0113 0107 0109 010B 010D 010F 0111 0113 AE BF BF 3F A6 B7 9B 7F 0A 06 00 F0 04 ldx stx stx clr lda sta sei #$7f spcr ddrc porta #$f0 ddra set spi cont. reg. set c0 as output clear keypad inputs set up port a a7-a4 out., a0-a3 in ** check keypad ** 0114 0117 0119 011B 011D 011F 0121 0123 0125 0127 CD A1 27 A1 27 A1 27 A1 27 20 01 67 0A 0E 0E 2B 0F 06 0B 02 EB key jsr cmp beq cmp beq cmp beq cmp beq bra keypad #$0a dtmp #$0e sttm #$0f dtmp #$0b dtmp key check for disp. temp check for set time check for disp. time check for disp. sec wait for next input ** display temp ** 0129 012B 012E 0130 0132 11 CD A1 27 20 02 01 59 0A 02 E0 dtmp 0134 9A 0135 20 DD 0137 013A 013C 013E 0140 0142 0144 0146 0148 014A 014C 014F 0151 0153 0155 0157 CD A1 27 A1 27 A1 27 A1 27 11 CD A1 27 A1 27 20 01 67 0A F9 0B F5 0E F1 0F ED 02 01 59 0C C1 0D BD DE bclr jsr cmp beq bra 0,portc spiwr #$0a cir key cir bra cli key ** set time ** nudig jsr cmp beq cmp beq cmp beq cmp beq sttm bclr jsr cmp beq cmp beq bra keypad #$0a nudig #$0b nudig #$0e nudig #$0f nudig 0,portc spiwr #$0c key #$0d key nudig send interruptfor spi send byte check for disp. temp. look for valid digit send int. for send value check for pm yes, wait for check for am yes, wait for get next time spi next input next input digit ** spi write subroutine ** 0159 0159 015B 015E 0160 spiwr B7 0C 0F 0B FD 10 02 81 equ sta brclr bset spiflg rts * spdr 7,spsr,* 0,portc put data in data reg. wait for end of byte done Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 15 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0114 0015 0016 0017 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 0130 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143 0144 0145 0146 0147 0148 0149 0150 0151 0152 0153 0154 0155 0156 0157 0158 0159 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 16 ** spi read subroutine ** 0161 0161 BF 0C 0163 0F 0B FD 0166 81 spird rdend equ stx brclr rts * spdr 7,spsr,* initiate transfer wait for end of byte ** keypad scanning routine ** 0167 keypad equ * ** 32 msec delay ** 0167 0169 016B 016D 016E 0170 0172 0174 0175 0177 0179 0178 017D 017F 0181 0183 0184 0186 0188 A6 B7 A6 4A 26 3A 26 5F A6 B7 B6 A4 A1 26 37 5C A3 23 20 20 B3 32 wtlp otlp inlp FD B3 F7 80 00 00 0F 00 09 00 03 F1 DD nxtr inval lda sta lda deca bne dec bne clrx lda sta lda and cmp bne asr incx cpx bls bra #$20 ct1 #$32 inlp ct1 otlp #$80 porta porta #$0f #$00 debnc porta #$03 nxtr wtlp set up outer loop counter set up inner loop dec. inner loop when 0, decrement outer loop set up row counter check first row check for key mask upper nibble look for zero branch if have a key try next row decrement row counter check for zero test next row no key pressed ** debounce key input ** 018A 018C 018E 0190 0191 0193 0195 0197 0199 B7 BF A6 4A 26 B6 A4 B1 26 B1 B0 FF debnc loop FD 00 0F B1 CC sta stx lda deca bne lda and cmp bne tmpa rwno #$ff save value save row number set up delay loop porta #$0f tmpa wtlp wait check row again mask upper nibble check for same key return if invalid ** wait for key release ** 019B 019D 019F 01A1 B6 A4 A1 26 00 0F 00 F8 wtr lda and cmp bne porta #$0f #$00 wtr check value mask upper nibble look for zero wait for release ** decode key value ** 01A3 01A5 01A6 01A7 01A9 01AA 01AC B6 B1 5F 44 25 03 5C 20 FA 58 nxtc col lda clrx lsra bcs incx bra lslx tmpa col restore value set up column ctr. shift columns branch if have column nxtc try next column Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0175 0176 0177 0178 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191 0192 0193 0194 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207 0208 0209 0210 0211 0212 0213 0214 0215 0216 0217 0218 0219 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 0230 0231 0232 0233 0234 0235 01AD 01AE 01AF 01B1 01B2 01B4 01B6 58 9F BB B0 97 E6 20 B7 B1 81 lslx txa add tax lda sta rts rwno kypd,x tmpa x=4*col. no. place x in a key value =4*col + row place a in x convert to decimal ****** temperature conversion routine ****** * * farenheit value is received from 705r3 via * spi and received in the a register. the value * is converted to celcius and the leftmost * led is blanked. 01B7 01B7 01BA 01BC 01BE 01C0 01C1 01C3 r3int CD B6 A0 24 40 AE BF 01 61 0C 20 05 0A B6 equ jsr lda sub bhs nega ldx stx * spird spdr #$20 conv #$0a base+2 read value transfer value to register subtract 32 if pos. convert negate ‘-’ pattern *** temperature conversion *** ** a 16-bit multiply by 5 is performed on the ** value received from the r3. this number ** is then divided by 9. 01C5 01C7 01C9 01CB 01CC 01CE 01CF 01D1 01D3 01D5 01D7 01D9 01DB 01DC 01DE 01E0 01E2 01E4 01E6 01E8 01EA 01EC 01EE 3F 3F B7 48 39 48 39 BB 24 3C 3F B7 98 3C B7 B6 A2 B7 B6 A0 24 3D 26 B9 B8 B8 conv B9 B9 B8 02 B9 B2 B8 B2 B8 B9 00 B9 B8 09 F0 B9 EC div nxt9 clr clr sta lsla rol lsla rol add bcc inc clr sta clc inc sta lda sbc sta lda sub bcc tst bne msb lsb lsb msb msb lsb div msb dctr lsb dctr lsb msb #$00 msb lsb #$09 nxt9 msb nxt9 clear counters multiply by 2 load overflow into msb multiply by 2 load overflow into msb a contains value x5 if overflow, inc msb subtract borrow from msb count factors of 9 if no borrow, repeat if borrow, check for end repeat if not end *** end of divide, add last 9 back in and *** check remainder for rounding 01F0 01F2 01F4 01F6 AB A1 22 3A 09 04 02 B2 add cmp bhl dec #$09 #$04 done dctr find remainder if greater then 4, round up Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 17 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0236 0237 0238 0239 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 0254 0255 0256 0257 0258 0259 0260 0261 0262 0263 0264 0265 0266 0267 0268 0269 0270 0271 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287 0288 0289 0290 0291 0292 0293 0294 0295 18 01FB B6 B2 done lda dctr 01FA AE 0B 01FC BF B7 pos ldx stx #$0b base+3 blank pattern blank most sig. digit *** convert binary value to bcd value *** * * the x registers begins with the binary value * and exits with zero. each digit, units, tens * and hundreds, is stored separately and checked * for a value equal to 10. 01FE 01FF 0200 0202 0204 0205 0207 0208 0209 020B 020D 020F 0211 0213 0215 0216 0218 021A 021C 97 4F 3F 3F 5D 27 5A 4C A1 26 3C B6 A1 27 4F 20 3F 3C 20 B5 B6 st 17 DA F7 B5 B5 0A 03 zero EC B5 B6 F7 hund tax clra clr clr tstx beq decx inca cmp bne inc lda cmp beq clra bra clr inc bra place a into x base+1 base+2 send #$0a st base+1 base+1 #$0a hund st base+1 base+2 zero clear values check for end if complete, send to r3 decrement hex number increment decimal number equal to 10? no, keep going increment tens test for 10 if equal, set hundreds clear ones count next 10 clear tens increment hundreds * send all digits to 70r3 via spi * start by interrupting r3 and then * sequentially sending four values 021E 0220 0222 0224 0226 0229 022A 022C 022E 022F 0231 0233 B7 B6 27 E6 CD 5C A3 26 80 A6 B7 2D B4 B6 0B B4 01 59 send nxtdg 03 F6 0B B6 EF blk sta lda beq lda jsr incx cpx bne rtl lda sta bra base base+2 blk base,x spiwr store ones #$03 nxtdg look for end if no, next digit start at base send to r3 #$06 base+2 nxtdg *** initialize interrupt vectors *** 1FF4 1FF4 1FF6 1FF8 1FFA 1FFC 1FFE 01 01 01 01 01 01 00 00 00 B7 00 00 spivec scivec tmrvec irqvec swivec reset org #1ff4 fdb fdb fdb fdb fdb fdb start start start r3int start start Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 0050 0051 0052 nam r3disp ************ REGISTER DEFINITION ************ 0001 0002 0005 0006 0008 0009 000E 000F portb portc ddrb ddrc tdr tcr acr arr 0040 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 004A wrdat timtmp ct ct1 result res1 bitct sec segmnt pm base equ equ equ equ equ equ equ equ 1 2 5 6 8 9 14 15 org $40 rmb rmb rmb rmb rmb rmb rmb rmb rmb rmb rmb 1 1 1 1 1 1 1 1 1 1 4 0080 org $80 *** display look-up table *** 0080 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 008A 008B 008C 008D 0090 01 4F 12 06 4C 24 20 0F 00 0C 7E 7F 7F 18 segtab equ fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb fcb org * %00000001 %01001111 %00010010 %00000110 %01001100 %00100100 %00100000 %00001111 %00000000 %00001100 %01111110 %01111111 %01111111 %00011000 $90 0 1 2 3 4 5 6 7 8 9 blank pm p program start Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 19 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0053 0054 0055 0056 0057 0058 0059 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 0100 0101 20 *** initialize variables *** 0090 0090 0092 0095 0097 0099 009B 009D 009F 00A1 00A3 00A5 00A7 00A9 00AB 00AD 00AF 00B1 00B3 00B5 00B7 00B9 00BB 00BD 00BF start A6 C7 A6 B7 B7 B7 B7 B7 B7 A6 B7 B7 A6 B7 A6 B7 3F 3F 3F A6 B7 A6 B7 9A 07 0F 38 FF 05 08 4A 4B 4C 4D EF 02 48 CF 06 0F 09 41 47 49 3B 42 08 43 equ lda sta lda sta sta sta sta sta sta lda sta sta lda sta lda sta clr clr clr lda sta lda sta cli * #$07 $f38 #$ff ddrb tdr base base+1 base+2 base+3 #$ef portc segmnt #$cf ddrc #$0f tcr timtmp sec pm #$3b ct #$08 ctl set MOR set up port b as output set timer for prescale of 128 blank time display set portc to choose msd set up c0-3, c6, c7 as outputs unmask timer interrupt start with time disp. set seconds to zero start with am set up timing loops * delay for 00C0 00C2 00C4 00C5 00C7 00C8 AE A6 4A 26 5A 26 FF FF FD F8 dlay ldx lda deca bne decx bne #$ff #$ff dlay+4 dlay+2 * temperature measurement * 00CA 00CC 00CE 00D0 00D2 00D4 00D6 00D8 00DA 3F B6 2A B6 A2 B7 B6 A1 26 0E 0E FC 0F 30 45 41 07 E4 clr lda bpl lda sbc sta lda cmp bne acr acr *-2 arr #$30 res1 timtmp #$07 dlay clear conv. complete flag get result adjust so 0 deg =$30 store in spi data register check for temp. update Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111 0112 0113 0114 0115 0116 0117 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 0130 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143 0144 0145 0146 0147 0148 0149 0150 0151 0152 0153 0154 0155 *** * * * 00DC 00DD 00DF 00E2 send temperature value to hc05c4 for conversion into celcius. start by interrupting the hc05c4 and then transmit data via the spi. 9B 1F 02 CD 01 18 AE 04 sei bclr jsr ldx 7,portc spiwr #$04 interrupt hc05c4 write data to hc05c4 * wait for return data ~ 140 cycles * 00E4 00E6 00E8 00EA 00EB A6 B7 A6 4A 26 0B 51 0E timlp FD lda sta lda deca bne #$0b base+7 #$0e timlp * get decimal values in celcius from * hc05c4 00ED 00F0 00F2 00F4 00F5 00F7 00F9 00FA CD B6 E7 5C A3 26 9A 20 01 01 44 4A nxtdg 07 F4 C4 jsr lda sta incx cpx bne cli bra spird result base,x #$07 nxtdg get value store check for end dlay ** select temperature display ** 00FC A6 07 00FE B7 41 0100 80 temp lda sta rti #$07 timtmp choose temp. display **** spi routines **** * the three pins used for the spi are * miso bit 6, portc * mosi bit 5, portc * sck bit 4, portc * the r3 waits for a high-to-low * transition on he spi clock, which * is provided by the hc05c4 and sent * on portc pin 4. a bit of data is * transferred on each high-to-low * transition of the clock. * spi read * 0101 0101 A6 08 0103 B7 46 spird equ lda sta * #$08 bitct set bit counter Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 21 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0156 0157 0158 0159 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 0175 0176 0177 0178 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191 0192 0193 0194 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207 0208 0209 0210 22 0105 08 02 FD 0108 0A 02 00 010B 010D 010F 0110 0112 0113 0115 0117 39 A6 4A 26 9D 3A 26 81 44 02 FD 46 EE nxt brset brset 4,portc,* 5,portc,str wait for clock transition check data status * * note: the brset command automatically * sets the carry bit to be equal to the * bit under test * str rol result store in result lda #$02 delay loop stall deca bne stall nop dec bitct check for end of byte bne nxt get next bit rts * spi write * * data to be sent is in result at * start of write 0118 0118 011A 011C 011E 0120 0122 0124 0126 0127 0128 012B 012D 012F 0131 A6 B7 39 25 1D 1E 19 9D 9D 08 3A 26 1E 81 08 46 45 12 02 02 02 spiwr 02 FD 46 ED 02 tst 0132 0134 0136 0138 1C 1E 18 20 02 02 02 EE set1 agn equ lda sta rol bcs bclr bset bclr nop nop brset dec bne bset rts * #$08 bitct res1 set1 6,portc 7,portc 4,portc bset bset bset bra 6,portc 7,portc 4,portc tst 4,portc,* bitct agn 7,portc set bit counter shift data check data status if 0, clear miso clear interrupt timing delay. wait for clock trans. check for end of byte clear interrupt if 1, set miso clear interrupt ** initialization of data read via spi ** * * a data read is initiated via an interrupt * from the hc05c4. the value received is * tested to determine which function is * requested and the processor jumps to the * proper routine. * 013A 013D 013F 0141 0143 CD A6 B7 B6 A1 01 01 03 41 44 0A c4int jsr lda sta lda cmp spird #$03 timtmp result #$0a get value choose time check for disp temp Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0211 0212 0213 0214 0215 0216 0217 0218 0219 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 0230 0231 0232 0233 0234 0235 0236 0237 0238 0239 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 0254 0255 0256 0257 0258 0259 0260 0261 0262 0263 0145 0147 0149 014B 014D 014F 0151 0153 0155 0157 0159 015B 015D 27 A1 27 A1 27 A1 27 A1 27 A1 26 A6 B7 B5 0F 3C 0E 39 0D 0C 0B 6A 0C 39 FF 49 beq cmp beq cmp beq cmp beq cmp beq cmp bne lda sta temp #$0f rtry #$0e clrtm #$0d am #$0b dsec #$0c dig #$ff pm check for display time check for set time check for am check for secs check for pm no, set digit set pm address ** check for valid input ** 015F 0161 0163 0165 0167 0169 016B 016D 016F 0171 0173 B6 27 A1 27 A1 26 A6 B7 B6 A1 22 4D 08 01 46 0B 48 0B 4D 4B 05 3E am blhr mtn lda beq cmp beq cmp bne lda sta lda cmp bhi base+3 blhr #$01 twoc #$0b blank #$0b base+3 base+1 #$05 blank check tens of hours if zero, blank digit look for blank if not, blank display blank tens of hours check tens of minutes check against 5 if greater, blank display * valid input, set timer counter * 0175 0177 0179 017B 017D 017F 0181 0183 0185 0187 A6 B7 A6 B7 A6 B7 3F 3F 3F 80 0F 09 43 42 06 43 47 52 53 rtry lda sta lda sta lda sta clr clr clr rti #$0f tcr #$43 ct #$06 ct1 sec base+8 base+9 unmask timer interrupt load inner loop counter load outer loop counter * clear displays * 0188 018A 018C 018E 0190 0192 A6 B7 B7 B7 B7 20 0B 4A 4B 4C 4D F3 clrtm lda sta sta sta sta bra #$0b base base+1 base+2 base+3 rtry * input digit * Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 23 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0264 0265 0266 0267 0268 0269 0270 0271 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287 0288 0289 0290 0291 0292 0293 0294 0295 0296 0297 0298 0299 0300 0301 0302 0303 0304 0305 0306 0307 0308 0309 0310 0311 0312 0313 0314 0315 0316 0317 0318 0319 24 *** time setting routine *** * time is inputted left to right * and the end of input is indicated * by pressing either the am or pm * button. pm is denoted on the * display by lighting the decimal * point. counters are set to zero out * after each second. * 0194 0195 0197 0199 019B 019D 019F 01A1 01A3 01A5 01A7 01A9 01AB 9A B6 B7 B6 B7 B6 B7 B6 B7 A1 22 B7 20 dig 4C 4D 4B 4C 4A 4B 44 4A 09 DE 4A DA cli lda sta lda sta lda sta lda sta cmp bhi sta bra base+2 base+3 base+1 base+2 base base+1 result base #$09 rtry base rtry shift data left one digit enter digit 1 check for valid digit get next number * check if time less than 12 o’clock * blank display if not 01AD 01AF 01B1 01B3 01B5 01B7 01B9 01BB 01BD 01BF 01C1 01C3 01C5 01C7 B6 A1 23 3F 3F A6 B7 A6 B7 20 4C 02 BC 4D 4C 0D 4B 05 A4 C6 B7 41 B7 55 B7 54 80 twoc blank lda cmp bls clr clr lda sta lda sta bra base+2 #$02 mtn base+3 base+2 #$0d base+1 #$05 base rtry **** seconds display **** * blank first two leds * dsec sta timtmp sta base+$b sta base+$a rti check hours units okay, check tens of min. send error message set timtmp to $0b blank 1st two leds **** display routine **** * * displays are refreshed every msec * when a timer interrupt occurs. the * most significant digit is displayed * first. at the conclusion of each * minute, the time is updated * Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0320 0321 0322 0323 0324 0325 0326 0327 0328 0329 0330 0331 0332 0333 0334 0335 0336 0337 0338 0339 0340 0341 0342 0343 0344 0345 0346 0347 0348 0349 0350 0351 0352 0353 0354 0355 0356 0357 0358 0359 0360 0361 0362 0363 0364 0365 0366 0367 0368 0369 0370 0371 0372 0373 01C8 tmrint equ 01C8 01C9 01CB 01CD 01CF 01D1 99 BE A6 B7 36 25 01D3 01D5 01D7 01D9 01DA 01DD 01DF 01E0 01E3 01E5 01E6 01E9 01EB 01ED 01EE 01F0 01F2 01F4 A6 B7 E6 5A 02 E6 5A 04 E6 5A 06 E6 A4 97 EE BF B6 B7 sec ldx lda sta ror bcs 41 FF 01 48 04 F7 48 4A min2 48 02 4A hrs1 48 02 4A hrs2 48 02 4A 0F disp 80 01 48 02 lds sta lda decx brset lda decx brset lda decx brset lda and tax ldx stx lda sta * timtmp #$ff portb segmnt min2 choose time or temp blank displays send to leds select display look for restart #$f7 segmnt base,x restart with msd 1,segment,hrs1 base,x 2,segment,hrs2 base,x 3,segment,disp base,x #$0f segtab,x portb segmnt portc load a with minutes point to next digit check hours units load a with tens of min. point to next digit check tens of hrs. load a with hours units point to next digit display value load a with tens of hrs mask upper nibble set x equal to a display value table enable display drivers enable display ** count display refreshes. 402 refreshes * equals one second. after 402 refreshes, * update clock * 01F6 01F8 01FA 01FC 01FE 0200 0202 0204 0206 0208 020A A6 B7 A6 B7 3A 26 A6 B7 3A 27 80 10 08 0F 09 42 08 3B 42 43 01 ret lda sta lda sta dec bne lda sta dec beq rti #$10 tdr #$0f tcr ct ret #$3b ct ct1 tmchg set timer to interrupt after 2048 cycles reset timer interrupt flag decrement inner loop reset inner loop decrement outer loop if one sec., to time change ***** time change routine ***** * when 60 seconds are counted, * increase minutes by one, if * necessary, blank minutes and increase * hours. change am/pm if needed. * Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 25 Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D 0374 0375 0376 0377 0378 0379 0380 0381 0382 0383 0384 0385 0386 0387 0388 0389 0390 0391 0392 0393 0394 0395 0396 0397 0398 0399 0400 0401 0402 0403 0404 0405 0406 0407 0408 0409 0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 0420 0421 0422 0423 0424 0425 0426 26 020B 020B 020D 020F 0211 0213 0215 0217 0219 021B 021D 021F 0221 0223 0225 0227 0229 022B 022D 022F 0231 0233 0235 0237 0239 023B 023D 023F 0241 0243 0245 0247 0249 024B tmchg 3C 3C B6 A1 27 A6 B1 26 3F 3F B6 A1 26 3F B6 A1 26 3F B6 A1 27 B6 A1 26 A6 B7 A6 B7 20 3C 20 3C 20 47 52 52 0A 38 3C 47 54 47 53 4A 09 20 4A 4B 05 1C 4B 4D 0B 1E 4C 02 2A 0B 4D 01 4C 2A 4A 26 4B 22 024D 3F 52 024F 3C 53 0251 20 C2 minck inm1 inm2 tens equ inc inc lda cmp beq lda cmp bne clr clr lda cmp bne clr lda cmp bne clr lda cmp beq lda cmp bne lda sta lda sta bra inc bra inc bra * sec base+8 base+8 #$0a tens #$3c sec ret1 sec base+9 base #$09 inm1 base base+1 #$05 inm2 base+1 base+3 #$0b hrck base+2 #$02 inhr1a #$0b base+3 #$01 base+2 ret1 base ret1 base+1 ret1 clr inc bra base+8 base+9 minck increase seconds inc. secs. units look for ten if yes, inc. tens look for a minute wait for next second zero display check min. units less than 9? increase min. units = 0 check tens of min. less than 5? increase tens of min =0 check tens of hrs. look for blank less than 10:00 check hrs. units less than 2? increase set time to 1:00 done increase min. units done increase tens of min. zero sec. units inc sec. tens * increase hours * 0253 0255 0257 0259 025B 025D 025F 0261 0263 0265 0267 0269 B6 A1 26 3F 3F 3C 20 3C 20 3C B6 A1 4C 09 08 4C 4D 4D 0E 4C 0A 4C 4C 02 hrck lda cmp bne clr clr inc bra inhr1 inc bra inhr1a inc lda cmp base+2 #$09 inhr1 base+2 base+3 base+3 ret1 base+2 ret1 base+2 base+2 #$02 check hours units less than 9? increase hours units =0 tens of hours =1 done increase hours units done increase hours units check value for 12:00 Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com Freescale Semiconductor, Inc. Freescale Semiconductor, Inc... AN991/D Code Listings 0427 0428 0429 0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 0440 0441 0442 0443 026B 026D 026F 0271 0273 0275 0277 26 33 A6 B7 A6 B7 80 9D 49 3B 42 08 43 ret1 bne com lda sta lda sta rti ret pm #$3b ct #$08 ct1 no, done switch pm indicator reset inner loop counter reset outer loop counter *** initialize interrupt vectors *** 0FF8 0FF8 0FFA 0FFC 0FFE 01 01 00 00 C8 3A 90 90 tmrvec intveq swiveq reset org $ff8 fdb fdb fdb fdb tmrint c4int start start Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers For More Information On This Product, Go to: www.freescale.com 27 Freescale Semiconductor, Inc. How to Reach Us: Home Page: www.freescale.com Freescale Semiconductor, Inc... E-mail: [email protected] USA/Europe or Locations Not Listed: Freescale Semiconductor Technical Information Center, CH370 1300 N. Alma School Road Chandler, Arizona 85224 +1-800-521-6274 or +1-480-768-2130 [email protected] Europe, Middle East, and Africa: Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen, Germany +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (German) +33 1 69 35 48 48 (French) [email protected] Japan: Freescale Semiconductor Japan Ltd. Headquarters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Japan 0120 191014 or +81 3 5437 9125 [email protected] Asia/Pacific: Freescale Semiconductor Hong Kong Ltd. Technical Information Center 2 Dai King Street Tai Po Industrial Estate Tai Po, N.T., Hong Kong +800 2666 8080 [email protected] For Literature Requests Only: Freescale Semiconductor Literature Distribution Center P.O. Box 5405 Denver, Colorado 80217 1-800-441-2447 or 303-675-2140 Fax: 303-675-2150 [email protected] Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters which may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including “Typicals” must be validated for each customer application by customer’s technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. AN991/D For More Information On This Product, Go to: www.freescale.com