Jump to content


Photo

Nokia 5110 C++ Template Class


  • Please log in to reply
5 replies to this topic

#1 oPossum

oPossum

    Poke me with a Stick

  • Members
  • 904 posts
  • LocationMichigan, USA


Posted 04 February 2012 - 10:55 PM

This is a C++ template for the Nokia 5100 that uses software SPI. Inspired by Rickta59's GPIO template

Using C++ templates allow the compiler to make decisions at compile time that would normally occur (repeatedly) at execution time. This results in smaller and faster code. They also are type safe and compatible with source level debugging (unlike macros).

Software SPI is used to make the code very portable to the entire MSP430 family and allow flexible pin assignment. Four wiring schemes are supported.

Attached File  Nokia5110wiring.png   85.25KB   385 downloads

This is the syntax for creating an instance of the template.
    Nokia5110< \        // Template name
        P1OUT,          // Output port for clock and data
        BIT0,           // Clock pin bitmask
        BIT1,           // Data pin bitmask
        P1OUT,          // Output port for DC (data/command), use PNONE if DC line is not used
        BIT2,           // DC pin bitmask (or clock stretch cycles if DC line is not used)
        P1OUT,          // Output port for CE (chip enable), use PNONE if CE line is not used
        BIT3,           // CE pin bitmask
        10000> \        // Reset cycle count
        lcd;            // Object name
