VK1056驱动程序,在STM32F103下可以运行,51单片机可以自己小改,后面附上封装和数据手册
单片机源程序如下:
- #include "vk1056b.h"
- #include "delay.h"
-
- const u8 vk1056B_segtab[9]={14,15,16,17,18,19,20,21,22};
- u8 vk1056B_addrbit=6;//驱动ic的ram地址线数A5-A0,
- u8 vk1056B_segi,vk1056B_comi;
- u8 vk1056B_dispram[14];//显示RAM buffer只使用低4位,bit0->com0,bit1->com1,bit2->com2,bit3->com3
- u8 vk1056B_myram[4]={0x00,0x00,0x00,0x00};
- /**
- * @brief 配置Vk1056B通信线GPIO.
- * @param None
- * @retval None
- */
- void Vk1056B_Lowlevel_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_15;//通讯线电平不同,可设为开漏输出,1056B有内部上拉电?
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //通信线电平一样,可设为推挽输出?
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- void Vk1056B_Init(void)
- {
- Vk1056B_Lowlevel_Init();
- //基本配置
- WriteCommandVk1056B(OSC_OFF); //00
- WriteCommandVk1056B(OSC_ON); //01
- WriteCommandVk1056B(DISP_ON); //03
-
- WriteCommandVk1056B(0x04);
- WriteCommandVk1056B(0x05);
- WriteCommandVk1056B(0x08);
-
- WriteCommandVk1056B(RC32K); //18
- WriteCommandVk1056B(COM_1_3__4);//29
-
- WriteCommandVk1056B(0x80);
-
- // WriteCommandVk1056B(COM_1_3__3);vk1056B_maxcom=3; //1/3bias 3com
- // WriteCommandVk1056B(COM_1_3__2);vk1056B_maxcom=2; //1/3bias 2com
- // WriteCommandVk1056B(COM_1_2__4);vk1056B_maxcom=4; //1/2bias 4com
- // WriteCommandVk1056B(COM_1_2__3);vk1056B_maxcom=3; //1/2bias 3com
- // WriteCommandVk1056B(COM_1_2__2);vk1056B_maxcom=2; //1/2bias 2com
- //上电默认配置(以下未用功能关闭降低功耗)
- // WriteCommandVk1056B(TIMER_DIS);
- // WriteCommandVk1056B(WDT_DIS);
- // WriteCommandVk1056B(BUZZ_OFF);
- // WriteCommandVk1056B(IRQ_DIS);
- }
- /**
- * @brief Vk1056B clk
- * @param None
- * @retval None
- */
- void WriteClockVk1056B(void)
- {
- WR=0;
- delay_us(10);
- WR=1;
- delay_us(10);
- }
- /**
- * @brief Write Vk1056B Command
- * @param FunctonCode->功能/命令码
- * @retval None
- */
- void WriteCommandVk1056B(unsigned char FunctonCode) //写命令
- {
- u8 Shift = 0x80;
- u8 i;
-
- CS=0;
- delay_us(5);
-
- DATA=1;
- WriteClockVk1056B();
- DATA=0;
- WriteClockVk1056B();
- DATA=0;
- WriteClockVk1056B();
- for(i = 0; i < 8; i++)
- {
- if(Shift & FunctonCode) //与1000 0000
- DATA=1;
- else
- DATA=0;
- WriteClockVk1056B();
- Shift = Shift >> 1;
- }
- DATA=0;
- WriteClockVk1056B(); //发送一个 0 16xx中最后一位 X
- CS=1;
- delay_us(5);
- DATA=1;
- }
- /**
- * @brief Write 1 data to Vk1056B
- * @param Addr->写入ram的地址
- * @param Databuf->写入ram的数据
- * @retval None
- */
- void Write1DataVk1056B(unsigned char Addr,unsigned char Dat)
- {
- unsigned char i; //写数据
- unsigned char Shift;
-
- Shift = 0x20; //屏蔽高3位 只用5位 0010 0000
-
- CS=0;
- delay_us(5);
- DATA=1;
- WriteClockVk1056B(); //101
- DATA=0;
- WriteClockVk1056B();
- DATA=1;
- WriteClockVk1056B();
- for( i = 0; i < vk1056B_addrbit; i++) //6
- {
- if (Addr & Shift) //与0010 0000
- DATA=1;
- else
- DATA=0;
- WriteClockVk1056B();
- Shift = Shift >> 1;
- }
- Shift = 0x01;
- for (i = 0; i < 4; i++) //与0000 0001
- {
- if( Dat & Shift)
- DATA=1;
- else
- DATA=0;
- WriteClockVk1056B();
- Shift = Shift << 1;
- }
- CS=1;
- delay_us(5);
- DATA=1;
- }
- /**
- * @brief Write n data to Vk1056B
- * @param Addr->写入ram的起始地址
- * @param Databuf->写入ram的数据buffer
- * @param Cnt->写入ram的数据个数
- * @retval None 连续写模式
- */
- void WritenDataVk1056B(unsigned char Addr,unsigned char *Databuf,unsigned char Cnt)
- {
- unsigned char i,j;
- unsigned char Shift;
- unsigned char dataval;
-
- CS=0;
- delay_us(5);
- DATA=1;
- WriteClockVk1056B(); //101
- DATA=0;
- WriteClockVk1056B();
- DATA=1;
- WriteClockVk1056B();
- Shift = 0x20; //0010 0000
- for( i = 0; i < 6; i++)
- {
- if (Addr & Shift)
- DATA=1;
- else
- DATA=0;
- WriteClockVk1056B();
- Shift = Shift >> 1;
- }
- for (j = 0; j < Cnt; j++)
- {
- Shift = 0x01;
- dataval=*Databuf++;
- for (i = 0; i < 4; i++)
- {
- if( dataval & Shift)
- DATA=1;
- else
- DATA=0;
- WriteClockVk1056B();
- Shift = Shift << 1;
- }
- }
- CS=1;
- delay_us(5);
- DATA=1;
- }
- /**
- * @brief lcd全显或全灭
- * @param state=1->lcd全亮
- * @param state=0->lcd全灭
- * @retval None
- */
- void Vk1056B_DisAll(unsigned char state)
- {
- unsigned char i;
-
- for(i=0;i<14;i++)
- {
- if(state==1)
- {
- vk1056B_dispram[i]=0x0f;
- }
- else
- {
- vk1056B_dispram[i]=0x00;
- }
- }
- WritenDataVk1056B(vk1056B_segtab[0],vk1056B_dispram,14);
- }
- //以下是根据段码屏厂家给出的表格做的,不同厂家资料程序不同,此处可以跳过不看了
- //A显示
- void Vk1056B_Display_A(u8 i)
- {
- switch(i)
- {
- case 0:
- Vk1056B_On(0,1);
- Vk1056B_On(0,2);
- Vk1056B_On(0,4);
- Vk1056B_On(0,8);
- Vk1056B_On(1,2);
- Vk1056B_OFF(1,4);
- Vk1056B_On(1,8);
- break;
- case 1:
- Vk1056B_OFF(0,1);
- Vk1056B_OFF(0,2);
- Vk1056B_OFF(0,4);
- Vk1056B_OFF(0,8);
-
- Vk1056B_On(1,2);
- Vk1056B_OFF(1,4);
- Vk1056B_On(1,8);
- break;
- case 2:
- Vk1056B_On(0,1);
- Vk1056B_On(0,2);
- Vk1056B_OFF(0,4);
- Vk1056B_On(0,8);
-
- Vk1056B_OFF(1,2);
- Vk1056B_On(1,4);
- Vk1056B_On(1,8);
- break;
- case 3:
- Vk1056B_On(0,1);
- Vk1056B_OFF(0,2);
- Vk1056B_OFF(0,4);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
VK1056驱动.zip
(3.66 KB, 下载次数: 48)
VK1056技术手册.zip
(1.88 MB, 下载次数: 35)
|