Hi! I'm trying to get this program work but haven't succeeded yet. I have a 3-digit common cathode 7-segment display and three transistors to turn the digits on. I'm using a PIC16F877A with a 4MHz crystal. Timer0 sets an interrupt after 1ms. I tried the multiplexing part of the code with 1ms counters written into code, without the interrupts and it worked perfectly. When I try to get the timing from TIMER0 it doesn't work. What's wrong with my code?
Rich (BB code):
PC EQU 02h
TRISA EQU 85h
PORTA EQU 05h
TRISB EQU 86h
PORTB EQU 06h
TRISC EQU 87h
PORTC EQU 07h
TRISD EQU 88h
PORTD EQU 08h
TRISE EQU 89h
PORTE EQU 09h
STATUS EQU 03h
TXSTA EQU 98h
TXREG EQU 19h
SPBRG EQU 99h
PCLATH EQU 0Ah
INTCON EQU 0Bh
OPTION_REG EQU 81h
TMR0 EQU 01h
W_TEMP EQU 70h
STATUS_TEMP EQU 71h
PCLATH_TEMP EQU 72h
BCD0 EQU 39h ; result of binary to bcd conversion in these 3 registers.
BCD1 EQU 3Ah
BCD2 EQU 3Bh
ORG 000h
goto INIT
ORG 004h ; Interrupt routine
movwf W_TEMP ; Copy W to TEMP register
swapf STATUS,0 ; Swap status to be saved into W
clrf STATUS ; bank 0, regardless of current bank, Clears IRP,RP1,RP0
movwf STATUS_TEMP ; Save status to bank zero STATUS_TEMP register
movf PCLATH,0 ; Only required if using pages 1, 2 and/or 3
movwf PCLATH_TEMP ; Save PCLATH into W
clrf PCLATH ; Page zero, regardless of current page
; 7-SEGMENT MULTIPLEXING
btfss PORTE,0 ; Is ones transistor on?
goto $+6
movlw b'100'
movwf PORTE ; Set hundreds transistor on.
movf BCD2,0 ; Move hundreds to 7-seg digit
movwf PORTC
goto INT_EXIT
btfss PORTE,1 ; Is tens transistor on?
goto $+6
movlw b'001'
movwf PORTE ; Set ones transistor on.
movf BCD0,0 ; Move ones to 7-seg digit
movwf PORTC
goto INT_EXIT
btfss PORTE,2 ; Is hundreds transistor on?
goto $+5
movlw b'010'
movwf PORTE ; Set tens transistor on.
movf BCD1,0 ; Moves tens to 7-seg digit
movwf PORTC
INT_EXIT movf PCLATH_TEMP,0 ; Restore PCLATH
movwf PCLATH ; Move W into PCLATH
swapf STATUS_TEMP,0 ; Swap STATUS_TEMP register into W
movwf STATUS ; Move W into STATUS register
swapf W_TEMP,1 ; Swap W_TEMP
swapf W_TEMP,0 ; Swap W_TEMP into W
movlw b'11111010' ; FAh (=250)
movwf TMR0
bcf INTCON,2 ; TMR0_INT
retfie
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INIT bsf STATUS,5 ; To bank 1
movlw b'000000'
movwf TRISA
movlw b'00001111'
movwf TRISB
movlw b'00000000'
movwf TRISC
movlw b'00000000'
movwf TRISD
movlw b'000'
movwf TRISE
movlw b'001'
movwf PORTE ; Sets the first digit on for multiplexing.
; SETUP TMR0
movlw b'01000001' ; Also sets PORTB pull-ups
movwf OPTION_REG
bcf STATUS,5 ; return to page 0
movlw b'10100000'
movwf INTCON ; GIE enable interrupts.
MAIN
; Main program here, I didn't include it this time...
Last edited: