;lsd.asm ; Example of writing to the 7 segment leds. ; ; The Raven board interfaces to the 7-segment LED's or LSD's through the Y outputs of the ; U12 multiplexor and PortD. The output of U12 controls the digit being written to ; with Y3 through Y8 controlling the digits from right to left, and RD0 through RD7 ; controlling the segments in the following way: ; ; |-- RD0 ; |---| ; RD5--| |--- RD1 ; RD6--|---| ; RD4--| |-- RD2 ; |---| []-- RD7 ; |-- RD3 LIST P=16F877, R=DEC INCLUDE "C:\MPLAB\P16F877.inc" ; Definitions ; __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC ; Define start of vars ScratchPad EQU 0x20 ; Variables Dippy EQU ScratchPad+0 ; Value from dip switch Temp EQU ScratchPad+1 Counter EQU ScratchPad+2 ; Start of the Program ORG 3 goto Start ; This code reads the dip switch and sends the results to the rightmost digit in the display. ; ORG 0x50 Start ; Set A4-A0 to be output and RD0-RD7 to be output. bsf STATUS, RP0 clrf TRISA clrf PORTD bsf TRISB,3 bcf TRISC,3 bcf STATUS, RP0 ; clrf SSPCON bcf PORTC,3 ; Now, we want to enable the 74LS165 and then disable it to create a low-going pulse. movlw 0x1E movwf PORTA movlw 0x10 movwf PORTA ; Now read each bit, shifting it into Dippy movlw 8 movwf Counter loop1 call ReadDipBit decfsz Counter,F goto loop1 ; Put the to LSD bit 5 comf Dippy,W call DispLSD loop2 ; loop to do something else. If you disable the segment enable, you will need to reenable ; it frequently enough to keep it from decaying to zero. 50 instructions is probably OK, ; 100 is probably too much. nop goto loop2 ReadDipBit ; Rotate Dippy to make room for the next bit. Clear bit zero and then test PORTB, bit 3 to ; see its state. If zero, we be done. If not, set bit 0 of Dippy rlf Dippy,F bcf Dippy,0 btfsc PORTB,3 bsf Dippy,0 ; toggle the clock to generate a pulse that reads the next. Setting the bit drives it low ; and clearing sets it high, giving a square wave, low-going pulse that causes the ; next bit to be shifted out. bsf PORTC,3 bcf PORTC,3 return DispLSD ; Enable LSD 5 and output to it movwf Temp ; save W movlw 0x13 movwf PORTA movf Temp,W movwf PORTD return ; Wait forever Forever waitforever nop goto waitforever return END