Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; PIC18F2550 Configuration Bit Settings
- ; ASM source line config statements
- #include "p18F2550.inc"
- ; CONFIG1L
- CONFIG PLLDIV = 2 ; PLL Prescaler Selection bits (Divide by 2 (8 MHz oscillator input))
- ; CONFIG CPUDIV = OSC1_PLL2 ; System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
- CONFIG CPUDIV = OSC4_PLL6 ; System Clock Postscaler Selection bits ([Primary Oscillator Src: /4][96 MHz PLL Src: /6])
- CONFIG USBDIV = 2 ; USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)
- ; CONFIG1H
- ;CONFIG FOSC = INTOSCIO_EC ; Oscillator Selection bits (Internal oscillator, port function on RA6, EC used by USB (INTIO))
- CONFIG FOSC = HSPLL_HS ; Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL))
- CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
- CONFIG IESO = OFF ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
- ; CONFIG2L
- CONFIG PWRT = OFF ; Power-up Timer Enable bit (PWRT enabled)
- CONFIG BOR = OFF ; Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
- CONFIG BORV = 3 ; Brown-out Reset Voltage bits (Minimum setting 2.05V)
- CONFIG VREGEN = OFF ; USB Voltage Regulator Enable bit (USB voltage regulator disabled)
- ; CONFIG2H
- CONFIG WDT = OFF ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
- CONFIG WDTPS = 32768 ; Watchdog Timer Postscale Select bits (1:32768)
- ; CONFIG3H
- CONFIG CCP2MX = OFF ; CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
- CONFIG PBADEN = OFF ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
- CONFIG LPT1OSC = OFF ; Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
- CONFIG MCLRE = OFF ; MCLR Pin Enable bit (RE3 input pin enabled; MCLR pin disabled)
- ; CONFIG4L
- CONFIG STVREN = ON ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
- CONFIG LVP = OFF ; Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
- CONFIG XINST = OFF ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode enabled)
- ; CONFIG5L
- CONFIG CP0 = OFF ; Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
- CONFIG CP1 = OFF ; Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
- CONFIG CP2 = OFF ; Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
- CONFIG CP3 = OFF ; Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
- ; CONFIG5H
- CONFIG CPB = OFF ; Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
- CONFIG CPD = OFF ; Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
- ; CONFIG6L
- CONFIG WRT0 = OFF ; Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
- CONFIG WRT1 = OFF ; Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
- CONFIG WRT2 = OFF ; Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
- CONFIG WRT3 = OFF ; Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
- ; CONFIG6H
- CONFIG WRTC = OFF ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
- CONFIG WRTB = OFF ; Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
- CONFIG WRTD = OFF ; Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
- ; CONFIG7L
- CONFIG EBTR0 = OFF ; Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
- CONFIG EBTR1 = OFF ; Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
- CONFIG EBTR2 = OFF ; Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
- CONFIG EBTR3 = OFF ; Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
- ; CONFIG7H
- CONFIG EBTRB = OFF ; Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
- RES_VECT CODE 0x0000 ; processor reset vector
- GOTO START ; go to beginning of program
- ; TODO ADD INTERRUPTS HERE IF USED
- ;DELAY EQU H'0000'
- TIMERH EQU 0x63
- TIMERL EQU 0xc0
- _mybank1 UDATA 0x0060
- DELAY res 1
- DELAY2 res 1
- LSR res D'3'
- LSRG res D'2' ; memory for the Galois LFSR
- R1 res 1
- R2 res 1
- R3 res 1
- PIXELS res 48
- timer res 1
- MAIN_PROG CODE ; let linker place main program
- START
- ;movlw B'01110010' ; 8 MHz INTOSCIO
- ;movwf OSCCON
- ;movlw B'00001111' ; tune it up to max
- ;movwf OSCTUNE
- CLRF PORTA
- CLRF PORTB
- CLRF PORTC
- CLRF LATA
- bcf UCON,3
- bsf UCFG,3
- MOVLW 0Fh
- MOVWF ADCON1
- MOVLW 07h
- MOVWF CMCON
- MOVLW 00h
- MOVWF TRISA
- MOVWF TRISB
- MOVWF TRISC
- movlw B'10000000'
- movwf T0CON
- movlw TIMERH
- movwf TMR0H
- movlw TIMERL
- movwf TMR0L
- bcf INTCON,TMR0IE
- bcf INTCON,TMR0IF
- MOVLW 01h
- MOVWF LSR
- MOVLW 00h
- MOVWF LSR+1
- movlw B'00001000'
- movwf LSR
- movwf LSR+1
- movwf LSR+2
- movwf LSRG
- movwf LSRG+1
- movlw 0x10
- movwf timer
- MAIN
- ;call CLRPIXELS
- call FADEPIXELS
- decf timer
- bnz _SKIP
- movlw 0x10
- movwf timer
- call LFSR_EXTERNAL
- call TO_PORTS
- btfsc LSR,7
- goto _SKIP
- ;movf LSR,0
- call LFSR_EXTERNAL
- call LFSR_INTERNAL
- call TO_PORTS
- call PUTPIXEL
- _SKIP
- call UpdateNeoPixels_x16
- call WaitForTimer
- goto MAIN
- WaitForTimer
- btfss INTCON,TMR0IF
- goto WaitForTimer
- bcf INTCON,TMR0IF
- movlw TIMERH
- movwf TMR0H
- movlw TIMERL
- movwf TMR0L
- return
- LFSR_EXTERNAL
- ; Fibonacci
- ; ab-cd--- ; the taps a,b,c,d
- ; -ab-cd-- ; shifted right to align
- ; -x--y--- ; bitwise xor'ed
- ; ----x--y ; shifted right three times
- ; ----z--- ; bitwise xor'ed again, move this bit to carry
- rrcf LSR+2,0 ; rotate and store in WREG
- xorwf LSR+2,0 ; xor wreg->wreg
- movwf R1 ; move it to r1, keep wreg intact
- rrcf R1 ; rotate x3
- rrcf R1
- rrcf R1
- xorwf R1 ; xor old wreg with R1.
- bcf STATUS,C ; clear carry flag
- btfss R1,3 ; bit test file (R1 bit3) skip if set
- goto SHIFT ;
- bsf STATUS,C ; set carry flag (only if R1 bit3 is set)
- SHIFT
- ; rotate the 24bit shiftregister using carry
- rlcf LSR
- rlcf LSR+1
- rlcf LSR+2
- return
- LFSR_INTERNAL
- ;Galois LFSR, 16 bit
- ;[16, 15, 13, 4] taps
- bcf STATUS,C
- rlcf LSRG
- rlcf LSRG+1 ; feedback enters carry
- bc LFSR_INTERNAL_1
- return
- LFSR_INTERNAL_1
- movlw B'00001000' ; mask high byte
- xorwf LSRG+1
- movlw B'00001011'; mask low byte
- xorwf LSRG
- return
- TO_PORTS
- ; to ports
- movlw B'11111110'
- andwf LSR,0
- movwf LATA
- ;movff LSR,LATA
- movff LSR+1,LATB
- movff LSR+2,LATC
- return
- PUTPIXEL
- movf LSR,0
- ;xorlw LSRG
- xorwf LSRG,0
- andlw B'00001111'
- movwf R1
- addwf R1,0
- addwf R1,0
- addlw PIXELS
- clrf FSR0H
- movwf FSR0L
- ; lfsr FSR0, R1
- movlw 0x00
- btfsc LSR,4
- movlw 0x60
- movwf POSTINC0
- movlw 0x00
- btfsc LSR,5
- movlw 0x60
- movwf POSTINC0
- movlw 0x00
- btfsc LSR,6
- movlw 0x60
- movwf POSTINC0
- return
- UpdateNeoPixels_x16
- ; changes R1, R2 and R3
- ;movlw 0x99
- ;movwf PIXELS
- movlw 48
- movwf R3 ; bytecounter
- lfsr FSR0, PIXELS
- UNP_NEXT_SUBPIXEL
- movlw 8
- movwf R2 ; bitcounter
- ;movf POSTINC0,0
- ;movwf R1 ; pixeldata
- movff POSTINC0,R1
- UNP_NEXT_BIT
- rlcf R1 ; rotate last bit into carry
- bnc UNP_WRITEL
- UNP_WRITEH
- bsf PORTA,0
- nop
- nop
- bcf PORTA,0
- decfsz R2
- goto UNP_NEXT_BIT
- decfsz R3
- goto UNP_NEXT_SUBPIXEL
- return
- UNP_WRITEL
- bsf PORTA,0
- bcf PORTA,0
- nop
- nop
- decfsz R2
- goto UNP_NEXT_BIT
- decfsz R3
- goto UNP_NEXT_SUBPIXEL
- return
- WriteL
- bsf PORTA, 0
- bcf PORTA, 0
- nop
- nop
- nop
- nop
- return
- WriteH
- bsf PORTA, 0
- nop
- nop
- bcf PORTA, 0
- nop
- nop
- return
- FADEPIXELS
- movlw d'48'
- movwf R1 ; byte counter
- bcf STATUS,C
- lfsr FSR0, PIXELS
- FP_NEXT
- ;rrncf INDF0
- ;bcf POSTINC0,7
- movlw 0x00
- cpfseq INDF0
- decf INDF0
- incf FSR0L
- decfsz R1
- goto FP_NEXT
- return
- CLRPIXELS
- movlw d'48'
- movwf R1
- lfsr FSR0, PIXELS
- CP_NEXT
- clrf POSTINC0
- decfsz R1
- goto CP_NEXT
- return
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement