LCD端子番号 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 16 | 15 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LCD端子名 | DB7 | DB6 | DB5 | DB4 | DB3 | DB2 | DB1 | DB0 | E | R/W | RS | Vo | Vdd | Vss | K | A |
LCD端子番号 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 16 | 15 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LCD端子名 | DB7 | DB6 | DB5 | DB4 | DB3 | DB2 | DB1 | DB0 | E | R/W | RS | Vo | Vdd | Vss | K | A |
PSoCPIN番号 | P2[3] | P2[2] | P2[1] | P2[0] | x | x | x | x | P2[4] | P2[6] | P2[5] | SiD | VDD | P0[6] | x | x |
void main()
{
BYTE gx,gy,gz;
M8C_EnableGInt ;
// TRIADC8モジュールを使ってGセンサの値をAD変換
TRIADC8_1_Start(TRIADC8_1_HIGHPOWER);
TRIADC8_1_GetSamples();
// ADCに入れる前にVoltageフォロワとして1倍のPGAを入れる
PGA_1_Start(PGA_1_HIGHPOWER);
PGA_2_Start(PGA_2_HIGHPOWER);
PGA_3_Start(PGA_3_HIGHPOWER);
LCD_1_Start();
LCD_1_InitBG(LCD_1_SOLID_BG);
while(1) {
while(!TRIADC8_1_fIsDataAvailable());
// 値の変動が気になるのでLowPassフィルタ(平均だけど)を掛ける
gz = (gz+TRIADC8_1_cGetData1())/2;
gx = (gx+TRIADC8_1_cGetData2())/2;
gy = (gy+TRIADC8_1_cGetData3ClearFlag())/2;
// バーグラフでGセンサの値を表示(大体0〜20になるように12で割る)
LCD_1_Position(0,1); LCD_1_PrHexByte(gx);
LCD_1_DrawBG(1,1,4,gx/12);
LCD_1_Position(0,6); LCD_1_PrHexByte(gy);
LCD_1_DrawBG(1,6,4,gy/12);
LCD_1_Position(0,11); LCD_1_PrHexByte(gz);
LCD_1_DrawBG(1,11,4,gz/12);
}
}
#define RA 0x80 // RA = P0[7]
#define RB 0x20 // RB = P0[5]
void main()
{
BYTE csw,psw,count=0;
PRT0DR = RA|RB; // RA,RB PullUp
psw = 0xFF;
LCD_1_Start();
LCD_1_PrCString("QuadratureDecode");
while(1) {
csw = PRT0DR; // Current Switch
if ((~psw&RA)&&(csw&RA)&&(csw&RB)) count--;
if ((~psw&RB)&&(csw&RB)&&(csw&RA)) count++;
LCD_1_Position(1,0);
LCD_1_PrHexByte(count);
psw = csw;
}
}
#define RA 0x80 // RA = P0[7]
#define RB 0x20 // RB = P0[5]
BYTE csw,psw=0xFF,count=0;
#pragma interrupt_handler timer8_1_int_func
void timer8_1_int_func(void)
{
csw = PRT0DR; // Current Switch
if ((~psw&RA)&&(csw&RA)&&(csw&RB)) count--;
if ((~psw&RB)&&(csw&RB)&&(csw&RA)) count++;
psw = csw;
}
void main()
{
PRT0DR = RA | RB // RA,RB PullUp
LCD_1_Start();
Timer8_1_Start();
Timer8_1_EnableInt();
M8C_EnableGInt;
LCD_1_PrCString("QuadratureDecode");
while(1) {
LCD_1_Position(1,0);
LCD_1_PrHexByte(count);
}
}
#define RA 0x80 // RA = P0[7]
#define RB 0x20 // RB = P0[5]
BYTE csw,count=0;
#pragma interrupt_handler gpio_int_func
void gpio_int_func(void)
{
csw = PRT0DR; // Current Switch
if ((~csw&RA)&&(csw&RB)) count++;
if ((~csw&RB)&&(csw&RA)) count--;
}
void main()
{
PRT0DR = RA | RB; // RA,RB PullUp
LCD_1_Start();
INT_MSK0 |= INT_MSK0_GPIO;
M8C_EnableGInt;
LCD_1_PrCString("QuadratureDecode");
while(1) {
LCD_1_Position(1,0);
LCD_1_PrHexByte(count);
}
}
enum eSTATE{IDLE,CW01,CW00,CW10,CCW10,CCW00,CCW01,END};
BYTE csw,count=0,stat;
#pragma interrupt_handler gpio_int_func
void gpio_int_func(void)
{
BYTE timeout=0;
stat = IDLE;
while(stat!=END) {
csw = PRT0DR; // Current Switch
switch(stat) {
case CW01: if ((~csw&RA)&&(~csw&RB)) stat = CW00; break;
case CW00: if ((csw&RA)&&(~csw&RB)) stat = CW10; break;
case CW10: if ((csw&RA)&&(csw&RB)) { stat = END; count++; } break;
case CCW10: if ((~csw&RA)&&(~csw&RB)) stat = CCW00; break;
case CCW00: if ((~csw&RA)&&(csw&RB)) stat = CCW01; break;
case CCW01: if ((csw&RA)&&(csw&RB)) { stat = END; count--; }break;
case IDLE:
if ((~csw&RA)&&(csw&RB)) stat = CW01;
if ((csw&RA)&&(~csw&RB)) stat = CCW10;
}
LCD_1_Delay50uTimes(20);
if (timeout++>100) stat = END; // タイムアウト
}
}
#define RA 0x80 // RA = P0[7]
#define RB 0x20 // RB = P0[5]
enum eSTATE{IDLE,CW01,CW00,CW10,CCW10,CCW00,CCW01,END};
BYTE csw,count=0,stat=IDLE;
#pragma interrupt_handler gpio_int_func
void gpio_int_func(void) {
while(stat!=END) {
csw = PRT0DR; // Current Switch
switch(stat) {
case CW01:
if ((~csw&RA)&&(~csw&RB)) stat = CW00;
if ((csw&RA)&&(csw&RB)) stat = END;
break;
case CW00:
if ((csw&RA)&&(~csw&RB)) stat = CW10;
if ((~csw&RA)&&(csw&RB)) stat = CW01;
if ((csw&RA)&&(csw&RB)) { stat = END; count++;}
break;
case CW10:
if ((csw&RA)&&(csw&RB)) { stat = END; count++;}
break;
case CCW10:
if ((~csw&RA)&&(~csw&RB)) stat = CCW00;
if ((csw&RA)&&(csw&RB)) stat = END;
break;
case CCW00:
if ((~csw&RA)&&(csw&RB)) stat = CCW01;
if ((csw&RA)&&(~csw&RB)) stat = CCW10;
if ((csw&RA)&&(csw&RB)) { stat = END; count--;}
break;
case CCW01:
if ((csw&RA)&&(csw&RB)) { stat = END; count--;}
break;
case IDLE:
if ((~csw&RA)&&(csw&RB)) stat = CW01;
if ((csw&RA)&&(~csw&RB)) stat = CCW10;
if ((csw&RA)&&(csw&RB)) stat = END;
break;
}
}
}
#define RA 0x08 // RA = P0[3]
#define RB 0x02 // RB = P0[1]
void main()
{
PRT0DR = RA | RB; // RA,RB PullUp
LCD_1_Start();
Counter8_1_Start();
Counter8_2_Start();
LCD_1_PrCString("QuadratureDecode");
while(1) {
LCD_1_Position(1,0);
LCD_1_PrHexByte(Counter8_2_bReadCounter()-Counter8_1_bReadCounter());
}
}
(5V - 2V) / 3mA = 1kΩ
// BYTE毎にアクセスするための共用体
typedef union {WORD w; BYTE x[2];} uniword;
typedef union {DWORD dw; BYTE x[4];} unidword;
// 点灯位置を表すテーブル(上位ByteがPort0,下位ByteがPort2)
const WORD Night[16] = {
0x4000,0x1000,0x0400,0x0100,0x0040,0x0010,0x0004,0x0001,
0x0001,0x0004,0x0010,0x0040,0x0100,0x0400,0x1000,0x4000
};
void main()
{
unidword N;
uniword Light;
WORD count;
// LEDを接続するポートをPull-Downする
PRT0DM0&=~0x55; PRT0DM1&=~0x55; PRT0DM2&=~0x55; // Port0-0,2,4,6 Pull-Down(000)
PRT2DM0&=~0x55; PRT1DM2&=~0x55; PRT2DM2&=~0x55; // Port2-0,2,4,6 Pull-Down(000)
for (count=0;;count++) {
// Port0,2に、LED点灯データを出力
PRT0DR = ~Light.x[0];
PRT2DR = ~Light.x[1];
// 残光位置保存・点灯データ位置を進める
if (!(count%1024)) {
N.dw >>= 8;
N.x[0] = (N.x[1]+1)%16;
}
// 残光データ処理
switch(count%8) {
case 0: Light.w = Night[N.x[0]] | Night[N.x[1]] ; break;
case 1: Light.w = Night[N.x[0]] | Night[N.x[2]] ; break;
case 2: Light.w = Night[N.x[0]] | Night[N.x[1]] ; break;
case 3: Light.w = Night[N.x[0]] | Night[N.x[3]] ; break;
case 4: Light.w = Night[N.x[0]] | Night[N.x[1]] ; break;
case 5: Light.w = Night[N.x[0]] | Night[N.x[2]] ; break;
case 6: Light.w = Night[N.x[0]] | Night[N.x[1]] ; break;
case 7: Light.w = Night[N.x[0]] ; break;
}
}
}