[PIC] PIC16f877a serial communication code

Status
Not open for further replies.

Syed WQ

Newbie level 3
Joined
Jan 2, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
21
plz any provide me simple basic Assembly code for PIC16f877a for serial communcation

or here it is my code ,,point the problem inthis code....
when i load it to proteus ,after connecting virtual terminal with PIC ,,virtual terminal is showing some curious code and always repeating..although i program for sending character only one time...here is code and schematic
Code:
	list p=16f877a
					#include "P16F877A.INC"
		
				__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_OFF &_CP_OFF
					
					
STATUS EQU 0x03
PORTC EQU 07H
TRISC EQU 87H
TXSTA EQU 98h
RCSTA EQU 18H
SPBRG EQU 99H
TXREG EQU 19H
PIR1 EQU 0CH

	ORG 0x00

	

	

	MOVLW D'15'
	MOVWF SPBRG
	MOVLW B'00100100'
	MOVWF TXSTA
	banksel RCSTA
	BSF RCSTA,SPEN
	BANKSEL TRISC
	BCF TRISC,6
	clrw
	MOVLW 'a'		
here
	banksel PIR1
	btfss PIR1,TXIF
	goto here	
	BANKSEL TXREG
	MOVWF TXREG
	
END
 
Last edited by a moderator:


Hi,

Almost there, ensure you specify in your code and to ISIS what you Oscillator frequency is, I have used 4 Mhz and changed you TX setting accordingly

EDIT - and of course ensure that your codes Baud rate agrees with the Terminals Baud rate which defaults to 9600

Code:
	list p=16f877a
	#include "P16F877A.INC"
		
	__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_OFF &_CP_OFF & _XT_OSC
					
					
;STATUS EQU 0x03   ; all system registers are specifield in the ".INC" file
;PORTC EQU 07H
;TRISC EQU 87H
;TXSTA EQU 98h
;RCSTA EQU 18H
;SPBRG EQU 99H
;TXREG EQU 19H
;PIR1 EQU 0CH

	cblock	0x20		; define work registers for delay
	d1,d2,d3
	endc

	ORG 0x00

	clrf 	PORTC
	banksel	TRISC
	clrf	TRISC   ; make port C outputs


	banksel SPBRG	; set up based on 4Mhz oscillator
	MOVLW D'25'
	MOVWF SPBRG
	MOVLW B'00100100'
	MOVWF TXSTA
	banksel RCSTA
	BSF RCSTA,SPEN
	BANKSEL TRISC
	BCF TRISC,6
	clrw
again	
	MOVLW 'a'		
here
	banksel PIR1
	btfss PIR1,TXIF
	goto here	
	BANKSEL TXREG
	MOVWF TXREG
	call	delay250		; so you can see the characters being sent

	goto	again

;Delay sub routine

delay250	movlw	d'250'				; delay 250 ms 
			movwf	d1
dly250_1	movlw	0xC7
			movwf	d2
			movlw	0x01
			movwf	d3
dly250_2
			decfsz	d2, f
			goto	dly250_3
			decfsz	d3, f
dly250_3	goto	dly250_2
			decfsz	d1	,f
			goto	dly250_1
			retlw	0x00


	
		END
 

Attachments

  • 000021.jpg
    90.4 KB · Views: 110
  • 000022.jpg
    111.6 KB · Views: 105
Last edited:
thanks very much. ihave just solved it with your help.. but i need more help from you. please provide me code for sending at command for mssege to ant from MCU to sim300cz through serial communication ..or edit above code for it.. please reply sonn i am waiting .....
 



Hi,


Have not used that module but if you search this forum and the web there are many projects using the sim300.
 
Hi,


Have not used that module but if you search this forum and the web there are many projects using the sim300.

ok ..dont worry send me code for any of modem in assembly.. i just wanna have ideas...how to send at command from MCU to Modem throug proteus via compim...please help me ...or send me any link where i can get these solution please plzzzzzzz
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…