Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial Port initialization for PIC16F876

Status
Not open for further replies.

charles01

Newbie level 5
Joined
Feb 15, 2010
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
leicester
Activity points
1,350
hi
i am trying to initialize the (USART) RX port (PORTC, bit 7) on the PIC16F876 so i can be able to receive data and drive an LED on another port say PORTB. the data is in serial format. is there any simple assembly program to do this trick?

thank you in advance
 

Hi,

This serial tutorial is good, I used it myself, most other sections are good although the adc hardware is overkill for most simple uses.

The serial data received is held in a byte /s so you can then manipulate and test its contents as you like to decide if you should turn on the leds on or off as needed.

http://www.winpicprog.co.uk/pic_tutorial7.htm
 

Hi,
Try this:
Code:
;CLOCK = 10MHz

	LIST P=16F876
	__CONFIG _CP_OFF & _CPD_OFF & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _XT_OSC

	#INCLUDE <P16F876.inc>

	ORG 0x00

MAIN
;	MOVLW	.7        ENABLE THESE 2 LINES IF USING 16F876A
;	MOVWF	CMCON
	CLRF	CCP1CON
	BANKSEL	TRISC ;BANK1
	MOVLW	0x80
	MOVWF	TRISC ;MAKE RC7 INPUT FOR RX
	CLRF	TRISB ;MAKE RB[0...7] OUTPUT FOR DISPLAY
	MOVLW	.7
	MOVWF	ADCON1 ;DISABLE ADC
	MOVLW	.64
	MOVWF	SPBRG ;BAUD RATE = 2400, 15 FOR 9600
	BCF		TXSTA, SYNC ;ASYNCHRONOUS MODE
	BANKSEL	RCSTA ;BANK0
	BSF		RCSTA, SPEN ;ENABLE SERIAL PORT
	BSF		RCSTA, CREN ;ENABLE CONTINUOUS RECEPTION
AGAIN
	MOVF	RCREG,W ;MOVE RECEIVED DATA TO W REG
	MOVWF	PORTB ;SHOW DATA ON PORTB
	GOTO	AGAIN
	
	END

Hope this helps.
Tahmid.
 

thanks very much
i got lost on one bit
what is CMCON standing for?


thanks in advance
 

Hi,
On 16F876, there is no comparator, but in 16F876A there are, I think, 2 comparators. So you need to turn those off. But when you are using 16F876, you don't need those to statements.
When you do:
Code:
MOVLW   .7
MOVWF   CMCON
You are disabling the comparators.

Hope this helps.
Tahmid.
 

Actually, unlike many other PIC models, 16F876A has 7 in CMCON after power-up (initial value), so these instructions aren't needed.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top