3 Pixel limitation when writing to DDRAM
Hi
I have been using the S128240D for a while and one of the issues I have is that I have to write data in groups of 3 pixels 3B3P in my case. The problem is when I write a section of a line and I have to start or finish on a pixel that isn’t a multiple of 3. I have to keep writing over what was on the screen until I make my group of 3 pixels.
Am I missing something? is there an easy way to modify 1 pixel?
Failing that has anyone tried writing some smart code that will read the group of 3 pixels then modify as necessary and write it back?
I am interested to hear what other people have tried.
Justin
Hello Justin,
As far as I know, the pixels must always be modified in blocks of three. I think the display handles the pixels internally in a '3 pixels / 16 bits' mode no matter how you write them. I haven't tried the reading back though.
-Akseli
If you have the capability to do a read-modify-write cycle, then you can write an individual pixel (by reading all three of them in, modifying one of them, and then writing them back out).
There's a command to do the RMW - it shouldn't be too bad.
Unfortunately, the code I've got for it is at home (I did a generic "write hline" function, which would be part of any rectangle/triangle plotting algorithm), but if I remember, I'll dig it out (I've moved on from this display, since I've had problems with the contrast).
Actually, I'll give you the hline function (I've just read exactly what you're doing, rather than skim-reading :) ). From memory, you give it a start X, an end X, a Y value and a shade, and it'll work out the best way to write to it. You might need to implement some of the lower level functions like lcd_cmd(c) and lcd_data(d) - but you should've already done that.
Hi,
Here's the code that I used for the project. It's written for the Hitech-C dsPIC compiler (targeting the dsPIC33FJ128MC804 device), but should be fairly portable.
The main bits you'll need to look at are the following 4 functions:
lcd_rmwread - this reads three pixels
lcd_rmwwrite - this writes three pixels
lcd_rmwstart - this initiates a RMW cycle
lcd_rmwend - this finishes a RMW cycle
The operation is:
1) lcd_rmwstart
2) lcd_rmwread
3) Modify the bytes
4) lcd_rmwwrite
5) lcd_rmwend
There's a single pixel function in the lcd_plot function, and an hline function in the lcd_hline function. Both use RMW cycles - although if you're doing a long hline, then it will only use them for the beginning and the end.
Note that the col_offsets code is written so I don't need any division routines (it uses lookup tables instead, which are much faster, albeit more [ROM] memory hungry).
There's no license attached with my code - treat it as BSD license [not that I'd ever check :) ]. The Lena file I took from elsewhere in the discussions.
Oh - and if you get the chance, can you see if you can repeat the problem I had ("mid-range gray over lena"). If you can't, then let me know - it could be a duff display.
Attachment: lcd_code.zip (14.0KB)