










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











list p=pic18F #include <p18F2520.inc> #include <TVinclude.inc> CONFIG OSC = ECIO ; __CONFIG _CONFIG1H, _ECIO_OSC_1H ; __CONFIG _CONFIG2H, _WDT_OFF_2H
; bsf PORTC, 2 ; bsf INTCounter, 1 ; return movlw DataStorage>>8 ; point to buffer movwf FSR0H movlw DataStorage movwf FSR0L movlw d'63' movwf COUNTER ClearRam CLRF POSTINC0 ; present data to table latch ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA ClearRam ;************ Main Loop ************************* MainLoop call CheckButton MainLoop movlw 0xFF cpfseq pointerl goto Output MainLoop call CheckButton movlw 0xFF cpfseq pointerl goto Record goto MainLoop ;************ Interruption Process ************** Interupt btfsc PORTB, 4 goto _continue bcf INTCON, RBIF retfie _continue btfsc INTCounter, 0 goto _Interrupt bsf T0CON, TMR0ON btfsc INTCounter, 2 call _Downtime bsf T1CON, TMR1ON bsf INTCounter, 0 bcf INTCON, RBIF retfie _Interrupt btfss INTCounter, 1 call setPWM clrf TMR0L clrf TMR0H
bcf INTCON, RBIF retfie _Downtime btg PORTB, 1 movf TMR1L, 0 ; addlw 0x0C movwf POSTINC ; clrf WREG ; addwfc TMR1H, 0 movf TMR1H, 0 movwf POSTINC ; movff TMR1H, PORTA ; movff TMR1L, PORTC clrf TMR1H movlw 0x movwf TMR1L return setPWM movff TMR0L, Store rrncf Store0, W andlw b'01111111' movwf Halfmod ; ************************** ; PWM setup ; rlncf Store0, W ; movff Store0, PR ; movf CCP1CON, ; andlw b'11001111' ; movwf CCP1CON ; btfsc Store0, 0 ; bsf CCP1CON, 4 ; btfsc Store0, 1 ; bsf CCP1CON, 5 ; rrncf Halfmod, 0 ; movwf CCPR1L ; movlw b'00000101' ; movwf T2CON ; movlw b'00001111' ; movwf CCP1CON ; bsf PORTC, 2 bsf INTCounter, 1 return ;************ CheckButton ************************ ;(returns starting memory address into pointerh and pointerl) CheckButton ; btfsc PORTC, 3 ; goto _button ; btfsc PORTC, 1 ; goto _button
_button movlw 0x0B movwf pointerh clrf pointerl return _button movlw 0x0C movwf pointerh clrf pointerl return _button movlw 0x0D movwf pointerh clrf pointerl return _button movlw 0x0E movwf pointerh clrf pointerl return _button movlw 0x0F movwf pointerh clrf pointerl return _button movlw 0x movwf pointerh clrf pointerl return _buttonVU movlw 0x movwf pointerh clrf pointerl return _buttonVD movlw 0x movwf pointerh clrf pointerl return _buttonCU movlw 0x movwf pointerh clrf pointerl return _buttonCD movlw 0x
movwf pointerh clrf pointerl return _buttonPW movlw 0x movwf pointerh clrf pointerl return _buttonREC movlw 0xff movwf pointerl return ;************* Output ***************************** Output movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL bcf T0CON, TMR0ON clrf TMR0H clrf TMR0L movf TMR0H movf TMR0L movlw d'63' movwf counter bsf PORTB, 1 bsf T0CON, TMR0ON setlength TBLRD+ movff TABLAT, outputl ; 0x30 high TBLRD+ movff TABLAT, outputh ; 0x31 low movlw 0xFF cpfseq outputh goto gooddata movlw 0x movwf outputh gooddata movlw 0xFF cpfseq outputl goto Running movlw 0x movwf outputl Running movf TMR0L, W movf outputh, 0 cpfseq TMR0H goto Running clrf TMR0H
goto _INTLoop movlw 0x cpfslt TMR1L goto _EndSignal goto _INTLoop _Store BTG PORTB, 1 ; movff TMR1H, PORTA ; movff TMR1L, PORTC bcf T1CON, TMR1ON movf TMR1L, 0 ; addwf Halfmod, 0 ; sublw 0x0C movwf POSTINC ; movff TMR1H, dummy ; movlw 0x ; addwfc dummy, dummy ; decf dummy, 0 movf TMR1H, 0 movwf POSTINC bcf INTCounter, 0 bsf T1CON, TMR1ON bcf T0CON, TMR0ON clrf TMR1H movlw 0xF subfwb Halfmod, 0 movwf TMR1L clrf TMR0H clrf TMR0L bsf INTCounter, 2 return _EndSignal bcf INTCounter, 0 bcf INTCounter, 2 movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory BSF EECON1, FREE ; enable Row Erase operation BCF INTCON, GIE ; disable interrupts MOVLW 55h MOVWF EECON2 ; write 55h MOVLW 0AAh MOVWF EECON2 ; write 0AAh BSF EECON1, WR ; start erase (CPU stall) ; BSF INTCON, GIE ; re-enable interrupts TBLRD*- ; dummy read decrement
MOVLW D'32' ; number of bytes in holding register MOVWF COUNTER LFSR FSR0, DataStorage movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart WRITE_BYTE_TO_HREGS MOVFF POSTINC0, TABLAT ; present data to table latch TBLWT+ ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA WRITE_BYTE_TO_HREGS PROGRAM_MEMORY movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory MOVLW 55h MOVWF EECON2 ; write 55h MOVLW 0AAh MOVWF EECON2 ; write 0AAh BSF EECON1, WR ; start program (CPU stall) BSF INTCON, GIE ; re-enable interrupts BCF EECON1, WREN ; disable write to memory nop WRITE_BUFFER_BACK MOVLW D'32' ; number of bytes in holding register MOVWF COUNTER LFSR FSR0, DataStorage movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart WRITE_BYTE_TO_HREGS MOVFF POSTINC0, TABLAT ; present data to table latch TBLWT+ ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA WRITE_BYTE_TO_HREGS PROGRAM_MEMORY ; movlw 0x ; movwf TBLPTRU ; movff pointerh, TBLPTRH ; movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory