本帖最后由 jinglixixi 于 2020-12-14 18:00 编辑
前面在使用CH579M-R1开发板时,便利用它对U盘的读写能力实现了图片显示功能,当时是利用按键触发翻页处理,这次则是在CH32V103开发板上再次重现了该功能,且将手动翻页改为延时自动翻页。 彩色OLED屏、米客方德4Gb T卡与CH32V103开发板的连接关系如图1所示。 图1 整体构成
在图片中的浏览过程中,其演示效果如图2~图4所示。 图2 卡通画效果
图3 油画效果
图4 国画效果
在程序中,进行相关语句定义有: #define LCD_W 160 #define LCD_H 80 #define OLED_SCLK_Set() GPIO_WriteBit(GPIOA, GPIO_Pin_2,Bit_SET) //CLK #define OLED_SCLK_Clr() GPIO_WriteBit(GPIOA, GPIO_Pin_2,Bit_RESET) #define OLED_SDIN_Set() GPIO_WriteBit(GPIOA, GPIO_Pin_3,Bit_SET) //DIN #define OLED_SDIN_Clr() GPIO_WriteBit(GPIOA, GPIO_Pin_3,Bit_RESET) #define OLED_RST_Set() GPIO_WriteBit(GPIOB, GPIO_Pin_3,Bit_SET) //RES #define OLED_RST_Clr() GPIO_WriteBit(GPIOB, GPIO_Pin_3,Bit_RESET) #define OLED_DC_Set() GPIO_WriteBit(GPIOB, GPIO_Pin_4,Bit_SET) //DC #define OLED_DC_Clr() GPIO_WriteBit(GPIOB, GPIO_Pin_4,Bit_RESET) #define OLED_CS_Set() GPIO_WriteBit(GPIOB, GPIO_Pin_5,Bit_SET) //CS #define OLED_CS_Clr() GPIO_WriteBit(GPIOB, GPIO_Pin_5,Bit_RESET) #define OLED_BLK_Set() GPIO_WriteBit(GPIOB, GPIO_Pin_6,Bit_SET)//BLK #define OLED_BLK_Clr() GPIO_WriteBit(GPIOB, GPIO_Pin_6,Bit_RESET) 相应的引脚功能配置函数为: void App_OledInit(void) { GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //使能与LED相关的GPIO端口时钟 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; //配置GPIO引脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度 GPIO_Init(GPIOB,&GPIO_InitStructure); //调用库函数,初始化GPIOA RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能与LED相关的GPIO端口时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3; //配置GPIO引脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度 GPIO_Init(GPIOA,&GPIO_InitStructure); //调用库函数,初始化GPIOA GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3); //设置引脚输出高电平 } 实现数码相框的主程序为: int main() { UINT8 s, c, i,B,w=0; UINT16 TotalCount,z; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); Delay_Init(); USART_Printf_Init(115200); printf("SystemClk:%d\r\n",SystemCoreClock); printf("USBHD HOSTTest\r\n"); USBHD_ClockCmd(RCC_USBCLKSource_PLLCLK_1Div5,ENABLE); pHOST_RX_RAM_Addr = RxBuffer; pHOST_TX_RAM_Addr = TxBuffer; USB_HostInit(); CHRV3LibInit(); printf( "Wait DeviceIn\r\n" ); App_OledInit(); Lcd_Init(); LCD_Clear(BLACK); LCD_Address_Set(0,0,159,79); while ( 1 ) { s = ERR_SUCCESS; if ( R8_USB_INT_FG& RB_UIF_DETECT ) { R8_USB_INT_FG =RB_UIF_DETECT ; s =AnalyzeRootHub( ); if ( s ==ERR_USB_CONNECT ) FoundNewDev = 1; } if ( FoundNewDev || s== ERR_USB_CONNECT ) { FoundNewDev =0; mDelaymS( 200); s =InitRootDevice( Com_Buffer ); if ( s == ERR_SUCCESS) { CHRV3DiskStatus= DISK_USB_ADDR; for ( i = 0; i != 10;i ++ ) { printf( "Wait DiskReady\n" ); s =CHRV3DiskReady( ); if ( s == ERR_SUCCESS) { break; } mDelaymS( 50 ); } B=1; z=0; if ( CHRV3DiskStatus>= DISK_MOUNTED ) { LOOP: z=0; LCD_Address_Set(0,0,159,79); if(B==1) { if(w==0) strcpy( (PCHAR)mCmdParam.Open.mPathName, "/C51/MOLED2.BIN" ); if(w==1) strcpy( (PCHAR)mCmdParam.Open.mPathName, "/C51/MOLED1.BIN" ); if(w==2) strcpy( (PCHAR)mCmdParam.Open.mPathName, "/C51/MOLED.BIN" ); 。。。 s =CHRV3FileOpen( ); if ( s ==ERR_MISS_DIR || s == ERR_MISS_FILE ) { printf( "no find\n" ); } else { while(z<256) { TotalCount = 100; printf( "read char :\n",TotalCount ); while ( TotalCount ) { if ( TotalCount >(MAX_PATH_LEN-1) ) c = MAX_PATH_LEN-1; else c = TotalCount; mCmdParam.ByteRead.mByteCount = c; mCmdParam.ByteRead.mByteBuffer= &buf[0]; s = CHRV3ByteRead( ); TotalCount -= mCmdParam.ByteRead.mByteCount; for ( i=0;i!=mCmdParam.ByteRead.mByteCount; i++ ) { LCD_WR_DATA8(buf); } if ( mCmdParam.ByteRead.mByteCount < c ) { printf( "\n" ); printf( "file end\n" ); break; } } printf( "%3d", z ); z++; } printf( "Close\n" ); i =CHRV3FileClose( ); mStopIfError( i ); mDelaymS(2000); w++; if(w==N) w=0; } } mDelaymS(1000); goto LOOP; } } } mDelaymS( 100 ); SetUsbSpeed( 1 ); } } 经程序的编译处理,其占用存储空间的情况如下图所示。 |