; The alphanumeric characters are a single unit with two integrated ; characters and an 18 pin interface. Each character is referred to as ; a 14-segment display. ; The alphanumeric characters have 15 segments 14 plus the decimal point), so ; it takes 15 bits obviously 16 are used) to set all the segments. Therefore, it takes two ; 8-bit transfers to set each character. The segments are organized as shown below. ; The coding of the parts is divided more or less along the lines of lower segments and ; upper segments, with one of each of the middle segments going in each part. ; The lower part is written first and then the upper part. In the following, the order ; is in bit order (MSB first). Note that bit 0 in the high-order byte is unused. ; ; 6 ; ___ ______ ; |\|/| 1 | \ | /| 7 4 ; _ _ 2 3 4 ---- ; |\|/| --- 1 2 3 ; ___ O 5 0 | / | \ | 7 ; ------- {} 6 ; 5 ; ; The bits are loaded lower bits first and then the upper bits. ; ; The Raven board interfaces to the two alphanumeric characters through ; a 74LS95 serial to parallel 8-bit shift registers. This is similar to the reading of the ; dip switches. It requires a clock signal to control the writing of the bits, a ; load/shift signal and enable signals for each character. These signals are connected to: ; ; Clock-In RC3 ; RCK (Load/Shift) Y14 ; Enable left Y9 ; Enable right Y10 ; ; Interestingly, the serial in for the right character is connected to ; the high order output pin of the left character, so to load the right ; character bits, you need to shift them through the left character, ; whose input is connected to RC5. This is handled by the shift register through the ; RCK signal. Alternating RCK high signals cause the data to be stored in the ; local latch, or sent out through the serial-out pin. ; ; This design is not completely arbitrary, since it is intended to make ; use of the Serial Peripheral Interface (SPI), which is integrated into the ; 16F877 Sycnhronous Serial Port. This is a standard way ; of communicating between devices in a bit-serial manner. It works ; like this: ; ; The SPI consists of 3 lines: ; SDO = Serial Output (connected to RC5) ; SDI = Serial Input (connected to RC4) ; SCK = Serial clock (connected to RC3) ; ; and some control registers. ; ; SSPBUF = the SPI buffer register (actually the SSP buffer) ; PIR1 = Peripheral Interrupt Register 1=20 ; SSPCON = The SSP control register. ; ; Data is written into the SSPBUF, which initiates a clocked transfer, ; in this case to the shift registers. You have to wait around for it to ; finish, which is indicated by the SSPIF bit in the ; PIR1 register. When it is done, the shift register is loaded. Note ; that when data is written to SSPBUF, the transfer only begins when the SSPIF ; bit is cleared. ; ; So this part is a snap. The other things that has to happen is that ; after the shift register is loaded, the load/shift signal tied to Y14 must be ; strobed to cause the shift. This can be done by simply enabling and then disabling Y14. ; Finally, the last thing to do is the enable the alphanumeric character ; with Y9 or Y10. ; ; LIST P=16F877, R=DEC INCLUDE "P16F877.inc" ; Definitions ; __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC20 ; Define start of vars ScratchPad EQU 0x20 ; Variables Value1Lo EQU ScratchPad+0 Value1Hi EQU ScratchPad+1 Value2Lo EQU ScratchPad+2 Value2Hi EQU ScratchPad+3 Temp EQU ScratchPad+4 Counter EQU ScratchPad+5 DTemp1 EQU ScratchPad+6 DTemp2 EQU ScratchPad+7 ; Start of the Program ORG 3 goto Start ; This code reads the dip switch and stores the bit pattern in Dippy and ; and outputs to the alphacharars ; ORG 0x20 ; These tables are incomplete. Alpha_Lower ; 0 = segment off, 1 = segment on addwf PCL,F retlw B'10010001' ; A retlw B'10110100' ; B retlw B'00100001' ; C retlw B'10100100' ; D retlw B'00100001' ; E retlw B'00000001' ; F retlw B'10110001' ; G retlw B'10010001' ; H retlw B'00100100' ; I retlw B'10100000' ; J retlw B'00001001' ; K retlw B'00100001' ; L retlw B'10000101' ; M retlw B'10001001' ; N retlw B'10100001' ; O retlw B'00010001' ; P retlw B'10010000' ; Q retlw B'00011001' ; R retlw B'10110000' ; S retlw B'00000100' ; T retlw B'10100001' ; U retlw B'00000011' ; V retlw B'10100101' ; W retlw B'00001010' ; X retlw B'00000100' ; Y retlw B'00100010' ; Z Alpha_Upper ; 0 = segment off, 1 = segment on (bit 0 unused) addwf PCL,F retlw B'11100011' ; A retlw B'11001001' ; B retlw B'01000011' ; C retlw B'11001001' ; D retlw B'01100011' ; E retlw B'01100011' ; F retlw B'01000011' ; G retlw B'10100011' ; H retlw B'01001001' ; I retlw B'10000001' ; J retlw B'00110011' ; K retlw B'00000011' ; L retlw B'11001011' ; M retlw B'10000111' ; N retlw B'11000011' ; O retlw B'11100011' ; P retlw B'11100011' ; Q retlw B'11100011' ; R retlw B'01100011' ; S retlw B'01001001' ; T retlw B'10000011' ; U retlw B'00010011' ; V retlw B'10001011' ; W retlw B'00010101' ; X retlw B'00010101' ; Y retlw B'01010001' ; Z Start bsf STATUS, RP0 clrf TRISA clrf TRISC bcf STATUS, RP0 ; Set up the clocking. RC3 is the clock output pin for the SPI ; interface and SSPCON is the register that controls the SPI. Since that might interfere ; with the use of RC3 set SSPCON to all zeros. Also, clear the clock bit on port C ; which sets the outgoing signal to low. Low causes the dip switch value to be loaded and ; then we can read the bits. movlw 'A' sublw 'C' call Alpha_Lower movwf Value1Lo movlw 'A' sublw 'C' call Alpha_Upper movwf Value1Hi movlw 'A' sublw 'S' call Alpha_Lower movwf Value2Lo movlw 'A' sublw 'S' call Alpha_Upper movwf Value2Hi DisplayLoop ; Initialize SPI movlw b'00110000' movwf SSPCON bcf PIR1, SSPIF ; Do lower part of left hand char movf Value1Lo,W xorlw 0xFF movwf SSPBUF ; Wait for transfer to finish Loop_Lo btfss PIR1, SSPIF goto Loop_Lo ; Strobe the clock to end transfer movlw 0x1E movwf PORTA movlw 0x10 movwf PORTA bcf PIR1, SSPIF ; Do upper part of left hand char movf Value1Hi,W xorlw 0xFF movwf SSPBUF ; Wait for end of transfer Loop_Hi btfss PIR1, SSPIF goto Loop_Hi ; Strobe again movlw 0x1E movwf PORTA movlw 0x10 movwf PORTA ; Enable left char movlw 0x19 movwf PORTA ; Delay to let things settle movlw 1 call Delay_ms ; reinitialize for the second character movlw b'00110000' movwf SSPCON bcf PIR1, SSPIF movf Value2Lo,W xorlw 0xFF movwf SSPBUF ; Wait for transfer to end Loop_Lo2 btfss PIR1, SSPIF goto Loop_Lo2 ; Strobe movlw 0x1E movwf PORTA movlw 0x10 movwf PORTA bcf PIR1, SSPIF ; Do it one more time movf Value2Hi,W xorlw 0xFF movwf SSPBUF Loop_Hi2 btfss PIR1, SSPIF goto Loop_Hi2 movlw 0x1E movwf PORTA movlw 0x10 movwf PORTA ; Enable the right character movlw 0x1A movwf PORTA ; Delay to let things settle movlw 1 call Delay_ms ; Cycle refreshing the alphanumeric displays goto DisplayLoop ; Delay milliseconds Delay_ms bsf STATUS,RP0 bsf STATUS,RP1 movwf DTemp1 dloop_0 ; number of ms to delay movlw 250 movwf DTemp2 dloop_1 ; 1 ms delay (approximately) fill (nop), 17 decfsz DTemp2,F goto dloop_1 decfsz DTemp1,F goto dloop_0 bcf STATUS,RP1 bcf STATUS,RP0 return END