69,374
社区成员
发帖
与我相关
我的任务
分享
u32 shift_picture(u32 color)
{
u32 r,g,b;
u32 out_color = 0;
r = (color & 0xFF0000) >> 16;//16位的数组文件在这里的结果只会是0,也就是丢掉红色的原因所在
g = (color & 0x00FF00) >> 8;
b = color & 0x0000FF;
switch(u8_LCDPixelFormat)//这里是图片显示格式,主函数里手动赋值为5或6都可以
{
case 3: // 12-bit
{
r = r >> 4;
g = g >> 4;
b = b >> 4;
out_color = (r << 8) | (g << 4) | b;
break;
}
case 5: // 16-bit
{
r = r >> 3;
g = g >> 2;
b = b >> 3;
out_color = (r << 11) | (g << 5) | b;
break;
}
case 6: // 18-bit
{
out_color = color & 0xFCFCFC;
break;
}
}
return out_color;
}
//
void printf_picture(dr35_LcdCoordinates_t coord,const u32* picture)//第一个参数是行地址和页地址的结构体,这里直接全屏显示,第二个参数就是图片的数组了
{
u16 x,y;
u8 odd_pixel = 0;
u32 prev_color = 0, current_color = 0;
p_dr35lcd_SetDisplayWindow(coord.x_ul, coord.x_lr, coord.y_ul, coord.y_lr);//全屏显示的意思
ILI9341WriteCmd(0x2c);//写显示内存的准备命令,无需理会
for(y = coord.y_ul; y <= coord.y_lr; y++)
{
for(x = coord.x_ul; x <= coord.x_lr; x++)
{
current_color = shift_picture(*picture);
picture++;
switch(u8_LCDPixelFormat)
{
case 3: // 12-bit
{
if (odd_pixel > 0)
{
ILI9341Write8bitData((prev_color >> 4) & 0xFF);
ILI9341Write8bitData((prev_color & 0xF) | ((current_color >> 8)) & 0xFF);
ILI9341Write8bitData(current_color & 0xFF);
}
break;
}
case 5: // 16-bit
{
ILI9341Write8bitData((current_color >> 8) & 0xFF);
ILI9341Write8bitData(current_color & 0xFF);
break;
}
case 6: // 18-bit
{
ILI9341Write8bitData((current_color >> 16) & 0xFF);
ILI9341Write8bitData((current_color >> 8) & 0xFF);
ILI9341Write8bitData(current_color & 0xFF);
break;
}
}
prev_color = current_color;
odd_pixel = (odd_pixel + 1) % 2;
}
}
#include <stdio.h>
unsigned char ui;
signed char si;
char main() {
ui=(unsigned char)0x80u;
si=( signed char)0x80;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
ui=ui>>1;
si=si>>1;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
printf("--------------\n");
ui=(unsigned char)0x80u;
si=( signed char)0x80;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
ui=(( signed char)ui)>>1;
si=((unsigned char)si)>>1;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
printf("==============\n");
ui=(unsigned char)0x80u;
si=( signed char)0x80;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
ui=ui<<1;
si=si<<1;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
printf("--------------\n");
ui=(unsigned char)0x80u;
si=( signed char)0x80;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
ui=(( signed char)ui)<<1;
si=((unsigned char)si)<<1;
printf("ui=%u\n",ui);
printf("si=%d\n",si);
return 0;
}
//ui=128
//si=-128
//ui=64
//si=-64
//--------------
//ui=128
//si=-128
//ui=192
//si=64
//==============
//ui=128
//si=-128
//ui=0
//si=0
//--------------
//ui=128
//si=-128
//ui=0
//si=0
C Integer Constants
An “integer constant” is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents an integral value. Use integer constants to represent integer values that cannot be changed.
Syntax
integer-constant :
decimal-constant integer-suffix opt
octal-constant integer-suffix opt
hexadecimal-constant integer-suffix opt
decimal-constant :
nonzero-digit
decimal-constant digit
octal-constant :
0
octal-constant octal-digit
hexadecimal-constant :
0x hexadecimal-digit
0X hexadecimal-digit
hexadecimal-constant hexadecimal-digit
nonzero-digit : one of
1 2 3 4 5 6 7 8 9
octal-digit : one of
0 1 2 3 4 5 6 7
hexadecimal-digit : one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
integer-suffix :
unsigned-suffix long-suffix opt
long-suffix unsigned-suffix opt
unsigned-suffix : one of
u U
long-suffix : one of
l L
64-bit integer-suffix :
i64
Integer constants are positive unless they are preceded by a minus sign (–). The minus sign is interpreted as the unary arithmetic negation operator. (See Unary Arithmetic Operators in Chapter 4 for information about this operator.)
If an integer constant begins with the letters 0x or 0X, it is hexadecimal. If it begins with the digit 0, it is octal. Otherwise, it is assumed to be decimal.
The following lines are equivalent:
0x1C /* = Hexadecimal representation for decimal 28 */
034 /* = Octal representation for decimal 28 */
No white-space characters can separate the digits of an integer constant. These examples show valid decimal, octal, and hexadecimal constants.
/* Decimal Constants */
10
132
32179
/* Octal Constants */
012
0204
076663
/* Hexadecimal Constants */
0xa or 0xA
0x84
0x7dB3 or 0X7DB3
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
unsigned int n;
int c;
//-------------------------------------------------------
void main(int argc,char *argv[])
{
if (argc<3) {
cprintf("Bin2Hex srcfile desfile");
return;
}
if ((fi=fopen(argv[1],"rb"))==NULL) {
cprintf("Can not find file %s",argv[1]);
return;
}
if ((fo=fopen(argv[2],"w"))==NULL) {
fclose(fi);
cprintf("Can not create file %s",argv[2]);
return;
}
n=0;
while (1) {
c=fgetc(fi);
if (EOF==c) break;
n++;
if (1==n) fprintf(fo, "0x%02X",c);
else {
if (1==n%16) fprintf(fo,"\n0x%02X",c);
else fprintf(fo, ",0x%02X",c);
}
}
fcloseall();
cprintf("OK to Bin2Hex %u bytes.",n);
}
u32 shift_picture(u32 color)
{
u32 r,g,b;
u32 out_color = 0;
r = (color & 0xFF0000) >> 16;//16位的数组文件在这里的结果只会是0,也就是丢掉红色的原因所在
g = (color & 0x00FF00) >> 8;
b = color & 0x0000FF;
switch(u8_LCDPixelFormat)//这里是图片显示格式,主函数里手动赋值为5或6都可以
{
case 3: // 12-bit
{
r = r >> 4;
g = g >> 4;
b = b >> 4;
out_color = (r << 8) | (g << 4) | b;
break;
}
case 5: // 16-bit
{
r = r >> 3;
g = g >> 2;
b = b >> 3;
out_color = (r << 11) | (g << 5) | b;
break;
}
case 6: // 18-bit
{
out_color = color & 0xFCFCFC;
break;
}
}
return out_color;
}