Newhaven 320x240 LCD

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pbevans89
Date:
Sun Feb 27 21:01:16 2011 +0000
Child:
1:fa44aeffcfd6
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
newhaven.cpp Show annotated file Show diff for this revision Revisions of this file
newhaven.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 27 21:01:16 2011 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "newhaven.h"
+
+BusInOut  MyBus(p8,p9,p10,p11,p12,p13,p14,p15);
+NHLCD   MyLCD(p5,p6,p7,p16,p17,&MyBus);
+
+int main() {
+    int i;
+    MyLCD.Init();
+    MyLCD.clearScreen();
+    wait(.5);
+    while(1)
+    {
+    MyLCD.text("Hello World!", 10, 1);
+    wait(1);
+    for(i = 0; i < 20; i++){
+        MyLCD.setPixel(i,i);
+    }
+    wait(1);
+    MyLCD.clearScreen();
+    wait(1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 27 21:01:16 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/newhaven.cpp	Sun Feb 27 21:01:16 2011 +0000
@@ -0,0 +1,145 @@
+#include "mbed.h"
+#include "newhaven.h"
+
+NHLCD::NHLCD(PinName PIN_E,PinName PIN_RW,PinName PIN_A0,PinName PIN_CS,PinName PIN_RST, BusInOut *BUSLCD)
+    : E(PIN_E),RW(PIN_RW),A0(PIN_A0),CS(PIN_CS),RST(PIN_RST){
+    LCD_PORT = BUSLCD;   
+}
+
+void delay(unsigned int n)
+{
+	unsigned int i,j;
+	for (i=0;i<n;i++)
+  		for (j=0;j<350;j++)
+  			{;}
+}
+void delay1(unsigned int i)
+{
+	while(i--);
+}
+
+
+void NHLCD::comm_out(unsigned char j){
+    LCD_PORT->output();  
+    A0 = 1;
+    LCD_PORT->write(j);
+    CS = 0;
+    RW = 0;
+    E = 1;
+    delay(1);
+    E = 0;
+    RW = 1;
+    CS = 1; 
+}
+
+void NHLCD::data_out(unsigned char j){
+    LCD_PORT->output();
+    A0 = 0;
+    LCD_PORT->write(j);
+    CS = 0;
+    RW = 0;
+    E = 1;
+    delay(1);
+    E = 0;
+    RW = 1;
+    CS = 1;
+}
+
+void NHLCD::clearScreen(){
+    int n;
+	comm_out(0x46);
+	data_out(0x00);
+	data_out(0x00);
+	comm_out(0x42);
+	for(n=0;n<1200;n++){
+		data_out(0x20);
+	}
+	comm_out(0x46);
+	data_out(0xB0);
+	data_out(0x04);
+	comm_out(0x42);
+	for(n=0;n<9600;n++){
+		data_out(0x00);
+	}
+}
+
+void NHLCD::text(char *text, char row, char col){
+    int c = row*40+col;
+    comm_out(0x46);
+    data_out((unsigned char)(c&0xFF));
+    data_out((unsigned char)((c&0xFF00)>>8));
+    comm_out(0x42);
+    while(*text != 0) {
+        data_out(*text);
+        text++;
+    }
+}
+
+
+void NHLCD::Init(void){
+    RST = 0;
+    delay(5);
+    RST = 1;
+    delay(10);
+    
+    comm_out(0x40);
+    delay(5);
+    data_out(0x30); //parameters
+    data_out(0x87); //horizontal character size (0x80 = 1) MUST BE MULTIPLE OF 320
+    data_out(0x07); //vertical character size (0x00 = 1)  MUST BE MULTIPLE OF 240
+    data_out(40); //addresses per line
+    data_out(80);
+    data_out(0xEF);
+    data_out(0x28);
+    data_out(0x00);
+    
+    comm_out(0x44);
+    data_out(0x00);
+    data_out(0x00);
+    data_out(0xEF);
+    data_out(0xB0);
+    data_out(0x04);
+    data_out(0xEF);
+    data_out(0x00);
+    data_out(0x00);
+    data_out(0x00);
+    data_out(0x00);
+    
+    comm_out(0x5A);
+    data_out(0x00);
+    
+    comm_out(0x5B);
+    data_out(0x00);
+    
+    comm_out(0x58);
+    data_out(0x56);
+    
+    comm_out(0x5D);
+    data_out(0x04);
+    data_out(0x86);
+    
+    comm_out(0x4C);
+    
+    comm_out(0x59);
+    data_out(0x16);
+    wait_ms(5);
+}
+
+void NHLCD::setPixel(int row, int col){
+    int loc = (0x04<<8)|(0xB0);
+    int c = loc+row*40+(col/8);
+    comm_out(0x46);
+    data_out((unsigned char)(c&0xFF));
+    data_out((unsigned char)((c&0xFF00)>>8));
+    comm_out(0x43);
+    LCD_PORT->input();
+    unsigned char buffer = LCD_PORT->read();
+    buffer = buffer|(1<<(7-((row*320+col)%8)));
+    LCD_PORT->output();
+    
+    comm_out(0x46);
+    data_out((unsigned char)(c&0xFF));
+    data_out((unsigned char)((c&0xFF00)>>8));
+    comm_out(0x42);
+    data_out(buffer);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/newhaven.h	Sun Feb 27 21:01:16 2011 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+
+class NHLCD {
+    public:
+        NHLCD(PinName PIN_E,PinName PIN_RW,PinName PIN_A0,PinName PIN_CS,PinName PIN_RST, BusInOut *BUSLCD);
+        void Init();
+        void comm_out(unsigned char j);
+        void data_out(unsigned char j);
+        void clearScreen();
+        void text(char* text, char row, char col);
+        void setPixel(int row, int col);
+        
+    private:
+        DigitalOut E,RW,A0,CS,RST;   
+        BusInOut *LCD_PORT;   
+        
+};
+
+void delay(unsigned int n);
+void delay1(unsigned int n);