list p=16F876 ;define target processor
#include <p16f876.inc> ;include processor specific definitions
RADIX HEX
__CONFIG, _CONFIG1 _T1OS0_ON & _CCP1_ON & _CCP2_ON & _WDT_OFF & _STVERN_ON
_CONFIG2 _XINST_OFF & _CP0_OFF & _FOSC_ECPLL & _FOSC2_ON &_IESO_OFF & _WDTPS_32768
; Constants
#define CHANNEL .000;
CBLOCK 0x8
CountH ;16-bit counter
CountL
RxBuffer: .512 ;512 bytes buffer allocation
ENDC
ORG 0x0
Main
call SetupSerial ;Setup Serial port and buffers
MainLoop
WaitBreak
btfsc PIR1,RCIF ; if a byte is received correctly
movf RCREG,W ; discard it
btfss RCSTA,FERR ; else
goto WaitBreak ; continue waiting until a frame error is detected
movf RCREG,W ; read the Receive buffer to clear the error condition
WaitForStart
btfss PIR1,RCIF ; wait until a byte is correctly received
goto WaitForStart
btfsc RCSTA,FERR
goto WaitForStart
movf RCREG,W
; check for the START code value
andlw 0xff
bnz MainLoop ; ignore the rest of the frame if not zero
; init receive counter and buffer pointer
clrf CountL
clrf CountH
lfsr RxBuffer
; third loop, receiving 512 bytes of data
WaitForData
btfsc RCSTA,FERR
goto RXend
; attempted
btfss PIR1,RCIF
goto WaitForData ;
movf RCREG,W ; MoveData
movwf POSTINC0
; (auto-incrementing pointer)
incf CountL,F ; increment 16-bit counter
btfss STATUS,C
goto WaitForData
incf CountH,F
btfss CountH,1 ; check if 512 bytes of data received
goto WaitForData
RXend
lfsr RxBuffer ; use indirect pointer 0 to address the receiver buffer
GetData
movlw LOW(CHANNEL) ; add the offset for the select channel
addwf FSR0L,F
movlw HIGH(CHANNEL)
addwfc FSR0H,F
movff INDF,CCPR2L ; retrieve the data and assign MSB to control PWM2
movff INDF,CCPR1L ; retreive the data and assign MSB to control PWM1
goto MainLoop ; return to main loop
; Setup Serial port and buffers
SetupSerial
; Clear the receive buffer
lfsr RxBuffer
CBloop
clrf POSTINC0 ; clear INDF register then increment pointer
incf CountL,F
btfss STATUS,C
goto CBloop
incf CountH,F
btfss CountH,1
goto CBloop
; Setup EUSART
bsf TRISC,B'10000000' ; allow the EUSART RX to control pin RC7
bsf TRISC,B'10000000'; allow the EUSART TX to control pin RC6
movlw 0x04 ; Disable transmission
movwf TXSTA ; enable transmission and CLEAR high baud rate
movlw 0x90
movwf RCSTA ; enable serial port and reception
bsf BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
clrf SPBRGH
movlw .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
movwf SPBRGH
; Setup PWM module
movlw 0x0c ; configure CCP2 for PWM mode
movwf CCP2CON
movlw 0x0c ; configure CCP1 for PWM mode
movwf CCP1CON
movlw 0X09 ; configure TIMER1 FOR OSCILLATOR OUTPUT
movwf T1CON
; Timer2 control
movlw 0x04 ; enable Timer2, select a prescale of 1:1
movwf T2CON
; PWM period
movlw 0xFF ; 256 x .25us = 64us period
movwf PR2
; init I/O
movlw b'11111111' ; make pins on port b input
movwf TRISB
; init I/O
movlw b'00000000' ; make pins on port a output
movwf TRISA
; init I/O
movlw b'10010000' ; make pins on port c input or output
movwf TRISC
return
END
Clean: Deleting intermediary and output files.
Clean: Done.
#include <p16f876.inc> ;include processor specific definitions
RADIX HEX
__CONFIG, _CONFIG1 _T1OS0_ON & _CCP1_ON & _CCP2_ON & _WDT_OFF & _STVERN_ON
_CONFIG2 _XINST_OFF & _CP0_OFF & _FOSC_ECPLL & _FOSC2_ON &_IESO_OFF & _WDTPS_32768
; Constants
#define CHANNEL .000;
CBLOCK 0x8
CountH ;16-bit counter
CountL
RxBuffer: .512 ;512 bytes buffer allocation
ENDC
ORG 0x0
Main
call SetupSerial ;Setup Serial port and buffers
MainLoop
WaitBreak
btfsc PIR1,RCIF ; if a byte is received correctly
movf RCREG,W ; discard it
btfss RCSTA,FERR ; else
goto WaitBreak ; continue waiting until a frame error is detected
movf RCREG,W ; read the Receive buffer to clear the error condition
WaitForStart
btfss PIR1,RCIF ; wait until a byte is correctly received
goto WaitForStart
btfsc RCSTA,FERR
goto WaitForStart
movf RCREG,W
; check for the START code value
andlw 0xff
bnz MainLoop ; ignore the rest of the frame if not zero
; init receive counter and buffer pointer
clrf CountL
clrf CountH
lfsr RxBuffer
; third loop, receiving 512 bytes of data
WaitForData
btfsc RCSTA,FERR
goto RXend
; attempted
btfss PIR1,RCIF
goto WaitForData ;
movf RCREG,W ; MoveData
movwf POSTINC0
; (auto-incrementing pointer)
incf CountL,F ; increment 16-bit counter
btfss STATUS,C
goto WaitForData
incf CountH,F
btfss CountH,1 ; check if 512 bytes of data received
goto WaitForData
RXend
lfsr RxBuffer ; use indirect pointer 0 to address the receiver buffer
GetData
movlw LOW(CHANNEL) ; add the offset for the select channel
addwf FSR0L,F
movlw HIGH(CHANNEL)
addwfc FSR0H,F
movff INDF,CCPR2L ; retrieve the data and assign MSB to control PWM2
movff INDF,CCPR1L ; retreive the data and assign MSB to control PWM1
goto MainLoop ; return to main loop
; Setup Serial port and buffers
SetupSerial
; Clear the receive buffer
lfsr RxBuffer
CBloop
clrf POSTINC0 ; clear INDF register then increment pointer
incf CountL,F
btfss STATUS,C
goto CBloop
incf CountH,F
btfss CountH,1
goto CBloop
; Setup EUSART
bsf TRISC,B'10000000' ; allow the EUSART RX to control pin RC7
bsf TRISC,B'10000000'; allow the EUSART TX to control pin RC6
movlw 0x04 ; Disable transmission
movwf TXSTA ; enable transmission and CLEAR high baud rate
movlw 0x90
movwf RCSTA ; enable serial port and reception
bsf BAUDCON,BRG16 ; Enable UART for 16-bit Asyn operation
clrf SPBRGH
movlw .15 ; Baud rate is 250KHz for 16MHz Osc. freq.
movwf SPBRGH
; Setup PWM module
movlw 0x0c ; configure CCP2 for PWM mode
movwf CCP2CON
movlw 0x0c ; configure CCP1 for PWM mode
movwf CCP1CON
movlw 0X09 ; configure TIMER1 FOR OSCILLATOR OUTPUT
movwf T1CON
; Timer2 control
movlw 0x04 ; enable Timer2, select a prescale of 1:1
movwf T2CON
; PWM period
movlw 0xFF ; 256 x .25us = 64us period
movwf PR2
; init I/O
movlw b'11111111' ; make pins on port b input
movwf TRISB
; init I/O
movlw b'00000000' ; make pins on port a output
movwf TRISA
; init I/O
movlw b'10010000' ; make pins on port c input or output
movwf TRISC
return
END
Clean: Deleting intermediary and output files.
Clean: Done.