|
硬件结构图
这是我的源代码:
- #include
- #include
- typedef unsigned char byte;
- typedef unsigned int byte2;
- typedef unsigned long byte4;
- typedef byte bool;
- #define TRUE 1
- #define FALSE 0
- sbit 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 osillator
- void 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。
仔细对照的datasheet写的程序,可是就是一点反应没有!
望牛人助我!
|
|