HT1622的使用问题,望牛人告知!
硬件结构图
这是我的源代码:
#include <reg51.h>#include <intrins.h>typedef unsigned char byte;typedef unsigned int byte2;typedef unsigned long byte4;typedef byte bool;#define TRUE 1#define FALSE 0sbit CS = P0^0;sbit WR_CLK = P0^1;sbit DATA = P0^2;byte addr_count = 0;const byte dat_buf[ 100 ] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60, 61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99};sbit STAT = P1^7;// HT1622 Write Operation void TurnOnLCD( bool openState ); // to enable system oscillator and to turn on LCD display // if openstate is TRUE, then turn on the LCD display, and enbale system oscillator // otherwisr, turn off the LCD display, and disable system osillatorvoid WriteHalfByte( byte addr, byte dat );void Ext0Svr();void Ext1Svr();void main(){ byte index = 0; _nop_(); P3 = 0x0F; EA = 1; EX0 = 1; IT0 = 1; EX1 = 1; IT1 = 1; STAT = 1; while ( TRUE );}////////////////////////////////////////////////////////void TurnOnLCD( bool openState ){ byte4 cmd_frame = 0; byte bit_count = 21; if ( openState ) { cmd_frame = 0x80203000; // this frame include comamnd ID( 1 0 0 ), SYS EN ID( 0 0 0 0 0 0 1 0 x ) // and TURB ON DISPLAY ID ( 0 0 0 0 0 0 1 1 x ) } else { cmd_frame = 0x80202000; // this frame include comamnd ID( 1 0 0 ), SYS EN ID( 0 0 0 0 0 0 1 0 x ) // and TURB ON DISPLAY ID ( 0 0 0 0 0 0 1 0 x ) } CS = 0; // Select the chip HT1622 to be valid _nop_(); _nop_(); WR_CLK = 1; while ( bit_count -- ) { WR_CLK = 0; DATA = ( cmd_frame & 0x80000000 ) == 0x80000000 ? 1 : 0; /*delay for 24 us*/ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); WR_CLK = 1; /*delay for 9 us*/ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); cmd_frame = _lrol_( cmd_frame, 1 ); } CS = 1; }void WriteHalfByte( byte addr, byte dat ){ byte2 write_frame = 0, temp_buf; //用来封装生成的帧 byte index = 0; write_frame = 0xA000; //封装写操作的指令码 1 0 1 temp_buf = _irol_( (byte2) addr, 7 ); write_frame += temp_buf; //封装地址A5-A0 dat &= 0x0F; temp_buf = 0; for ( ; index < 4; index ++ ) { if ( ( dat & 0x01 ) == 0x01 ) { temp_buf += _irol_( (byte2)1, 6 - index ); } dat = _cror_( dat, 1 ); } _nop_(); write_frame += temp_buf; //封装半字节数据D0-D3 index = 13; CS = 0; // Select the chip HT1622 to be valid _nop_(); _nop_(); WR_CLK = 1; while ( index -- ) { /*delay for 30 us*/ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); WR_CLK = 0; /*delay for 24 us*/ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_(); DATA = (write_frame & 0x8000 ) == 0x8000 ? 1 : 0; /*delay for 30 us*/ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); WR_CLK = 1; write_frame = _irol_( write_frame, 1 ); } CS = 1;}void Ext0Svr() interrupt 0{ for ( addr_count = 0; addr_count < 100; addr_count ++ ) { WriteHalfByte( addr_count, dat_buf[ addr_count ] ); }}void Ext1Svr() interrupt 2{ STAT = ~STAT; TurnOnLCD( STAT );}
//定义HT1622的命令和数据#define RCosc 0x30 //内部RC振荡器(上电默认)1000 0011 0000 #define LCD_on 0x06 //打开LCD 偏压发生器 1000 0000 0110 #define LCD_off 0x04 //打开LCD 偏压发生器 1000 0000 0100 #define Sys_en 0x02 //系统振荡器开 1000 0000 0010 #define Sys_dis 0x00 //系统振荡器开 1000 0000 0000 #define Tim_dis 0x00 //系统振荡器开 1000 0000 1000 #define Wtd_dis 0x00 //系统振荡器开 1000 0000 1010 #define Ton_off 0x00 //系统振荡器开 1000 0001 0000 #define lcd_wr 5#define lcd_cs 4#define lcd_da 6#define LCDPORT PORTA//定义简单的命令#define SETLCDWR() LCDPORT|=1<<lcd_wr#define CLRLCDWR() LCDPORT&=~(1<<lcd_wr)#define SETLCDCS() LCDPORT|=1<<lcd_cs#define CLRLCDCS() LCDPORT&=~(1<<lcd_cs)#define SETLCDDA() LCDPORT|=1<<lcd_da#define CLRLCDDA() LCDPORT&=~(1<<lcd_da)/**------------------------------------- Name: SendBit_1622(送数据程序) INPUT: sdata 送入的数据 cnt 数据的长度---------------------------------------*/ void SendBit_1622(uchar sdata,uchar cnt) //sdata 的高cnt 位写入HT1622,高位在前 { uchar i; for(i=0;i<cnt;i++) { if(sdata&0x80) SETLCDDA(); else CLRLCDDA(); CLRLCDWR(); SETLCDWR(); sdata<<=1; } } /**------------------------------------- Name: SendCmd(送命令) ---------------------------------------*/ void SendCmd_1622(uchar command) { CLRLCDCS(); SendBit_1622(0x80,4); //写入标志码“100”和9 位command 命令,由于 SendBit_1622(command,8); //没有使有到更改时钟输出等命令,为了编程方便 SETLCDCS(); //直接将command 的最高位写“0” } /**------------------------------------- Name: Write_1622(送数据和命令程序) ---------------------------------------*/ void Write_1622(uchar addr,uchar sdata,uchar longth){ addr<<=2; CLRLCDCS(); SendBit_1622(0xa0,3); //写入标志码“101” SendBit_1622(addr,6); //写入addr 的高6位 SendBit_1622(sdata,longth); //写入data 的高long位 SETLCDCS(); } /**------------------------------------- Name: all_off(清除1622显示) ---------------------------------------*/ void HT1622_all_off(void) { uchar i; CLRLCDCS(); SendBit_1622(0xa0,3); //写入标志码“101” SendBit_1622(0,6); //写入addr 的高6位 for(i=0;i<64;i++) SendBit_1622(0,4); //写入data 的高long位 SETLCDCS(); } /**************************************************************************** Name: Init_1622(初始化1622) *****************************************************************************/ void Init_1622(void) { SendCmd_1622(RCosc); SendCmd_1622(Sys_en); SendCmd_1622(LCD_on); } void show_all(void)//show all the memery{ uchar i; CLRLCDCS(); SendBit_1622(0xa0,3); //写入标志码“101” SendBit_1622(0,6); //写入addr 的高6位 for(i=0;i<64;i++) SendBit_1622(disp_buff[i],4); //写入data 的高long位 SETLCDCS(); SETLCDDA(); SETLCDWR(); }