|
/ht1622 的相关定义与函数
// CS 接在ATMEGA16的PA5上
// WR 接在ATMEGA16的PA6上
// DATA 接在ATMEGA16的PA7上
#define uchar unsigned char
//#define BIAS 0x52 //0b1000 0101 0010 1/3bais 4duty 0x52
#define BIAS 0x2e //0b1000 0010 1110 1/4bias 8duty 0x2e
#define SYSDIS 0X00 //0b1000 0000 0000 关系统振荡器和LCD偏压发生器
#define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压
#define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压
#define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器
#define XTAL 0x28 //0b1000 0010 1000 外部接时钟
#define RC256 0X30 //0b1000 0011 0000 内部时钟
#define TONEON 0X12 //0b1000 0001 0010 打开声音输出
#define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出
#define WDTDIS 0X0A //0b1000 0000 1010 禁止看门狗
#define LCD_CS PORTA&=~(1<<5) //
#define LCD_CSH() PORTA|=(1<<5) //
#define LCD_CSL() PORTA&=~(1<<5) //
//#define LCD_RD P4DIR|=BIT5 //
//#define LCD_RDH() P4OUT|=BIT5 //
//#define LCD_RDL() P4OUT&=~BIT5 //
#define LCD_WR PORTA&=~(1<<6) //06.03.10 BY TZQ
#define LCD_WRH() PORTA|=(1<<6) //
#define LCD_WRL() PORTA&=~(1<<6) //
#define LCD_DATA PORTA&=~(1<<7) //
#define LCD_DATAH() PORTA|=(1<<7) //
#define LCD_DATAL() PORTA&=~(1<<7) //
//#define LCD_DIN P4DIR&=~BIT3 //
//#define LCD_DTST P4IN&BIT3 //LCD引脚
//uchar Tab1[32]={0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
// 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
uchar Tab2[32]={0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
//uchar Tab3[32]={0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
// 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40};
uchar Tab4[32]={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80};
//########### ht1622的子程序
//延时函数
void s_ms(unsigned int t)
{
for(;t>1;t--)
{
}
}
/*************************************************
*原型:void SendBit_1622(unsigned char bit,unchar cnt)
*功能:LCD送数
*说明:LCD-HT1622 数据在高锁存
*参数:bit
*返回:无
**************************************************/
void SendBit_1622(uchar data,uchar cnt) //data 的高cnt 位写入HT1622,高位在前
{
uchar i;
for(i =0; i <cnt; i ++)
{
if((data&0x80)==0) LCD_DATAL();
else LCD_DATAH();
LCD_WRL();
s_ms(60);
LCD_WRH();
data<<=1;
}
}
void SendDataBit_1622(uchar data,uchar cnt) //data 的低cnt 位写入HT1622,低位在前
{
uchar i;
for(i =0; i <cnt; i ++)
{
if((data&0x01)==0) LCD_DATAL();
else LCD_DATAH();
LCD_WRL();
s_ms(60);
LCD_WRH();
data>>=1;
}
}
void SendCmd(uchar command)
{
LCD_CSL();
//s_ms(10);
SendBit_1622(0x80,3); //写入标志码"100"
SendBit_1622(command,9); //写入9 位数据,其中前8 位为command 命令,最后1 位任意
//s_ms(10);
LCD_CSH();
}
void Write_1622(uchar addr,uchar data)
{
LCD_CSL();
//s_ms(10);
SendBit_1622(0xa0,3); //写入标志码"101"
SendBit_1622(addr<<2,6); //写入6 位addr
SendDataBit_1622(data,4); //写入data 的低4 位
//s_ms(10);
LCD_CSH();
}
void WriteAll_1622(uchar addr,uchar *p,uchar cnt)
{
uchar i;
LCD_CSL();
//s_ms(10);
SendBit_1622(0xa0,3); //写入标志码"101"
SendBit_1622(addr<<2,6); //写入6 位addr
for(i =0; i <cnt; i ++,p++) //连续写入数据
{
SendDataBit_1622(*p,8);
}
//s_ms(10);
LCD_CSH();
}
#include<avr/io.h>
#include"ht1622.h"
#define uchar unsigned char
#define uint unsigned int
int main()
{
uchar a[10];
a[0]=0x21;a[1]=0x43;a[2]=0x65;a[3]=0x87;a[4]=0xa9;
DDRA=0xff; //端口A为输出
PORTA=0xFF; //关闭所有LED
LCD_WRH();
LCD_DATAH();
LCD_CSL();
s_ms(100);
LCD_CSH();
SendCmd(BIAS); //设置偏压和占空比
SendCmd(SYSEN); //打开系统振荡器
SendCmd(LCDON); //打开LCD 偏压发生器
Write_1622(0x09,0x01); //在地址0x09 处写入数据0x01
WriteAll_1622(0,a,5); //在起始地址为0 处连续写入5 个字节数据
// a为写入数据的起始地址,5 为写入的字节数
// SendCmd(LCDOFF); //关闭LCD 显示
while(1)
{
//PORTD=~led; //端口输出led值
//if (led==128)
// led=1;
// led=led*2; //向左移动一位
//led<<=1; //2010-04-22用移位方法测试
//s_ms(65535); //延时
//s_ms(65535);
//s_ms(65535);
//s_ms(65535);
}
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|