
//=================================================================================
	MAX7219.DATA_IN = DATA_IN; MAX7219.DATA_OUT = DATA_OUT; MAX7219.DATA_DIR = DATA_DIR;
	MAX7219.LOCK_IN = LOCK_IN; MAX7219.LOCK_OUT = LOCK_OUT; MAX7219.LOCK_DIR = LOCK_DIR;
	MAX7219.SHIFT_IN = SHIFT_IN; MAX7219.SHIFT_OUT = SHIFT_OUT; MAX7219.SHIFT_DIR = SHIFT_DIR;
	
	unit MAX7219
	{
		public link bit DATA_IN; public link bit DATA_OUT; public link bit DATA_DIR;
		public link bit LOCK_IN; public link bit LOCK_OUT; public link bit LOCK_DIR;
		public link bit SHIFT_IN; public link bit SHIFT_OUT; public link bit SHIFT_DIR;
		
		//---------------------------------------------------
		//初始化
		public void init()
		{
			DATA_DIR = 1;
			DATA_OUT = 0;
			SHIFT_DIR = 1;
			SHIFT_OUT = 1;
			LOCK_DIR = 1;
			LOCK_OUT = 1;
			
			//解码格式为非BCD
			send_byte( 0b0000_1001, 0x00 );
			
			//亮度为最大
			send_byte( 0b0000_1010, 0x0F );
			
			//扫描数目为8
			send_byte( 0b0000_1011, 0x07 );
			
			//非掉电模式 - 最低位 0 关断, 1 工作
			send_byte( 0b0000_1100, 0x01 );
			
			//非测试模式 - 最低位 0 关断, 1 工作
			send_byte( 0b0000_1111, 0x00 );
		}
		//---------------------------------------------------
		//设置亮度
		public void set_light( uint8 d )
		{
			send_byte( 0b0000_1010, d );
		}
		//---------------------------------------------------
		//发送一组数据, 1-点亮  0-熄灭
		// bit0: G
		// bit1: F
		// bit2: E
		// bit3: D
		// bit4: C
		// bit5: B
		// bit6: A
		// bit7: H
		public void send( [uint8*?] data, uint8 point )
		{
			for( uint8 i = 0; i < 8; i + 1 ) {
				uint8 d = data[i];
				uint8 d1;
				d1.0(bit) = d.6(bit);
				d1.1(bit) = d.5(bit);
				d1.2(bit) = d.4(bit);
				d1.3(bit) = d.3(bit);
				d1.4(bit) = d.2(bit);
				d1.5(bit) = d.1(bit);
				d1.6(bit) = d.0(bit);
				//d1.7(bit) = d.7(bit);
				d1.7(bit) = point.0(bit);
				point >> 1;
				send_byte( 8 - i, d1 );
			}
		}
		//==============================================
		void send_byte( uint8 addr, uint8 data )
		{
			uint16 d = data;
			d.8(uint8) = addr;
			LOCK_OUT = 0;
			loop( 16 ) {
				DATA_OUT = d.15(bit);
				d << 1;
				SHIFT_OUT = 0;
				SHIFT_OUT = 1;
			}
			LOCK_OUT = 1;
		}
	}
