; File: 18F14K22_cntHour_pica_OTTM.ASM ; Author: picass/Ottmar ; Date: 29.07.2025 ;********************************** ; Das hier ist die Umsetzung des ursprünglich unter ; stundenzaehler05.txt ; von picass mitgeteilten ASM-Files. Dieses wurde von mir umgarbeitet ; und es tut was es soll: 1 blinkende LED an RB7. ; picass möge mir verzeihen, wenn ich das Programmgerüst ziemlich ; neu geordnet habe, das war dem logischen Aufbau und der besseren ; Übersicht geschuldet ; mfg Ottmar ; ;********************************************************************* ;--SURPRESSED ERRORS ; ERRORLEVEL -302 ;surpress the 'not in bank0' warning ERRORLEVEL -207 ; Found label after column 1. ERRORLEVEL -203 ; Found opcode in column 1 ; #INCLUDE ; ;--CONIFG SETTINGS CONFIG IESO = OFF, PLLEN = OFF, FOSC = IRC, FCMEN = OFF, PCLKEN = OFF CONFIG BOREN = SBORDIS, BORV = 19, PWRTEN = OFF, WDTEN = OFF CONFIG MCLRE = OFF, HFOFST = OFF, DEBUG = OFF, STVREN = ON ;--VARIABLE DEFINITIONS ;; GPR_VAR UDATA LOC_VAR UDATA ;;/rupi RES 1 ;unbenutzt (vormals ports einlesen) d2 RES 1 ;counters in Delay (not implemented) d1 RES 1 d0 RES 1 ;********************************************************************** ;--RESET VECTOR ;Programm starts here RES_VECT CODE 0x0000 ;processor reset vector BRA init ;initialize Ports and Modules ; -------------------------------------------------------------------- ;--HIGH PRIORITY INTERRUPT VECTOR ISRH CODE 0x0008 BRA ISR_H ;GOTO high_isr ; -------------------------------------------------------------------- ;; Org 0x0000 ;; bra START ;; Org 0x0008 ;vector für high priority irq ;; bra ruptus ; init: ;initialize inernal Modules / SFR ;;START: ;Setup main init ; ;--OSCCON movlw b'00000010' ; .000.... ; set 31kHz cpu clock speed ; ......10 ; byInternal oscillator block movwf OSCCON ; ;--OSCTUNE ; movlw b'00000000' ; 0....... ;31 kHz device clock derived directly from LFINTOSC internal oscillator clrf OSCTUNE ; ;--PORTA clrf LATA movlw b'00100000' ;port a5 clock eingang, rest ausgang movwf TRISA ; clrf WPUA ;keine pull ups widerstände an port a clrf ANSEL ;alle input pins auf digital ; ;--PORTB Port is used for a flashing LED clrf LATB clrf TRISB ; ;Rename RB7 for easier use LED EQU RB7 ;you can now call: LATB,LED ; ;--PORTC clrf LATC ;Port unused clrf TRISC ; ;---T1CON: TIMER1 CONTROL REGISTER DS.94 movlw b'00000000' ; ......0. b6/TMR1CS 0/1 = Internal(external clock (FOSC/4) ; .......0 b7/TMR1ON 0/1 disable/enable TMR1 movwf T1CON clrf TMR1H ;clear Hi-Byt ;TMR1 is set o 0x0000 clrf TMR1L ;clear Lo-Byte ;--Preset TMR1 ; The LED should flash with f=1Hz ; Fosc = 31.000Hz -> 7750 clocks/s -> working cycles (wc) ; Preset to 500ms _> 775/2 = 3875 = 0x0F23 ; to generate an overflow TMR1H:L has to be set 61661 = F0DDh ; movlw 0xF0 ;TMR1 value for preset in ISR ; movwf TMR1H ;65536 ; movlw 0xDD ; movwf TMR1L ;INITIALIZATION OF INTERRUPT ;--INTCON INTERRUPT CONTROL REGISTER movlw b'01000000' ; 0....... b7/GIE 0/1 Interrupts global disabled/enabled DS.62 ; .1...... b6 PEIE/GIEL: Peripheral Interrupt z.B. movwf INTCON ; TMR1-overflow-inter. 0/1 disabled/enabled ; ;-- PIR1: PERIPHERAL INTERRUPT REQUEST clrf PIR1 ;b0/TMR1IF: TMR1 Overflow Interrupt Flag DS.65 ; ;b0=1/0 TMR1 has/not overflowed ; ;--: PERIPHERAL INTERRUPT ENABLE movlw b'00000001' ; .......1 ;b0/TMR1IE 0/1 disable/enalbe TMR1 overfl. interr. movwf PIE1 ; ;--IPR1: PERIPHERAL INTERRUPT PRIORITY REGISTER 1 DS.69 movlw b'00000001' ;b0/TMR1IP set TMR1 Overflow Interrupt Priority movwf IPR1 ; ;--RCON: RESET CONTROL REGISTER movlw b'10000000' ;b7/IPEN=1 Enable priority levels on interrupts movwf RCON ; ;--ACTIVATE INTERRUPTS bsf INTCON,GIE ;Interrupts are enable bsf T1CON,TMR1ON ;TMR1 starts with counter value = 0x0000 ; ;********************************************************************* ; MAIM PROGRAMM ;********************************************************************* main: clrf LATB bsf LATB,LED main_loop: BRA main_loop ;********************************************************************* ; SUBROUTINES ISR_H: ; 500.00ms ISR-Interval should be ; ; -498.967ms ISR-Interval is ;------------------------------- ; 33ms difference ; TMR1L was therefore adjusted to account for the shortfall, as with ; fosc=31kHz, the last 2 digits of the timer overflow cannot be hit ; precisely. bcf PIR1,TMR1IF ;b0->0 clear TMR1 overflow-flag movlw 0xF0 ;Preset TMR1 to 61661 + ISR specific wc's movwf TMR1H ;Isr-Aufruf -> ?wc movlw 0xEE ;BRA ISR_H -> 2wc movwf TMR1L ;preset TRM1 -> 4wc ; movlw b'10000000' ;LED flashes every time the ISAR is called xorwf PORTB,f RETFIE FAST ;********************************************************************* END