/* H8/3052F Test Program */ #include "3048f.h" /* ================================================================== * 通信部分 * ================================================================== */ /* SCIを初期化 */ void InitializeSCI(void) { unsigned int i; /* SCI Initialize */ SCI1.SCR.BYTE = 0; SCI1.SMR.BYTE = 0; SCI1.BRR = 13; /* BRR: 8:115200bps 13:57600 19:38400 */ for(i=0;i<1000;i++) ; SCI1.SCR.BYTE = 0x30; /* T,R enable */ SCI1.SSR.BYTE &= 0x80; } /* 一文字送信 */ void PutChar(char c) { while(!SCI1.SSR.BIT.TDRE) ; SCI1.TDR = c; SCI1.SSR.BIT.TDRE = 0; } void PrintString(char *s) { while(*s) { PutChar(*s); s++; } } void PrintUInt(unsigned int i) { int f=0; if((i>=10000)||f) { PutChar((i/10000)+'0'); f=1; i=i%10000; } else { PutChar(' '); } if((i>=1000 )||f) { PutChar((i/1000 )+'0'); f=1; i=i%1000 ; } else { PutChar(' '); } if((i>=100 )||f) { PutChar((i/100 )+'0'); f=1; i=i%100 ; } else { PutChar(' '); } if((i>=10 )||f) { PutChar((i/10 )+'0'); f=1; i=i%10 ; } else { PutChar(' '); } PutChar(i+'0'); } char *_HexStr="0123456789ABCDEF"; void PrintXInt(unsigned int i) { PutChar(_HexStr[(i>>12)&0xf]); PutChar(_HexStr[(i>> 8)&0xf]); PutChar(_HexStr[(i>> 4)&0xf]); PutChar(_HexStr[ i &0xf]); } int __dummyint=0; int __dummygint; /* ================================================================== * 通信部分ここまで * ================================================================== */ /* プログラム本体 */ void main(void) { unsigned char b; unsigned int w,c; /* SCI 初期化 */ InitializeSCI(); /* AD初期化 */ AD.CSR.BYTE=0x33; /* CH0-3連続変換 */ /* 入力値:AD.DRA AD.DRB AD.DRC (AD.DRD>>6) 0-1023 */ /* DA初期化 */ DA.CR.BYTE=0xe0; /* DA0,1 有効 */ /* 出力値:DA.DR0 DA.DR1 0-255*/ c=0; while(1) { PrintUInt(c); b=P1.DR.BYTE; PrintString(" P1:"); PrintUInt(b); PrintString(" (0x"); PrintXInt(b); PrintString(") "); PrintString("AD:"); w=AD.DRA>>6; /* 0-1023 */ PrintUInt(w); PrintString(","); w=AD.DRB>>6; /* 0-1023 */ PrintUInt(w); PrintString(","); w=AD.DRC>>6; /* 0-1023 */ PrintUInt(w); PrintString(","); w=AD.DRD>>6; /* 0-1023 */ PrintUInt(w); PrintString("\r\n"); c++; } }