Compact Flash Library. EEPROM Library. Epson S1D13700 Graphic Lcd Library. Ethernet PIC18FxxJ60 Library. Flash Memory Li
MikroC Library Built-in Routines
Hardware Libraries
ADC Library CAN Library CANSPI Library Compact Flash Library EEPROM Library Epson S1D13700 Graphic Lcd Library Ethernet PIC18FxxJ60 Library Flash Memory Library Graphic Lcd Library I²C Library Keypad Library Lcd Library Manchester Code Library Memory Manager Library Multi Media Card Library OneWire Library Peripheral Pin Select Library Port Expander Library PS/2 Library PWM Library RS-485 Library Software I²C Library Software SPI Library Software UART Library Sound Library SPI Library SPI Remappable Library SPI Ethernet Library SPI Ethernet ENC24J600 Library SPI Graphic Lcd Library SPI Lcd Library SPI Lcd8 Library SPI T6963C Graphic Lcd Library T6963C Graphic Lcd Library TFT Display Library TFT 16-bit Display Library Touch Panel Library Touch Panel TFT Display Library UART Library UART Remappable Library USB Library
Miscellaneous Libraries
Button Library Conversions Library PrintOut Library
www.raguvaran.puzl.com
Setjmp Library Sprint Library Time Library Trigonometry Library
Built-in Routines The mikroC PRO for PIC compiler provides a set of useful built-in utility functions. The Lo, Hi, Higher, Highest routines are implemented as macros. If you want to use these functions you must include built_in.h header file (located in the include folder of the compiler) into your project. The Delay_us and Delay_ms routines are implemented as “inline”; i.e. code is generated in the place of a call, so the call doesn’t count against the nested call limit. The Vdelay_ms, Vdelay_advanced_ms, Delay_Cyc, Get_Fosc_kHz and Get_Fosc_Per_Cyc are actual C routines. Their sources can be found in Delays.c file located in the uses folder of the compiler. Lo Hi Higher Highest LoWord HiWord Delay_us Delay_ms Vdelay_ms Vdelay_Advanced_ms Delay_Cyc Clock_kHz Clock_MHz Get_Fosc_kHz Swap
Lo Prototype
#define Lo(param) ((char *)¶m)[0]
Returns
Lowest 8 bits (byte) of param, bits 7..0.
Description
Function returns the lowest byte of param. Function does not interpret bit patterns of param – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
None.
Example
d = 0x12345678; tmp = Lo(d); // Equals 0x78 Lo(d) = 0xAA; // d equals 0x123456AA
www.raguvaran.puzl.com
Hi Prototype
#define Hi(param) ((char *)¶m)[1]
Returns
Returns next to the lowest byte of param, bits 8..15.
Description
Function returns next to the lowest byte of param. Function does not interpret bit patterns of param – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
None.
Example
d = 0x12345678; tmp = Hi(d); // Equals 0x56 Hi(d) = 0xAA; // d equals 0x1234AA78
Higher Prototype
#define Higher(param) ((char *)¶m)[2]
Returns
Returns next to the highest byte of param, bits 16..23.
Description
Function returns next to the highest byte of param. Function does not interpret bit patterns of param – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
None.
Example
d = 0x12345678; tmp = Higher(d);
// Equals 0x34
Higher(d) = 0xAA; // d equals 0x12AA5678
Highest Prototype
#define Highest(param) ((char *)¶m)[3]
www.raguvaran.puzl.com
Returns
Returns the highest byte of param, bits 24..31.
Description
Function returns the highest byte of param. Function does not interpret bit patterns of param – it merely returns 8 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
None.
Example
d = 0x12345678; tmp = Highest(d);
// Equals 0x12
Highest(d) = 0xAA; // d equals 0xAA345678
LoWord Prototype
unsigned int LoWord(unsigned long number);
Description
The function returns low word of number. The function does not interpret bit patterns of number – it merely returns 16 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Parameters
number: input number
Returns
Low word of number, bits 15..0.
Requires
Nothing.
Example
d = 0x12345678; tmp = LoWord(d);
// Equals 0x5678
LoWord(d) = 0xAAAA; // d equals 0x1234AAAA
Notes
None.
HiWord Prototype
unsigned int HiWord(unsigned long number);
Description
The function returns high word of number. The function does not interpret bit patterns of number – it merely returns 16 bits as found in register. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Parameters
number: input number
www.raguvaran.puzl.com
Returns
High word of number, bits 31..16.
Requires
Nothing.
Example
d = 0x12345678; tmp = HiWord(d);
// Equals 0x1234
HiWord(d) = 0xAAAA; // d equals 0xAAAA5678
Notes
None.
Delay_us Prototype
void Delay_us(const unsigned long time_in_us);
Returns
Nothing.
Description
Creates a software delay in duration of time_in_us microseconds (a constant). Range of applicable constants depends on the oscillator frequency. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. This routine generates nested loops using registersR13, R12, R11 and R10. The number of used registers varies from 0 to 4, depending on requested time_in_us.
Requires
Nothing.
Example
Delay_us(1000);
/* One millisecond pause */
Delay_ms Prototype
void Delay_ms(const unsigned long time_in_ms);
Returns
Nothing.
Description
Creates a software delay in duration of time_in_ms milliseconds (a constant). Range of applicable constants depends on the oscillator frequency. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit. This routine generates nested loops using registersR13, R12, R11 and R10. The number of used registers varies from 0 to 4, depending on requested time_in_ms.
Requires
Nothing.
www.raguvaran.puzl.com
Example
/* One second pause */
Delay_ms(1000);
Vdelay_ms Prototype
void Vdelay_ms(unsigned time_in_ms);
Returns
Nothing.
Description
Creates a software delay in duration of time_in_ms milliseconds (a variable). Generated delay is not as precise as the delay created by Delay_ms. Note that Vdelay_ms is library function rather than a built-in routine; it is presented in this topic for the sake of convenience.
Requires
Nothing.
Example
pause = 1000; // ... Vdelay_ms(pause);
// ~ one second pause
VDelay_Advanced_ms Prototype
void VDelay_Advanced_ms(unsigned time_in_ms, unsigned Current_Fosc_kHz);
Returns
Nothing.
Description
Creates a software delay in duration of time_in_ms milliseconds (a variable), for a given oscillator frequency. Generated delay is not as precise as the delay created by Delay_ms. Note that Vdelay_ms is library function rather than a built-in routine; it is presented in this topic for the sake of convenience.
Requires
Nothing.
Example
pause = 1000; fosc = 10000; VDelay_Advanced_ms(pause, fosc); // Generates approximately one second pause, for a oscillator frequency of 10 MHz
Delay_Cyc Prototype
void Delay_Cyc(char Cycles_div_by_10);
www.raguvaran.puzl.com
Returns
Nothing.
Description
Creates a delay based on MCU clock. Delay lasts for 10 times the input parameter in MCU cycles. Note that Delay_Cyc is library function rather than a built-in routine; it is presented in this topic for the sake of convenience. There are limitations for Cycles_div_by_10 value. Value Cycles_div_by_10 must be between 3 and 255.
Requires
Nothing.
Example
Delay_Cyc(10);
/* Hundred MCU cycles pause */
Clock_kHz Prototype
unsigned Clock_kHz(void);
Returns
Device clock in kHz, rounded to the nearest integer.
Description
Function returns device clock in kHz, rounded to the nearest integer. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
Nothing.
Example
clk = Clock_kHz();
Clock_MHz Prototype
unsigned short Clock_MHz(void);
Returns
Device clock in MHz, rounded to the nearest integer.
Description
Function returns device clock in MHz, rounded to the nearest integer. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
Nothing.
Example
clk = Clock_MHz();
www.raguvaran.puzl.com
Get_Fosc_kHz Prototype
unsigned long Get_Fosc_kHz(void);
Returns
Device clock in kHz, rounded to the nearest integer.
Description
Function returns device clock in kHz, rounded to the nearest integer. Note that Get_Fosc_kHz is library function rather than a built-in routine; it is presented in this topic for the sake of convenience.
Requires
Nothing.
Example
clk = Get_Fosc_kHz();
Swap Prototype
char swap(char input);
Returns
Swapped nibbles of the input byte.
Description
Function swaps nibbles of the input parameter. This is an “inline” routine; code is generated in the place of the call, so the call doesn’t count against the nested call limit.
Requires
Nothing.
Example
char input, swapped_input;
input = 0xAF; swapped_input = swap(input); // routine will return 0xFA i.e. swapped nibbles of the input parameter
www.raguvaran.puzl.com
ADC Library ADC (Analog to Digital Converter) module is available with a number of PIC MCU modules. ADC is an electronic circuit that converts continuous signals to discrete digital numbers. ADC Library provides you a comfortable work with the module.
Library Routines
ADC_Init ADC_Get_Sample ADC_Read
ADC_Init Prototype
void ADC_Init();
Returns
Nothing.
Description
This routine initializes PIC’s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion (min 12TAD).
Requires Example
MCU with built-in ADC module.
ADC_Init();
// Initialize ADC module with default settings
ADC_Get_Sample Prototype
unsigned ADC_Get_Sample(unsigned short channel);
Returns
10 or 12-bit unsigned value read from the specified channel (MCU dependent).
Description
The function aquires analog value from the specified channel. Parameter channel represents the channel from which the analog value is to be acquired. Refer to the appropriate td="">
S1D13700_OVERLAY_AND
The text and graphic td="">
S1D13700_OVERLAY_AND
The text and graphic content="3;url=http://192.168.20.60"> PIC18FxxJ60 Mini Web Server Reload
| PORTB | " ; const char *indexPage2 = " | |
This is HTTP request # " ; /*********************************** * RAM variables */ unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, unsigned char myIpAddr[4] = {192, 168, 20, 60 unsigned char gwIpAddr[4] = {192, 168, 20, 6 address unsigned char ipMask[4] = {255, 255, 255, 0 example : 255.255.255.0) unsigned char dnsIpAddr[4] = {192, 168, 20, 1
www.raguvaran.puzl.com
0x76, 0x19, 0x3f} ; } ; } ;
// my MAC address // my IP address // gateway (router) IP
} ;
// network mask (for
} ;
// DNS server IP address
unsigned char unsigned char response unsigned long requests
getRequest[15] ; dyna[30] ;
// HTTP request buffer // buffer for dynamic
httpCounter = 0 ;
// counter of HTTP
/******************************************* * functions */ /* * put the constant string pointed to by s to the Ethernet controller's transmit buffer. */ /*unsigned int putConstString(const char *s) { unsigned int ctr = 0 ; while(*s) { Ethernet_putByte(*s++) ; ctr++ ; } return(ctr) ; }*/ /* * it will be much faster to use library Ethernet_putConstString routine * instead of putConstString routine above. However, the code will be a little * bit bigger. User should choose between size and speed and pick the implementation that * suites him best. If you choose to go with the putConstString definition above * the #define line below should be commented out. * */ #define putConstString Ethernet_putConstString /* * put the string pointed to by s to the Ethernet controller's transmit buffer */ /*unsigned int putString(char *s) { unsigned int ctr = 0 ; while(*s) { Ethernet_putByte(*s++) ; ctr++ ; } return(ctr) ; }*/ /* * it will be much faster to use library Ethernet_putString routine * instead of putString routine above. However, the code will be a little * bit bigger. User should choose between size and speed and pick the implementation that * suites him best. If you choose to go with the putString definition above * the #define line below should be commented out. * */ #define putString Ethernet_putString /* * * * * * *
this function is called by the library the user accesses to the HTTP request by successive calls to Ethernet_getByte() the user puts ;") ; // add AN3 value to reply IntToStr(ADC_Read(3), dyna) ; len += putConstString("var AN3=") ; len += putString(dyna) ; len += putConstString(";") ; // add PORTB value (buttons) to reply len += putConstString("var PORTB=") ; IntToStr(PORTB, dyna) ; len += putString(dyna) ; len += putConstString(";") ; // add PORTD value (LEDs) to reply len += putConstString("var PORTD=") ; IntToStr(PORTD, dyna) ; len += putString(dyna) ; len += putConstString(";") ;
www.raguvaran.puzl.com
// HTTP header // with text MIME type
// add HTTP requests counter to reply IntToStr(httpCounter, dyna) ; len += putConstString("var REQ=") ; len += putString(dyna) ; len += putConstString(";") ; } else if(getRequest[5] == 't') with t, toggle PORTD (LED) bit number that comes after { unsigned char bitMask = 0 ;
// if request path name starts
// for bit mask // if 0
White color
CL_YELLOW_16bit
Yellow color
font_orientation: sets font orientation : Value
Description
FO_HORIZONTAL_16bit
Horizontal orientation
FO_VERTICAL_16bit
Vertical orientation
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Set_Ext_Font(173296, CL_BLACK_16bit, FO_HORIZONTAL_16bit);
TFT_16bit_Write_Char Prototype
void TFT_16bit_Write_Char(unsigned int c, unsigned int x, unsigned int y);
Returns
Nothing.
Description
Writes a char on the TFT at coordinates (x, y).
c: char to be written. x: char position on x-axis. y: char position on y-axis.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Write_Char('A',22,23,);
www.raguvaran.puzl.com
TFT_16bit_Write_Text Prototype
void TFT_16bit_Write_Text(unsigned char *text, unsigned int x, unsigned int y);
Returns
Nothing.
Description
Writes text on the TFT at coordinates (x, y). Parameters :
text: text to be written. x: text position on x-axis. y: text position on y-axis.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Write_Text("TFT 16-bit Library DEMO, WELCOME !", 0, 0,);
TFT_16bit_Write_Const_Text Prototype
void TFT_16bit_Write_Const_Text(const far char *text, unsigned int x, unsigned int y);
Returns
Nothing.
Description
Writes text located in the program memory on the TFT at coordinates (x, y). Parameters :
text: text to be written. x: text position on x-axis. y: text position on y-axis.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
const char ctext[] = "mikroElektronika"; ... TFT_16bit_Write_Const_Text(ctext, 0, 0,);
TFT_16bit_Fill_Screen Prototype
void TFT_16bit_Fill_Screen(unsigned int color);
Returns
Nothing.
Description
Fills screen memory block with given color.
www.raguvaran.puzl.com
Parameters :
color: color to be filled : Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
CL_YELLOW_16bit
Yellow color
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Fill_Screen(CL_BLACK_16bit);
TFT_16bit_Dot Prototype
void TFT_16bit_Dot(int x, int y, unsigned int color);
Returns
Nothing.
Description
Draws a dot on the TFT at coordinates (x, y).
www.raguvaran.puzl.com
Parameters :
x: dot position on x-axis. y: dot position on y-axis. color: color parameter. Valid values : Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
CL_YELLOW_16bit
Yellow color
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Dot(50, 50, CL_BLACK_16bit);
TFT_16bit_Set_Pen Prototype
void TFT_16bit_Set_Pen(unsigned int pen_color, char pen_width);
Returns
Nothing.
www.raguvaran.puzl.com
Description
Sets color and thickness parameter for drawing line, circle and rectangle elements. Parameters :
pen_color: Sets color. Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
CL_YELLOW_16bit
Yellow color
pen_width: sets thickness.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Set_Pen(CL_BLACK_16bit, 10);
TFT_16bit_Set_Brush Prototype
void TFT_16bit_Set_Brush(char brush_enabled, unsigned
www.raguvaran.puzl.com
int brush_color, char gradient_enabled, char gradient_orientation, unsigned intgradient_color_from, unsigned int gradient_color_to); Returns
Nothing.
Description
Sets color and gradient which will be used to fill circles or rectangles. Parameters :
brush_enabled: enable brush fill. Value
Description
1
Enable brush fill.
0
Disable brush fill.
brush_color: set brush fill color. Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
www.raguvaran.puzl.com
CL_YELLOW_16bit
Yellow color
gradient_enabled: enable gradient Value
Description
1
Enable gradient.
0
Disable gradient.
gradient_orientation: sets gradient orientation : Value
Description
LEFT_TO_RIGHT_16bit
Left to right gradient orientation
TOP_TO_BOTTOM
Top to bottom gradient orientation
gradient_color_from: sets the starting gradient color. Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
CL_YELLOW_16bit
Yellow color
gradient_color_to: sets the ending gradient color.
www.raguvaran.puzl.com
Value
Description
CL_AQUA_16bit
Aqua color
CL_BLACK_16bit
Black color
CL_BLUE_16bit
Blue color
CL_FUCHSIA_16bit
Fuchsia color
CL_GRAY_16bit
Gray color
CL_GREEN_16bit
Green color
CL_LIME_16bit
Lime color
CL_MAROON_16bit
Maroon color
CL_NAVY_16bit
Navy color
CL_OLIVE_16bit
Olive color
CL_PURPLE_16bit
Purple color
CL_RED_16bit
Red color
CL_SILVER_16bit
Silver color
CL_TEAL_16bit
Teal color
CL_WHITE_16bit
White color
CL_YELLOW_16bit
Yellow color
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
// Enable gradient from black to white color, left-right orientation TFT_16bit_Set_Brush(0, 0, 1, LEFT_TO_RIGHT_16bit, CL_BLACK_16bit, CL_WHITE_16bit);
TFT_16bit_Line Prototype
void TFT_16bit_Line(int x1, int y1, int x2, int y2);
Returns
Nothing.
Description
Draws a line from (x1, y1) to (x2, y2).
www.raguvaran.puzl.com
Parameters :
x1: x coordinate of the line start. y1: y coordinate of the line end. x2: x coordinate of the line start. y2: y coordinate of the line end.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Line(0, 0, 239, 127);
TFT_16bit_H_Line Prototype
void TFT_16bit_H_Line(int x_start, int x_end, int y_pos);
Returns
Nothing.
Description
Draws a horizontal line on TFT. Parameters :
x_start: x coordinate of the line start. x_end: x coordinate of the line end. y_pos: y coordinate of horizontal line.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
// Draw a horizontal line between dots (10,20) and (50,20) TFT_16bit_H_Line(10, 50, 20);
TFT_16bit_V_Line Prototype
void TFT_16bit_V_Line(int y_start, int y_end, int x_pos);
Returns
Nothing.
Description
Draws a vertical line on TFT. Parameters :
y_start: y coordinate of the line start. y_end: y coordinate of the line end. x_pos: x coordinate of vertical line.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
// Draw a vertical line between dots (10,5) and (10,25) TFT_16bit_V_Line(5, 25, 10);
www.raguvaran.puzl.com
TFT_16bit_Rectangle Prototyp e
void TFT_16bit_Rectangle(int x_upper_left, int y_upper_left, int x_bottom_righ t, int y_bottom_right);
Returns
Nothing.
Descript ion
Draws a rectangle on TFT. Parameters :
x_upper_left: x coordinate of the upper left rectangle corner. y_upper_left: y coordinate of the upper left rectangle corner. x_bottom_right: x coordinate of the lower right rectangle corner. y_bottom_right: y coordinate of the lower right rectangle corner.
Require s
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Rectangle(20, 20, 219, 107);
TFT_16bit_Rectangle_Round_Edges Prototype
void TFT_16bit_Rectangle_Round_Edges(unsigned int x_upper_left, unsigned int y_upper_left, unsigned int x_bottom_right, unsigned inty_bottom_right, unsigned int round_radius);
Returns
Nothing.
Description
Draws a rounded edge rectangle on TFT. Parameters :
x_upper_left: x coordinate of the upper left rectangle corner. y_upper_left: y coordinate of the upper left rectangle corner. x_bottom_right: x coordinate of the lower right rectangle corner. y_bottom_right: y coordinate of the lower right rectangle corner. round_radius: radius of the rounded edge.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Rectangle_Round_Edges(20, 20, 219, 107, 12);
TFT_16bit_Circle Prototype
void TFT_16bit_Circle(int x_center, int y_center, int radius);
www.raguvaran.puzl.com
Returns
Nothing.
Description
Draws a circle on TFT. Parameters :
x: x coordinate of the circle center. y: y coordinate of the circle center. r: radius size.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Circle(120, 64, 110);
TFT_16bit_Image Prototype
void TFT_16bit_Image(unsigned int left, unsigned int top, code const far unsigned short * image, unsigned short stretch);
Returns
Nothing.
Description
Displays an image on a desired location. Parameters :
left: position of the image's left edge. top:position of the image's top edge. image: image to be displayed. Bitmap array is located in code memory. stretch: stretches image by a given factor (if 2, it will double the image.).
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Image(0, 0, image, 1);
TFT_16bit_Ext_Image Prototype
void TFT_16bit_Ext_Image(unsigned int left, unsigned int top, unsigned long image, unsigned short stretch);
Returns
Nothing.
Description
Displays an image from an external resource on a desired address. Parameters :
left: position of the image's left edge. top:position of the image's top edge.
www.raguvaran.puzl.com
image: image to be displayed. This parameter represents the address in the exteral resource from where the image data begins. stretch: stretches image by a given factor (if 2, it will double the image.).
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Image(0, 0, 153608, 1);
TFT_16bit_Partial_Image Prototype
void TFT_16bit_Partial_Image(unsigned int left, unsigned int top, unsigned int width, unsigned int height, code const far unsigned short * image,unsigned short stretch);
Returns
Nothing.
Description
Displays a partial area of the image on a desired location. Parameters :
left: left coordinate of the image. top: top coordinate of the image. width: desired image width. height: desired image height. image: image to be displayed. Bitmap array is located in code memory. stretch: stretches image by a given factor (if 2, it will double the image.).
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
// Draws a 10x15 part of the image starting from the upper left corner on the coordinate (10,12) TFT_16bit_Partial_Image(10, 12, 10, 15, image, 1);
TFT_16bit_Ext_Partial_Image Prototype
void TFT_16bit_Ext_Partial_Image(unsigned int left, unsigned int top, unsigned int width, unsigned int height, unsigned long image, unsigned shortstretch);
Returns
Nothing.
Description
Displays a partial area of the image, located on an external resource, on a desired location of the screen. Parameters :
left: left coordinate of the image. top: top coordinate of the image. width: desired image width. height: desired image height.
www.raguvaran.puzl.com
image: image to be displayed. This parameter represents the address in the exteral resource from where the image data begins. stretch: stretches image by a given factor (if 2, it will double the image.).
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Ext_Partial_Image(159,0,160,120,0,1);
TFT_16bit_Image_Jpeg Prototype
Returns
Description
char TFT_16bit_Image_Jpeg(unsigned int left, unsigned int top, code const far unsigned short *image);
0 - if image is loaded and displayed successfully. 1 - if error occured.
Displays a JPEG image on a desired location. Parameters :
left: left coordinate of the image. top: top coordinate of the image. image: image to be displayed. Bitmap array is located in code memory.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Image_Jpeg(0, 0, image);
TFT_16bit_RGBToColor16bit Prototype
unsigned int TFT_16bit_RGBToColor16bit(char rgb_red, char rgb_green, char rgb_blue);
Returns
Returns a color value in the following bit-order : 5 bits red, 6 bits green and 5 bits blue color.
Description
Converts 5:6:5 RGB format into true color format. Parameters :
rgb_red: red component of the image. rgb_green: green component of the image. rgb_blue: blue component of the image.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
color16 = TFT_16bit_RGBToColor16bit(150, 193, 65);
TFT_16bit_Color16bitToRGB
www.raguvaran.puzl.com
Prototype
void TFT_16bit_Color16bitToRGB(unsigned int color, char *rgb_red, char *rgb_green, char *rgb_blue);
Returns
Nothing.
Description
Converts true color into 5:6:5 RGB format. Parameters :
color: true color to be converted. rgb_red: red component of the input color. rgb_green: green component of the input color. rgb_blue: blue component of the input color.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
TFT_16bit_Color16bitToRGB(start_color, &red_start, &green_start, &blue_start);
TFT_16bit_Rotate_180 Prototype
void TFT_16bit_Rotate_180(char rotate);
Returns
Nothing.
Description
Rotates the TFT display. Parameters :
rotate: parameter for rotating display. Valid values :
0 - display will not be rotated. 1 - display will be rotated for 180 degrees.
Requires
TFT module needs to be initialized. Please, see appropriate TFT initialization routine.
Example
// Rotate TFT display for 180 degrees TFT_16bit_Rotate_180(1); // Initialize TFT display TFT_Init_HX8352A(240, 320);
Touch Panel Library The mikroC PRO for PIC provides a library for working with Touch Panel.
www.raguvaran.puzl.com
Library Dependency Tree
External dependencies of Touch Panel Library The following variables must be defined in all projects using Touch Panel Library:
Description :
Example :
extern sfr sbit DriveA;
DriveA line.
sbit DriveA at RC0_bit;
extern sfr sbit DriveB;
DriveB line.
sbit DriveB at RC1_bit;
extern sfr sbit DriveA_Direction;
Direction of the DriveA pin.
sbit DriveA_Direction at TRISC0_bit;
extern sfr sbit DriveB_Direction;
Direction of the DriveB pin.
sbit DriveB_Direction at TRISC1_bit;
Library Routines
TP_Init TP_Set_ADC_Threshold TP_Press_Detect TP_Get_Coordinates TP_Calibrate_Bottom_Left TP_Calibrate_Upper_Right TP_Get_Calibration_Consts TP_Set_Calibration_Consts
TP_Init Prototype
void TP_Init(unsigned int display_width, unsigned int display_height, char readX_ChNo, char readY_ChNo);
Description
Initialize touch panel display. Default touch panel ADC threshold value is set to 3900.
Parameters
display_width: set display width. display_height: set display height. readX_ChNo: read X coordinate from desired ADC channel. readY_ChNo: read Y coordinate from desired ADC channel.
Returns
Nothing.
Requires
Before calling this function initialize ADC module.
Example
ADC_Init();
www.raguvaran.puzl.com
// Initalize ADC module
// Initialize touch panel, dimensions 128x64
TP_Init(128, 64, 6, 7);
TP_Set_ADC_Threshold Prototype
void TP_Set_ADC_Threshold(unsigned int threshold);
Description
Set custom ADC threshold value, call this function after TP_Init.
Parameters
threshold: custom ADC threshold value.
Returns
Nothing.
Requires
TP_Init has to be called before using this routine.
Example
TP_Set_ADC_Threshold(3900);
// Set touch panel ADC threshold
TP_Press_Detect Prototype
char TP_Press_Detect();
Description
Detects if the touch panel has been pressed.
Parameters
None.
Returns
Requires
1 - if touch panel is pressed. 0 - otherwise.
Global variables : DriveA: DriveA. DriveB: DriveB. DriveA_Direction: Direction of DriveA pin. DriveB_Direction: Direction of DriveB pin. must be defined before using this function.
Example
// Touch Panel module connections sbit DriveA at RC0_bit; sbit DriveB at RC1_bit; sbit DriveA_Direction at TRISC0_bit; sbit DriveB_Direction at TRISC1_bit; // End Touch Panel module connections if (TP_Press_Detect()) { ... }
TP_Get_Coordinates
www.raguvaran.puzl.com
Prototype
char TP_Get_Coordinates(unsigned int *x_coordinate, unsigned int *y_coordinate);
Description
Get touch panel coordinates and store them in x_coordinate and y_coordinate parameters.
Parameters
x_coordinate: x coordinate of the place of touch. y_coordinate: y coordinate of the place of touch.
Returns
0 - if reading is within display dimension range. 1 - if reading is out of display dimension range.
Requires
Nothing.
Example
if (TP_Get_Coordinates(&x_coord, &y_coord) == 0) { ... }
TP_Calibrate_Bottom_Left Prototype
void TP_Calibrate_Bottom_Left();
Description
Calibrate bottom left corner of the touch Panel.
Parameters
None.
Returns
Nothing.
Requires
Nothing.
Example
TP_Calibrate_Bottom_Left();
// Calibration of bottom left corner
TP_Calibrate_Upper_Right Prototype
void TP_Calibrate_Upper_Right();
Description
Calibrate upper right corner of the touch panel.
Parameters
None.
www.raguvaran.puzl.com
Returns
Nothing.
Requires
Nothing.
Example
TP_Calibrate_Upper_Right();
// Calibration of upper right corner
TP_Get_Calibration_Consts Prototype
void TP_Get_Calibration_Consts(unsigned int *x_min, unsigned int *x_max, unsigned int *y_min, unsigned int *y_max);
Description
Gets calibration constants after calibration is done and stores them in x_min, x_max, y_min and y_max parameters.
Parameters
x_min: x_max: y_min: y_max:
x x y y
coordinate coordinate coordinate coordinate
of of of of
the the the the
bottom left upper right bottom left upper right
corner corner corner corner
of of of of
the working the working the working the working
Returns
Nothing.
Requires
Nothing.
Example
TP_Get_Calibration_Consts(&x_min, &y_min, &x_max, &y_max); constants
area. area. area. area.
// Get calibration
TP_Set_Calibration_Consts Prototype
void TP_Set_Calibration_Consts(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max);
Description
Sets calibration constants.
Parameters
x_min: x_max: y_min: y_max:
Returns
Nothing.
Requires
Nothing.
www.raguvaran.puzl.com
x x y y
coordinate coordinate coordinate coordinate
of of of of
the the the the
bottom left upper right bottom left upper right
corner corner corner corner
of of of of
the working the working the working the working
area. area. area. area.
TP_Set_Calibration_Consts(148, 3590, 519, 3370);
Example
// Set calibration constants
Library Example The following drawing demo tests routines of the Touch Panel library : Copy Code To Clipboard
// Glcd module connections char GLCD_DataPort at PORTD; sbit sbit sbit sbit sbit sbit
GLCD_CS1 GLCD_CS2 GLCD_RS GLCD_RW GLCD_EN GLCD_RST
at at at at at at
RB0_bit; RB1_bit; RB2_bit; RB3_bit; RB4_bit; RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit; sbit GLCD_CS2_Direction at TRISB1_bit; sbit GLCD_RS_Direction at TRISB2_bit; sbit GLCD_RW_Direction at TRISB3_bit; sbit GLCD_EN_Direction at TRISB4_bit; sbit GLCD_RST_Direction at TRISB5_bit; // End Glcd module connections // Touch Panel module connections sbit DriveA at RC0_bit; sbit DriveB at RC1_bit; sbit DriveA_Direction at TRISC0_bit; sbit DriveB_Direction at TRISC1_bit; // End Touch Panel module connections bit write_erase; char pen_size; char write_msg[] = "WRITE"; char clear_msg[] = "CLEAR"; char erase_msg[] = "ERASE"; unsigned int x_coord, y_coord; void Initialize() { DriveA_Direction = 0; DriveB_Direction = 0; ANSEL = 3; inputs ANSELH = 0; TRISA = 3;
// GLCD menu messages
// Set DriveA pin as output // Set DriveB pin as output // Configure AN0 and AN1 pins as analog // and other AN pins as digital I/O
C1ON_bit = 0; C2ON_bit = 0;
// Disable comparators
Glcd_Init(); Glcd_Fill(0);
// Initialize GLCD // Clear GLCD
ADC_Init(); TP_Init(128, 64, 0, 1); TP_Set_ADC_Threshold(900);
// Initialize ADC // Initialize touch panel // Set touch panel ADC threshold
} void Calibrate() { Glcd_Dot(0,63,1); Glcd_Write_Text("TOUCH BOTTOM LEFT",12,3,1); TP_Calibrate_Bottom_Left();
www.raguvaran.puzl.com
// Draw bottom left dot // Calibration of bottom left corner
Delay_ms(1000); Glcd_Dot(0,63,0); Glcd_Dot(127,0,1); Glcd_Write_Text(" ",12,3,1); Glcd_Write_Text("TOUCH UPPER RIGHT",12,4,1); TP_Calibrate_Upper_Right();
// Clear bottom left dot // Draw upper right dot
// Calibration of upper right corner
Delay_ms(1000); } void main() { Initialize(); Glcd_Write_Text("CALIBRATION",32,3,1); Delay_ms(1000); Glcd_Fill(0); Calibrate();
// Clear GLCD
Glcd_Fill(0); Glcd_Write_Text("WRITE ON SCREEN", 20, 5, 1) ; Delay_ms(1000); Glcd_Fill(0); Glcd_V_Line(0,7,0,1); Glcd_Write_Text(clear_msg,1,0,0); Glcd_V_Line(0,7,97,1); Glcd_Write_Text(erase_msg,98,0,0);
// Clear GLCD
// Pen Menu: Glcd_Rectangle(41,0,52,9,1); Glcd_Box(45,3,48,6,1); Glcd_Rectangle(63,0,70,7,1); Glcd_Box(66,3,67,4,1); Glcd_Rectangle(80,0,86,6,1); Glcd_Dot(83,3,1); write_erase = 1; pen_size = 1; while (1) { if (TP_Press_Detect()) { // After a PRESS is detected read X-Y and convert it to 128x64 space if (TP_Get_Coordinates(&x_coord, &y_coord) == 0) { if ((x_coord < 31) && (y_coord < 8)) { Glcd_Fill(0); // Pen Menu: Glcd_Rectangle(41,0,52,9,1); Glcd_Box(45,3,48,6,1); Glcd_Rectangle(63,0,70,7,1); Glcd_Box(66,3,67,4,1); Glcd_Rectangle(80,0,86,6,1); Glcd_Dot(83,3,1); Glcd_V_Line(0,7,0,1); Glcd_Write_Text(clear_msg,1,0,0); Glcd_V_Line(0,7,97,1); if (write_erase) Glcd_Write_Text(erase_msg,98,0,0); else Glcd_Write_Text(write_msg,98,0,0); }
www.raguvaran.puzl.com
// If write/erase is pressed if ((x_coord > 96) && (y_coord < 8)) { if (write_erase) { write_erase = 0; Glcd_Write_Text(write_msg,98,0,0); Delay_ms(500); } else { write_erase = 1; Glcd_Write_Text(erase_msg,98,0,0); Delay_ms(500); } } // If pen size is selected if ((x_coord >= 41) && (x_coord