mikroMMB GetPixel function

Beta Testing discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
Peter Camilleri
Posts: 5
Joined: 02 Feb 2011 20:29

mikroMMB GetPixel function

#1 Post by Peter Camilleri » 08 Feb 2011 19:49

I noticed that the demo code that ships with the PIC32 mikroMMB does not include the GetPixel routine. I've spent some time trying to write one with no luck. I am starting to wonder if the display is "write-only". Has anyone else had any luck with a working GetPixel routine? :?:

Thanks in advance;

Best Regards;

Peter Camilleri

User avatar
marko.ziv
mikroElektronika team
Posts: 530
Joined: 06 Dec 2007 10:11
Contact:

Re: mikroMMB GetPixel function

#2 Post by marko.ziv » 16 Feb 2011 14:59

Hello,
I am starting to wonder if the display is "write-only".
Two way communication is possible, you can read different (TFT) register values.
Only problem here that it is not implemented in our TFT library.
I will add this request to libraries enhancement list, and it will be included in some of the coming
releases of compilers.

Best Regards

marek
Posts: 9
Joined: 25 Feb 2011 20:33

Re: mikroMMB GetPixel function

#3 Post by marek » 25 Feb 2011 20:41

What lcd board are you using? For hx8347-d getpixel code is simple.

Peter Camilleri
Posts: 5
Joined: 02 Feb 2011 20:29

Re: mikroMMB GetPixel function

#4 Post by Peter Camilleri » 21 Mar 2011 01:26

I am using the mikroMMB for PIC32 Board. I finally figured it out on my own.
There were two issues to overcome.

First the PMP and the LCD controllers both have pipelines that are transparent on write, but require dummy reads on read. So there are 2 dummy reads needed.

Secondly, the data format of read is not the same as that for writing. On write, data is packed in a 5:6:5 pixel in 16 bits. On read, pixel data is spread across 2 reads with a 6:2x:6:2x format. Really, two pixels are read in three reads.

To this end I have a working GetPixel routine and a GetSlice routine that grabs more data.

FrancisV
Posts: 31
Joined: 18 Oct 2011 14:31

Re: mikroMMB GetPixel function

#5 Post by FrancisV » 20 Nov 2011 10:27

Hi Peter,

could you post your getpixel and slice routines please ?
This way i don't have to reinvent everything frm scratch.

Thxs in advance !

Greetinges Francis

FrancisV
Posts: 31
Joined: 18 Oct 2011 14:31

Re: mikroMMB GetPixel function

#6 Post by FrancisV » 24 Nov 2011 18:14

no need of the routines anymore. I wrote them myself by now. Timing of PMP bus is critical ! Wait bits are needed. :D

bisnouk
Posts: 11
Joined: 15 Dec 2011 20:45
Location: Avignon - France
Contact:

Re: mikroMMB GetPixel function

#7 Post by bisnouk » 03 Feb 2012 16:21

see below for this function 8)
Last edited by bisnouk on 06 Feb 2012 09:22, edited 1 time in total.
Regards,
Thierry - Avignon - France

bisnouk
Posts: 11
Joined: 15 Dec 2011 20:45
Location: Avignon - France
Contact:

Re: mikroMMB GetPixel function

#8 Post by bisnouk » 03 Feb 2012 19:08

Here is a valid function, I'm working (hard) and it's a success !
In first, I must declare PMP routine to have a good parallel port but why, i don't know.

Code: Select all

void InitPMP(void)
{
    PMMODE = 0;
    PMAEN = 0;
    PMCON = 0;
    PMMODEbits.MODE  = 2;  // Master 2
    PMMODEbits.WAITB  = 0;
    PMMODEbits.WAITM  = 3;
    PMMODEbits.WAITE  = 0;

    PMMODEbits.MODE16 = 1;  // 16 bit mode
    PMCONbits.CSF    = 0;
    PMCONbits.PTRDEN = 1;
    PMCONbits.PTWREN = 1;
    PMCONbits.PMPEN  = 1;
}
Precondition :

Code: Select all

typedef unsigned short          BYTE;                   
typedef unsigned int            WORD; 
/*********************************************************************
* IOS FOR THE DISPLAY CONTROLLER
*********************************************************************/
// Definitions for reset pin
#define RST_TRIS_BIT        TRISC1_bit
#define RST_LAT_BIT         LATC1_bit
// Definitions for RS pin
#define RS_TRIS_BIT         TRISB15_bit
#define RS_LAT_BIT          LATB15_bit
// Definitions for CS pin
#define CS_TRIS_BIT         TRISF12_bit
#define CS_LAT_BIT          LATF12_bit
// Definitions for Backlight power pin
#define BL_TRIS_BIT         TRISD2_bit
#define BL_LAT_BIT          LATD2_bit
#define BacklightOn()       BL_LAT_BIT = 1
#define BacklightOff()      BL_LAT_BIT = 0
/*********************************************************************
* Macros: RGB565CONVERT(red, green, blue)
* Overview: Converts HX8347 GRAM 12 bits (6:6:6) color into 5:6:5 RGB format.
* Input: Red, Green, Blue components in 6 bits color format.
* Output: 5 bits red, 6 bits green, 5 bits blue color.
* Side Effects: none
********************************************************************/
    #define RGB565CONVERT(red, green, blue) (WORD) (((red >> 1) << 11) | (green << 5) | (blue >> 1));
