; ; primer programa ASM del PIC ; Sebastia, 14 de Abril de 2008. ; ; Conectar el pin 5 (RA3) a R=1 K cap al Anode del LED. ; XTAL 4 MHz entre pin 13 i 14. ; 2x C (22pf) del pin 13 i 14 a massa. ; list p=16f452 #include ; Configuration bits : ; ; Oscillator mode := XT ; ; Watch Dog Timer := off ; ; Low Voltage Programming := on : config WDT=OFF config OSC=XT ; User data ; MYDATA UDATA ; ;DTEMP res 1 ; reserve 1 address location ;DFLAG res 1 ; CBLOCK 0x020 DTEMP ; DFLAG ; BsrTemp ; copy of BSR StatusTemp ; copy of STATUS WregTemp ; copy of WREG ENDC DFL0 equ 0x00 ; define constant : set flag bit = 0 bit of DFLAG. ; +++ code start MYCODE CODE org 0x0000 ; Reset vector goto Start ; skip interrupt vectors org 0x0008 ; High Priority Interrupt Vector bcf T0CON,TMR0ON ; T0CON bit 7 off => stops timer 0 bcf INTCON,TMR0IF ; clear timer has overflowed flag bcf DFLAG, DFL0 ; clear soft (own) flag retfie FAST ; return from interrupt - pop W,STATUS & BSR off the stack org 0x0018 ; Low Priority Interrupt Vector goto ISR_space org 0x0040 ISR_space movff STATUS, StatusTemp ; save STATUS register movff WREG, WregTemp ; save WREG movff BSR, BsrTemp ; save BSR register ; low priority code movff BsrTemp,BSR ; restore BSR movff WregTemp, WREG ; restore working register movff StatusTemp, STATUS ; restore STATUS register retfie ; return from interrupt org 0x0100 ; Program start Start ; banksel CONFIG1H ; movlw 0x21 ; XT mode ; movwf CONFIG1H banksel TRISB ; select TRIS bank clrf TRISB ; clear TRISB =>set PORTB as Outputs. clrf PORTB ; clear PORT B data clrf TRISA ; clear TRISA => set PORTA as Output. clrf PORTA ; clear PORT A (output) data => set LOW. banksel INTCON ; select INTCON bank bsf INTCON, GIE ; enable Global Interrupts bsf INTCON, TMR0IE ; set INTCON bit 5 => enable Timer 0 interrupt Bucle movlw 0x55 ; odd pins HIGH, even pins LOW movwf PORTA ; set port A data call Delay1 ; use 1 or 2 ... movlw 0xAA ; even pins HIGH, odd pins LOW movwf PORTA ; set port A data call Delay2 ; use 2 or 1 ... goto Bucle ; own subroutines Delay1 movlw 0xF0 ; set Timer0 value movwf TMR0L ; 0x00 = longest, 0xFF = shortest delay. clrf DFLAG ; bsf DFLAG, DFL0 ; set flag bit movlw 0xC8 ; (7) enable, (6) 8-bit, (5) internal, (4) low-to-high, (3) noprescaler, (2-1-0) prescaler value movwf T0CON ; start Timer0 Tloop btfsc DFLAG, DFL0 ; wait for overflow (bit test, skip if clear) goto Tloop ; after interrupt, DFL0 = 0. return ; end of Delay1 ; Delay2 movlw 0xFF ; set DTEMP value movwf DTEMP ; 0x00 = shortest, 0xFF = longest delay Dloop decfsz DTEMP, F ; use countdown to create delay (decrement, skip if Zero) goto Dloop ; end loop when DTEMP = 0 return szID DB 0x55, 0x55, 0xAA, 0xAA ; eye catcher. DT "22/04/2008, v 1.2a" ; RETLW 8-bit. DB 0x55, 0x55, 0xAA, 0xAA ; eye catcher. end