Re: pcflcd Kategorie: Programmierung (von Willi aus Oelde - 3.02.2003 22:24) | |
Als Antwort auf pcflcd von ChristianK - 3.02.2003 13:29
| |
Hallo Christian, Du verwendest mit " " eine Konstante und keine Variable. Die Routine erwartet aber einen Bytepufferzeiger. Ich habe eine schnellere PCFLCD.C2 Routine angehängt. Für ein schnelles löschen solltest Du diese erweitern. ( 20 x blank ausgeben ) Der Zugriff auf Bytepuffervariablen ist extrem langsam !!! Mfg, Willi aus Oelde /******************************************************************/ /* Treiberbibliothek fuer ext. LCD am I²C-Bus im 4-Bit Mode */ /* und PCF-LCD-Interface von http://cctools.hs-control.de */ /* Author : André Helbig (andre.h@cc2net.de / www.CC2Net.de) */ /* Versionen : 1.3 Test Willi 21.1.2003 */ /* Datum : 3. August 2002 */ /* Geändert : Kontinuierlich ....... */ /* Getestet : naja */ /* Benötigt : i2c.c2 */ /******************************************************************/ /* Neu in V1.3 */ /* Capture eingefügt */ /* */ /******************************************************************/ /* P0 = RS */ /* P1 = R/W */ /* P2 = E */ /* P3 = LCD-Light */ /* P4-7= Data */ /******************************************************************/ byte PCF ; byte light ; // Betriebsbits setzen byte En,Mode,Enz,Modez; byte Enc; // const Enable=0b100; //Don't change !! const Line3 =0x94; // Für 4x20 LCD const Line4 =0xD4; // Für 4x20 LCD const Line[]= 0x80,0x80,0xC0,0x94,0xD4; // für 4x20 LCD //const chars_per_line=20;// Für 4x20 LCD //const Line3 =0x90; // Für 4x16 LCD //const Line4 =0xD0; // Für 4x16 LCD //const Line[]= 0x80,0x80,0xC0,0x90,0xD0; // für 4x16 LCD //const chars_per_line=16;// Für 4x16 LCD /*************************************/ /* Baustein auswählen */ /* (für Mehr-Display-Betrieb) */ /* 0-7 PCF8574; 8-15 PCF8574A */ /*************************************/ // Lohnt sich nicht zu verbessern ! function setpcf(byte pcfnr) { if pcfnr > 7 PCF=((pcfnr+16) shl 1)or 64; else PCF=(pcfnr shl 1) or 64; } /*************************************/ /* LCD-Beleuchtung ein/ausschalten */ /*************************************/ // Lohnt sich nicht zu verbessern ! function setLight(byte state) {capture i2c.flag ; light = (state!=0) and 8 ; i2c.start (PCF) ; i2c.write (light) ; i2c.stop () ; Enz =light or 0b00110101 ; // Für Zahlen Modez =light or 0b00110001 ; Enc =light or 0b00000100 ; // Für Command ?? En =light or 0b00000101 ; Mode =light or 0b00000001 ; release ; } /*************************************/ /* Byte im 4-Bit-Mode zum LCD senden */ /*************************************/ // Nur von Line verwendet !! function Write_4_Bit(byte a, byte mode) { mode=mode or light ; capture i2c.flag ; i2c.start(PCF) ; i2c.write((a & 0xF0) or mode or 0b100); i2c.write((a & 0xF0) or mode) ; i2c.write((a shl 4) or mode or 0b100); i2c.write((a shl 4) or mode) ; i2c.stop() ; release; } /*************************************/ /* Befehl an LCD senden */ /*************************************/ function WriteCommand ( byte command ) {capture i2c.flag; i2c.start(PCF) ; i2c.write((command & 0xF0) or Enc ); // ?? i2c.write((command & 0xF0) or light); // ?? i2c.write((command shl 4) or Enc ); i2c.write((command shl 4) or light); i2c.stop(); release; } /*************************************/ /* Display löschen */ /*************************************/ function clear() { capture i2c.flag; i2c.start(PCF); i2c.write(0x04 or light); i2c.write( light); i2c.write(0x14 or light); i2c.write(0x10 or light); i2c.stop(); release; sleep 2; } /*************************************/ /* Initialisierung */ // geht nicht !!??? /*************************************/ function init() { capture i2c.flag; i2c.start(PCF) ; light=light and 8 ; i2c.write(light or 0xF0); //8Bit-Mode i2c.write(0x30 or light); i2c.write(0x30 or Enc ); i2c.write(0x30 or light); sleep 5; i2c.write(0x30 or light); i2c.write(0x30 or Enc ); i2c.write(0x30 or light); sleep 5; i2c.write(0x30 or light); // zus. i2c.write(0x30 or Enc ); i2c.write(0x30 or light); sleep 5; //4Bit-Mode i2c.write(0x20 or light); i2c.write(0x20 or Enc ); i2c.write(0x20 or light); sleep 5; //Funtions-Set i2c.write(0x20 or light); i2c.write(0x20 or Enc ); i2c.write(0x20 or light); sleep 5; i2c.write(0x80 or light); i2c.write(0x80 or Enc ); i2c.write(0x80 or light); //Display Control: i2c.write(Enc ); i2c.write(light); i2c.write(0xC0 or Enc ); i2c.write(0xC0 or light); //Display Clear: i2c.write(Enc ); i2c.write(light); i2c.write(0x10 or Enc ); i2c.write(0x10 or light); sleep 3; //Entry-Mode: i2c.write(Enc ); i2c.write(light); i2c.write(0x60 or Enc ); i2c.write(0x60 or light); release; } /*************************************/ /* Schreibt ein Zeichen auf LCD */ // modifiziert 20.1.2002 /*************************************/ function put( byte a ) {capture i2c.flag ; i2c.start(PCF) ; i2c.write((a & 0xF0) or En) ; i2c.write((a & 0xF0) or Mode) ; i2c.write((a shl 4) or En) ; i2c.write((a shl 4) or Mode) ; i2c.stop() ; release; } /***********************************/ /* writes a string to lcd */ /* sets the mode to DataMode */ /***********************************/ function print( byte s[] ) {byte a; capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); for a=0 ... s[31]-1 { i2c.write((s[a] & 0xF0) or En ); i2c.write((s[a] & 0xF0) or Mode); i2c.write((s[a] <<4) or En ); i2c.write((s[a] <<4) or Mode); } i2c.stop(); release; } /****************************************/ /* writes a string or byte-array to lcd */ /****************************************/ function printlength ( byte s[], byte length ) {byte a; capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); for a=0 ... length-1 { i2c.write((s[a] & 0xF0) or En ); i2c.write((s[a] & 0xF0) or Mode); i2c.write((s[a] <<4) or En ); i2c.write((s[a] <<4) or Mode); } i2c.stop(); release; } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ /* Leerzeichen ausgeben */ /*************************************/ function blank() {i2c.write((0b00100101) or light); // Leerzeichen i2c.write((0b00100001) or light); i2c.write(En ); i2c.write(Mode ); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ /* Null ausgeben */ /*************************************/ function Null() {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ /*************************************/ function Minus() {i2c.write((0b00100101) or light); // "-" i2c.write((0b00100001) or light); i2c.write((0b11010101) or light); i2c.write((0b11010001) or light); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ // Für Zeitaugaben /*************************************/ // ohne Beleuchtung function Doppel_alt() {i2c.write((0b00110101) or light); // ":" i2c.write((0b00110001) or light); i2c.write((0b10100101) or light); i2c.write((0b10100001) or light); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ // Für Zeitaugaben /*************************************/ function Doppel() {i2c.write(Enz) ; // ":" i2c.write(Modez) ; i2c.write((0b10100101) or light); i2c.write((0b10100001) or light); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ /*************************************/ function Komma() {i2c.write((0b00100101) or light); // "," i2c.write((0b00100001) or light); i2c.write((0b11000101) or light); i2c.write((0b11000001) or light); } /*************************************/ /* Wird von den Zahl-Funkt. benötigt */ /* Ziffern 0-9 */ /*************************************/ function ziffd(byte x) { i2c.write (Enz) ; i2c.write (Modez); i2c.write((x shl 4) or En ); i2c.write((x shl 4) or Mode ); } /*************************************/ /* Datum ausgeben(byte) */ /*************************************/ function datum() {byte zahl; zahl = system.hour(); capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >9 ziffd(zahl/10); else Null(); // blank(); ziffd(zahl % 10 ); Doppel(); zahl = system.minute(); if zahl >9 ziffd(zahl/10); else Null(); // blank(); ziffd(zahl % 10 ); Doppel(); zahl = system.second(); if zahl >9 ziffd(zahl/10); else Null(); // blank(); ziffd(zahl % 10 ); i2c.stop(); release; } /*************************************/ /* Zeit ausgeben(byte) */ // Geht mit und ohne Beleuchtung ! /*************************************/ function Zeit() {byte x; capture i2c.flag; i2c.start(PCF); i2c.write(0x01); Minus(); if system.hour() >9 {x =(system.hour()/10) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez ); i2c.write(En ); i2c.write(Mode ); } i2c.write(Enz ); i2c.write(Modez ); x =(system.hour()%10) shl 4; i2c.write(x or En ); i2c.write(x or Mode ); Doppel(); if system.minute() >9 {x =(system.minute()/10) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(system.minute() % 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); Doppel(); if system.second() >9 {x =(system.second()/10) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(system.second()%10) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); Minus(); i2c.stop(); release; } /*************************************/ /* Datum ausgeben */ // geht mit und ohne Beleuchtung /*************************************/ function Datum() {byte zahl,x; zahl = system.day(); capture i2c.flag; i2c.start(PCF); i2c.write(0x01); // Minus(); i2c.write((0b00100101) or light); // "-" i2c.write((0b00100001) or light); i2c.write((0b11010101) or light); i2c.write((0b11010001) or light); if zahl >9 {x =(zahl / 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(zahl % 10 ) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); // Minus(); i2c.write((0b00100101) or light); // "-" i2c.write((0b00100001) or light); i2c.write((0b11010101) or light); i2c.write((0b11010001) or light); zahl = system.month(); if zahl >9 {x =(zahl / 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(zahl % 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); Minus(); zahl = system.year()-2000; if zahl >9 {x =(zahl / 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(zahl % 10 ) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); i2c.write((0b00100101) or light); // "-" i2c.write((0b00100001) or light); i2c.write((0b11010101) or light); i2c.write((0b11010001) or light); i2c.stop(); release; } /*************************************/ /* Datum ausgeben / weniger Code */ // geht mit und ohne Beleuchtung /*************************************/ function Z1(byte zahl) {byte x; if zahl >9 {x =(zahl / 10 ) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {i2c.write(Enz ); // "0" i2c.write(Modez); i2c.write(En ); i2c.write(Mode ); } x =(zahl % 10 ) shl 4; i2c.write(Enz ); i2c.write(Modez ); i2c.write(x or En ); i2c.write(x or Mode ); } function Datum_1() {capture i2c.flag; i2c.start(PCF); i2c.write(0x01); Minus(); Z1(system.day()); Minus(); Z1(system.month()); Minus(); Z1(system.year()-2000); Minus(); i2c.stop(); release; } /*************************************/ /* 2-stellige Zahl ausgeben(byte) */ // führende 0 /*************************************/ function zahl2(byte zahl) {capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >9 ziffd(zahl/10); else Null(); // blank(); ziffd(zahl % 10 ); i2c.stop(); release; } /*************************************/ /* Byte-Zahl ausgeben(3 Stellen) */ /*************************************/ function zahl3(byte zahl) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >99 ziffd(zahl/100 ) ; else blank(); if zahl > 9 ziffd((zahl % 100)/10 ); else blank(); ziffd(zahl % 10); i2c.stop(); release; } /**************************************/ /* 3-stellige Zahl ausgeben(pos & neg)*/ /* byte & Integer (Format:-99 bis 999)*/ /**************************************/ function zahl3n(int zahl) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >99 ziffd(zahl/100 ); else if zahl & 0x8000 {Minus(); zahl=(not zahl) + 1;} else blank(); if zahl >9 ziffd((zahl % 100)/10 ); else blank(); ziffd(zahl % 10 ); i2c.stop(); release; } function zahl4(byte zahl) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >999 ziffd( zahl / 1000 ); else blank(); if zahl > 99 ziffd( zahl % 1000/100 ); else blank(); if zahl > 9 ziffd((zahl % 100)/ 10 ); else blank(); ziffd(zahl % 10 ); i2c.stop(); release; } /**************************************/ /* Integer-Zahl ausgeben (nur positiv)*/ /**************************************/ function zahlp(int zahl) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl >9999 ziffd( zahl / 10000 ); else blank(); if zahl > 999 ziffd((zahl % 10000)/1000 ); else blank(); if zahl > 99 ziffd((zahl % 1000)/ 100 ); else blank(); if zahl > 9 ziffd((zahl % 100)/ 10 ); else blank(); ziffd(zahl % 10 ); i2c.stop(); release; } /**************************************/ /* Integer-Zahl ausgeben (pos & neg) */ // mod. mit & ohne Beleuchtung /* Format: -32768 bis 32767 */ /**************************************/ function zahl(int zahl) {byte x; capture i2c.flag ; i2c.start(PCF) ; i2c.write(0x01) ; if zahl & 0x8000 {Minus() ; zahl=(not zahl)+1; } else blank(); if zahl > 9999 {x = (zahl/10000) shl 4; i2c.write (Enz ) ; i2c.write (Modez ) ; i2c.write (x or En ) ; i2c.write (x or Mode) ; } else {blank(); } // ----1000er Stelle ----- if zahl > 999 {x = ((zahl % 10000)/1000 )shl 4 ; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {blank(); } // ----100er Stelle ----- if zahl > 99 {x = ((zahl % 1000)/100 )shl 4 ; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else {blank(); } // ----10er Stelle ----- if zahl > 9 {x = ((zahl % 100)/10) shl 4; i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); } else { blank(); } // -- letzte Ziffer ---- x = (zahl % 10) shl 4; // oder ziffd i2c.write (Enz ); i2c.write (Modez); i2c.write(x or En ); i2c.write(x or Mode ); i2c.stop(); release; } /**************************************/ /* Integer-Zahl ausgeben (pos & neg) */ /* Format: -32768 bis 32767 */ //leicht modifiziert Willi /**************************************/ function zahlalt(int zahl) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if zahl & 0x8000 {Minus();zahl=(not zahl) + 1;} else blank(); if zahl >9999 ziffd (zahl /10000 ); else blank(); if zahl > 999 ziffd((zahl % 10000)/1000 ); else blank(); if zahl > 99 ziffd((zahl % 1000) / 100 ); else blank(); if zahl > 9 ziffd((zahl % 100) / 10 ); else blank(); ziffd(zahl % 10 ); i2c.stop(); release; } /*************************************/ /* formatierte Zahlausgaben */ /* Format: ##0,0 (-99,9 - 999,9) */ /* -999 - 9999 entspr. -99,9 - 999,9 */ /*************************************/ function zahl4n1(int num) { capture i2c.flag; i2c.start(PCF); i2c.write(0x01 or light); if num>999 ziffd(num /1000 ); else if num & 0x8000 {Minus();num=(not num) + 1;} else blank(); if num>99 ziffd((num % 1000)/ 100 ); else blank(); ziffd((num % 100) / 10 ); Komma(); ziffd(num % 10 ); i2c.stop(); release; } /***********************************/ /* Cursor position */ /***********************************/ function home() { WriteCommand(0x02); sleep 1; } function line1() { WriteCommand(0x80);} function line2() { WriteCommand(0xC0);} function line1a() // modifiziert { capture i2c.flag ; i2c.start(PCF) ; i2c.write(0x84 or light); i2c.write(0x80 or light); i2c.write(0x04 or light); i2c.write(0x00 or light); i2c.stop(); release; } function line2a() // modifiziert { capture i2c.flag ; i2c.start(PCF) ; i2c.write(0xC4 or light); i2c.write(0xC0 or light); i2c.write(0x04 or light); i2c.write(0x00 or light); i2c.stop(); release; } function line3() { WriteCommand(Line3); } function line4() { WriteCommand(Line4); } function line4a() // von Willi modifiziert { capture i2c.flag; i2c.start(PCF) ; i2c.write(0xD4 or light); i2c.write(0xD0 or light); i2c.write(0x44 or light); i2c.write(0x40 or light); i2c.stop(); release; } function line(byte line)// 1 bis 4 { Write_4_Bit(Line[line],0); } function goto(byte line, byte col) // line = 1 bis 4, col =0 bis 19 { Write_4_Bit(Line[line]+col,0); } /***********************************/ /* Cursor/Display-Schieben */ /***********************************/ function move(byte dispcur, byte RL) //dispcur=0:Cursor,dispcur=1:Display; // RL=0:Links,RL=1:Rechts { WriteCommand(0x10 or (dispcur shl 3) or (RL shl 2) ); } /***********************************/ /* Cursor-Eigenschaften */ /***********************************/ function cursorset(byte show, byte blink) { WriteCommand(0x0C or (show shl 1) or blink ); } /***************************************/ /* Display ausshalten */ /* Einschalten mit Cursor-Eigenschaften*/ /***************************************/ function LCDoff() {WriteCommand(0x08);} | |
Antwort schreiben Antworten: Re: pcflcd (von ChristianK - 3.02.2003 23:08) |