1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| //STC12C5A60S2 @12M晶振 #include <STC12C5A60S2.H> #include <intrins.h>
sbit R1 = P0 ^ 0; sbit G1 = P0 ^ 1; sbit B1 = P0 ^ 2; sbit R2 = P0 ^ 3; sbit G2 = P0 ^ 4; sbit B2 = P0 ^ 5;
sbit IA = P2 ^ 7; //行控制线A sbit IB = P2 ^ 6; //行控制线B sbit IC = P2 ^ 5; //行控制线C sbit ID = P2 ^ 4; //行控制线D
sbit CK = P2 ^ 2; //时钟 sbit LS = P2 ^ 1; //锁存 sbit OE = P2 ^ 0; //输出,低电平有效
#define uint unsigned int #define uchar unsigned char #define SCAN(X) IA=(X)&1; IB=(X)&2; IC=(X)&4; ID=(X)&8;
uchar xdata Red_Gray[1][16][8]=0; //行,灰度,列 uchar xdata Green_Gray[1][16][8]=0; uchar xdata Blue_Gray[1][16][8]=0; uchar code color[]={ //G B R 0X03,0X0F,0X04,0X0F,0X06,0X0F,0X08,0X0F,0X0A,0X0F,0X0C,0X0F,0X0E,0X0F,0X0F,0X0F, //1111 1111 0000 1111 0XAF,0X00,0XAF,0X00,0XAF,0X00,0XAF,0X00,0X9F,0X01,0X9F,0X01,0X9F,0X01,0X9F,0X02, 0X8F,0X02,0X8F,0X02,0X7F,0X03,0X7F,0X03,0X7E,0X04,0X6E,0X04,0X6E,0X04,0X5E,0X05, 0X5E,0X05,0X4E,0X06,0X4E,0X06,0X4E,0X07,0X3D,0X07,0X3D,0X07,0X2D,0X08,0X2D,0X08, 0X2D,0X09,0X1D,0X09,0X1D,0X09,0X1D,0X0A,0X0C,0X0A,0X0C,0X0B,0X0C,0X0B,0X0C,0X0B, 0X0C,0X0B,0X0C,0X0C,0X0C,0X0C,0X0B,0X0C,0X0B,0X0C,0X0B,0X0C,0X0B,0X0D,0X0B,0X0D, 0X0A,0X0D,0X0A,0X0D,0X0A,0X0D,0X0A,0X0D,0X0A,0X0D,0X19,0X0E,0X19,0X0E,0X19,0X0E, 0X19,0X0E,0X19,0X0E,0X18,0X0E,0X28,0X0E,0X28,0X0E,0X28,0X0E,0X28,0X0E,0X28,0X0E, 0X28,0X0F,0X37,0X0F,0X37,0X0F,0X37,0X0F,0X37,0X0F,0X37,0X0F,0X37,0X0F,0X37,0X0F, };
void Delay100us() //@12.000MHz { unsigned char i, j;
_nop_(); _nop_(); i = 2; j = 38; do { while (--j); } while (--i); }
void RGB444_2_16gray() { uchar row,line,bitn; int r,g,b,j; for(row=0;row<1;row++)//每行 { for(line=0;line<8;line++)//字节列 { for(bitn=0;bitn<8;bitn++)//位 { r=color[row*128+line*16+bitn*2+1]&0x0f; //分离红色通道 g=(color[row*128+line*16+bitn*2]>>4)&0x0f; //分离绿色通道 b=color[row*128+line*16+bitn*2]&0x0f; //分离蓝色通道 for(j=0;j<16;j++)//16级灰度 { ((r-j)>0)?(Red_Gray[row][j][line]|=0x01<<(7-bitn)):(Red_Gray[row][j][line]&=~0x01<<(7-bitn)); //计算灰度 并存入红色通道显存地址 ((g-j)>0)?(Green_Gray[row][j][line]|=0x01<<(7-bitn)):(Green_Gray[row][j][line]&=~0x01<<(7-bitn));//计算灰度 并存入绿色通道显存地址 ((b-j)>0)?(Blue_Gray[row][j][line]|=0x01<<(7-bitn)):(Blue_Gray[row][j][line]&=~0x01<<(7-bitn)); //计算灰度 并存入蓝色通道显存地址 } } } } } void Frane_Interlac_Scan() { uchar RowCount,Gray16,LineCount,Byte2bit,R1_ColorBuff,G1_ColorBuff,B1_ColorBuff; uchar i; for(i = 0; i < 2; i++) //扫描行 { SCAN(i); for(Gray16=0;Gray16<16;Gray16++) { for(LineCount=0;LineCount<8;LineCount++) { //字节数据RGB R1_ColorBuff=Red_Gray[RowCount][Gray16][LineCount]; G1_ColorBuff=Green_Gray[RowCount][Gray16][LineCount]; B1_ColorBuff=Blue_Gray[RowCount][Gray16][LineCount]; for(Byte2bit=0;Byte2bit<8;Byte2bit++) { R1=R1_ColorBuff>>7; R2=R1; G1=G1_ColorBuff>>7; G2=G1; B1=B1_ColorBuff>>7; B2=B1; CK=1; CK=0; R1_ColorBuff<<=1; G1_ColorBuff<<=1; B1_ColorBuff<<=1; } } LS=1;//行数据锁存 LS=0;
OE=0;//显示 Delay100us(); OE=1;//不显示 } } } void main() { RGB444_2_16gray(); while(1) { Frane_Interlac_Scan(); } }
|