#include #define DELAY 65 #define delayus(us) do { TMR1 = 0; while(TMR1 <= us*DELAY); } while(0); /* pinguino */ /*PORTD*/ #define D0 0x04 #define D1 0x08 #define D2 0x10 /*sheet 4 xref_table -> if(0x10 output) -> 0x01 input and viceversa */ #define D3 0x20 #define D4 0x40 #define D5 0x80 #define D6 0x100 #define D7 0x800 /*PORTB*/ #define D9 0x4000 #define LCD_RS 0x4000 /*PORTG*/ #define D10 0x200 #define LCD_RW 0x200 #define D8 0x40 /*lcd clock */ #define LCD_EN 0x40 void lcd_ck(int ud) { if(ud) PORTGSET = LCD_EN; else PORTGCLR = LCD_EN; //ck 0 delayus(15); } int getPortFromIndex(int i) { return i == 0 ? D0 : i == 1 ? D1 : i == 2 ? D2 : i == 3 ? D3 : i == 4 ? D4 : i == 5 ? D5 : i == 6 ? D6 : D7; } void lcdSendCommand(int rs,int rw, int db[8]) { int i; lcd_ck(1); if(rs) PORTBSET = LCD_RS; else PORTBCLR = LCD_RS; if(rw) PORTGSET = LCD_RW; else PORTGCLR = LCD_RW; for(i=0; i<8; ++i) { if(db[i]) PORTDSET = getPortFromIndex(i); else PORTDCLR = getPortFromIndex(i); } lcd_ck(0); } int *getData(int *data, int b0, int b1, int b2, int b3, int b4, int b5, int b6, int b7) { data[0] = b0; data[1] = b1; data[2] = b2; data[3] = b3; data[4] = b4; data[5] = b5; data[6] = b6; data[7] = b7; return data; } /* LCD */ void setup() { int data[8]; /*pinguino */ /* data output buffer */ TRISDCLR = D0; TRISDCLR = D1; TRISDCLR = D2; TRISDCLR = D3; TRISDCLR = D4; TRISDCLR = D5; TRISDCLR = D6; TRISDCLR = D7; //outputs TRISDSET = 0; //bit 0 as output (value 1) /* enable and select register [LCD] */ TRISBCLR = D9; /* lcd rw */ TRISGCLR = D10; TRISGCLR = D8; /* timer init */ T1CON = 0x8030; PR1 = 0xFFFF; delayus(50); /* setup time lcd */ lcdSendCommand(0,0,getData(data,0,0,0,0,1,1,0,0));//0x30 lcdSendCommand(0,0,getData(data,0,0,0,1,1,1,0,0));//0x38 lcdSendCommand(0,0,getData(data,0,0,0,1,0,0,0,0));//8 lcdSendCommand(0,0,getData(data,1,0,0,0,0,0,0,0));//clear display lcdSendCommand(0,0,getData(data,0,1,1,0,0,0,0,0));//display on and lcdSendCommand(0,0,getData(data,0,0,1,1,0,0,0,0));//0x0C //lcd ready to accept data } int main(void) { int data[8]; short int i=0; setup(); while(1) { for(i=0;i<40;++i) lcdSendCommand(1,0,getData(data,0,0,0,0,0,1,0,0)); //white space delayus(1000); delayus(1000); delayus(1000); delayus(1000); delayus(1000); //center lcdSendCommand(1,0,getData(data,0,1,1,1,1,1,1,0)); //-> lcdSendCommand(1,0,getData(data,0,0,0,0,0,1,0,0)); //white space lcdSendCommand(1,0,getData(data,1,1,1,0,1,0,1,0));// 'W' lcdSendCommand(1,0,getData(data,1,1,1,0,1,0,1,0));// 'W' lcdSendCommand(1,0,getData(data,1,1,1,0,1,0,1,0));// 'W' lcdSendCommand(1,0,getData(data,0,1,1,1,0,1,0,0));// '.' lcdSendCommand(1,0,getData(data,0,1,1,1,0,0,1,0));// 'N' lcdSendCommand(1,0,getData(data,1,0,1,0,0,0,1,0));// 'E' lcdSendCommand(1,0,getData(data,0,1,0,0,1,0,1,0));// 'R' lcdSendCommand(1,0,getData(data,0,0,1,0,0,0,1,0));// 'D' lcdSendCommand(1,0,getData(data,0,1,0,1,1,0,1,0));// 'Z' lcdSendCommand(1,0,getData(data,0,1,1,1,0,1,0,0));// '.' lcdSendCommand(1,0,getData(data,1,0,1,0,0,0,1,0));// 'E' lcdSendCommand(1,0,getData(data,1,0,1,0,1,0,1,0));// 'U' lcdSendCommand(1,0,getData(data,0,0,0,0,0,1,0,0)); //white space lcdSendCommand(1,0,getData(data,1,1,1,1,1,1,1,0)); //<- delayus(1000); delayus(1000); delayus(1000); delayus(1000); delayus(1000); lcdSendCommand(0,0,getData(data,1,0,0,0,0,0,0,0)); //cls //go to line 2 } return 0; }