Ported Control Serial Display Via Commands. Uses Highest Speed BAUD Rate Possible. You can DRAW,TYPE Create Menus or whatever you like just by communicating with the mbed over serial connection. I did this a while back however Ian Uploaded most of the files i published a while back to his account.
Everything should be working. If not start a discussion and i'll help you asap.
Here is some VB.NET code to help you get started playing with the tft screen through serial. This code will create a menu based graphics which you can select the menu on the left of the screen You can create your own in menu graphics and items however you like, and modify the code to make the mbed do anything you like from inside the windows vb.net application, All you will need is 6 buttons on the form.
VB.NET CODE
Imports System.Threading Public Class Form1 dim com_port as string = "COM6" 'CHANGE THIS TO YOUR MBED COM PORT NUMBER 'Load/Close Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing SerialPort1.WriteLine("fill,255,255,255") SerialPort1.Close() Try End Catch Thread.EndThreadAffinity() End Try End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SerialPort1.PortName = com_port SerialPort1.Open() SerialPort1.WriteLine("fill,255,255,255") Thread.Sleep(2000) 'Required SerialPort1.WriteLine("rot,3") init_menu() End Sub 'Create TFT Graphics Public Sub write_text(ByVal msg As String, ByVal x As Integer, ByVal y As Integer, ByVal size As Integer, ByVal rgb As String) Dim send_string As String = "text," + msg + "," + x.ToString + "," + y.ToString + "," + size.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(40) End Sub Public Sub create_rect(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "rect," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_fillrect(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "frect," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_line(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "dline," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_circle(ByVal x As Integer, ByVal y As Integer, ByVal size As Integer, ByVal rgb As String) Dim send_string As String = "circle," + x.ToString + "," + y.ToString + "," + size.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub 'draw main menu UI Public Sub init_menu() SerialPort1.WriteLine("rot,3") write_text("TFT_PANEL", 100, 13, 2, "200,0,0") create_line(80, 40, 320, 40, "255,0,0") 'Boarder Horizontal create_line(80, 40, 80, 240, "255,0,0") 'Boarder Vertical create_fillrect(0, 0, 80, 40, "100,100,100") 'MENU 1 write_text("Welcome", 12, 17, 1, "0,0,0") create_fillrect(0, 40, 80, 40, "100,100,100") 'MENU 2 write_text("Menu_1", 15, 57, 1, "0,0,0") create_fillrect(0, 80, 80, 40, "100,100,100") 'MENU 3 write_text("Menu_2", 15, 97, 1, "0,0,0") create_fillrect(0, 120, 80, 40, "100,100,100") 'MENU 4 write_text("Menu_3", 15, 137, 1, "0,0,0") create_fillrect(0, 160, 80, 40, "100,100,100") 'MENU 5 write_text("Menu_4", 15, 177, 1, "0,0,0") create_fillrect(0, 200, 80, 40, "100,100,100") 'MENU 6 write_text("Menu_5", 15, 217, 1, "0,0,0") 'Select Top Menu c_menu(0) End Sub 'Unselect previous selected menu tab Public Sub unselect() If last_selected = 0 Then create_fillrect(0, 0, 80, 40, "100,100,100") 'MAIN MENU write_text("Welcome", 12, 17, 1, "0,0,0") End If If last_selected = 1 Then create_fillrect(0, 40, 80, 40, "100,100,100") 'MENU 2 write_text("Menu_1", 15, 57, 1, "0,0,0") End If If last_selected = 2 Then create_fillrect(0, 80, 80, 40, "100,100,100") 'MENU 3 write_text("Menu_2", 15, 97, 1, "0,0,0") End If If last_selected = 3 Then create_fillrect(0, 120, 80, 40, "100,100,100") 'MENU 4 write_text("Menu_3", 15, 137, 1, "0,0,0") End If If last_selected = 4 Then create_fillrect(0, 160, 80, 40, "100,100,100") 'MENU 5 write_text("Menu_4", 15, 177, 1, "0,0,0") End If If last_selected = 5 Then create_fillrect(0, 200, 80, 40, "100,100,100") 'MENU 6 write_text("Menu_5", 15, 217, 1, "0,0,0") End If End Sub 'Select Menu Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click c_menu(0) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click c_menu(1) End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click c_menu(2) End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click c_menu(3) End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click c_menu(4) End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click c_menu(5) End Sub 'SELECT MENU GRAPHICS! Dim last_selected As Integer Public Sub c_menu(ByVal menu As Integer) unselect() If menu = 0 Then last_selected = 0 create_rect(0, 0, 80, 40, "255,255,255") write_text("Welcome", 12, 17, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Welcome_Panel_Menu", 90, 50, 1, "255,0,0") write_text("This_Is_A_Welcome_Panel", 90, 70, 1, "255,0,0") write_text("Menus_Can_Be_Opened_On_Left", 90, 80, 1, "255,0,0") create_circle(100, 100, 5, "255,0,0") End If If menu = 1 Then last_selected = 1 create_rect(0, 40, 80, 40, "255,255,255") write_text("Menu_1", 15, 57, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_1", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FIRST_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 2 Then last_selected = 2 create_rect(0, 80, 80, 40, "255,255,255") 'MENU 3 write_text("Menu_2", 15, 97, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_2", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_SECOND_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 3 Then last_selected = 3 create_rect(0, 120, 80, 40, "255,255,255") 'MENU 3 write_text("Menu_3", 15, 137, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_3", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_THIRD_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 4 Then last_selected = 4 create_rect(0, 160, 80, 40, "255,255,255") 'MENU 4 write_text("Menu_4", 15, 177, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_4", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FOURTH_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 5 Then last_selected = 5 create_rect(0, 200, 80, 40, "255,255,255") 'MENU 5 write_text("Menu_5", 15, 217, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_5", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FIFTH_MENU", 90, 70, 1, "255,0,0") write_text("There_are_NO_menus_ahead...", 90, 80, 1, "255,0,0") End If End Sub End Class
ILI9340_Driver.h@0:d67893e6f32f, 2014-08-28 (annotated)
- Committer:
- Elitism
- Date:
- Thu Aug 28 17:29:23 2014 +0000
- Revision:
- 0:d67893e6f32f
Serial Control of ILI9340C TFT Display.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Elitism | 0:d67893e6f32f | 1 | /* PORTED FROM ARDUINO ADAFRUIT TO MBED */ |
Elitism | 0:d67893e6f32f | 2 | |
Elitism | 0:d67893e6f32f | 3 | |
Elitism | 0:d67893e6f32f | 4 | |
Elitism | 0:d67893e6f32f | 5 | #include "mbed.h" |
Elitism | 0:d67893e6f32f | 6 | |
Elitism | 0:d67893e6f32f | 7 | #ifndef ILI9340_DRIVER_h |
Elitism | 0:d67893e6f32f | 8 | #define ILI9340_DRIVER_h |
Elitism | 0:d67893e6f32f | 9 | |
Elitism | 0:d67893e6f32f | 10 | |
Elitism | 0:d67893e6f32f | 11 | #define _TFTWIDTH 240 |
Elitism | 0:d67893e6f32f | 12 | #define _TFTHEIGHT 320 |
Elitism | 0:d67893e6f32f | 13 | |
Elitism | 0:d67893e6f32f | 14 | #define ILI9340_NOP 0x00 |
Elitism | 0:d67893e6f32f | 15 | #define ILI9340_SWRESET 0x01 |
Elitism | 0:d67893e6f32f | 16 | #define ILI9340_RDDID 0x04 |
Elitism | 0:d67893e6f32f | 17 | #define ILI9340_RDDST 0x09 |
Elitism | 0:d67893e6f32f | 18 | |
Elitism | 0:d67893e6f32f | 19 | #define ILI9340_SLPIN 0x10 |
Elitism | 0:d67893e6f32f | 20 | #define ILI9340_SLPOUT 0x11 |
Elitism | 0:d67893e6f32f | 21 | #define ILI9340_PTLON 0x12 |
Elitism | 0:d67893e6f32f | 22 | #define ILI9340_NORON 0x13 |
Elitism | 0:d67893e6f32f | 23 | |
Elitism | 0:d67893e6f32f | 24 | #define ILI9340_RDMODE 0x0A |
Elitism | 0:d67893e6f32f | 25 | #define ILI9340_RDMADCTL 0x0B |
Elitism | 0:d67893e6f32f | 26 | #define ILI9340_RDPIXFMT 0x0C |
Elitism | 0:d67893e6f32f | 27 | #define ILI9340_RDIMGFMT 0x0A |
Elitism | 0:d67893e6f32f | 28 | #define ILI9340_RDSELFDIAG 0x0F |
Elitism | 0:d67893e6f32f | 29 | |
Elitism | 0:d67893e6f32f | 30 | #define ILI9340_INVOFF 0x20 |
Elitism | 0:d67893e6f32f | 31 | #define ILI9340_INVON 0x21 |
Elitism | 0:d67893e6f32f | 32 | #define ILI9340_GAMMASET 0x26 |
Elitism | 0:d67893e6f32f | 33 | #define ILI9340_DISPOFF 0x28 |
Elitism | 0:d67893e6f32f | 34 | #define ILI9340_DISPON 0x29 |
Elitism | 0:d67893e6f32f | 35 | |
Elitism | 0:d67893e6f32f | 36 | #define ILI9340_CASET 0x2A |
Elitism | 0:d67893e6f32f | 37 | #define ILI9340_PASET 0x2B |
Elitism | 0:d67893e6f32f | 38 | #define ILI9340_RAMWR 0x2C |
Elitism | 0:d67893e6f32f | 39 | #define ILI9340_RAMRD 0x2E |
Elitism | 0:d67893e6f32f | 40 | |
Elitism | 0:d67893e6f32f | 41 | #define ILI9340_PTLAR 0x30 |
Elitism | 0:d67893e6f32f | 42 | #define ILI9340_MADCTL 0x36 |
Elitism | 0:d67893e6f32f | 43 | |
Elitism | 0:d67893e6f32f | 44 | |
Elitism | 0:d67893e6f32f | 45 | #define ILI9340_MADCTL_MY 0x80 |
Elitism | 0:d67893e6f32f | 46 | #define ILI9340_MADCTL_MX 0x40 |
Elitism | 0:d67893e6f32f | 47 | #define ILI9340_MADCTL_MV 0x20 |
Elitism | 0:d67893e6f32f | 48 | #define ILI9340_MADCTL_ML 0x10 |
Elitism | 0:d67893e6f32f | 49 | #define ILI9340_MADCTL_RGB 0x00 |
Elitism | 0:d67893e6f32f | 50 | #define ILI9340_MADCTL_BGR 0x08 |
Elitism | 0:d67893e6f32f | 51 | #define ILI9340_MADCTL_MH 0x04 |
Elitism | 0:d67893e6f32f | 52 | |
Elitism | 0:d67893e6f32f | 53 | #define ILI9340_PIXFMT 0x3A |
Elitism | 0:d67893e6f32f | 54 | |
Elitism | 0:d67893e6f32f | 55 | #define ILI9340_FRMCTR1 0xB1 |
Elitism | 0:d67893e6f32f | 56 | #define ILI9340_FRMCTR2 0xB2 |
Elitism | 0:d67893e6f32f | 57 | #define ILI9340_FRMCTR3 0xB3 |
Elitism | 0:d67893e6f32f | 58 | #define ILI9340_INVCTR 0xB4 |
Elitism | 0:d67893e6f32f | 59 | #define ILI9340_DFUNCTR 0xB6 |
Elitism | 0:d67893e6f32f | 60 | |
Elitism | 0:d67893e6f32f | 61 | #define ILI9340_PWCTR1 0xC0 |
Elitism | 0:d67893e6f32f | 62 | #define ILI9340_PWCTR2 0xC1 |
Elitism | 0:d67893e6f32f | 63 | #define ILI9340_PWCTR3 0xC2 |
Elitism | 0:d67893e6f32f | 64 | #define ILI9340_PWCTR4 0xC3 |
Elitism | 0:d67893e6f32f | 65 | #define ILI9340_PWCTR5 0xC4 |
Elitism | 0:d67893e6f32f | 66 | #define ILI9340_VMCTR1 0xC5 |
Elitism | 0:d67893e6f32f | 67 | #define ILI9340_VMCTR2 0xC7 |
Elitism | 0:d67893e6f32f | 68 | |
Elitism | 0:d67893e6f32f | 69 | #define ILI9340_RDID1 0xDA |
Elitism | 0:d67893e6f32f | 70 | #define ILI9340_RDID2 0xDB |
Elitism | 0:d67893e6f32f | 71 | #define ILI9340_RDID3 0xDC |
Elitism | 0:d67893e6f32f | 72 | #define ILI9340_RDID4 0xDD |
Elitism | 0:d67893e6f32f | 73 | |
Elitism | 0:d67893e6f32f | 74 | #define ILI9340_GMCTRP1 0xE0 |
Elitism | 0:d67893e6f32f | 75 | #define ILI9340_GMCTRN1 0xE1 |
Elitism | 0:d67893e6f32f | 76 | /* |
Elitism | 0:d67893e6f32f | 77 | #define ILI9340_PWCTR6 0xFC |
Elitism | 0:d67893e6f32f | 78 | |
Elitism | 0:d67893e6f32f | 79 | */ |
Elitism | 0:d67893e6f32f | 80 | |
Elitism | 0:d67893e6f32f | 81 | // Color definitions |
Elitism | 0:d67893e6f32f | 82 | #define ILI9340_BLACK 0x0000 |
Elitism | 0:d67893e6f32f | 83 | #define ILI9340_BLUE 0x001F |
Elitism | 0:d67893e6f32f | 84 | #define ILI9340_RED 0xF800 |
Elitism | 0:d67893e6f32f | 85 | #define ILI9340_GREEN 0x07E0 |
Elitism | 0:d67893e6f32f | 86 | #define ILI9340_CYAN 0x07FF |
Elitism | 0:d67893e6f32f | 87 | #define ILI9340_MAGENTA 0xF81F |
Elitism | 0:d67893e6f32f | 88 | #define ILI9340_YELLOW 0xFFE0 |
Elitism | 0:d67893e6f32f | 89 | #define ILI9340_WHITE 0xFFFF |
Elitism | 0:d67893e6f32f | 90 | |
Elitism | 0:d67893e6f32f | 91 | |
Elitism | 0:d67893e6f32f | 92 | |
Elitism | 0:d67893e6f32f | 93 | class ILI9340_Display { |
Elitism | 0:d67893e6f32f | 94 | |
Elitism | 0:d67893e6f32f | 95 | public: |
Elitism | 0:d67893e6f32f | 96 | |
Elitism | 0:d67893e6f32f | 97 | uint16_t _height; |
Elitism | 0:d67893e6f32f | 98 | uint16_t _width; |
Elitism | 0:d67893e6f32f | 99 | |
Elitism | 0:d67893e6f32f | 100 | ILI9340_Display(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst, PinName dc); |
Elitism | 0:d67893e6f32f | 101 | |
Elitism | 0:d67893e6f32f | 102 | void DispInit(); |
Elitism | 0:d67893e6f32f | 103 | void WriteCommand(uint8_t); |
Elitism | 0:d67893e6f32f | 104 | void WriteData(uint8_t); |
Elitism | 0:d67893e6f32f | 105 | void SetRotation(uint8_t); |
Elitism | 0:d67893e6f32f | 106 | void InvertDisplay(bool); |
Elitism | 0:d67893e6f32f | 107 | void SetAddrWindow(uint16_t, uint16_t, uint16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 108 | |
Elitism | 0:d67893e6f32f | 109 | void DrawPixel(uint16_t, uint16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 110 | void FillScreen(uint16_t); |
Elitism | 0:d67893e6f32f | 111 | void DrawFastVLine(int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 112 | void DrawFastHLine(int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 113 | void FillRect(int16_t, int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 114 | void DrawRect(int16_t, int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 115 | void DrawCircle(int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 116 | uint16_t Colour565(uint8_t, uint8_t, uint8_t); |
Elitism | 0:d67893e6f32f | 117 | |
Elitism | 0:d67893e6f32f | 118 | void DrawAscii(unsigned char, uint16_t, uint16_t, uint16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 119 | void DrawString(char *string, uint16_t, uint16_t, uint8_t, uint16_t); |
Elitism | 0:d67893e6f32f | 120 | void IntToChars (char*, int, uint8_t, uint8_t, uint16_t, uint16_t, uint8_t, uint16_t); |
Elitism | 0:d67893e6f32f | 121 | |
Elitism | 0:d67893e6f32f | 122 | void Swap(int16_t*, int16_t*); |
Elitism | 0:d67893e6f32f | 123 | void DrawLine(int16_t, int16_t, int16_t, int16_t, uint16_t); |
Elitism | 0:d67893e6f32f | 124 | |
Elitism | 0:d67893e6f32f | 125 | protected: |
Elitism | 0:d67893e6f32f | 126 | SPI spi; // mosi, miso, sclk |
Elitism | 0:d67893e6f32f | 127 | DigitalOut cs; |
Elitism | 0:d67893e6f32f | 128 | DigitalOut rst; |
Elitism | 0:d67893e6f32f | 129 | DigitalOut dc; |
Elitism | 0:d67893e6f32f | 130 | |
Elitism | 0:d67893e6f32f | 131 | uint8_t orientation; |
Elitism | 0:d67893e6f32f | 132 | |
Elitism | 0:d67893e6f32f | 133 | }; |
Elitism | 0:d67893e6f32f | 134 | |
Elitism | 0:d67893e6f32f | 135 | |
Elitism | 0:d67893e6f32f | 136 | |
Elitism | 0:d67893e6f32f | 137 | |
Elitism | 0:d67893e6f32f | 138 | |
Elitism | 0:d67893e6f32f | 139 | #endif |