Futaba M11BT222A VFD(主控PT6311)STC51单片机驱动程序

/*
Futaba M11BT222A VFD 显示屏驱动程序


    Coder   : Farman
    Version : 2018-01-07


该显示屏采用PT6311芯片驱动,但板子端口和PT6311之间的信号经过了
其他芯片的转换,SCLK和STB信号被翻转。在程序中要相应的进行变换。


Pin :  
    1 - VCC +5V
    2 - GND
    3 - No Connection
    4 - Booster  1:On 0:OFF
    5 - SDA
    6 - GND
    7 - SCLK
    8 - STB
*/




#include 
#include "Delay.h"


sbit M11BT222A_SDA     = P0^7; // SPI 数据线
sbit M11BT222A_SCLK    = P0^6; // SPI 串行时钟
sbit M11BT222A_STB     = P0^5; // 片选信号,0-不选 1-选中。
sbit M11BT222A_BOOSTER = P0^4; // 板上电压发生器控制,1-ON 0-OFF


// Futaba M11BT222A 接口信号与 M11BT222A 之间经过了器件转换,SCLK 和 STB 信号电平翻转
#define M11BT222A_SDA_HIGH  1
#define M11BT222A_SCLK_HIGH 0
#define M11BT222A_STB_HIGH  0


//--------------------------------------------------------




void M11BT222A_delay()
{
    _nop_();
}




//----------------------------------------------------------




void M11BT222A_enable()
{
    M11BT222A_STB  = !M11BT222A_STB_HIGH; 
    M11BT222A_delay();
}


void M11BT222A_disable()
{
    M11BT222A_STB = M11BT222A_STB_HIGH;
    M11BT222A_delay();
}


void M11BT222A_write_byte(unsigned char byte_to_write)
{
    unsigned char mask = 0x01;
    unsigned char n;


    for(n=0; n<8; n++)
    {
        M11BT222A_SCLK =!M11BT222A_SCLK_HIGH;
        M11BT222A_delay();

        M11BT222A_SDA = (mask & byte_to_write) ? 1 : 0; M11BT222A_delay();
    
        M11BT222A_SCLK = M11BT222A_SCLK_HIGH; 
        M11BT222A_delay();


        mask += mask;
    }


    return;
}




void M11BT222A_write_command_byte(unsigned char command_byte)
{
    M11BT222A_enable();
    M11BT222A_write_byte(command_byte);
    M11BT222A_disable();
}




//----------------------------------------------------------




// digits_could_display : 8 - 16
// 命令前必须有一次 STB 有效,
// 命令后必须有一次 STB 释放。
void M11BT222A_command1(unsigned char digits_could_display)
{
    M11BT222A_write_command_byte(digits_could_display - 1);
}


// 命令前必须有一次 STB 有效,
// 命令后必须有一次 STB 释放。
void M11BT222A_command2(bit enable_inc_addr_after_write)
{
    unsigned char command = 0x40;


    command += enable_inc_addr_after_write ? 0x00 : 0x04;
    M11BT222A_write_command_byte(command);  
}




// addr : 0x00 - 0x2F
// 该命令后面要紧跟写入显示RAM的数据,且该命令与数据之间不允许有 STB 释放操作
// 数据与数据之间也不允许有 STB 释放。
// 
// 所以,在该命令前要 调用一次 M11BT222A_enable()
// 所有的显示RAM传输结束后,调用一次 M11BT222A_disable().
void M11BT222A_command3(unsigned char RAM_addr_to_write)
{
    M11BT222A_write_byte(0xC0 + RAM_addr_to_write);
}


// 命令前必须有一次 STB 有效,
// 命令后必须有一次 STB 释放。
void M11BT222A_command4(bit enable_display)
{
    M11BT222A_write_command_byte(enable_display ? 0x8F : 0x87);
}




//----------------------------------------------------------




void M11BT222A_write_display_RAM(unsigned char addr, unsigned char display_data_byte)
{
    M11BT222A_enable();
    M11BT222A_command3(addr);
    M11BT222A_write_byte(display_data_byte);
    M11BT222A_disable();
}


void M11BT222A_fill_display(unsigned char pattern)
{
    unsigned char m;


    M11BT222A_command2(1);


    M11BT222A_enable();
    M11BT222A_command3(0);


    for(m=0x00; m<0x30; m++)
    {
        M11BT222A_write_byte(pattern);
    }


    M11BT222A_disable();
}




