;Sample interrupt program ; Definitionen list p=16f84 include ; Variables IRQFlag equ 0x0C ; Interrupt flag Z0 equ 0x0D ; Delay counter for the LCD Z1 equ 0x0E ; Delay counter for the LCD kit equ 0x0F ; Location on the LCD screen LorR EQU 0x10 ; Left or Right movement ; Reset-Vector --> Goto the start of the program org 0x00 goto ProgramStart ; TMR0-Interrupt. org 0x04 ;movlw 0x0A ; TMR0 = 10 initialize ;movwf TMR0 ; Used to set counter to a certian value bsf IRQFlag,0 ; IRQFlag = 1. bcf INTCON,2 ; TMR0 Interrupt-Flag clear. retfie org 0x50 ; A table to convert numbers. Number: addwf PCL,1 dt "0123456789ABCDEF" text1: addwf PCL,1 dt "Mobiles Hardware" ; Pause. Delay movwf Z1 ; Z1 = W. clrf Z0 ; Z0 = 0. incfsz Z0,1 ; Z0++ und Test auf Z0 == 0. goto $-1 incfsz Z1,1 ; Z1++ und Test auf Z1 == 0. goto $-4 return ; Inhalt des "Working Registers" an PORTB / LCD ausgeben. WREG2LCD: movwf PORTB ; PORTB = WREG. bsf PORTA,2 ; "Enable LCD" aktivieren (E = 1). movlw 0xFD ; W = 0xFD (Parameter für Funktion Delay). call Delay bcf PORTA,2 ; "Enable LCD" deaktivieren (E = 0). return ; Funktion beenden. ; The print function that prints the details on the screan mattPrint: bcf PORTA,3 ; "Instruction Register" (RS=0). movf kit,0 addlw b'10000000' ; Move to the correct position on the LCD screen call WREG2LCD bsf PORTA, 3 ; "Data Register" (RS=1). movf kit,0 ; Put letter on the LCD call text1 ;call Number call WREG2LCD btfsc LorR,0 ; check to see if I increment or decrement goto mpSub incf kit,1 btfss kit,4 return bsf LorR,0 decf kit,1 return mpSub: decf kit,1 btfss kit,7 return bcf LorR,0 incf kit,1 return ; Main Program ProgramStart: ; PORTA / PORTB initialize clrf PORTA ; PORTA clear. clrf PORTB ; PORTB clear. bsf STATUS,5 ; Bank 1 select. bcf STATUS,6 clrf TRISB ; Set PortB output. clrf TRISA ; Set PortA output. bsf TRISA,0 ; PIN 0 from PORTA input (button S5). bsf TRISA,1 ; PIN 1 von PORTA input (button S6). bcf STATUS,5 ; Bank 0 select. ; LCD-Display initialisieren (siehe Datenblatt HD44780U, Seite 45). bcf PORTA,3 ; "Instruction Register" (RS=0). movlw b'00110000' ; Initialisierung. call WREG2LCD movlw b'00110000' ; Initialisierung. call WREG2LCD movlw b'00110000' ; Initialisierung. call WREG2LCD movlw b'00111000' ; 2 Zeilen, 5*8 Pixel (siehe Datenblatt HD44780U, Seite 29). call WREG2LCD movlw b'00001100' ; LCD ein, Cursor aus (siehe Datenblatt HD44780U, Seite 26-28). call WREG2LCD movlw b'00000001' ; Display loeschen. call WREG2LCD bsf PORTA,3 ; "Data Register" (RS=1). ; TMR0 initialisieren. clrf IRQFlag bsf STATUS,5 ; Bank 1 select. bcf STATUS,6 movlw b'00000111' ; Prescaler 1:256 TMR0 movwf OPTION_REG bcf STATUS,5 ; Bank 0 select. movlw b'10100000' ; Activate Interrupt TMRO. Global=7, TOIE=5, TOIF=2 movwf INTCON clrf LorR clrf kit Loop ; Update? btfss IRQFlag,0 ; Wait for an interrupt goto $-1 bcf IRQFlag,0 ; Clear the interrupt flag bcf PORTA,3 ; "Instruction Register" (RS=0). movlw b'00000001' ; Clear Display call WREG2LCD bsf PORTA,3 ; "Data Register" (RS=1). call mattPrint ; Print text goto Loop ; Repeat main program end ; End of program