;*********************************************************************** ;* Filename: GearSelector.asm ;* Date: Aug 12, 2012 ;* Version: 1.02 ;* Author: Jerry Komor ;*********************************************************************** ; This program displays gear selection on 5x7 commom-anode LED display. ; Multiplexing display rows with gear selector switches, hardware is minimized with addition of fiew extra diodes. ; ; NOTE: gear switches must be connected through RA4 pin (3) for proper operation ; ; Processor target 16F627/A, 16F628/A, 16F648A ; ; Pin connection description ; ; ---U--- ; RA2 |1 18| RA1 Col3 ; RA3 |2 17| RA0 Col4 ; sw common RA4 |3 16| RA7 Col1 ; RA5 |4 15| RA6 Col2 ; Vss |5 14| Vdd +5.0v ; sw1 Row6 RB0 |6 13| RB7 Col0 ; sw2 Row5 RB1 |7 12| RB6 sw7 Row0 ; sw3 Row4 RB2 |8 11| RB5 sw6 Row1 ; sw4 Row3 RB3 |9 10| RB4 sw5 Row2 ; ------- ; ; ;*********************************************************************** ifdef __16F627 #define PICFile P16F627.INC endif ifdef __16F627A #define PICFile P16F627A.INC endif ifdef __16F628 #define PICFile P16F628.INC endif ifdef __16F628A #define PICFile P16F628A.INC endif ifdef __16F648A #define PICFile P16F648A.INC endif ifdef PICFile #include PICFile else error "Wrong Processor type selected !!!" endif ; __config _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_OFF ;------------------------------------------------------------------------------------------------ ; EEPROM Charachter data ;------------------------------------------------------------------------------------------------ org 0x2100 CharN de 0x11, 0x19, 0x15, 0x15, 0x13, 0x11, 0x11 ; (N) Char1 de 0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E ; (1) Char2 de 0x0E, 0x11, 0x01, 0x0E, 0x10, 0x10, 0x1F ; (2) Char3 de 0x0E, 0x11, 0x01, 0x06, 0x01, 0x11, 0x0E ; (3) Char4 de 0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02 ; (4) Char5 de 0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E ; (5) Char6 de 0x0E, 0x10, 0x10, 0x1E, 0x11, 0x11, 0x0E ; (6) Char7 de 0x0F, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02 ; (7) CharR de 0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11 ; (R) LEDRow de b'01111110' de b'01111101' de b'01111011' de b'01110111' de b'01101111' de b'01011111' de b'00111111' ;------------------------------------------------------------------------------------------------ ; Constants ;------------------------------------------------------------------------------------------------ ; ; diverse Programmeinstellungen ; TimerInterval equ -.250 ; PortADirection equ b'00000000' PortBDirectionLED equ b'00000000' PortBDirectionKey equ b'01111111' PortAInit equ b'00010000' PortBInit equ b'01111111' LED_Rows_Port equ PORTB Key_Signal_Port equ PORTA Key_Signal equ 4 ;------------------------------------------------------------------------------------------------ ; Variables ;------------------------------------------------------------------------------------------------ cblock 0x70 w_ISR, status_ISR DisplayValue, DisplayLine, DisplayTemp endc ;------------------------------------------------------------------------------------------------ ; Macros ;------------------------------------------------------------------------------------------------ Bank0 macro bcf STATUS, RP0 bcf STATUS, RP1 endm Bank1 macro bsf STATUS, RP0 bcf STATUS, RP1 endm Bank2 macro bcf STATUS, RP0 bsf STATUS, RP1 endm Bank3 macro bsf STATUS, RP0 bsf STATUS, RP1 endm move macro arg1, arg2 errorlevel -302 movlw arg2 movwf arg1 errorlevel +302 endm ;------------------------------------------------------------------------------------------------ ; Reset-Vector ;------------------------------------------------------------------------------------------------ org 0x0000 clrf INTCON clrf STATUS goto start ;------------------------------------------------------------------------------------------------ ; Interrupt-Vector ;------------------------------------------------------------------------------------------------ org 0x0004 movwf w_ISR swapf STATUS, w movwf status_ISR btfss INTCON, T0IF goto ISR_End Bank0 move TMR0, TimerInterval call ReadKey call DisplayRefresh incf DisplayLine, w andlw 0x07 movwf DisplayLine ISR_End bcf INTCON, T0IF swapf status_ISR, w movwf STATUS swapf w_ISR, f swapf w_ISR, w retfie ;------------------------------------------------------------------------------------------------ ; Check if key is pressed ;------------------------------------------------------------------------------------------------ ReadKey bcf PORTA, 0 bcf PORTA, 1 bcf PORTA, 6 bcf PORTA, 7 bcf PORTB, 7 Bank1 move TRISB, PortBDirectionKey Bank0 bcf Key_Signal_Port, Key_Signal movlw Low CharN btfss LED_Rows_Port, 0 movlw Low Char1 btfss LED_Rows_Port, 1 movlw Low Char2 btfss LED_Rows_Port, 2 movlw Low Char3 btfss LED_Rows_Port, 3 movlw Low Char4 btfss LED_Rows_Port, 4 movlw Low Char5 btfss LED_Rows_Port, 5 movlw Low Char6 btfss LED_Rows_Port, 6 movlw Low CharR movwf DisplayValue bsf Key_Signal_Port, Key_Signal Bank1 move TRISB, PortBDirectionLED Bank0 return ;------------------------------------------------------------------------------------------------ ; Display update ;------------------------------------------------------------------------------------------------ DisplayRefresh movf DisplayValue, w addwf DisplayLine, w Bank1 movwf EEADR bsf EECON1, RD movf EEDATA, W movwf DisplayTemp movlw Low LEDRow addwf DisplayLine, w movwf EEADR bsf EECON1, RD movf EEDATA, w Bank0 movwf LED_Rows_Port btfsc DisplayTemp, 0 bsf PORTA, 0 btfsc DisplayTemp, 1 bsf PORTA, 1 btfsc DisplayTemp, 2 bsf PORTA, 6 btfsc DisplayTemp, 3 bsf PORTA, 7 btfsc DisplayTemp, 4 bsf PORTB, 7 return ;------------------------------------------------------------------------------------------------ ; Main Loop ;------------------------------------------------------------------------------------------------ start move CMCON, 0x07 Bank1 move OPTION_REG, 0x01 move PCON, 0x08 move TRISA, PortADirection move TRISB, PortBDirectionLED Bank0 move PORTA, PortAInit move PORTB, PortBInit clrf DisplayLine clrf DisplayTemp pause decfsz DisplayTemp, f goto pause decfsz DisplayLine, f goto pause move TMR0, TimerInterval move INTCON, 0xA0 MainLoop goto MainLoop ;------------------------------------------------------------------------------------------------ end