What method do you use to output the 4 LCD data bits?LATx doesn't seem have any RMW issues. Even if you think it does, adding nop should cure it.
Max.
What method do you use to output the 4 LCD data bits?LATx doesn't seem have any RMW issues. Even if you think it does, adding nop should cure it.
I am assuming that this also applies to PORTA where 6 pins RA0-5 are used for LCD and RA6-7 are the external Clk Xtal?. I generally run 6 LCD pins on LATB; 4data, RS and E. Writing all togther for data means writing 6 digital outputs, writing 0 to E at that time of course.
The other two pins are the USART TX/RX
In your case, I would do something like that:What method do you use to output the 4 LCD data bits?
; assuming data are loaded in wreg with correct shift
xorwf LATx, w
andlw 0x0f ; only changing the selected 4 bits - low nibble in this case
xorwf LATx, f
You do realize that the last statement works by using a R-M-W sequence?In your case, I would do something like that:
Rich (BB code):; assuming data are loaded in wreg with correct shift xorwf LATx, w andlw 0x0f ; only changing the selected 4 bits - low nibble in this case xorwf LATx, f
That's exactly the way I do it (to protect the b4..b7 bits which may be being utilized in other parts of the program). I've always assumed RMW is not an issue with a LATx register (or other non-PORTx registers). Please correct me if I'm wrong.In your case, I would do something like that:
Rich (BB code):; assuming data are loaded in wreg with correct shift xorwf LATx, w andlw 0x0f ; only changing the selected 4 bits - low nibble in this case xorwf LATx, f
Of course. I would even say R-M-R-M-W. I don't see any problem with that because it uses LAT, not PORT.You do realize that the last statement works by using a R-M-W sequence?
Yeah it would. But generally I reserve PORTA for the valuable ADC and comparator inputs.I am assuming that this also applies to PORTA where 6 pins RA0-5 are used for LCD and RA6-7 are the external Clk Xtal?
Max.
The whole point of adding the latch "register" is to get around the RMW effects of directly reading port pins. 100% safe and sureI've always assumed RMW is not an issue with a LATx register (or other non-PORTx registers). Please correct me if I'm wrong.
Me neither, though there seems to be an undercurrent of opposition to this point.Of course. I would even say R-M-R-M-W. I don't see any problem with that because it uses LAT, not PORT.
Sounds Good, On my development board I can assign the LCD to any port combo.Yeah it would.
They use a standard pin connect for the LCD on PORTB 0-5 for good reasons, which have been well thought out, leaving RB6,7 for USART. PORTA is valuable for ADC and comparator, and PORTC has the CCPs, SPI, etc depending on which PIC it is.
.
I think that interpretation of "100% safe" is what separates the pros from the hobbyists?The whole point of adding the latch "register" is to get around the RMW effects of directly reading port pins. 100% safe and sure
...
PORTB = shadow_b; // used on PIC16F
LATB = shadow_b; // used on PIC18F
Once again you start with a straw man argument.I think that interpretation of "100% safe" is what separates the pros from the hobbyists?
Again, extraordinary claims require extraordinary evidence. Do you have a single instance of a RMW on a LATCH register causing issues?The LAT register makes writing bits to a port MUCH safer, but I would not say it is "100% safe" and it is far from being the best way to write a parallel value out a port as a general practice.
You can just create your own LATx on PIC16F which you copy to PORTx when needed, but you don't do it on PIC18F where you already have it. Only one extra line of code is required on PIC16F.If the code is part of a library that might be reused on PIC16F or PIC18F, then what do you do? Have one set of code that uses a MOVWF to safely write to the port in one operation on the PIC16F, but the code for the port write on the PIC18F uses a lot of clunky bsf/bcf operations?
Looks good to me too, you should have no issues doing just that.So what is wrong with using the only 6 available bits (0-5) on portA (6-7 Xtal Osc) and output the high and then low nibble together with RW-RS using MOVFF LATA?
E to be a bsf/bcf LATx on separate port.
mAX.
Although I quoted you the bulk of my text was not aimed at you specifically....
So dont you think its just a tad unfair when I say something about a LATCH register to object that it doesnt apply to a PORT register?
...
It's not the RMW itself that is the problem. The hardware is more stable and more reliable writing to an entire port in one operation. Fast successive bsf/bcf operations can cause pin latch up....Again, extraordinary claims require extraordinary evidence. Do you have a single instance of a RMW on a LATCH register causing issues?
...
That's a great way to do it. You can also have E on the same port, and MOVFF again to set E high, and then again to clear E. That is how I generally do it. All 6 required LCD pins on one port.MaxHeadRoom said:So what is wrong with using the only 6 available bits (0-5) on portA (6-7 Xtal Osc) and output the high and then low nibble together with RW-RS using MOVFF LATA?
E to be a bsf/bcf LATx on separate port. ...
;Called with byte in temp_wr, e.g. 0xc0
LCDWriteNibble:
bsf LCD_E ; Setup to clock data
swapf temp_wr
btfss Flags, 7
bcf temp_wr, 4 ;LCD_RS
btfsc Flags, 7
bsf temp_wr, 4 ;LCD_RS
bcf temp_wr, 5 ;LCD_RW
movff temp_wr, LATA
NOP
NOP
bcf LCD_E ; Send the port data
return
by Duane Benson
by Duane Benson
by Jake Hertz