新闻中心

EEPW首页 > 模拟技术 > 设计应用 > 用于MAX7456随屏显示器SPI

用于MAX7456随屏显示器SPI

作者: 时间:2011-04-22 来源:网络 收藏

读字节操作程序

读字节操作(图2)程序如下所示,与上述程序类似。首先发送地址,然后发送时钟从MISO读回数据。

/*************************************************************************************** spiReadReg** Reads an 8-bit register with the SPI port.* Data is returned. **************************************************************************************/unsigned char spiReadReg (const unsigned char regAddr){unsigned char SPICount;                                       // Counter used to clock out the dataunsigned char SPIData;                  SPI_CS = 1;                                                   // Make sure we start with active-low CS highSPI_CK = 0;                                                   // and CK lowSPIData = regAddr;                                            // Preload the data to be sent with Address and DataSPI_CS = 0;                                                   // Set active-low CS low to start the SPI cyclefor (SPICount = 0; SPICount  8; SPICount++)                  // Prepare to clock out the Address and Data{if (SPIData  0x80)SPI_MOSI = 1;elseSPI_MOSI = 0;SPI_CK = 1;SPI_CK = 0;SPIData = 1;}                                                             // and loop back to send the next bitSPI_MOSI = 0;                                                 // Reset the MOSI data lineSPIData = 0;for (SPICount = 0; SPICount  8; SPICount++)                  // Prepare to clock in the data to be read{SPIData =1;                                               // Rotate the dataSPI_CK = 1;                                                 // Raise the clock to clock the data out of the MAX7456SPIData += SPI_MISO;                                        // Read the data bitSPI_CK = 0;                                                 // Drop the clock ready for the next bit}                                                             // and loop backSPI_CS = 1;                                                   // Raise CSreturn ((unsigned char)SPIData);                              // Finally return the read data}

自动递增模式下的写字节操作程序

自动递增模式下的写字节操作(图3)程序如下所示,与和上述单字节写程序类似。首先发送地址,然后发送时钟从MISO读回数据。

/*************************************************************************************** spiWriteRegAutoIncr** Writes to an 8-bit register with the SPI port using the MAX7456's autoincrement mode**************************************************************************************/void spiWriteRegAutoIncr(const unsigned char regData){unsigned char SPICount;                                       // Counter used to clock out the dataunsigned char SPIData;                                        // Define a data structure for the SPI data.SPI_CS = 1;                                                   // Make sure we start with active-low CS highSPI_CK = 0;                                                   // and CK lowSPIData = regData;                                            // Preload the data to be sent with Address and DataSPI_CS = 0;                                                   // Set active-low CS low to start the SPI cyclefor (SPICount = 0; SPICount  8; SPICount++)                  // Prepare to clock out the Address and Data{if (SPIData  0x80)SPI_MOSI = 1;elseSPI_MOSI = 0;SPI_CK = 1;SPI_CK = 0;SPIData = 1;}                                                             // and loop back to send the next bit   SPI_MOSI = 0;                                                 // Reset the MOSI data line}

自动递增模式下写显示存储器的程序

自动递增模式下写显示存储器的程序如下,程序使用称为 "data"的全局变量数组。定义如下:

extern volatile unsigned char data[DATA_BUF_LENGTH];DATA_BUF_LENGTH = 968

调用程序时,data[]包含显示存储器内容,格式如下:

data[0] = ignored (contains a command byte used by the EV kit GUI software)data[1] = character byte 1data[2] = attribute byte 1data[3] = character byte 2data[4] = attribute byte 2etc.

自动递增模式通过写0xFF结束,所以该模式下不能向显示寄存器写0xFF。如果需要写OxFF,可以采用单字节写指令。

/*************************************************************************************** spiWriteCM** Writes to the Display Memory (960 bytes) from "data" extern.* 960 = 16 rows × 30 columns × 2 planes {char vs. attr} screen-position-indexed memory**************************************************************************************/void spiWriteCM()                                               // On entry: global data[1..960]// contains char+attr bytes   // (optionally terminated by 0xFF data)// First, write data[1,3,5,...] Character plane;// MAX7456 WriteReg(0x05,0x41)// "Character Memory Address High";// 0x02:Attribute bytes; // 0x01:character memory address msb{volatile unsigned int Index = 0x0001;                        // Index for lookup into// data[1..960]                    spiWriteReg(DM_ADDRH_WRITE,0x00);                            // initialise the Display Memory high-bytespiWriteReg(DM_ADDRL_WRITE,0x00);                            // and the low-bytespiWriteReg(DM_MODE_WRITE ,0x41);                            // MAX7456 WriteReg(0x04,0x41) "Display Memory Mode";// 0x40:Perform 8-bit operation; 0x01:AutoIncrementDo                                                           // Loop to write the character data{if (data[Index] == 0xFF) {                                // Check for the break characterbreak; }                                             // and finish if foundspiWriteRegAutoIncr(data[Index]);                         // Write the characterIndex += 2;                                               // Increment the index to the next character, // skipping over the attribute  } while(Index  0x03C1);                                     // 0x03C1 = 961// and loop back to send the next characterspiWriteRegAutoIncr(0xFF);                                   // Write the "escape character" to end AutoIncrement 
				
            
                
			
							

评论


相关推荐

技术专区

关闭