用于MAX7456随屏显示器SPI
时间:04-22
来源:互联网
点击:
自动递增模式下的写字节操作(图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 // modespiWriteReg(DM_ADDRH_WRITE,0x02); // Second, write data[2,4,6,...] // Attribute plane; MAX7456// WriteReg(0x05,0x41)// "Character Memory Address High"; // 0x02:Attribute bytes; 0x01:character memory address // msbspiWriteReg(DM_ADDRL_WRITE,0x00);spiWriteReg(DM_MODE_WRITE,0x41); // MAX7456 WriteReg(0x04,0x41) "Character Memory // Mode"; 0x40:Perform 8-bit operation; 0x01:Auto-// IncrementIndex = 0x0002;do{if (data[Index] == 0xFF)break;spiWriteRegAutoIncr(data[Index]);Index += 2;} while(Index 0x03C1);spiWriteRegAutoIncr(0xFF);}
写字符存储器程序
模拟电路 模拟芯片 德州仪器 放大器 ADI 模拟电子 相关文章:
- 12位串行A/D转换器MAX187的应用(10-06)
- AGC中频放大器设计(下)(10-07)
- 低功耗、3V工作电压、精度0.05% 的A/D变换器(10-09)
- PIC16C5X单片机睡眠状态的键唤醒方法(11-16)
- 用简化方法对高可用性系统中的电源进行数字化管理(10-02)
- 利用GM6801实现智能快速充电器设计(11-20)
灏勯涓撲笟鍩硅鏁欑▼鎺ㄨ崘
栏目分类