//----------------------------------------------------------


code unsigned char M11BT222A_16seg_digit[] = 
{
    0x46, 0x31, // '0'
    0x10, 0x84, // '1'
    0x45, 0xD1, // '2'
    0x43, 0xD1, // '3'
    0x03, 0xF0, // '4'
    0x43, 0xE1, // '5'
    0x47, 0xE1, // '6'
    0x10, 0x89, //0x02, 0x11, // '7'
    0x47, 0xF1, // '8'
    0x43, 0xF1  // '9'
};


void M11BT222A_show_16seg_digit(unsigned char pos, unsigned char digit)
{
    M11BT222A_write_display_RAM(pos*3+1,   M11BT222A_16seg_digit[digit*2]);
    M11BT222A_write_display_RAM(pos*3, M11BT222A_16seg_digit[digit*2 + 1]);
}




code unsigned char M11BT222A_8seg_digit[] = 
{
    0x77, 0x12, 0x6B, 0x5B, 0x1E, 0x5D, 0x7D, 0x13, 0x7F, 0x5F
};


code unsigned char M11BT222A_8seg_pos[] = 
{
    0x00, 0x06, 0x07, 0x03, 0x04, 0x01
};


void M11BT222A_show_8seg_digit(unsigned char pos, unsigned char digit)
{
    M11BT222A_write_display_RAM(15 + M11BT222A_8seg_pos[pos], M11BT222A_8seg_digit[digit]);
    //M11BT222A_write_display_RAM(15 + pos, M11BT222A_8seg_digit[digit]);
}


void M11BT222A_show_disk(unsigned char pattern)
{
    M11BT222A_write_display_RAM(24, pattern);
}




void M11BT222A_show_network(unsigned int pattern)
{
    M11BT222A_write_display_RAM(30, pattern/256);
    M11BT222A_write_display_RAM(31, pattern);
}




void M11BT222A_show_usb(unsigned int pattern)
{
    M11BT222A_write_display_RAM(27, pattern/256);
    M11BT222A_write_display_RAM(28, pattern);
}


//----------------------------------------------------------


void M11BT222A_booster_enable()
{
    M11BT222A_BOOSTER = 1;
}


void M11BT222A_booster_disable()
{
    M11BT222A_BOOSTER = 0;
}




//----------------------------------------------------------


void M11BT222A_init()
{
    M11BT222A_disable();
    M11BT222A_SCLK = 0;
    M11BT222A_SDA  = 1;


    M11BT222A_booster_enable();


    Delay200ms();


    M11BT222A_command2(1);
    M11BT222A_fill_display(0xFF);
    M11BT222A_command1(11);
    M11BT222A_command4(1);
}




//----------------------------------------------------------




void M11BT222A_main()  
{
    unsigned char m, n, seg;


    M11BT222A_init();
    M11BT222A_fill_display(0xFF); Delay200ms();
    M11BT222A_fill_display(0x00); Delay200ms();
    M11BT222A_fill_display(0xFF); Delay200ms();
    M11BT222A_fill_display(0x00); Delay200ms();
    M11BT222A_fill_display(0xFF); Delay200ms();
    M11BT222A_fill_display(0x00); Delay200ms();


    while(1)
    {
        seg = 0x01;


        M11BT222A_show_usb(0x5555);
        continue;


        M11BT222A_show_network(0x5555); Delay1s();
        M11BT222A_show_network(0xAAAA); Delay1s();


        M11BT222A_show_disk(0x55);  


        for(m=0; m<10; m++)
        {
            M11BT222A_show_8seg_digit(0, 0);
            M11BT222A_show_8seg_digit(1, 1);
            M11BT222A_show_8seg_digit(2, 2);
            M11BT222A_show_8seg_digit(3, 3);
            M11BT222A_show_8seg_digit(4, 4);
            M11BT222A_show_8seg_digit(5, 9);


            Delay1s();
        }


        for(m=0; m<10; m++)
        {
            M11BT222A_show_16seg_digit(0, m);
            M11BT222A_show_16seg_digit(1, m);
            M11BT222A_show_16seg_digit(2, m);
            M11BT222A_show_16seg_digit(3, m);
            M11BT222A_show_16seg_digit(4, m);
            Delay1s();
        }
    }
}

 

你可能感兴趣的:(硬件,显示,硬件)