Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Here's some code I wrote when I was learning to do RS232 on the 18F1320. It's just simple polled RS232. I have some 4550 code, but I don't know if it works. This 1320 code definitely does.neelam29 said:I'm trying to make a project on interfacing rs232 with pic18f4550. I'm new to rs232. Can anybody please help me with some examples based on rs232 communication with pic18f.
list p=18F1320
include <p18f1320.inc>
CONFIG OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF,DEBUG=ON
cblock 0x00
d1,d2,d3,dec1,dec2,count,num
endc
org 0x0000
init bsf OSCCON,IRCF2 ;set to 8MHz clock
bsf OSCCON,IRCF1
bsf OSCCON,IRCF0
movlw 0x7f ;set PortA to all digital
movwf ADCON1
clrf TRISA ;set PortA pins to output
clrf LATA ;turn off LEDs
clrf count
movlw b'00010010' ;set PortB - RB4=RX=input
movwf TRISB
call rs_init
bsf TXSTA,TXEN ;transmit enable
main clrf TBLPTRH
movlw text
movwf TBLPTRL
next_ch tblrd *+
movf TABLAT,W
bz goagain
call rs_send
goto next_ch
goagain incf num
movf num,W
call fix
movf dec1,W
call rs_send
movf dec2,W
call rs_send
movlw 0x0d
call rs_send
movlw 0x0a
call rs_send
call delay
call delay
call delay
call delay
goto main
;Sends byte in W to RS232
rs_send movwf TXREG
sdloop btfss TXSTA,TRMT
goto sdloop
return
text db "RS232 on the 8 MHz clocked PIC 18F1320!",0x0d,0x0a,"It is the
greatest!",0x0d,0x0a,0x0a
rs_init movlw 0x0c ;set for 9600 baud @ 8MHz clock
movwf SPBRG
bcf TXSTA,BRGH ;clear Baud Rate Select Bit (low speed)
bcf BAUDCTL,BRG16 ;select 8-bit baud rate generator
bcf TXSTA,SYNC ;asynchronous mode
bsf RCSTA,SPEN ;enable serial port
return
;*********************************************************
;*fix - subroutine takes byte passed in W - splits it into
;*two ascii bytes in dec1 and dec2, representing decimal digits.
fix movwf dec2 ;put number in dec2
clrf count ;count = 0
movlw 10 ;W = 10
tens subwf dec2,F ;subtract 10 from number
btfsc STATUS,C ;check if result <10
goto again ;no, go again
movf count,W ;yes, put count in W
addlw 0x30 ;add $30 to make it an ASCII number
movwf dec1 ;and store it in dec1
movf dec2,W ;get remainder (2nd digit)
addlw 10 ;put the last subtract back
addlw 0x30 ;add $30 to make it ASCII
movwf dec2 ;store it back in dec2
return ;and return
again incf count,F ;increment count
goto tens ;go again
delay movlw 0x01
movwf d1
movlw 0x7f
movwf d2
movlw 0x01
movwf d3
delay_0 decfsz d1,f
goto $+6
decfsz d2,f
goto $+6
decfsz d3,f
goto delay_0
return
end
neelam29 said:dear all,
m trying to make a project on interfacing rs232 with pic18f4550. m new to rs232 .cananybody please help me with some examples based on rs232 communication with pic18f.
The reason is because ur variable is too large to fit in the allocated memory..error which m getting while complilation is
Error - section 'bigdata' can not fit the section. Section 'bigdata' length=0x0000011e
Errors : 1
#pragma udata bigdata1
#pragma udata bigdata2