The class template
namespace nokia5110 {

unsigned char PNONE;

typedef enum {
    lcd_command = 0,        // Array of one or more commands
    lcd_data = 1,           // Array of one or more bytes of data
    lcd_data_repeat = 2     // One byte of data repeated
} lcd_cmd_type;

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
struct Nokia5110
{
    void write(const unsigned char *cmd, unsigned len, const lcd_cmd_type type = lcd_data);
    void reset(void);
    void init(void);
    void vert(void);
    void home(void);
    void pos(unsigned char x, unsigned char y);
    void clear(unsigned char x = 0);
    void bitmap(const unsigned char *bmp, signed char x, signed char y, unsigned char w, unsigned char h);
    inline void bitmap(const unsigned char *bmp, signed char x, signed char y) { bitmap(bmp + 2, x, y, bmp[0], bmp[1]); };
    void print(char c);
    inline void print(unsigned char x, unsigned char y, char c) { pos(x, y); print(c); };
    void print(char *s);
    inline void print(unsigned char x, unsigned char y, char *s) { pos(x, y); print(s); };
    void printv(unsigned char x, unsigned char y, char *s);
};

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::write(const unsigned char *cmd, unsigned len, const lcd_cmd_type type)
{
    register unsigned mask;
    
    if(&_EP != &PNONE) _EP &= ~_CE;
    do {
        mask = 0x0080;
        do {
            if(*cmd & mask) {
                _SP |= _DATA;
                _SP &= ~_CLK;
            } else {
                _SP &= ~(_CLK | _DATA);
            }
            _SP |= _CLK;
            mask >>= 1;
        } while(!(mask & 1));
        if(&_CP == &PNONE) {
            __delay_cycles(_DC);
        } else {
            if(!type) _CP &= ~_DC;
        }
        if(*cmd & mask) {
            _SP |= _DATA;
            _SP &= ~_CLK;
        } else {
            _SP &= ~(_CLK | _DATA);
        }
        _SP |= _CLK;
        if(&_CP != &PNONE) _CP |= _DC;
        if(!(type & 2)) ++cmd;
    } while(--len);
    if(&_EP != &PNONE) _EP |= _CE;
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::reset(void)
{
                                    // --- Set initial state of CLK, DC and CE as needed
                                    // * = output used for reset
    if(&_CP == &PNONE) {
        if(&_EP != &PNONE) {        // CLK*, DATA, CE
            _EP |= _CE;
        } // else                   // CLK*, DATA
    } else {
        if(&_EP != &PNONE) {        // CLK, DATA, DC*, CE
            if(&_SP == &_EP) {
                _SP |= (_CLK | _CE);
            } else {
                _SP |= _CLK;
                _EP |= _CE;
            }
        } // else                   // CLK, DATA, DC*
    }
                                    // --- Reset pulse on CLK or DC as needed
    if(&_CP == &PNONE) {            // No DC port, use CLK to reset
        _SP &= ~_CLK;
        __delay_cycles(_RST);
        _SP |= _CLK;
    } else {                        // Use DC to reset
        _CP &= ~_DC;
        __delay_cycles(_RST);
        _CP |= _DC;
    }
    __delay_cycles(_RST);
}
 
template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::init(void)
{
    static const unsigned char init[] = {
        0x20 | 0x01,        // Function set - extended instructions enabled
        //0x80 | 64,            // Set vop (contrast) 0 - 127
        0x80 | 70,          // Higher contrast improves animation
        0x04 | 2,           // Temperature control
        0x10 | 3,           // Set bias system
        0x20 | 0x00,        // Function set - chip active, horizontal addressing, basic instructions
        0x08 | 0x04         // Display control - normal mode
    };
    
    write(init, sizeof(init), lcd_command);
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::vert(void)
{
    static const unsigned char v[] = {
        0x20 | 0x02,        // Function set - chip active, vertical addressing, basic instructions
    };
    
    write(v, sizeof(v), lcd_command);
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::home(void)
{
    static const unsigned char home[] = { 0x40, 0x80 };
    write(home, sizeof(home), lcd_command);
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::pos(unsigned char x, unsigned char y)
{
    unsigned char c[2];
    c[0] = 0x80 | x;
    c[1] = 0x40 | y;
    write(c, sizeof(c), lcd_command);
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::clear(unsigned char x)
{
    home();
    write(&x, 504, lcd_data_repeat);
    home();
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::bitmap(const unsigned char *bmp, signed char x, signed char y, unsigned char w, unsigned char h)
{
    unsigned char c[2];
    unsigned char ww;
    if(x < 0) {
        ww = w + x;
        bmp -= x;
        x = 0;
    } else if(x + w >= 84) {
        ww = (84 - x);
    } else {
        ww = w;
    }
    c[0] = 0x80 | x;
    c[1] = 0x40 | y;
    while(h--) {
        write(c, sizeof(c), lcd_command);
        ++c[1];
        write(bmp, ww);
        bmp += w;
    }
}

static const unsigned char font[96][5] = {
    0x00, 0x00, 0x00, 0x00, 0x00, //
    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, 0x56, 0x20, 0x50, // &
    0x00, 0x08, 0x07, 0x03, 0x00, // '
    0x00, 0x1C, 0x22, 0x41, 0x00, // (
    0x00, 0x41, 0x22, 0x1C, 0x00, // )
    0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // *
    0x08, 0x08, 0x3E, 0x08, 0x08, // +
    0x00, 0x40, 0x38, 0x18, 0x00, // ,
    0x08, 0x08, 0x08, 0x08, 0x08, // -
    0x00, 0x00, 0x60, 0x60, 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, 0x49, 0x4D, 0x33, // 3
    0x18, 0x14, 0x12, 0x7F, 0x10, // 4
    0x27, 0x45, 0x45, 0x45, 0x39, // 5
    0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
    0x41, 0x21, 0x11, 0x09, 0x07, // 7
    0x36, 0x49, 0x49, 0x49, 0x36, // 8
    0x06, 0x49, 0x49, 0x29, 0x1E, // 9
    0x00, 0x00, 0x14, 0x00, 0x00, // :
    0x00, 0x00, 0x40, 0x34, 0x00, // ;
    0x00, 0x08, 0x14, 0x22, 0x41, // <
    0x14, 0x14, 0x14, 0x14, 0x14, // =
    0x00, 0x41, 0x22, 0x14, 0x08, // >
    0x02, 0x01, 0x51, 0x09, 0x06, // ?
    0x3E, 0x41, 0x5D, 0x59, 0x4E, // @
    0x7C, 0x12, 0x11, 0x12, 0x7C, // A
    0x7F, 0x49, 0x49, 0x49, 0x36, // B
    0x3E, 0x41, 0x41, 0x41, 0x22, // C
    0x7F, 0x41, 0x41, 0x41, 0x3E, // D
    0x7F, 0x49, 0x49, 0x49, 0x41, // E
    0x7F, 0x09, 0x09, 0x09, 0x01, // F
    0x3E, 0x41, 0x49, 0x49, 0x7A, // 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, 0x1C, 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
    0x26, 0x49, 0x49, 0x49, 0x32, // S
    0x01, 0x01, 0x7F, 0x01, 0x01, // T
    0x3F, 0x40, 0x40, 0x40, 0x3F, // U
    0x1F, 0x20, 0x40, 0x20, 0x1F, // V
    0x3F, 0x40, 0x38, 0x40, 0x3F, // W
    0x63, 0x14, 0x08, 0x14, 0x63, // X
    0x03, 0x04, 0x78, 0x04, 0x03, // Y
    0x61, 0x51, 0x49, 0x45, 0x43, // Z
    0x00, 0x7F, 0x41, 0x41, 0x41, // [
    0x02, 0x04, 0x08, 0x10, 0x20, // '\'
    0x00, 0x41, 0x41, 0x41, 0x7F, // ]
    0x04, 0x02, 0x01, 0x02, 0x04, // ^
    0x80, 0x80, 0x80, 0x80, 0x80, // _
    0x00, 0x03, 0x07, 0x08, 0x00, // '
    0x20, 0x54, 0x54, 0x54, 0x78, // a
    0x7F, 0x28, 0x44, 0x44, 0x38, // b
    0x38, 0x44, 0x44, 0x44, 0x28, // c
    0x38, 0x44, 0x44, 0x28, 0x7F, // d
    0x38, 0x54, 0x54, 0x54, 0x18, // e
    0x00, 0x08, 0x7E, 0x09, 0x02, // f
    0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g
    0x7F, 0x08, 0x04, 0x04, 0x78, // h
    0x00, 0x44, 0x7D, 0x40, 0x00, // i
    0x00, 0x20, 0x40, 0x40, 0x3D, // j
    0x00, 0x7F, 0x10, 0x28, 0x44, // k
    0x00, 0x41, 0x7F, 0x40, 0x00, // l
    0x7C, 0x04, 0x78, 0x04, 0x78, // m
    0x7C, 0x08, 0x04, 0x04, 0x78, // n
    0x38, 0x44, 0x44, 0x44, 0x38, // o
    0xFC, 0x18, 0x24, 0x24, 0x18, // p
    0x18, 0x24, 0x24, 0x18, 0xFC, // q
    0x7C, 0x08, 0x04, 0x04, 0x08, // r
    0x48, 0x54, 0x54, 0x54, 0x24, // s
    0x04, 0x04, 0x3F, 0x44, 0x24, // 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
    0x4C, 0x90, 0x90, 0x90, 0x7C, // y
    0x44, 0x64, 0x54, 0x4C, 0x44, // z
    0x00, 0x08, 0x36, 0x41, 0x00, // {
    0x00, 0x00, 0x77, 0x00, 0x00, // |
    0x00, 0x41, 0x36, 0x08, 0x00, // }
    0x02, 0x01, 0x02, 0x04, 0x02, // ~
    0x00, 0x06, 0x09, 0x09, 0x06, // degrees
};

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::print(char c)
{
    write(&font[c - 32][0], 5);
    write(&font[0][0], 1);
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::print(char *s)
{
    while(*s) {
        write(&font[*s - 32][0], 5);
        write(&font[0][0], 1);
        ++s;
    }
}

template <volatile unsigned char &_SP, unsigned char _CLK, unsigned char _DATA, volatile unsigned char &_CP, unsigned char _DC, volatile unsigned char &_EP, unsigned char _CE, unsigned _RST>
void Nokia5110<_SP, _CLK, _DATA, _CP, _DC, _EP, _CE, _RST>::printv(unsigned char x, unsigned char y, char *s)
{
    while(*s) {
        pos(x, y);
        ++y;
        write(&font[*s - 32][0], 5);
        write(&font[0][0], 1);
        ++s;
    }
}

} // namespace

Test code

#include "msp430g2553.h"

#include "nokia5110tl.h"

using namespace nokia5110;

static const unsigned char ti[] = {
    48, 48 / 8,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
    0xFC,0xFC,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0xF0,
    0xF0,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    0xFF,0xFF,0xFF,0xFF,0xFC,0xFC,0x3C,0x80,0xFC,0xFD,
    0xFD,0xFD,0x3D,0x81,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
    0xFC,0xFC,0xFC,0xFC,0x00,0x00,0x00,0x00,
    
    0x00,0x1C,0x7C,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
    0xFC,0xFC,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    0xFF,0xFF,0xF7,0xF0,0xF0,0x00,0xF0,0xFF,0xFF,0xFF,
    0xFF,0x0F,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xFF,
    0xFF,0xFF,0xFF,0xFF,0xF8,0xF0,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x3F,0x7F,0xFF,
    0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x3F,0x7F,0xFF,0xFF,
    0xFF,0xFF,0xFF,0x1F,0x00,0x1E,0x1F,0x1F,0x1F,0x1F,
    0x01,0x1E,0x1F,0xDF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    0xFF,0x7F,0x7F,0x3F,0x3F,0x3F,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
    0x0F,0x3F,0xFF,0xFE,0xFE,0xFE,0xFC,0xFC,0xFC,0xFC,
    0xFC,0xFC,0xFC,0x7F,0x1F,0x07,0x03,0x03,0x01,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x01,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,
    0x3F,0x3F,0x3F,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

static const unsigned char g0[] = {
    40, 40 / 8,
    0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0x20,
    0x20,0x40,0x80,0x80,0x00,0x00,0xE0,0x1E,0x02,0x02,
    0x0C,0x30,0xC0,0x80,0x40,0x20,0x20,0x10,0x08,0x08,
    0xD0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    
    0x00,0xC0,0x40,0x40,0x40,0x40,0x40,0x43,0x6C,0x10,
    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,
    0x11,0x10,0x10,0x08,0x08,0x08,0x88,0xB0,0x40,0x00,
    
    0x00,0x03,0x02,0x04,0x84,0x88,0x48,0x70,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x1E,0x12,0x21,0x21,0x20,0x40,0xC0,0x00,
    
    0x00,0x02,0x0D,0x11,0x10,0x10,0x10,0x08,0x08,0x88,
    0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,
    0x08,0x36,0xC2,0x02,0x02,0x02,0x02,0x02,0x03,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0B,
    0x10,0x10,0x08,0x04,0x04,0x02,0x01,0x03,0x0C,0x30,
    0xC0,0x40,0x78,0x07,0x00,0x00,0x01,0x01,0x02,0x04,
    0x04,0x08,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00
};

static const unsigned char g1[] = {
    40, 40 / 8,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
    0xC8,0x08,0x04,0x08,0x30,0x40,0x80,0x80,0xC0,0x38,
    0x06,0x02,0x02,0x1E,0xE0,0x00,0x00,0x80,0x80,0x40,
    0x40,0x20,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,
    
    0x00,0x00,0x30,0x4C,0x84,0x84,0x04,0x08,0x08,0x08,
    0x09,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,
    0x20,0x58,0x44,0x43,0x40,0x80,0x80,0x80,0x80,0x00,
    
    0x00,0xE0,0x20,0x10,0x10,0x10,0x09,0x0E,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x70,0x90,0x08,0x08,0x08,0x04,0x07,0x00,
    
    0x00,0x01,0x01,0x01,0x01,0x02,0xC2,0x22,0x1A,0x04,
    0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x90,
    0x10,0x10,0x10,0x20,0x21,0x21,0x32,0x0C,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x04,0x02,
    0x02,0x01,0x01,0x00,0x00,0x07,0x78,0x40,0x40,0x60,
    0x1C,0x03,0x01,0x01,0x02,0x0C,0x10,0x20,0x10,0x13,
    0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

static const unsigned char g2[] = {
    40, 40 / 8,
    0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0xFC,0x04,0x02,0x02,0x0C,0x30,0xC0,
    0x80,0x80,0x60,0x18,0x06,0x02,0xC4,0x3C,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x03,0x04,0x19,0xA1,0x42,0x02,
    0x04,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x02,0x04,0x04,
    0x02,0x82,0x42,0x21,0x11,0x0A,0x04,0x00,0x00,0x00,
    
    0x00,0x1C,0x14,0x22,0x22,0x22,0x41,0x41,0x80,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x01,0x82,0x82,0x44,0x44,0x44,0x28,0x38,0x00,
    
    0x00,0x00,0x00,0x20,0x50,0x88,0x84,0x42,0x41,0x40,
    0x20,0x20,0x40,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x20,
    0x40,0x42,0x85,0x98,0x20,0xC0,0x00,0x00,0x00,0x00,
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x3C,0x23,0x40,0x60,0x18,0x06,0x01,0x01,
    0x03,0x0C,0x30,0x40,0x40,0x20,0x3F,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00
};

static const unsigned RXD = BIT2;
static const unsigned SWITCH = BIT3;
static const unsigned LCD_DC = BIT0;
static const unsigned LCD_CE = BIT4;
static const unsigned LCD_CLK = BIT5;
static const unsigned LCD_BACKLIGHT = BIT6;
static const unsigned LCD_DATA = BIT7;

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;

    P1REN = RXD | SWITCH;
    P1DIR = LCD_DC | LCD_CE | LCD_CLK | LCD_BACKLIGHT | LCD_DATA;
    P1OUT = LCD_CLK | LCD_DC | RXD | SWITCH | LCD_CE | LCD_BACKLIGHT;

    Nokia5110<P1OUT, LCD_CLK, LCD_DATA, P1OUT, LCD_DC, P1OUT, LCD_CE, 10000> lcd;

    lcd.reset();
    lcd.init(); 
    lcd.clear();
    

    for(int x = -47; x < 14; ++x) {
        lcd.bitmap(ti, x, 0);
        __delay_cycles(20000);
    }

    lcd.printv(0, 0, "MSP430");
    lcd.printv(70, 0, "Nokia");
    lcd.printv(78, 2, "5110");
    __delay_cycles(2000000);
    
    lcd.clear();
    
    for(int x = 14; x < 84; ++x) {
        lcd.bitmap(ti, x, 0);
        __delay_cycles(20000);
    }
    
    lcd.home();
    char c;
    for(c = 33; c <= 116; ++c) {
        lcd.print(c);
    }
    __delay_cycles(2000000);

    lcd.clear();
    lcd.print(0, 5, "Template Class");
    for(;<img src='http://forum.43oh.com/public/style_emoticons/<#EMO_DIR#>/icon_e_wink.gif' class='bbc_emoticon' alt=';)' /> {
        for(signed char x = -39; x < 84; ) {
            lcd.bitmap(g0, x++, 0);
            __delay_cycles(100000);
            lcd.bitmap(g1, x++, 0);
            __delay_cycles(100000);
            lcd.bitmap(g2, x++, 0);
            __delay_cycles(100000);
        }
    }
        
    return 0;
}

http://www.youtube.com/watch?v=Y8YhD9NEvvQ
  • timotet, SugarAddict, Rickta59 and 7 others like this
Think in assembly, write in C. Sent from a bunker in an undisclosed location deep beneath a mountain.

#2 Rickta59

Rickta59

    Level 4

  • Global Moderators
  • 998 posts
  • LocationEastern NC


Posted 04 February 2012 - 11:29 PM

So does the Alan Parsons Project music indicate you have loftier goals than just a Nokia display?

-rick

#3 timotet

timotet

    Level 2

  • Members
  • 172 posts

Posted 05 February 2012 - 05:08 AM

thanks again for more awesome code!

#4 oPossum

oPossum

    Poke me with a Stick

  • Members
  • 904 posts
  • LocationMichigan, USA


Posted 05 February 2012 - 05:45 PM

If you want to psychoanalyze the music choice...

"I wouldn't want to be like you" suggests that I don't want to be a conformist who uses C with #if[def] and macros.

I will be using more templates, working on HD44780 character LCD controller right now.

I see a lot of potential in templates. It will take some time for me to really learn how to use them effectively.
Think in assembly, write in C. Sent from a bunker in an undisclosed location deep beneath a mountain.

#5 Rickta59

Rickta59

    Level 4

  • Global Moderators
  • 998 posts
  • LocationEastern NC


Posted 05 February 2012 - 06:41 PM

I was thinking more the song being from from the "I Robot" album. Mainly wondering if there was a template based
robot on the horizon : )

-rick

#6 oPossum

oPossum

    Poke me with a Stick

  • Members
  • 904 posts
  • LocationMichigan, USA


Posted 05 February 2012 - 06:44 PM

Not working on a Robot.

Keep waiting for tideals.com to have the evalbot for cheap. Missed out on the deals they had earlier.
Think in assembly, write in C. Sent from a bunker in an undisclosed location deep beneath a mountain.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users