;------------------------------------------------------------------------------- ; FILE: Matrix ; AUTH: Ed's Projects ; DATE: 27/08/2016 ; DESC: 5x7 LED Dot Matrix Display ;------------------------------------------------------------------------------- LIST P=16F690, R=DEC ; All numbers Decimal format unless otherwise stated. include ; Define configurations, registers, etc. __config _FCMEN_OFF & _IESO_OFF & _BOREN_ON & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDTE_OFF & _INTRC_OSC_NOCLKOUT ;------------------------------------------------------------------------------- ;----------------------------- Port Definitions ------------------------------ ;------------------------------------------------------------------------------- ; PortA - Output - RA0 - Pin 19 - Row 1 ; PortA - Output - RA1 - Pin 18 - Row 2 ; PortA - Output - RA2 - Pin 17 - Row 3 ; PortC - Output - RC0 - Pin 16 - Row 4 ; PortB - Output - RB7 - Pin 10 - Row 5 ; PortC - Output - RC7 - Pin 9 - Row 6 ; PortC - Output - RC6 - Pin 8 - Row 7 ; PortC - Output - RC1 - Pin 15 - Column 1 ; PortC - Output - RC2 - Pin 14 - Column 2 ; PortB - Output - RB4 - Pin 13 - Column 3 ; PortB - Output - RB5 - Pin 12 - Column 4 ; PortB - Output - RB6 - Pin 11 - Column 5 ;------------------------------------------------------------------------------- ;-------------------------------- Variables ---------------------------------- ;------------------------------------------------------------------------------- cblock h'20' temp temp2 temp3 temp4 C1 ; Column 1 Variable C2 C3 C4 C5 ; Column 5 Variable endc ;------------------------------------------------------------------------------- ;----------------------------- Define Symbols -------------------------------- ;------------------------------------------------------------------------------- #define ROW1 PORTA, 0 #define ROW2 PORTA, 1 #define ROW3 PORTA, 2 #define ROW4 PORTC, 0 #define ROW5 PORTB, 7 #define ROW6 PORTC, 7 #define ROW7 PORTC, 6 #define COL1 PORTC, 1 #define COL2 PORTC, 2 #define COL3 PORTB, 4 #define COL4 PORTB, 5 #define COL5 PORTB, 6 ;------------------------------------------------------------------------------- ;------------------------------- Program Code -------------------------------- ;------------------------------------------------------------------------------- ORG 0 ;------------------------------------------------------------------------------- ;-------------------------- Initialisation of Ports -------------------------- ;------------------------------------------------------------------------------- Init bsf STATUS,RP0 bcf STATUS,RP1 ; Bank 1 Selected movlw b'00000000' movwf TRISA movlw b'00000000' movwf TRISB movlw b'00000000' movwf TRISC bcf STATUS,RP0 bsf STATUS,RP1 ; Bank 2 Selected clrf VRCON ; Set Vref to off clrf CM1CON0 ; Turn off comparator 1 clrf CM2CON0 ; Turn off comparator 2 clrf ANSEL ; Set analogue inputs to digital clrf ANSELH ; Set analogue inputs to digital bsf STATUS,RP0 ; Bank 3 Selected clrf SRCON ; Disable SR latch bcf STATUS,RP0 bcf STATUS,RP1 ; Bank 0 Selected clrf PORTA clrf PORTB clrf PORTC ;------------------------------------------------------------------------------- ;-------------------------------- Initialisaton ------------------------------ ;------------------------------------------------------------------------------- movlw d'8' call delay1 ; Wait 2 second movlw b'00110000' movwf C1 movlw b'01000110' movwf C2 movlw b'01000000' movwf C3 movlw b'01000110' movwf C4 movlw b'00110000' movwf C5 goto Start ;------------------------------------------------------------------------------- ;-------------------------------- Delay Loops -------------------------------- ;------------------------------------------------------------------------------- delay1 movwf temp4 loopy2 movlw d'100' ;multiples of 2.5ms movwf temp3 loopy movlw d'250' movwf temp initloop goto $+1 ;2us goto $+1 ;2us goto $+1 ;2us nop ;1us decfsz temp, f ;1us goto initloop ;2us decfsz temp3, f goto loopy ;250ms total decfsz temp4, f goto loopy2 ;Multiples of 250ms return msdelay movlw d'100' movwf temp loop goto $+1 ;2us goto $+1 ;2us goto $+1 ;2us nop ;1us decfsz temp, f ;1us goto loop ;2us return ;------------------------------------------------------------------------------- ;-------------------------------- Main Program ------------------------------- ;------------------------------------------------------------------------------- Start call Disp goto Start ;------------------------------------------------------------------------------- ;-------------------------------- Display Cycle ------------------------------ ;------------------------------------------------------------------------------- Disp movf C1, w call PRTLD bsf COL1 call msdelay bcf COL1 movf C2, w call PRTLD bsf COL2 call msdelay bcf COL2 movf C3, w call PRTLD bsf COL3 call msdelay bcf COL3 movf C4, w call PRTLD bsf COL4 call msdelay bcf COL4 movf C5, w call PRTLD bsf COL5 call msdelay bcf COL5 return PRTLD movwf temp bsf ROW1 bsf ROW2 bsf ROW3 bsf ROW4 bsf ROW5 bsf ROW6 bsf ROW7 btfsc temp, 0 bcf ROW1 btfsc temp, 1 bcf ROW2 btfsc temp, 2 bcf ROW3 btfsc temp, 3 bcf ROW4 btfsc temp, 4 bcf ROW5 btfsc temp, 5 bcf ROW6 btfsc temp, 6 bcf ROW7 return end