#include <3052.h> #include int cnt; // パターン番号 int stat; int brank_y; int x; struct rgb{ unsigned char r:6; unsigned char g:6; unsigned char b:6; }; union bf{ unsigned char byte; struct{ unsigned char b7:1; unsigned char b6:1; unsigned char b5:1; unsigned char b4:1; unsigned char b3:1; unsigned char b2:1; unsigned char b1:1; unsigned char b0:1; }bit; }; void Data_Out(int x,int y); void out(struct rgb c); void HardWare_SetUp(){ PA.DDR = 0xFF; //portA出力に設定 ITU0.TCR.BYTE = 0x40; //clock φ ITU0.GRA = 1; //ノンオーバーラップ期間 ITU0.GRB = 2; //パルス出力期間 ITU0.TIER.BYTE = 0xF9; //ITU0のGRAによるコンペアマッチ割込みを許可*/ PA.DR.BYTE = 0x03; //PA出力初期化 TPC.NDERA.BYTE = 0x0F; //3〜0bitをTPC使用許可 TPC.TPCR.BYTE = 0xF0; //ITU0をトリガとする。 TPC.NDRA1.BYTE = 0x0A; //次の出力データ設定 TPC.TPMR.BYTE = 0x01; //ノンオーバーラップ動作 ON TP0〜TP3 ITU.TSTR.BIT.STR0 = 1; //カウント開始 } /* メイン関数 ****************************************/ int main(void){ EI; //割り込みマクロ cnt = 0; stat=0; HardWare_SetUp(); while(1){ } } /* ITU0A割り込み処理******************************/ /*割り込み処理はIMIAのみ (デバッグの結果次第でIMIBを使用するか決める)*/ //パルス生成 //GRAコンペマッチ時次パルス列をセットする void int_imia0(void){ //clock TPC.NDRA1.BYTE |= 0x02; //clock 常に1をセット TPC.NDRA1.BYTE &= 0xFB; //水平同期リセット switch(stat){ case 0: //垂直同期リセット if(cnt > 152){ TPC.NDRA1.BYTE &= 0xF7; stat=1; cnt=0; } break; case 1: //ブランク期間 if(cnt > 323){ brank_y++; TPC.NDRA1.BYTE |= 0x04; cnt=0; } if(brank_y > 15){ brank_y=0; stat= 2 ; } break; case 2: //x=107ブランク期間 if(cnt > 107 ){ Data_Out(x,brank_y); x++; } if(cnt > 400){ TPC.NDRA1.BYTE |= 0x04; brank_y++; x=0; cnt=0; } if(brank_y > 96){ brank_y=0; stat=0; TPC.NDRA1.BYTE |= 0x08; } break; } cnt++; // cntの数を1つ増やす ITU0.TSR.BIT.IMFA = 0; // 割込み検知フラグを戻して再開 } void Data_Out(int x,int y){ struct rgb red={63,0,0}; struct rgb green={0,63,0}; //円を書く円内部赤 背景緑 半径10 オフセットなし if((x * x) == (100-(y*y)) && (y*y) == (100 - (x*x))) out(red); else out(green); } void out(struct rgb c){ union bf b; b.byte=c.r; P3.DR.BIT.B0=b.bit.b5; P3.DR.BIT.B1=b.bit.b4; P3.DR.BIT.B2=b.bit.b3; P3.DR.BIT.B3=b.bit.b2; P3.DR.BIT.B4=b.bit.b1; P3.DR.BIT.B5=b.bit.b0; b.byte=c.g; P2.DR.BIT.B0=b.bit.b5; P2.DR.BIT.B1=b.bit.b4; P2.DR.BIT.B2=b.bit.b3; P2.DR.BIT.B4=b.bit.b2; P2.DR.BIT.B5=b.bit.b1; P2.DR.BIT.B6=b.bit.b0; b.byte=c.b; P1.DR.BIT.B0=b.bit.b5; P1.DR.BIT.B1=b.bit.b4; P1.DR.BIT.B2=b.bit.b3; P1.DR.BIT.B3=b.bit.b2; P1.DR.BIT.B4=b.bit.b1; P1.DR.BIT.B5=b.bit.b0; }