2017/07/03

Dependents:   mbed_vfd_ntp

kt_vfd.cpp

Committer:
kojie
Date:
2017-07-11
Revision:
1:e1e942d03093
Parent:
0:94347d9bbcf4

File content as of revision 1:e1e942d03093:

/**
 * @bref VFD class imprementation
 * for GU256X128C-3900
 */
#include "mbed.h"
#include "kt_vfd.h"

KT_VFD::KT_VFD(PinName rd, PinName wr,
               PinName d0, PinName d1, PinName d2, PinName d3,
               PinName d4, PinName d5, PinName d6, PinName d7) :
    _rd(rd), _wr(wr),
    _d(d0, d1, d2, d3, d4, d5, d6, d7)
{
    _rd = 1 ;
    _wr = 1 ;

    wait_ms(100) ;
    write_byte(0x1b) ;
    write_byte(0x40) ;
    wait_ms(100) ;
}

void KT_VFD::write_mode(unsigned char mode)
{
    write_byte(0x1f) ;
    write_byte(0x28) ;
    write_byte(0x77) ;
    write_byte(0x10) ;
    write_byte(mode) ;
}

void KT_VFD::disp_mode(unsigned char mode)
{
    write_byte(0x1f) ;
    write_byte(mode) ;
}

void KT_VFD::scroll_speed(unsigned char n)
{
    write_byte(0x1f) ;
    write_byte(0x73) ;
    write_byte(n) ; // 0x00 - 0x1f: 
}

void KT_VFD::scroll_act(unsigned int w, unsigned int c, unsigned char s)
{
    write_byte(0x1f) ;
    write_byte(0x28) ;
    write_byte(0x61) ;
    write_byte(0x10) ;
    write_byte(w%0x100) ;
    write_byte(w/0x100) ;
    write_byte(c%0x100) ;
    write_byte(c/0x100) ;
    write_byte(s) ;
}

void KT_VFD::cls()
{
    write_byte(0x0C) ;
    locate(0, 0) ;
}

void KT_VFD::locate(unsigned int x, unsigned int y)
{
    write_byte(0x1f) ;
    write_byte(0x24) ;
    write_byte(x % 0x100) ; // xL
    write_byte(x / 0x100) ; // xH
    write_byte(y % 0x100) ; // yL
    write_byte(y / 0x100) ; // yH
}

void KT_VFD::lf()
{
    write_byte(0x0a) ;
}

void KT_VFD::cr()
{
    write_byte(0x0d) ;
}

void KT_VFD::font_size(unsigned char m)
{
    write_byte(0x1f) ;
    write_byte(0x28) ;
    write_byte(0x67) ;
    write_byte(0x01) ;
    write_byte(m) ;
}

void KT_VFD::char_ext(unsigned char x, unsigned char y)
{
    write_byte(0x1f) ;
    write_byte(0x28) ;
    write_byte(0x67) ;
    write_byte(0x40) ;
    write_byte(x) ;
    write_byte(y) ;
}

int KT_VFD::_putc(int c)
{
    if (c == '\n') {
        cr() ;
        lf() ;
    } else {
        write_byte(c) ;
    }
    return 0 ;
}

int KT_VFD::_getc()
{
    return -1 ;
}

void KT_VFD::write_byte(unsigned char value)
{
#if 0
    bool ok ;
    _d[7] = 0 ;
    do {
        _rd = 0 ;
        wait_us(0.08) ;
        ok = _d[7] ;
        _rd = 1 ;
    } while (ok) ;
    _d[7] = 1 ;
#else
    while (!_rd) ;
#endif

    _d = value ;
    _wr = 0 ;
    wait_us(0.11) ;
    _wr = 1 ;
//    wait_us(1.6) ;
    wait_us(16) ;
}