因为项目需求,最近一直在研究GDEW042Z15电子墨水屏幕。
电子墨水屏即为使用电子墨水的屏幕。电子墨水屏又被称为电子纸显示技术。
电子墨水是一种革新信息显示的新方法和技术。像多数传统墨水一样,电子墨水和改变它颜色的线路是可以打印到许多表面的,从弯曲塑料、聚脂膜、纸到布。和传统纸差异是电子墨水在通电时改变颜色,并且可以显示变化的图象,像计算器或手机那样的显示。
再驱动屏幕时使用了STM32芯片,可以驱动屏幕进行切换图片,高速刷新等功能。
单片机源程序如下:
- /*******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "24cxx.h"
- #include "sys.h"
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- ErrorStatus HSEStartUpStatus;
- /* Private function prototypes -----------------------------------------------*/
- void RCC_Configuration(void);
- void NVIC_Configuration(void);
- void GPIO_Configuration(void);
- void uart_init(u32 bound);
- void LED_Init(void);
- void EEPROM_PLAY(void);
- void EEPROM_Display(void);
- void EPPROM_READ(void);
- #define SDA_H GPIO_SetBits(GPIOD, GPIO_Pin_10); //PD.10
- #define SDA_L GPIO_ResetBits(GPIOD, GPIO_Pin_10); //PD.10
- #define SCLK_H GPIO_SetBits(GPIOD, GPIO_Pin_9); //PD.9
- #define SCLK_L GPIO_ResetBits(GPIOD, GPIO_Pin_9);
- #define nCS_H GPIO_SetBits(GPIOD, GPIO_Pin_8); //PD.8
- #define nCS_L GPIO_ResetBits(GPIOD, GPIO_Pin_8);
- #define nDC_H GPIO_SetBits(GPIOE, GPIO_Pin_15); //PE.15
- #define nDC_L GPIO_ResetBits(GPIOE, GPIO_Pin_15);
- #define nRST_H GPIO_SetBits(GPIOE, GPIO_Pin_14); //PE.14
- #define nRST_L GPIO_ResetBits(GPIOE, GPIO_Pin_14);
- #define nBUSY GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_13) //PE.13
- #define nBS_H GPIO_SetBits(GPIOE, GPIO_Pin_11); //PE.11
- #define nBS_L GPIO_ResetBits(GPIOE, GPIO_Pin_11);
- #define VPP_H GPIO_SetBits(GPIOA, GPIO_Pin_4); //PA4
- #define VPP_L GPIO_ResetBits(GPIOA, GPIO_Pin_4); //PA4
- #define LED_1 GPIO_ResetBits(GPIOE, GPIO_Pin_12);
- #define LED_0 GPIO_SetBits(GPIOE, GPIO_Pin_12);
- void SPI4W_WRITECOM(unsigned char INIT_COM);
- void SPI4W_WRITEDATA(unsigned char INIT_DATA);
- void SPI4W_WRITE(unsigned char INIT_COM,unsigned char INIT_DATA);
- void MYRESET(void);
- void DELAY_100nS(unsigned int delaytime);
- void DELAY_mS(unsigned int delaytime);
- void DELAY_S(unsigned int delaytime);
- void DELAY_M(unsigned int delaytime);
- void READBUSY(void);
- int k=0;
- //unsigned char RECEIVE[15000];
- int RxCounter;
- unsigned int ReceiveState;
- unsigned char ZW[]=
- {
- 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
- …………
- …………
- …………限于本文篇幅 余下代码请从电子发烧友下载附件…………
- 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
- };*/
- void DELAY_100nS(unsigned int delaytime) // 30us
- {
- int i,j;
- for(i=0;i for(j=0;j<1;j++);
- }
- void DELAY_mS(unsigned int delaytime) // 1ms
- {
- int i,j;
- for(i=0;i {for(j=0;j<200;j++);}
- }
- void DELAY_S(unsigned int delaytime) // 1s
- {
- int i,j,k;
- for(i=0;i {
- for(j=0;j<4000;j++)
- {
- for(k=0;k<222;k++);
- }
- }
- }
- void DELAY_M(unsigned int delaytime) // 1M
- {
- int i;
- for(i=0;i DELAY_S(60);
- }
- void lcd_chkstatus(void)
- {
- unsigned char busy;
- do
- {
- SPI4W_WRITECOM(0x71);
- busy = nBUSY;
- busy =!(busy & 0x01);
- }
- while(busy);
- DELAY_mS(200);
- }
- void EPD_W21_Init(void)
- {
- nBS_L; //4 wire spi mode selected
- nRST_L; //module reset
- DELAY_mS(1000);
- nRST_H;
- DELAY_mS(1000);
- }
- void Ultrachip1(void)
- {
- unsigned int i;
- for(i=0;i<15000;i++)
- {
- SPI4W_WRITEDATA(G_Ultrachip1);
- }
- DELAY_mS(2);
- }
- void Ultrachip_red1(void)
- {
- unsigned int i;
- for(i=0;i<15000;i++)
- {
- SPI4W_WRITEDATA(G_Ultrachip_red1);
- }
- DELAY_mS(2);
- }
- /*void Ultrachip2(void)
- {
- unsigned int i;
- for(i=0;i<15000;i++)
- {
- SPI4W_WRITEDATA(G_Ultrachip2);
- }
- DELAY_mS(2);
- }*/
- void Ultrachip_red2(void)
- {
- unsigned int i;
- for(i=0;i<15000;i++)
- {
- SPI4W_WRITEDATA(G_Ultrachip_red2);
- }
- DELAY_mS(2);
- }
- void EPPROM_READ(void)
- {
- unsigned int i,b;
- unsigned char c;
- b =100 ;
- for(i=0;i<15000;i++)
- {
- c=AT24CXX_ReadOneByte(b);
- SPI4W_WRITEDATA(c);
- b++;
- }
- DELAY_mS(2);
- }
- void pic_display(void)
- {
- SPI4W_WRITECOM(0x10);
- Ultrachip1();
- SPI4W_WRITECOM(0x13);
- Ultrachip_red1();
- }
- void Display(void)
- {
- EPD_W21_Init();
- SPI4W_WRITECOM(0x06); //boost设定
- SPI4W_WRITEDATA (0x17);
- SPI4W_WRITEDATA (0x17);
- SPI4W_WRITEDATA (0x17); //07 0f 17 1f 27 2F 37 2f
- SPI4W_WRITECOM(0x04);
- lcd_chkstatus();
- SPI4W_WRITECOM(0x00);
- SPI4W_WRITEDATA(0x0f); // LUT from OTP
- pic_display();
- SPI4W_WRITECOM(0x12);
- DELAY_mS(100);
- lcd_chkstatus();
- SPI4W_WRITECOM(0X50);
- SPI4W_WRITEDATA(0xf7); //border floating
- SPI4W_WRITECOM(0X02); //power off
- lcd_chkstatus();
- SPI4W_WRITECOM(0X07); //deep sleep
- SPI4W_WRITEDATA(0xA5);
- DELAY_mS(100);
- }
- void EEPROM_Display(void)
- {
- EPD_W21_Init();
- SPI4W_WRITECOM(0x06); //boost设定
- SPI4W_WRITEDATA (0x17);
- SPI4W_WRITEDATA (0x17);
- SPI4W_WRITEDATA (0x17); //07 0f 17 1f 27 2F 37 2f
- SPI4W_WRITECOM(0x04);
- lcd_chkstatus();
- SPI4W_WRITECOM(0x00);
- SPI4W_WRITEDATA(0x0f); // LUT from OTP
- EEPROM_PLAY();
- SPI4W_WRITECOM(0x12);
- DELAY_mS(100);
- lcd_chkstatus();
- /************************power off Sequence************************/
- SPI4W_WRITECOM(0X50);
- SPI4W_WRITEDATA(0xf7); //border floating
- SPI4W_WRITECOM(0X02); //power off
- lcd_chkstatus();
- SPI4W_WRITECOM(0X07); //deep sleep
- SPI4W_WRITEDATA(0xA5);
- /************************power off Sequence************************/
- DELAY_mS(100);
- }
- void EEPROM_PLAY(void)
- {
- SPI4W_WRITECOM(0x10);
- EPPROM_READ();
- SPI4W_WRITECOM(0x13);
- Ultrachip_red2();
- }
- /*****************************************************************************************************/
- void SPI4W_WRITECOM(unsigned char INIT_COM)
- {
- unsigned char TEMPCOM;
- unsigned char scnt;
- TEMPCOM=INIT_COM;
- nCS_H
- nCS_L
- SCLK_L
- nDC_L
- for(scnt=0;scnt<8;scnt++)
- {
- if(TEMPCOM&0x80)
- SDA_H
- else
- SDA_L
- DELAY_100nS(10);
- SCLK_H
- DELAY_100nS(10);
- SCLK_L
- TEMPCOM=TEMPCOM<<1;
- DELAY_100nS(10);
- }
- nCS_H
- }
- void SPI4W_WRITEDATA(unsigned char INIT_DATA)
- {
- unsigned char TEMPCOM;
- unsigned char scnt;
- TEMPCOM=INIT_DATA;
- nCS_H
- nCS_L
- SCLK_L
- nDC_H
- for(scnt=0;scnt<8;scnt++)
- {
- if(TEMPCOM&0x80)
- SDA_H
- else
- SDA_L
- DELAY_100nS(10);
- SCLK_H
- DELAY_100nS(10);
- SCLK_L
- TEMPCOM=TEMPCOM<<1;
- DELAY_100nS(10);
- }
- nCS_H
- }
- /*******************************************************************************
- * Function Name : main
- * Description : Main program
- * Input : None
- * Output : None
- * Return : None
- #define NVIC_VectTab_FLASH misc.h
- *******************************************************************************/
- /*int main(void)
- {
- #ifdef DEBUG
- debug();
- #endif
- int v,q,s;
- char c;
- DELAY_S(1);
- // 系统时钟设置
- RCC_Configuration();
- //GPIO参数设置
- GPIO_Configuration();
- uart_init(115200);
- AT24CXX_Init();
- LED_Init();
- //EPD_W21_Init();
- AT24CXX_Init();
- // VPP_H;
- k=0;
- v=100;
- //EEPROM_Display();
- Display();
- while(1)
- {
- if(ReceiveState==1)
- {
- ReceiveState=0;
- while(RxCounter--)
- {
- AT24CXX_WriteOneByte(v,RECEIVE[k]);
- v++;
- k++;
- //DELAY_mS(5);
- }
- LED_0;
- //c=AT24CXX_ReadOneByte(107);
- //USART_SendData(USART1,c);
- //while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
- EEPROM_Display();
- RxCounter=0;
- v=100;
- k=0;
- }
- }
- }*/
- int main(void)
- {
- #ifdef DEBUG
- debug();
- #endif
- int i;
- char c;
- DELAY_S(1);
- // 系统时钟设置
- RCC_Configuration();
- //GPIO参数设置
- GPIO_Configuration();
- uart_init(115200);
- AT24CXX_Init();
- LED_Init();
- //EPD_W21_Init();
- AT24CXX_Init();
- DELAY_mS(5000);
- for(i=1;i<30000;i++)
- {
- //c=ZW;
- //USART_SendData(USART1,c);
- //while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
- AT24CXX_WriteOneByte(i,0x1c);
- }
- for(i=1;i<30000;i++)
- {
- c=AT24CXX_ReadOneByte(i); ;
- USART_SendData(USART1,c);
- while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
- }
- LED_1;
- while(1);
- }
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- // 复位RCC时钟配置(用于调试模式)
- RCC_DeInit();
- // 使能外部晶振
- RCC_HSEConfig(RCC_HSE_ON);
- // 等待外部晶振稳定
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)
- {
- // 设置锁相环频率PLLCLK = 8MHz * 9 = 72 MHz
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- }
- else {
- // 使能内部晶振
- RCC_HSICmd(ENABLE);
- // 等待内置振荡器稳定
- while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
- // 设置锁相环频率PLLCLK = 8MHz/2 * 16 = 64 MHz
- RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_16);
- }
- // 使能FLASH的预取缓冲
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- //设置代码延时值,FLASH_Latency_2为两个延时周期
- FLASH_SetLatency(FLASH_Latency_2);
- //设置系统总线时钟
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
- //设置高速设备总线时钟,RCC_HCLK_Div1为系统时钟除以1
- RCC_PCLK2Config(RCC_HCLK_Div1);
- //设置低速设备总线时钟,RCC_HCLK_Div2为系统时钟除以2
- RCC_PCLK1Config(RCC_HCLK_Div2);
- //使能锁相环倍频
- RCC_PLLCmd(ENABLE);
- // 等待锁相环倍频后的频率稳定
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
- // 选择锁相环时钟为系统时钟源
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- // 等待设置完成
- while(RCC_GetSYSCLKSource() != 0x08);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
- RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO,
- ENABLE);
- }
- /*******************************************************************************
- * 函数名 : GPIO_Configuration
- * 描述 : 设置设置串口所用GPIO引脚的参数
- * 输入 : None
- * 输出 : None
- * 返回 : None
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10; //abcd OE ST LT0输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_14 |GPIO_Pin_15; //abcd OE ST LT0输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //abcd OE ST LT0输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //VPP
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- void uart_init(u32 bound)
- {
- //GPIO端口设置
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA时钟
- //USART1_TX GPIOA.9
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
- GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.9
- //USART1_RX GPIOA.10初始化
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
- GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.10
- //Usart1 NVIC 配置
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
- NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
- //USART 初始化设置
- USART_InitStructure.USART_BaudRate = bound;//串口波特率
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
- USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
- USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
- USART_Init(USART1, &USART_InitStructure); //初始化串口1
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
- USART_Cmd(USART1, ENABLE); //使能串口1
- }
- void LED_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_SetBits(GPIOE,GPIO_Pin_12);
- }
- /*******************************************************************************
- * Function Name : NVIC_Configuration
- * Description : Configures Vector Table base location.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- // NVIC_InitTypeDef NVIC_InitStructure;
- ;
- }
- #ifdef DEBUG
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None
- * Return : None
- *******************************************************************************/
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %drn", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /*void USART1_IRQHandler(void)
- {
- unsigned char num;
- if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
- {
- USART_ClearITPendingBit(USART1, USART_IT_RXNE);
- num=USART_ReceiveData(USART1);
- LED_1;
- if(num==0XDD)
- {
- ReceiveState=1;
- }
- else
- {
- RECEIVE[RxCounter++]=num;
- }
- //USART_SendData(USART1,RECEIVE[2]);
- }
- }*/
所有资料51hei提供下载:
GDEW042Z15程序示例-OTP.rar
|
0
|
|
|
|