HT1622驱动
本帖最后由 shuxmpx123 于 2012-8-9 17:33 编辑在网上找了个HT1622的,发现用不了,自己花了2天写了个出来:#ifndef _HT1622_H_
#define _HT1622_H_
#define HT1622_CS_DDR DDRA
#define HT1622_RD_DDR DDRA
#define HT1622_WR_DDR DDRA
#define HT1622_DATA_DDR DDRA
#define HT1622_CS_PORT PORTA
#define HT1622_RD_PORT PORTA
#define HT1622_WR_PORT PORTA
#define HT1622_DATA_PORT PORTA
#define HT1622_CS_PIN 0x08
#define HT1622_RD_PIN 0x10
#define HT1622_WR_PIN 0x20
#define HT1622_DATA_PIN 0x40
#define HT1622_CS_OUT_HIGH() (HT1622_CS_PORT |= HT1622_CS_PIN)
#define HT1622_CS_OUT_LOW() (HT1622_CS_PORT &= ~HT1622_CS_PIN)
#define HT1622_RD_OUT_HIGH() (HT1622_RD_PORT |= HT1622_RD_PIN)
#define HT1622_RD_OUT_LOW() (HT1622_RD_PORT &= ~HT1622_RD_PIN)
#define HT1622_WR_OUT_HIGH() (HT1622_WR_PORT |= HT1622_WR_PIN)
#define HT1622_WR_OUT_LOW() (HT1622_WR_PORT &= ~HT1622_WR_PIN)
#define HT1622_DATA_OUT_HIGH() (HT1622_DATA_PORT |= HT1622_DATA_PIN)
#define HT1622_DATA_OUT_LOW() (HT1622_DATA_PORT &= ~HT1622_DATA_PIN)
#define HT_SYS_DIS 0x00
#define HT_SYS_EN 0x01
#define HT_LCD_OFF 0x02
#define HT_LCD_ON 0x03
void Ht1622_Port_Init(void);
void Lcd_Init(void);
void Lcd_Disp(void);
void Lcd_Clear(uint8_t dat);
void Lcd_Wrcmd(uint8_t cmmd);
void Lcd_Write_Ndata(uint8_t addr,uint8_t *buff,uint8_t num);
#endif
#ifndef _MAIN_H_
#define _MAIN_H_
#define LCD_BUFF_SIZE 64
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef struct{
uint8_t lcd_buff;
}SYS;
extern SYS sys;
#include <avr/io.h>
#include "main.h"
#include "Ht1622.h"
void Ht1622_Port_Init(void)
{
HT1622_CS_DDR |= HT1622_CS_PIN;
HT1622_RD_DDR |= HT1622_RD_PIN;
HT1622_WR_DDR |= HT1622_WR_PIN;
HT1622_DATA_DDR |= HT1622_DATA_PIN;
HT1622_CS_OUT_HIGH();
HT1622_RD_OUT_HIGH();
HT1622_WR_OUT_HIGH();
HT1622_DATA_OUT_HIGH();
}
void Lcd_Wrcmd(uint8_t cmmd)
{
uint8_t i;
HT1622_DATA_OUT_HIGH();
HT1622_WR_OUT_LOW();
HT1622_CS_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
for (i = 0; i < 8; i++)
{
if (cmmd&0x80)
{
HT1622_DATA_OUT_HIGH();
}
else
{
HT1622_DATA_OUT_LOW();
}
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH();
asm("nop"); asm("nop"); asm("nop");
cmmd <<= 1;
HT1622_WR_OUT_LOW();
}
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); //无关位
asm("nop"); asm("nop"); asm("nop");
HT1622_CS_OUT_HIGH();
}
void Lcd_Write_Ndata(uint8_t addr,uint8_t *buff,uint8_t num)
{
uint8_t i;
uint8_t j;
uint8_t dat;
HT1622_DATA_OUT_HIGH();
HT1622_WR_OUT_LOW();
HT1622_CS_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_HIGH();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
for (i = 0; i < 6; i++) //send addr
{
if ((addr&0x20) == 0)
{
HT1622_DATA_OUT_LOW();
}
else
{
HT1622_DATA_OUT_HIGH();
}
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH();
addr <<= 1;
}
for (i = 0; i < num; i++)
{
dat = buff;
for (j = 0; j < 4; j++) //data
{
HT1622_WR_OUT_LOW();
if (dat&0x01)
{
HT1622_DATA_OUT_HIGH();
}
else
{
HT1622_DATA_OUT_LOW();
}
dat >>= 1;
//asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH();
}
}
HT1622_CS_OUT_HIGH();
}
void Lcd_Init(void)
{
Lcd_Wrcmd(HT_SYS_EN);
Lcd_Wrcmd(HT_LCD_ON);
}
void Lcd_Clear(uint8_t dat)
{
uint8_t i;
for (i = 0; i < LCD_BUFF_SIZE; i++)
{
sys.lcd_buff = dat;
}
}
#include <avr/io.h>
#include <avr/interrupt.h>s
#include "main.h"
#include "Ht1622.h"
SYS sys;
int main(void)
{
int a;
int b;
a = 1;
b = 2;
//init_devices();
Ht1622_Port_Init();
Lcd_Wrcmd(HT_SYS_EN);
Lcd_Wrcmd(HT_LCD_ON);
Lcd_Clear(0xFF);
Lcd_Write_Ndata(0,sys.lcd_buff,64);
//sei();//asm("sei"); on interrupt
cli();//asm("cli"); off interrupt
//asm("sei");
while(1)
{
a++;
if (a > 40) // 200HZ -- 200
{
a = 0;
//Lcd_Write_Ndata(0,sys.lcd_buff,64);
//Lcd_Wrcmd(0x03);
}
}
} {:lol:}最近也在写这个驱动代码。 还没开始,先参考学习下。 有个函数写错了地址没有发出去更正一下:void Lcd_Write_Ndata(uint8_t addr,uint8_t *buff,uint8_t num)
{
uint8_t i;
uint8_t j;
uint8_t dat;
uint8_t address;
address = addr;
HT1622_DATA_OUT_HIGH();
HT1622_WR_OUT_LOW();
HT1622_CS_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_HIGH();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
//asm("nop"); asm("nop"); asm("nop");
//HT1622_WR_OUT_LOW();
for (i = 0; i < 6; i++) //send addr
{
HT1622_WR_OUT_LOW();
if ((address&0x20) == 0)
{
HT1622_DATA_OUT_LOW();
}
else
{
HT1622_DATA_OUT_HIGH();
}
address <<= 1;
//asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH();
}
for (i = addr; i < (num + addr); i++)
{
dat = buff;
for (j = 0; j < 4; j++) //data
{
HT1622_WR_OUT_LOW();
if (dat&0x01)
{
HT1622_DATA_OUT_HIGH();
}
else
{
HT1622_DATA_OUT_LOW();
}
dat >>= 1;
//asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH();
}
}
HT1622_CS_OUT_HIGH();
} 牛牛牛顶顶顶 {:smile:}你好,最近我在做ht1622驱动断码LCD,试过你写的驱动,但是SEG脚的电平没有变化,不知道是什么原因,请大侠指教,谢谢! sbgavin 发表于 2013-7-11 10:26 static/image/common/back.gif
你好,最近我在做ht1622驱动断码LCD,试过你写的驱动,但是SEG脚的电平没有变化,不知道是什么原 ...
#define HT1622_CS_DDR DDRA
#define HT1622_RD_DDR DDRA
#define HT1622_WR_DDR DDRA
#define HT1622_DATA_DDR DDRA
这几个引脚设置对吗,有波形没有,你的硬件有没有问题,是用STM8? 时钟是多少? shuxmpx123 发表于 2013-7-11 15:51 static/image/common/back.gif
#define HT1622_CS_DDR DDRA
#define HT1622_RD_DDR DDRA
#define HT16 ...
你好,我用的是LPC1114,电路如图,我不能确定没有错误,请指正,谢谢! uint8_t i;
HT1622_DATA_OUT_HIGH();
HT1622_WR_OUT_LOW();
HT1622_CS_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 1
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
HT1622_DATA_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_HIGH(); // 0
asm("nop"); asm("nop"); asm("nop");
HT1622_WR_OUT_LOW();
我的时钟也12M
这里的延时asm("nop"); asm("nop"); asm("nop"); 是需要的,代码就这些,没有什么要注意的了,你用示波器看波形吧! shuxmpx123 发表于 2013-7-13 16:52 static/image/common/back.gif
uint8_t i;
HT1622_DATA_OUT_HIGH();
你好,不显示的问题找到了,是因为我的rd引脚初始化时没有设置高电平,设置低电平就可以了。但是显示不清楚,还请指教。 sbgavin 发表于 2013-7-15 09:26 static/image/common/back.gif
你好,不显示的问题找到了,是因为我的rd引脚初始化时没有设置高电平,设置低电平就可以了。但是显示不清 ...
你是说显示的色度吗,可以调节LCD电压偏置电压,对比度那些,具体看你的LCD资料 本帖最后由 sbgavin 于 2013-7-15 12:58 编辑
shuxmpx123 发表于 2013-7-15 10:19 static/image/common/back.gif
你是说显示的色度吗,可以调节LCD电压偏置电压,对比度那些,具体看你的LCD资料 ...
我的显示屏的供电电压是3V,HT1622的偏压可调范围是0~3V,这个范围的电压都试过了,但是没有用,很模糊,正面看基本上看不清楚,SEG脚和COM脚的波形如附图,绿色的是COM脚,黄色的是SEG脚。请指教!谢谢! 能显示说明通信没有问题了,看不清楚的话,就是配置的问题,仔细看看1622有哪些需要配置的都试试吧。 shuxmpx123 发表于 2013-7-15 13:31 static/image/common/back.gif
能显示说明通信没有问题了,看不清楚的话,就是配置的问题,仔细看看1622有哪些需要配置的都试试吧。 ...
HT1622的com口输出1/4偏压,分别是:0、1/3V、2/3V、V,和我之前理解的不太一样,我想1/3偏压是:0、1/2V、V,不知道这样理解是否正确,请指教? 太及时了 16C22 不是I2C 驱动呀?就SCL和SDA ,,怎么有WR CSDATA?求解 你好,我写这个命令是不是正确的,我研究两天都没点亮我的屏!
HT1622_CMD(0x30); //内部晶振
HT1622_CMD(0x00); //关闭系统振荡器和LCD偏置发生器
HT1622_CMD(0x0a); //禁止 WDT 溢出标志输出
HT1622_CMD(0x02); //打开系统振荡器
HT1622_CMD(0x06); // 打开 LCD 这是我的完整程序
#include <stdint.h>
#include "LPC17xx.h"
#include "type.h"
#include "1754_IO.h"
#include "1754_LCD.h"
#define uchar unsigned char
#define uint unsigned int
#define tim 50
/*********************************************************************************************************
** Function name: delay
** Descriptions: 软件延时 100us
*********************************************************************************************************/
void delay(uintt)
{
uint i,j;
for(i = 0;i < t;i++)
{
for(j = 0;j < 1000;j++) ;
}
}
externvoid Write_Bit_L(uint data, uchar cnt);
extern void Write_Bit_H(uint data, uchar cnt);
uchar a={0xff,0xff,0xff,0x00,0xaa,0xff,0x55};
//////////////////////////////////////////////////////
//延时 us
void delayus(uchar us)
{
while(us--);
}
//延时 ms
void delayms(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<65;j++)
{
delayus(tim);
}
}
//写字节
void HT1622_WR_Data(uchar data,uchar cnt)
{
uchar i;
for(i=0;i<cnt;i++)
{
HT1622_WR_L;
delayus(tim);
if((data&0x80)==0x80)
{
HT1622_DATA_H;
}
else
{
HT1622_DATA_L;
}
delayus(tim);
HT1622_WR_H;
delayus(tim);
data<<=1;
}
}
//指定地址写数据
void HT1622_WR_Addr_Data(uchar addr,uchar data)
{
HT1622_CS_L;
HT1622_WR_Data(0xa0,3);//101
HT1622_WR_Data(addr,6);//addre
HT1622_WR_Data(data,4); //data
HT1622_CS_H;
}
//连续写数据
void HT1622_ALL_Data(void)
{
uchar i;
HT1622_CS_L;
HT1622_WR_Data(0xa0,3);
HT1622_WR_Data(0x00<<2,6);
for(i=0;i<16;i++)
{
HT1622_WR_Data(0xaa,8);
}
HT1622_CS_H;
}
//写命令
void HT1622_CMD(uchar cmd)
{
HT1622_CS_L;
delayus(tim);
// HT1622_WR_Data(0x80,3);
// HT1622_WR_Data(cmd,8);
HT1622_WR_Data(0x80,3);
HT1622_WR_Data(cmd,9);
HT1622_CS_H;
}
//初始化
void HT1622Int(void)
{
HT1622_CS_H;
HT1622_WR_H;
HT1622_DATA_H;
delayms(20);
HT1622_CMD(0x30); //内部晶振
HT1622_CMD(0x00); //关闭系统振荡器和LCD偏置发生器
HT1622_CMD(0x0a); //禁止 WDT 溢出标志输出
HT1622_CMD(0x02); //打开系统振荡器
HT1622_CMD(0x06); // 打开 LCD
}
///TES1**********
/////////////////////////////////////////////////////
int main(void)
{
unsigned char i;
SystemInit();
GPIO_Init(); //初始化GPIO
// HT1622_Init();
/////////////////////////
HT1622Int();
delayms(50);
while(1)
{
//HT1622_ALL_Data();
delayms(500);
HT1622_WR_Addr_Data(0x80,0x55);
delayms(500);
}
}
本帖最后由 shuxmpx123 于 2017-2-7 22:39 编辑
400KHz读写24AA64,调试OK;
/*******************************************************************
*
*
* I2C drive
*
*******************************************************************/
void I2C_Delay(void)
{
/*
asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); // clock 16MHz I2C frequency 243KHz
asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); // clock 16MHz I2C frequency 243KHz
asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop"); // clock 16MHz I2C frequency 243KHz
asm("nop"); asm("nop"); asm("nop");
asm("nop"); asm("nop"); asm("nop");
*/
u8 i;
for (i = 0; i < 4; i++) // clock 16MHz I2C frequency 400KHz
{
asm("nop");
}
}
void I2C_Delay2(void)
{
u8 i;
for (i = 0; i < 6; i++) // clock 16MHz I2C frequency 400KHz
{
asm("nop");
}
}
void I2C_Delay3(void)
{
u8 i;
for (i = 0; i < 2; i++) // clock 16MHz I2C frequency 400KHz
{
asm("nop");
}
}
void _I2C_Start(void)
{
disableInterrupts();
//SCL_LOW();
//I2C_Delay();
//SCL_HIGH();
SDA_HIGH();
SCL_HIGH();
I2C_Delay();
SDA_LOW();
I2C_Delay();
SCL_LOW();
enableInterrupts();
}
void _I2C_Stop(void)
{
disableInterrupts();
I2C_Delay();
I2C_Delay();
I2C_Delay();
SDA_LOW();
I2C_Delay();
SCL_HIGH();
I2C_Delay();
SDA_HIGH();
/*SCL_LOW();
I2C_Delay();
SDA_LOW();
I2C_Delay();
SCL_HIGH();
I2C_Delay();
SDA_HIGH();*/
enableInterrupts();
}
u8 _I2C_Wirte_Byte(u8 data)
{
u8 ack,i;
u8 writeData = data;
disableInterrupts();
for (i = 0; i < 8; i++)
{
SCL_LOW();
I2C_Delay3();
if ((writeData&0x80) == 0)
{
SDA_LOW();
}
else
{
SDA_HIGH();
}
writeData <<= 1;
I2C_Delay3();
SCL_HIGH();
I2C_Delay();
}
//I2C_Delay();
SCL_LOW();
I2C_Delay();
SDA_HIGH();
I2C_Delay();
SCL_HIGH();
if (READ_SDA())
{
ack = 1;
}
else
{
ack = 0;
}
I2C_Delay();
SCL_LOW();
I2C_Delay();
SDA_HIGH();
I2C_Delay();
enableInterrupts();
return ack;
}
void _I2C_Response_ACK(u8 ack)
{
disableInterrupts();
SCL_LOW();
I2C_Delay();
if (ack)
{
SDA_HIGH();
}
else
{
SDA_LOW();
}
I2C_Delay();
SCL_HIGH();
I2C_Delay();
SCL_LOW();
I2C_Delay();
enableInterrupts();
}
//volatile u16 testHCnt;
//volatile u16 testLCnt;
u8 _I2C_Read_Byte(void)
{
u8 i;
u8 resValue = 0;
disableInterrupts();
SCL_LOW();
nop();
nop();
SDA_HIGH();
for (i = 0; i < 8; i++)/*要传送的数据长度为8位*/
{
SCL_LOW();
I2C_Delay2();
SCL_HIGH();
I2C_Delay();
resValue <<= 1;
if(READ_SDA())
{
//testHCnt++;
resValue |= 0x01;
}
else
{
//testLCnt++;
resValue &= 0xfe;
}
}
enableInterrupts();
return resValue;
}
u16 i2cOKCnt;
u16 i2cErrCnt;
u8 _24XX_WriteNbytes(uint16_t addr, uint8_t *pInData, uint8_t bytes)
{
u8 i;
u8 res = 0;
_I2C_Start();
if (_I2C_Wirte_Byte(WR_ADD) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
if (_I2C_Wirte_Byte(addr>>8) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
if (_I2C_Wirte_Byte(addr&0xFF) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
for (i = 0; i < bytes; i++)
{
if (_I2C_Wirte_Byte(*pInData++) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
res = 1;
break;
}
}
_I2C_Stop();
return res;
}
u8 _I2C_Read_NBytes(u16 addr, u8* pOutData, u8 bytes)
{
u8 i;
_I2C_Start();
if (_I2C_Wirte_Byte(WR_ADD) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
if (_I2C_Wirte_Byte(addr>>8) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
if (_I2C_Wirte_Byte(addr&0xFF) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
_I2C_Start();
if (_I2C_Wirte_Byte(RD_ADD) == 0)
{
i2cOKCnt++;
}
else
{
i2cErrCnt++;
_I2C_Stop();
return 1;
}
for (i = 0; i < bytes-1; i++)
{
*pOutData++ = _I2C_Read_Byte();
_I2C_Response_ACK(0);
}
*pOutData = _I2C_Read_Byte();
_I2C_Response_ACK(1);
_I2C_Stop();
return 0;
}
页:
[1]