//================文件tm1629.h================================
#ifndef _TM1629_H_
#define _TM1629_H_
//#include "tm1629.h"
/*
#define P_1668DAT LATA0 //数据输出端口
#define P_1668CLK LATA1
#define P_1668CS LATC0
*/
//数据命令设置
#define V_MDAT1 0x40 //写数据到显示区 自动地址增加
#define V_MDAT4 0x44 //写数据到显示区 固定地址
//地址命令设置
#define V_ADDR0 0xC0 //地址0
#define V_ADDR1 0xC1 //地址1
#define V_ADDR2 0xC2 //地址2
#define V_ADDR3 0xC3 //地址3
#define V_ADDR4 0xC4 //地址4
#define V_ADDR5 0xC5 //地址5
#define V_ADDR6 0xC6 //地址6
#define V_ADDR7 0xC7 //地址7
#define V_ADDR8 0xC8 //地址8
#define V_ADDR9 0xC9 //地址9
#define V_ADDR10 0xCA //地址10
#define V_ADDR11 0xCB //地址11
#define V_ADDR12 0xCC //地址12
#define V_ADDR13 0xCD //地址13
#define V_ADDR14 0xCE //地址14
#define V_ADDR15 0xCF //地址15
//显示控制 - 亮度调节
#define V_DIS16_01 0x80 //显示宽度1/16
#define V_DIS16_02 0x81 //显示宽度2/16
#define V_DIS16_03 0x82 //显示宽度4/16
#define V_DIS16_10 0x83 //显示宽度10/16
#define V_DIS16_11 0x84 //显示宽度11/16
#define V_DIS16_12 0x85 //显示宽度12/16
#define V_DIS16_13 0x86 //显示宽度13/16
#define V_DIS16_14 0x87 //显示宽度14/16
#define V_DIS16_OFF 0x00 //显示关
#define V_DIS16_ON 0x88 //显示开
//---------------------------------------------
// V_DIS16_01
#define V_LED_LIGHT1 (V_DIS16_02|V_DIS16_ON) //显示亮度设置
#define V_LED_LIGHT2 (V_DIS16_12|V_DIS16_ON) //显示亮度设置
//-------------------------------------------
extern void TM1629_WriteCommand(uint8 Comm);
extern void TM1629_WriteDat(uint8 *InDat,uint8 DspLight);
#endif
//================文件tm1629.c==============================
#include "global.h"
#include "tm1629.h"
#define TM1629_CS_HIGH P_1629CS = 1
#define TM1629_CS_LOW P_1629CS = 0
#define TM1629_DAT_HIGH P_1629DAT = 1
#define TM1629_DAT_LOW P_1629DAT = 0
#define TM1629_CLK_HIGH P_1629CLK = 1
#define TM1629_CLK_LOW P_1629CLK = 0
//----------------------------
#define V_NOP 1//3 5
//*************************************
// 函数名称:Nop1629
// 函数功能:延时函数
// 入口参数:延时时间
// 出口参数:无
//***************************************
void Nop1629(uint8 T_Dly)
{
while(T_Dly--);
return ;
}
//**************************************
// 函数名称:TM1629_WriteByteData
// 函数功能:TM1668发送一字节数据
// 入口参数:要发送的数据
// 出口参数:
//***************************************
void TM1629_WriteByteData(uint8 Data)
{
uint8 i;
Nop1629(V_NOP) ;
for(i=8;i>0;i--)
{
TM1629_CLK_LOW ;
if(Data & 0x01)
{
TM1629_DAT_HIGH ;
}
else
{
TM1629_DAT_LOW ;
}
Data >>= 1 ;
Nop1629(V_NOP) ;
TM1629_CLK_HIGH ;
Nop1629(V_NOP) ;
}
}
//**************************************
// 函数名称:TM1668_WriteCommand
// 函数功能:写设置命令
// 入口参数:设置命令参数
// 出口参数:无
//***************************************
void TM1629_WriteCommand(uint8 Comm)
{
TM1629_CS_LOW ;
Nop1629(V_NOP) ;
TM1629_WriteByteData(Comm);
TM1629_CS_HIGH ;
}
//**************************************
// 函数名称:TM1668_WriteAddrData
// 函数功能:向固定地址写一个数据
// 入口参数:地址 数据
// 出口参数:无
//***************************************
void TM1629_WriteAddrData(uint8 Addr,uint8 Data)
{
TM1629_CS_LOW ;
TM1629_WriteByteData(Addr); //写地址
TM1629_WriteByteData(Data); //写数据SS
TM1629_CS_HIGH ;
}
//**************************************
// 函数名称:TM1629_WriteDat
// 函数功能:TM1629 写缓冲区数据
// 入口参数:显示数据缓存区
// 出口参数:
// 备注:
//***************************************
void TM1629_WriteDat(uint8 *InDat,uint8 DspLight)
{
uint8 i ;
uint8 Addr ;
TM1629_WriteCommand(V_MDAT4) ; //写数据到1629 固定地址模式
TM1629_WriteCommand(DspLight) ; //V_LED_LIGHT1 显示对比度
//-----
Addr = V_ADDR0 ;//从第1个地址开始写
for(i=16;i>0;i--) //刷显数据 6
{
TM1629_WriteAddrData(Addr,*InDat) ;
Addr ++ ;
InDat ++ ;
}
//-----
}
原文地址:http://blog.csdn.net/libiaojs/article/details/39899549