PIC16f877 help

Hey there,

I am currently having programming problems with a PIC16F877.I am trying to program it to send instructions to a HCS301 encoder but the code that im using in order to setup is not working. the code below is the code that i am using. IF anyone would be able to help it would be extremely appreciated...

list P = 16F877 ; include "P16f877.inc" ; ; ------------------ ; CONFIGURATION FUSE ; ------------------ ; __CONFIG _CP_OFF & _WRT_ENABLE_ON & _RC_OSC & _WDT_ON & _PWRTE_OFF & _BODEN_ON & _LVP_ON & _CPD_OFF & _DEBUG_OFF ; ; CRYSTAL SPEED = 12000000Hz ; CBLOCK 0x20

dataL

ENDC ; ; ------------- ; PROGRAM START ; ------------- ; org 0x0000 ; startup = 0000h ; Start movlw 0x00 ; setup ports movwf PORTA movlw 0x00 movwf PORTB movlw 0x40 movwf PORTC movlw 0x00 movwf PORTD movlw 0x00 movwf PORTE bsf STATUS,RP0 ; RAM Page 1 movlw 0x00 movwf TRISA movlw 0x00 movwf TRISB movlw 0x80 movwf TRISC movlw 0xFF movwf TRISD movlw 0xFF movwf TRISE ; ; ------------------------- ; SET ANALOG/DIGITAL INPUTS ; ------------------------- ; movlw 0x06 ; all digital movwf ADCON1 ; ; ------------------------------------ ; SET BAUD RATE TO COMMUNICATE WITH PC ; ------------------------------------ ; Boot Baud Rate = 19200, No Parity, 1 Stop Bit ; movlw 0x0C ; 19200 baud movwf SPBRG movlw b'00100100' ; brgh = high (2) movwf TXSTA ; enable Async Transmission, set brgh movlw b'10010000' ; enable Async Reception bcf STATUS,RP0 ; RAM Page 0 movwf RCSTA ; ; ------------------------------------ ; PROVIDE A SETTLING TIME FOR START UP ; ------------------------------------ ; clrf dataL settle decfsz dataL,F goto settle ; movf RCREG,W movf RCREG,W movf RCREG,W ; flush receive buffer

Loop call Receive ; wait for a char movwf TXREG ; echo data back to sender goto Loop ; ; ---------------------------- ; RECEIVE CHARACTER FROM RS232 ; ---------------------------- ; This routine does not return until a character is received. ; Receive btfss PIR1,RCIF ; (5) check for received data goto Receive ; movf RCREG,W return ; ; ------------------------------------ ; WAIT UNTIL RS232 IS FINISHED SENDING ; ------------------------------------ ; TransWt bsf STATUS,RP0 WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi goto WtHere ; clrf STATUS ; RAM Page 0 return ; ; end

Thank you soo much for your time, regards, roddity

Reply to
roddity
Loading thread data ...

First thing is, you need to change the callouts at the beginning. #1 = turn off the watchdog timer, or else add "clrwdt" commands inside all of your loops. Also, you probably don't want RC_OSC or LVP enabled.

Also, I see some subroutines, but I don't see a main control loop.

- dan michaels

formatting link
=======================

complete

Reply to
dan

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.