williB
New Member
i have a problem with the 877A
Below i've recycled a Pwm pgm which worked on a F88 , but needed some changes on the 877A
specifically the 877 has no ANSEL register , it took me a few hours to essentially remove two lines and correct the bits put into ADCON1
i was able to load the program into the F877 and run it ,which may not sound like much , but for me it was alot.
no joy on the either ccp/pwm pin
is there anything in the factory config settings , that would prevent this from working? because i havnt changed them
pwm is not my strong suit, which is why i checked both outputs
if someone could check the pwm for me i would be very greatfull
the Fosc is 5 Mhz but i can divide it down with counters if needed , i'm looking to get 20 - 25 khz varible pwm out
thanks for reading
Below i've recycled a Pwm pgm which worked on a F88 , but needed some changes on the 877A
specifically the 877 has no ANSEL register , it took me a few hours to essentially remove two lines and correct the bits put into ADCON1
i was able to load the program into the F877 and run it ,which may not sound like much , but for me it was alot.
no joy on the either ccp/pwm pin
is there anything in the factory config settings , that would prevent this from working? because i havnt changed them
pwm is not my strong suit, which is why i checked both outputs
if someone could check the pwm for me i would be very greatfull
the Fosc is 5 Mhz but i can divide it down with counters if needed , i'm looking to get 20 - 25 khz varible pwm out
thanks for reading
Code:
LIST P=16F877A
include "P16F877A.inc"
errorlevel -302 ;Eliminate bank warning
TEMP EQU 0x20
ADON EQU 0X00
ADIF EQU 0X06
GO_DONE EQU 0X02
TMR2ON EQU 0X02
TMR2IF EQU 0X01
RP0 EQU 0x05
RP1 EQU 0x06
W EQU H'0000'
F EQU H'0001'
;----- Register Files------------------------------------------------------
INDF EQU H'0000'
TMR0 EQU H'0001'
PCL EQU H'0002'
STATUS EQU H'0003'
FSR EQU H'0004'
PORTA EQU H'0005'
PORTB EQU H'0006'
PCLATH EQU H'000A'
INTCON EQU H'000B'
PIR1 EQU H'000C'
PIR2 EQU H'000D'
TMR1L EQU H'000E'
TMR1H EQU H'000F'
T1CON EQU H'0010'
TMR2 EQU H'0011'
T2CON EQU H'0012'
CCPR1L EQU H'0015'
CCPR1H EQU H'0016'
CCP1CON EQU H'0017'
RCSTA EQU H'0018'
TXREG EQU H'0019'
RCREG EQU H'001A'
ADRESH EQU H'001E'
ADCON0 EQU H'001F'
OPTION_REG EQU H'0081'
TRISA EQU H'0085'
TRISB EQU H'0086'
PIE1 EQU H'008C'
PCON EQU H'008E'
PR2 EQU H'0092'
TXSTA EQU H'0098'
SPBRG EQU H'0099'
EEDATA EQU H'010C'
CMCON EQU H'009C'
EECON2 EQU H'018D'
ADRESL EQU H'009E'
ADCON1 EQU H'009F'
org 0x00 ; Reset Vector
clrf PORTA ;B0
clrf PORTB ;B0
CLRF STATUS ;B0
;B0
Banksel TRISA ;B1
CLRF TRISA ;B1
CLRF TRISB ;B1
;B1
BCF STATUS ,RP0 ;B0
;B0
CLRF T2CON ;B0
MOVLW D'000' ;B0
MOVWF CCPR1L ;B0
BSF STATUS,RP0 ;B1
MOVLW d'255'-1 ;B1
MOVWF PR2 ;B1
BCF STATUS,RP0 ;B0
MOVLW b'00001100' ;B0
MOVWF CCP1CON ;B0
BSF T2CON,TMR2ON ;B0
;B0
BSF STATUS,RP0 ;B1
MOVLW b'00000001' ;B1
MOVWF TRISA ;B1
;B1
;B1
MOVLW b'10001111' ;B1 AN0 as input: AN2 as Vref-
MOVWF ADCON1 ;B1 : AN3 as Vref+
BCF STATUS,RP0 ;B0
MOVLW b'01000000' ;B0
MOVWF ADCON0 ;B0
BSF ADCON0,ADON ;B0 turn on A2D
CLRF PIR1 ;B0
;B0
LOOP CALL ADC ;B0
MOVWF CCPR1L ;B0
GOTO LOOP ;B0
;B0
ADC BTFSS PIR1,TMR2IF ;B0
GOTO ADC ;B0
BCF PIR1,TMR2IF ;B0
;B0
MOVF ADRESH,W ;B0
BSF ADCON0,GO_DONE ;B0
RETURN
END