Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Software UART for PIC18F

Status
Not open for further replies.

alanh

New Member
Hello all,

My first post, please be gentle :)

I'm trying to adapt Mike's PIC 16F819 full duplex software uart code to an 18F, but it's not working yet, but it's crashing in the IRQ handler. Wonder if someone can take at this code snipped.

The baud rate I need is 7812.5 and it's XTAL is at 8MHz.

I've changed some instructions like FSR, to FSR0L and FSR0H and saving those including PCLATH and PCLATU etc. I've not updated the timing information per instruction yet, but I calculated the value of 85 for PR2 for 7812.5 baud.

Also, I think I've fixed up the jump table correctly by doing RLNCF WREG, W before loading PCL.

_ISR movwf _W_ISR ; save W-reg |B?
swapf STATUS,W ; doesn't change STATUS bits |B?
movwf _S_ISR ; save STATUS reg |B?
clrf STATUS ; bank 0 |B0
movf PCLATH,W ; get PCLATH |B0
movwf _P_ISR ; save PCLATU |B0
movf PCLATU,W ; get PCLATU |B0
movwf _P_ISRU ; save PCLATU |B0
bcf PIR1,TMR2IF ; clear TMR2 interrupt flag |B0
;
; enter the TX state machine
;
;
clrf PCLATH ; |B0
clrf PCLATU ; |B0
movf _TX_SM,W ; get TX state machine |B0
RLNCF WREG, W ; 18f ?
addwf PCL,f ; off we go |B0

Does this look right ?

Thanks.
 
Hi,


For ISR context saving use the Template example file found in your MpASM\Template\Code folder.

Typically you need to save W,Status and BSR plus any other key resisters you ISR code is likely to affect.

You do not say which chip you are using and seeing your code in full will probably be better that just the isr snippet.
Also you do not give a link to Mikes (?) project code ..?
 
Status
Not open for further replies.

Latest threads

Back
Top