/*********************************************************************
* Macros:  PMPWaitBusy()
* Overview: Delays execution for PMP cycle time.
* Input: none
* Output: none
********************************************************************/
    #define PMPWaitBusy()   while(PMMODEbits.BUSY);
/*********************************************************************
* Macros:  SetIndex(index)
* Overview: Writes index register.
* Input: index - Index register.
* Output: none
********************************************************************/
    #define SetIndex(index) \
    RS_LAT_BIT = 0;         \
    PMDIN = index;         \
    PMPWaitBusy();
/*********************************************************************
* Macros:  WriteCommand(cmd)
* Overview: Writes command.
* Input: command.
* Output: none
********************************************************************/
    #define WriteCommand(cmd) \
    RS_LAT_BIT = 1;           \
    PMDIN = cmd;             \
    PMPWaitBusy();
/*********************************************************************
* Macros:  WriteData(data)
* Overview: Writes data
* Input: data
* Output: none
********************************************************************/
    #define WriteData(data) \
    RS_LAT_BIT = 1;         \
    PMDIN = data;          \
    PMPWaitBusy();
/*********************************************************************
* Function :  ReadData()
* Overview: Read data
* Input: none
* Output: WORD DATA
********************************************************************/
WORD ReadData(void){
    WORD dat;
    
    RS_LAT_BIT = 1;
    dat = PMDIN;          // start a read sequence
    PMPWaitBusy();      // wait for read completion
    dat = PMDIN;
    return (dat);
}
/*********************************************************************
* Macros:  SetAddress(x,y)
* Overview: Writes address pointer.
* Input: x - horizontal position
*        y - vertical position
********************************************************************/
    #define SetAddress(x, y)       \
    SetIndex(0x02);                \
    WriteCommand((WORD)(x>>8));    \
    SetIndex(0x03);                \
    WriteCommand((WORD)(x&0x0FF)); \
    SetIndex(0x06);                \
    WriteCommand((WORD)(y>>8));    \
    SetIndex(0x07);                \
    WriteCommand((WORD)(y&0x0FF)); \
    SetIndex(0x22);
/*********************************************************************
* Function:  void  SetReg(BYTE index, BYTE value)
* Input: index - register number
*        value - value to be set
* Output: none
* Side Effects: none
* Overview: sets graphics controller register
********************************************************************/
void  SetReg(BYTE index, BYTE value){

    CS_LAT_BIT = 0;
    SetIndex(index);
    WriteCommand(value);
    CS_LAT_BIT = 1;
}
GetPixel function :

Code: Select all

/*********************************************************************
* Function: WORD GetPixel(WORD x, WORD y)
* Input: x,y - pixel coordinates
* Output: WORD pixel Color in RGB565
********************************************************************/
WORD GetPixel(WORD x, WORD y){
    WORD val;
    BYTE r,g,b;

    CS_LAT_BIT = 0;
    SetAddress(x,y);
    
    ReadData();  // Dummy Read for PMP read acces
    ReadData();  // Dummy Read for TFT GRAM read acces
    val = ReadData();
    r = (BYTE)hi(val)>>2;
    g = (BYTE)lo(val)>>2;
    val = ReadData();
    b = (BYTE)hi(val)>>2;
    CS_LAT_BIT = 1;
    return  (WORD)RGB565CONVERT(r,g,b);
}
Regards,
Thierry - Avignon - France

FrancisV
Posts: 31
Joined: 18 Oct 2011 14:31

Re: mikroMMB GetPixel function

#9 Post by FrancisV » 22 Feb 2012 19:58

holy ****... what a routine !
Mine is 20 lines long in all :)

bisnouk
Posts: 11
Joined: 15 Dec 2011 20:45
Location: Avignon - France
Contact:

Re: mikroMMB GetPixel function

#10 Post by bisnouk » 27 Feb 2012 18:37

Yes, this code was the first and as Elektronika build-in functions are not public, I prefer write mine for debugging.
Now I use build-in functions for address TFT and the GetPixel function is shorter !
Regards,
Thierry - Avignon - France

Post Reply

Return to “mikroC PRO for PIC32 Beta Testing”