/* TREVA 取り込みテスト */ /* P74 で CLK 出力 (負論理) PB1 で信号受けとり (負論理) */ #include <3664f.h> #include "sci3.h" int read_bit(void); unsigned char read_byte(void); void main() { unsigned long magic; int i,j; int Y1,U,Y2,V; int R,G,B; /* sci3_init(); */ IO.PCR7 = 0xff; while (!IO.PDR8.BIT.B5) ; /* ボタンが押されるまで待つ */ #if 1 /* マジックナンバ'0xaa55ff'を待つ */ magic = 0; while (magic != 0xaa55ff){ magic = ((magic << 1) | read_bit()) & 0xffffff; } /* 続く29byte分のデータは無視 */ for (i=0; i<29*8; i++) read_bit(); #endif #if 0 /* 連続65bit分の'0'を検出 */ i = 0; while (i<65) { if (!read_bit()) i++; else i = 0; } /* 続く2byte分のデータは無視 */ for ( i=0; i<2*8; i++ ) read_bit(); #endif /* PPM header */ sci3_puts( "P3\r\n96 72 255\r\n" ); /* ここから画像データ取得開始 */ for (i=0; i<48; i++) { for (j=0; j<72; j++) { V = read_byte() - 128; Y1 = read_byte(); U = read_byte() - 128; Y2 = read_byte(); /* R = 1.40*(U - 128) + Y G = 1.02*Y - 0.750*(U - 128) - 0.336*(V - 128) B = 1.77*(V - 128) + Y */ R = U * 7 / 5 + Y1; G = Y1 - U * 3 / 4 - V / 3; B = V * 7 / 8 + Y1; send(R); send(G); send(B); R = U * 7 / 5 + Y2; G = Y2 - U * 3 / 4 - V / 3; B = V * 7 / 8 + Y2; send(R); send(G); send(B); sci3_puts("\r\n"); } /* j */ } /* i */ } /* 1bit読み出し */ int read_bit(void) { int i,a; IO.PDR7.BYTE = 0xff; /* CLK = 0 */ for (i=0;i<42;i++) ; IO.PDR7.BYTE = 0; /* CLK = 1 */ a = !IO.PDRB.BIT.B1; /* 立ち上がりでDOUTを読み込み */ for (i=0;i<42;i++) ; /* sci3_outch(a?'1':'0'); */ return a; } unsigned char read_byte(void) { unsigned char v; int i; for ( i=0; i<8; i++) { v = (v << 1) | read_bit(); } return v; } send(int v) { int u,w; if (v>255) v = 255; if (v<0) v = 0; w = 100; while (w>1) { u = v / w; sci3_outch('0'+u); v -= u * w; w = w / 10; } sci3_outch('0'+v); sci3_outch(' '); }