Testbespiel 1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Bulme2
Date:
Wed Jan 16 10:53:26 2019 +0000
Commit message:
1/2019

Changed in this revision

C12832.cpp Show annotated file Show diff for this revision Revisions of this file
C12832.h Show annotated file Show diff for this revision Revisions of this file
font.h Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r 9718a8784c1b C12832.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.cpp	Wed Jan 16 10:53:26 2019 +0000
@@ -0,0 +1,227 @@
+/* mbed library for the mbed Lab Board  128*32 pixel LCD
+ * use C12832 controller
+ * Copyright (c) 2012 Peter Drescher - DC2PD
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Library überarbeitet: 15.1.2014 Copyright (c) Dr.C.Eichtinger
+ * File GraphicDisplay und TextDisplay, sowie small_7 font gestrichen
+ * C12832.h und C12832.cpp überarbeitet und mit Ziffernfont ergänzt
+ * Erweiterung: Zeichengröße 1..4
+ */
+
+#include "mbed.h"
+#include "C12832.h"
+#include <stdio.h>
+#include "font.h"
+
+
+
+C12832::C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs)
+    : _spi(mosi,NC,sck),_reset(reset),_A0(a0),_CS(ncs)
+{  
+    lcd_reset();
+}
+
+void C12832::invert(unsigned int o)
+{
+    if(o == 0) wr_cmd(0xA6);
+    else wr_cmd(0xA7);
+}
+
+
+
+void C12832::wr_cmd(unsigned char cmd)
+{
+    _A0 = 0;
+    _CS = 0;
+    _spi.write(cmd);
+    _CS = 1;
+}
+
+void C12832::wr_dat(unsigned char dat)
+{
+    _A0 = 1;
+    _CS = 0;
+    _spi.write(dat);
+    _CS = 1;
+}
+
+void C12832::lcd_reset()
+{
+
+    _spi.format(8,3);                 // 8 bit spi mode 3
+    _spi.frequency(20000000);          // 19,2 Mhz SPI clock
+    _A0 = 0;
+    _CS = 1;
+    _reset = 0;                        // display reset
+    wait_us(50);
+    _reset = 1;                       // end reset
+    wait_ms(5);
+
+    /* Start Initial Sequence ----------------------------------------------------*/
+
+    wr_cmd(0xAE);   //  display off
+    wr_cmd(0xA2);   //  bias voltage
+
+    wr_cmd(0xA0);
+    wr_cmd(0xC8);   //  colum normal
+
+    wr_cmd(0x22);   //  voltage resistor ratio
+    wr_cmd(0x2F);   //  power on
+    //wr_cmd(0xA4);   //  LCD display ram
+    wr_cmd(0x40);   // start line = 0
+    wr_cmd(0xAF);     // display ON
+
+    wr_cmd(0x81);   //  set contrast
+    wr_cmd(0x17);   //  set contrast
+
+    wr_cmd(0xA6);     // display normal
+
+
+    // clear and update LCD
+    memset(buffer,0x00,512);  // clear display buffer
+    copy_to_lcd();
+}
+
+void C12832::pixel(int x, int y, int color)
+{
+    // first check parameter
+    if(x > 127 || y > 31 || x < 0 || y < 0) return;
+
+        if(color == 0)
+            buffer[x + ((y/8) * 128)] &= ~(1 << (y%8));  // erase pixel
+        else
+            buffer[x + ((y/8) * 128)] |= (1 << (y%8));   // set pixel
+
+}
+
+void C12832::copy_to_lcd(void)
+{
+    
+    int i=0;
+    
+    //page 0
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB0);      // set page address  0
+    _A0 = 1;
+    for(i=0; i<128; i++) {
+        wr_dat(buffer[i]);
+    }
+
+    // page 1
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB1);      // set page address  1
+    _A0 = 1;
+    for(i=128; i<256; i++) {
+        wr_dat(buffer[i]);
+    }
+
+    //page 2
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB2);      // set page address  2
+    _A0 = 1;
+    for(i=256; i<384; i++) {
+        wr_dat(buffer[i]);
+    }
+
+    //page 3
+    wr_cmd(0x00);      // set column low nibble 0
+    wr_cmd(0x10);      // set column hi  nibble 0
+    wr_cmd(0xB3);      // set page address  3
+    _A0 = 1;
+
+    _CS = 0;
+    
+    for(i=384; i<512; i++) {
+        wr_dat(buffer[i]);
+    }
+
+}
+
+void C12832::cls(void)
+{
+    memset(buffer,0x00,512);  // clear display buffer
+    copy_to_lcd();
+}
+
+void C12832::rectangle(int x1, int x2, int y1, int y2)
+{
+    for(int i=x1;i<=x2;i++)
+    {
+        pixel(i,y1,1);
+        pixel(i,y2,1);
+    }
+    
+    for(int i=y1;i<=y2;i++)
+    {
+        pixel(x1,i,1);
+        pixel(x2,i,1);
+    }
+}
+
+
+void C12832::text(int ix, int iy, char* ctext, int length, int size)
+{
+    int i;
+    for(i=0;i<length;i++)
+    {
+        character(ix+i*6*size,iy,ctext[i],size);    
+    }
+}
+
+
+int C12832::character(int ix, int iy, char c, int size)
+{
+    int code = 0;
+    
+    if(ix >127 || ix < 0) return -1;
+    if(iy >31  || iy < 0) return -1;
+    if(c>= 0x20){
+        code = (int)(c - 0x20);
+    } else if(c == 0x00) {
+        code = 96;
+    } else {
+        return -1;
+    }   
+    if((size < 0)||(size > 4)) return -1;
+    
+    int index = code*5;
+    unsigned char  codebyte = 0;
+    unsigned char codebit = 0;
+    
+    
+    for(int i=0; i< 5 ; i++)
+    {
+        codebyte = font[index+i];
+        for(int j=0; j<7; j++)
+        {
+             codebit =  codebyte & (1<<j);
+             for (int k=0; k<size; k++) {
+                for(int l=0;l<size;l++) {
+                    pixel(ix+i*size+k,iy+l+j*size,codebit);   
+                }             
+             }
+             
+        }     
+    } 
+    return 0;
+}    
+
+void C12832::set_contrast(unsigned char volume)
+{
+    wr_cmd(0x81);      //  set volume
+    wr_cmd(volume & 0x3F);
+}   
+
+
diff -r 000000000000 -r 9718a8784c1b C12832.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.h	Wed Jan 16 10:53:26 2019 +0000
@@ -0,0 +1,49 @@
+/* mbed library for the mbed Lab Board  128*32 pixel LCD
+ * use C12832 controller
+ * Copyright (c) 2012 Peter Drescher - DC2PD
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Library überarbeitet: 15.1.2014 Copyright (c) Dr.C.Eichtinger
+ * File GraphicDisplay und TextDisplay, sowie small_7 font gestrichen
+ * C12832.h und C12832.cpp überarbeitet und mit Ziffernfont ergänzt
+ * Erweiterung: Zeichengröße 1..4
+ */
+#ifndef C12832_H
+#define C12832_H
+
+class C12832 {
+public:
+    C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs);
+    void pixel(int x, int y,int colour);
+    void copy_to_lcd(void);    
+    void cls();
+    void set_contrast(unsigned char volume);
+    
+    SPI _spi;
+    DigitalOut _reset;
+    DigitalOut _A0;
+    DigitalOut _CS;
+
+    void invert(unsigned int o);    
+    void rectangle(int x0,int x1,int y0,int y1);   
+    int character(int ix, int iy, char c, int size);
+    void text(int ix, int iy, char* ctext, int length, int size);
+    
+    
+protected:
+    void lcd_reset();
+    void wr_dat(unsigned char value);
+    void wr_cmd(unsigned char value);
+    unsigned char buffer[512];
+};
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9718a8784c1b font.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/font.h	Wed Jan 16 10:53:26 2019 +0000
@@ -0,0 +1,100 @@
+
+unsigned char font[] = {
+    0x00, 0x00, 0x00, 0x00, 0x00,// (space)
+    0x00, 0x00, 0x5F, 0x00, 0x00,// !
+    0x00, 0x07, 0x00, 0x07, 0x00,// "
+    0x14, 0x7F, 0x14, 0x7F, 0x14,// #
+    0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
+    0x23, 0x13, 0x08, 0x64, 0x62,// %
+    0x36, 0x49, 0x55, 0x22, 0x50,// &
+    0x00, 0x05, 0x03, 0x00, 0x00,// '
+    0x00, 0x1C, 0x22, 0x41, 0x00,// (
+    0x00, 0x41, 0x22, 0x1C, 0x00,// )
+    0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
+    0x08, 0x08, 0x3E, 0x08, 0x08,// +
+    0x00, 0x50, 0x30, 0x00, 0x00,// ,
+    0x08, 0x08, 0x08, 0x08, 0x08,// -
+    0x00, 0x60, 0x60, 0x00, 0x00,// .
+    0x20, 0x10, 0x08, 0x04, 0x02,// /
+    0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
+    0x00, 0x42, 0x7F, 0x40, 0x00,// 1
+    0x42, 0x61, 0x51, 0x49, 0x46,// 2
+    0x21, 0x41, 0x45, 0x4B, 0x31,// 3
+    0x18, 0x14, 0x12, 0x7F, 0x10,// 4
+    0x27, 0x45, 0x45, 0x45, 0x39,// 5
+    0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
+    0x01, 0x71, 0x09, 0x05, 0x03,// 7
+    0x36, 0x49, 0x49, 0x49, 0x36,// 8
+    0x06, 0x49, 0x49, 0x29, 0x1E,// 9
+    0x00, 0x36, 0x36, 0x00, 0x00,// :
+    0x00, 0x56, 0x36, 0x00, 0x00,// ;
+    0x00, 0x08, 0x14, 0x22, 0x41,// <
+    0x14, 0x14, 0x14, 0x14, 0x14,// =
+    0x41, 0x22, 0x14, 0x08, 0x00,// >
+    0x02, 0x01, 0x51, 0x09, 0x06,// ?
+    0x32, 0x49, 0x79, 0x41, 0x3E,// @
+    0x7E, 0x11, 0x11, 0x11, 0x7E,// A
+    0x7F, 0x49, 0x49, 0x49, 0x36,// B
+    0x3E, 0x41, 0x41, 0x41, 0x22,// C
+    0x7F, 0x41, 0x41, 0x22, 0x1C,// D
+    0x7F, 0x49, 0x49, 0x49, 0x41,// E
+    0x7F, 0x09, 0x09, 0x01, 0x01,// F
+    0x3E, 0x41, 0x41, 0x51, 0x32,// G
+    0x7F, 0x08, 0x08, 0x08, 0x7F,// H
+    0x00, 0x41, 0x7F, 0x41, 0x00,// I
+    0x20, 0x40, 0x41, 0x3F, 0x01,// J
+    0x7F, 0x08, 0x14, 0x22, 0x41,// K
+    0x7F, 0x40, 0x40, 0x40, 0x40,// L
+    0x7F, 0x02, 0x04, 0x02, 0x7F,// M
+    0x7F, 0x04, 0x08, 0x10, 0x7F,// N
+    0x3E, 0x41, 0x41, 0x41, 0x3E,// O
+    0x7F, 0x09, 0x09, 0x09, 0x06,// P
+    0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
+    0x7F, 0x09, 0x19, 0x29, 0x46,// R
+    0x46, 0x49, 0x49, 0x49, 0x31,// S
+    0x01, 0x01, 0x7F, 0x01, 0x01,// T
+    0x3F, 0x40, 0x40, 0x40, 0x3F,// U
+    0x1F, 0x20, 0x40, 0x20, 0x1F,// V
+    0x7F, 0x20, 0x18, 0x20, 0x7F,// W
+    0x63, 0x14, 0x08, 0x14, 0x63,// X
+    0x03, 0x04, 0x78, 0x04, 0x03,// Y
+    0x61, 0x51, 0x49, 0x45, 0x43,// Z
+    0x00, 0x00, 0x7F, 0x41, 0x41,// [
+    0x02, 0x04, 0x08, 0x10, 0x20,// "\"
+    0x41, 0x41, 0x7F, 0x00, 0x00,// ]
+    0x04, 0x02, 0x01, 0x02, 0x04,// ^
+    0x40, 0x40, 0x40, 0x40, 0x40,// _
+    0x00, 0x01, 0x02, 0x04, 0x00,// `
+    0x20, 0x54, 0x54, 0x54, 0x78,// a
+    0x7F, 0x48, 0x44, 0x44, 0x38,// b
+    0x38, 0x44, 0x44, 0x44, 0x20,// c
+    0x38, 0x44, 0x44, 0x48, 0x7F,// d
+    0x38, 0x54, 0x54, 0x54, 0x18,// e
+    0x08, 0x7E, 0x09, 0x01, 0x02,// f
+    0x08, 0x14, 0x54, 0x54, 0x3C,// g
+    0x7F, 0x08, 0x04, 0x04, 0x78,// h
+    0x00, 0x44, 0x7D, 0x40, 0x00,// i
+    0x20, 0x40, 0x44, 0x3D, 0x00,// j
+    0x00, 0x7F, 0x10, 0x28, 0x44,// k
+    0x00, 0x41, 0x7F, 0x40, 0x00,// l
+    0x7C, 0x04, 0x18, 0x04, 0x78,// m
+    0x7C, 0x08, 0x04, 0x04, 0x78,// n
+    0x38, 0x44, 0x44, 0x44, 0x38,// o
+    0x7C, 0x14, 0x14, 0x14, 0x08,// p
+    0x08, 0x14, 0x14, 0x18, 0x7C,// q
+    0x7C, 0x08, 0x04, 0x04, 0x08,// r
+    0x48, 0x54, 0x54, 0x54, 0x20,// s
+    0x04, 0x3F, 0x44, 0x40, 0x20,// t
+    0x3C, 0x40, 0x40, 0x20, 0x7C,// u
+    0x1C, 0x20, 0x40, 0x20, 0x1C,// v
+    0x3C, 0x40, 0x30, 0x40, 0x3C,// w
+    0x44, 0x28, 0x10, 0x28, 0x44,// x
+    0x0C, 0x50, 0x50, 0x50, 0x3C,// y
+    0x44, 0x64, 0x54, 0x4C, 0x44,// z
+    0x00, 0x08, 0x36, 0x41, 0x00,// {
+    0x00, 0x00, 0x7F, 0x00, 0x00,// |
+    0x00, 0x41, 0x36, 0x08, 0x00,// }
+    0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
+    0x08, 0x1C, 0x2A, 0x08, 0x08,// <-
+    0x00, 0x02, 0x05, 0x02, 0x00 // grad Symbol
+    };
diff -r 000000000000 -r 9718a8784c1b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 16 10:53:26 2019 +0000
@@ -0,0 +1,102 @@
+#include "mbed.h"
+#include "C12832.h"
+
+#define NORD 0
+#define OST 1
+#define WEST 2
+#define SUED 3
+#define FIRE 4
+
+C12832 lcd1(p5, p7, p6, p8, p11);
+Ticker lcdram;
+
+InterruptIn nord(p15);
+InterruptIn ost(p16);
+InterruptIn west(p13);
+InterruptIn sued(p12);
+InterruptIn fire(p14);
+
+int display = NORD;
+char buffer[6];
+
+void show()
+{
+          lcd1.cls();
+              switch(display)
+                {
+                    case NORD:                      
+                        sprintf(buffer, "NORD 0");                      
+                        break;
+                    case OST:                   
+                        sprintf(buffer, "OST  1");
+                        break;
+                    case WEST:
+                        sprintf(buffer, "WEST 2");
+                        break;
+                    case SUED:
+                        sprintf(buffer, "SUED 3");
+                        break;
+                    default:
+                          sprintf(buffer,  "FIRE 4");
+                          break;
+            }   
+        lcd1.text(8,5,buffer,6,3);
+        lcd1.rectangle(0,127,0,31); 
+}
+
+
+void isrnord()
+{
+      display = NORD;
+      show();
+}
+
+void isrost()
+{
+      display = OST;
+      show();
+}
+
+void isrwest()
+{
+      display = WEST;
+      show();
+}
+
+void isrsued()
+{
+      display = SUED;
+      show();
+}
+
+void isrfire()
+{
+      display = FIRE;
+      show();
+}
+
+void update()
+{
+   lcd1.copy_to_lcd();
+}
+
+
+
+int main()
+{    
+    lcdram.attach(&update,0.1); 
+
+    nord.rise(&isrnord);
+    ost.rise(&isrost);
+    west.rise(&isrwest);
+    sued.rise(&isrsued);
+    fire.rise(&isrfire);
+    
+    lcd1.cls();   
+    
+    
+    while(1)
+    {
+        
+    }
+}
diff -r 000000000000 -r 9718a8784c1b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 16 10:53:26 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file