51驱动VFD问题,说是用SPI,能解释一下不。
http://beee.zxq.net/DIY/img/IMGP8331.jpg这是附的程序,32M晶振,STC12C5A60S2
能给解释一下不
#include <reg51.h>//这里应该是引用STC的头文件吧。
#include "ascii16.h"
#include "logo.h"
sbit led=P3^0;
sbit lat=P1^0;
sbit bk=P1^1;
sbit clkg=P1^2;
sbit sig=P1^3;
//绿色这几句是不可以接其它的IO口。
//sbit as=P1^4;//<-----SPI接口是这两条吗?SS接口
//sbit cka=P1^5;//<---SPI接口是这两条吗?MOSI接口
unsigned char gird = 43;
#define LAT_LOW() lat=0
#define LAT_HIGH() lat=1
#define BK_LOW() bk=0 //PA6 (MISO None used)
#define BK_HIGH() bk=1
#define CLKG_LOW() clkg=0
#define CLKG_HIGH() clkg=1
#define SIG_LOW() sig=0
#define SIG_HIGH() sig=1
//#define A_LOW() as=0
//#define A_HIGH() as=1
//#define CK_LOW() cka=0
//#define CK_HIGH() cka=1
xdata unsigned char a_buf; //定义屏幕寄存器区,为128行,8页
void delay(unsigned int i)
{
for (i;i>0;i--);
}
void SPI2_SendByte_soft(unsigned char byte)//栅级前几列
{
unsigned char i = 0;
for(i = 0;i < 5;i++)
{
CLKG_LOW();
if((byte & 0x01) == 0x00)
{
SIG_LOW();
}
else
{
SIG_HIGH();
}
byte >>= 1;
CLKG_HIGH();
}
}
void SPI1_SendByte(unsigned char i ) //spi发送数据
{
SPSTAT = 0xf0;
//delay(2);
SPDAT=i;//这句是不将数据写到MOSI上,
delay(1);
}
//--------------------------------------------------------------------------------------
//VFD扫描程序,程序工作时必须保证此扫描连续进行,可以放到主程序或者通过定时器周期执行
//不能长时间停滞否则有烧伤荧光粉危险
//屏幕扫描时寄存器a_buf寄存器竖着排列,每个缓存寄存器对应屏幕上8八个点,主程序只要更改缓存寄存器内容,图像即可刷新
void Scan_VFD(void) //vfd扫描
{
// static unsigned char gird = 43; //栅极列数
unsigned char gird_tmp = 0;
unsigned char tmp = 0;
unsigned char i = 0;
unsigned char base_a = 0;
if(gird >= 43)
{
gird = 0;
SPI2_SendByte_soft(0x03);
}
CLKG_LOW();
CLKG_HIGH();
gird_tmp = 42 - gird;
base_a = (gird_tmp >> 1) * 6;
if((gird_tmp & 0x01) == 0x01) //双数列
{
for(i = 0;i < 8;i++)
{
tmp=((a_buf<<1)&0x02);
tmp|=((a_buf<<3)&0x08);
tmp|=((a_buf<<5)&0x20);
tmp|=((a_buf<<6)&0x80);
SPI1_SendByte(tmp);
tmp= a_buf & 0x02;
tmp|=(((a_buf)<<2)&0x08);
tmp|=(((a_buf)<<3)&0x20);
tmp|=(((a_buf)<<5)&0x80);
SPI1_SendByte(tmp);
tmp=(((a_buf)>>1)&0x02);
tmp |= a_buf & 0x08;
tmp|=(((a_buf)<<2)&0x20);
tmp|=(((a_buf)<<4)&0x80);
SPI1_SendByte(tmp);
tmp=(((a_buf)>>3)&0x02);
tmp|=(((a_buf)>>1)&0x08);
tmp|=(((a_buf)<<1)&0x20);
tmp|=(((a_buf)<<2)&0x80);
SPI1_SendByte(tmp);
tmp=(((a_buf)>>4)&0x02);
tmp|=(((a_buf)>>2)&0x08);
tmp|=(((a_buf)>>1)&0x20);
tmp|=(((a_buf)<<1)&0x80);
SPI1_SendByte(tmp);
tmp=(((a_buf)>>5)&0x02);
tmp|=(((a_buf)>>4)&0x08);
tmp|=(((a_buf)>>2)&0x20);
tmp |= a_buf & 0x80;
SPI1_SendByte(tmp);
}
}
else //单数列
{
for(i = 0;i < 8;i++)
{
//if(i==0)
// {
//
// BK_HIGH();
// }
tmp= a_buf & 0x01;
tmp|=(a_buf<<2&0x04);
tmp|=(a_buf<<4&0x10);
tmp|=(a_buf<<5&0x40);
SPI1_SendByte(tmp);
tmp=(a_buf>>1&0x01);
tmp|=(a_buf<<1&0x04);
tmp|=(a_buf<<2&0x10);
tmp|=(a_buf<<4&0x40);
SPI1_SendByte(tmp);
tmp=(a_buf>>2&0x01);
tmp|=(a_buf>>1&0x04);
tmp|=(a_buf<<1&0x10);
tmp|=(a_buf<<3&0x40);
SPI1_SendByte(tmp);
tmp=(a_buf>>4&0x01);
tmp|=(a_buf>>2&0x04);
tmp |= a_buf & 0x10;
tmp|=(a_buf<<1&0x40);
SPI1_SendByte(tmp);
tmp=(a_buf>>5&0x01);
tmp|=(a_buf>>3&0x04);
tmp|=(a_buf>>2&0x10);
tmp |= a_buf & 0x40;
SPI1_SendByte(tmp);
tmp=(a_buf>>6&0x01);
tmp|=(a_buf>>5&0x04);
tmp|=(a_buf>>3&0x10);
tmp|=(a_buf>>1&0x40);
SPI1_SendByte(tmp);
}
}
BK_HIGH();
LAT_HIGH();
LAT_LOW();
BK_LOW();
gird++;
}
void vfd_putc_asc16(unsigned char x,unsigned char y,unsigned char ch) //显示asc字符
{
const unsigned char *pt1,*pt2;
unsigned char i = 0;
if((ch < 128) && (ch > 31) && (x < 16) && (y < 4))
{
pt1 = &ascii16x16 + ((ch - 32) * 16);
pt2 = pt1 + 8;
for(i = 0;i < 8;i++)
{
a_buf = *pt1;
pt1++;
a_buf = *pt2;
pt2++;
}
}
}
void vfd_puts_asc16(unsigned char x,unsigned char y,unsigned char *str) //显示asc字符串
{
while(*str != 0x00)
{
vfd_putc_asc16(x,y,*str);
str++;
x++;
}
}
void disp_image_64(unsigned char pos,const unsigned char *dat) //现实64*64图片
{
unsigned char i = 0;
unsigned char j = 0;
for(i = 0;i < 8;i++)
{
for(j = 0;j < 64;j++)
{
a_buf = *dat;
dat++;
}
}
}
spi_init() //spi初始化
{
SPCTL=0x78; //79
SPSTAT = 0xff;
}
void main()
{
spi_init(); //spi初始化
disp_image_64(1, &aa); //显示图片1
disp_image_64(0, &aas); //显示图片2
while(1)
{
Scan_VFD(); //扫描
}
}
一直不理解是怎么驱动的。不停的扫描吗,跟点阵是不是一个原理。 差不多 ,一直扫 我关心在那里买的VFD 只要有VFD的资料
就很容易驱动了
页:
[1]