原理图 (原文件名:HT1621.GIF)
HT1261Bourdev_253183.pdf(文件大小:189K) (原文件名:HT1621B-48SSOP.pdf)
//ICC-AVR application builder : 2000-12-14 16:33:32
// Target : M8
// Crystal: 1.0000Mhz
//此版本适用于DIP28封装的MEGA8
//保密位: 0X00C0
//熔丝位: 0X9121 1M
//熔丝位: 0xD124 8M
#include <iom8v.h>
#include <macros.h>
void port_init(void)
{
PORTB = 0b11000000;
DDRB = 0b00000011;
PORTC = 0x00; //m103 output only
DDRC = 0b00111000;
PORTD = 0b00000000;
DDRD = 0b11111111;
}
//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x1F;
WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
}
void watchdog(void)
{
WDR(); //看门狗计数清零
WDTCR=0x1F; //使能watchdog,并且,采用2048K分频,典型溢出时间5V时2.1S
WDTCR=0x0F; //使能watchdog,并且,采用2048K分频,典型溢出时间5V时2.1S
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
watchdog_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x45; //timer interrupt sources
//TIMSK = 0x05; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//------------------------------------------------------------------------------
//Ht1621相关引脚
#define HT_WR PB7
#define SET_HT_WR() PORTB |= (1 << HT_WR)
#define CLS_HT_WR() PORTB &= ~ (1 << HT_WR)
#define HT_DATA PD5
#define SET_HT_DATA() PORTD |= (1 << HT_DATA)
#define CLS_HT_DATA() PORTD &= ~ (1 << HT_DATA)
#define HT_CS PB6
#define SET_HT_CS() PORTB |= (1 << HT_CS)
#define CLS_HT_CS() PORTB &= ~ (1 << HT_CS)
#define BIAS 0x28
#define SYSEN 0x01
#define LCDOFF 0x02
#define LCDON 0x03
void delay(void)
{
unsigned char i;
for (i = 16; i > 0; i--)
{
_NOP();
}
}
void SendBit_1621(unsigned char data, unsigned char cnt) //data的高cnt位写入HT1621,高位在前
{
unsigned char i;
for (i = 0; i < cnt; i++)
{
if ((data & 0x80) == 0)
{
CLS_HT_DATA();
}
else
{
SET_HT_DATA();
}
delay();
CLS_HT_WR();
// delay();
SET_HT_WR();
//delay();
data <<= 1;
}
}
void SendDataBit_1621(unsigned char data, unsigned char cnt) //data的低cnt位写入HT1621,低位在前
{
unsigned char i;
for (i = 0; i < cnt; i++)
{
if ((data & 0x01) == 0)
{
CLS_HT_DATA();
}
else
{
SET_HT_DATA();
}
delay();
CLS_HT_WR();
//delay();
SET_HT_WR();
//delay();
data >>= 1;
}
}
void SendCmd(unsigned char command)
{
CLS_HT_CS();
SendBit_1621(0x80,3); //写入标志码"100"
SendBit_1621(command,9); //写入9 位数据,其中前8 位为command 命令,最后1 位任意
SET_HT_CS();
}
void Write_1621(unsigned char addr, unsigned char data)
{
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr << 2,6); //写入6 位addr
SendDataBit_1621(data,4); //写入data 的低4 位
SET_HT_CS();
}
void WriteAll_1621(unsigned char addr, unsigned char * p, unsigned char cnt)
{
unsigned char i;
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr << 2,6); //写入6 位addr
for(i =0; i <cnt; i ++,p++) //连续写入数据
{
SendDataBit_1621(*p,8);
}
SET_HT_CS();
}
void Writetest_1621(void)
{
unsigned int i,p;
CLS_HT_CS();
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(0,6); //写入6 位addr
for (p = 0; p < 32; p++)
{
for(i = 0; i < 8; i ++) //连续写入数据
{
SendDataBit_1621(p,8);
delay();
}
}
SET_HT_CS();
}
void Cls_1621(void)
{
unsigned int i,p;
CLS_HT_CS();
SendBit_1621(0xa0,8); //写入标志码"101"
SendBit_1621(0,6); //写入6 位addr
for (p = 0; p < 32; p++)
{
for(i = 0; i < 8; i ++) //连续写入数据
{
SendDataBit_1621(0,8);
delay();
}
}
SET_HT_CS();
}
//==============================================================================
void main(void)
{
init_devices();
SendCmd(BIAS); //设置偏压和占空比
SendCmd(SYSEN); //打开系统振荡器
SendCmd(LCDON); //打开LCD偏压发生器
while (1)
{
WDR(); //this prevents a timout on enabling
Write_1621(0x00,0b1001);
Write_1621(0x01,0b1111);
Write_1621(0x02,0b0000);
Write_1621(0x03,0b1101);
Write_1621(0x04,0b1110);
Write_1621(0x05,0b1111);
} |
|
|
|