STM32G031J6M6と74hc164を使い
液晶にクリスマスと表示する。
開発中で現在は、5ビットで組み合わせは、32個
7ビットを通せる様になると変換の手間が省ける
ichgojamの処理系で遅延が発生しているのでぎりぎり
4ビット分のタイミングまでしか会わない。
やり方は、2つあつて二回で送るとのさらに速度を遅くする方法がある。
二回で送る方式は、冒険的要素は、なく確実に出来るがプログラムが複雑になる。
速度を遅くする方法は、チャレンジが必要になり、もしかしたら動かない可能性
がある。しかも問題を見つける為には、時間がかかる事が予想出来る。
プログラムをシンブルにするために速度を遅くする方式を検討する。
第三の方法
根本的には、同期が取れていないのでスタートビットで同期(オートボーレット)
すれば処理系や処理の方法が変わっても自動的にビット長を調整すれば
7ビット通る可能性が高い。とりあえず現行5ビットのアルゴリズムのままテスト
する。1ビットは、論理値で決め打ちしているのは、1ビット目は、誤差が蓄積
される前なので読み取れると推定した。5ビット現行アルゴリズムは、おおむね
成功して、次のステップは、7ビット化と微調整のみ、オートのビット間隔に1ms
足すか引くかと推定される。
同期の自動化は、適当に使っていれば同期化するが強制的に合わせるには、
スタートビットの次の1ビットめは、1にすればよい、ビット反転させているので
'@'辺りを送ると同期が完了する。
調整マイナス1msで7ビットが通った。
!!プログラムが大幅に変わる場合がありますが機能は、同じです!!











arduino側
#include <Arduino.h>
//* ***** *****
//* * * *
//* * * *
//* * * *
//* * * *
//******** ***** *****
////#define swdclk PA14
////#define swdio PA13
#define DW digitalWrite
#define swdclk PA8
#define swdio PA12
#define en PA0
#define in7 PB7
void setup() {
delay(3000);
pinMode(swdclk,OUTPUT);
pinMode(swdio,OUTPUT);
pinMode(en,OUTPUT);
pinMode(in7,INPUT_PULLUP);
DW(en,0);
DW(swdio,0);
for(int i=0;i<10;i++){
DW(swdclk,1);
delay(15);
DW(swdclk,0);
delay(15);
}
}
int v;
int rs;
void seg1()
{
DW(swdio,(v>>7)&1);DW(swdclk,1);DW(swdclk,0); //7
DW(swdio,(v>>6)&1);DW(swdclk,1);DW(swdclk,0); //6
DW(swdio,(v>>5)&1);DW(swdclk,1);DW(swdclk,0); //5
DW(swdio,(v>>4)&1);DW(swdclk,1);DW(swdclk,0); //4
DW(swdio,(v>>3)&1);DW(swdclk,1);DW(swdclk,0); //3
DW(swdio,(v>>2)&1);DW(swdclk,1);DW(swdclk,0); //2
DW(swdio,(v>>1)&1);DW(swdclk,1);DW(swdclk,0); //1
DW(swdio,(v>>0)&1);DW(swdclk,1);DW(swdclk,0); //0
DW(swdio,rs); //delay(500);
DW(en,1); delayMicroseconds(40);
DW(en,0); //delay(500);
}
int a; //1
int b; //2
int c; //3
int d; //4
int e; //5
int f; //6
int g; //7
int bl;
int bh;
int s;
int cursor1 = 0;
int tl;
int tls;
int tl_f;
void loop() {
//ファンクションセット1
rs=0;
v=0x30;seg1();
delay(5); //delay(1000);
//ファンクションセット2
rs=0;
v=0x30;seg1();
delay(1); //delay(1000);
//ファンクションセット3
rs=0;
v=0x30;seg1(); //delay(1000);
//ファンクションセット 2ラインモード
rs=0;
v=0x38;seg1(); //delay(1000);
//表示オフ
rs=0;
v=0x08;seg1(); //delay(1000);
//画面クリア
rs=0;
v=0x01;seg1();
delay(2); //delay(1000);
//エントリーモードセット
rs=0;
v=0x06;seg1(); //delay(1000);
//表示オン
rs=0;
v=0x08+0x04;seg1();//delay(1000);
//@文字の表示
rs=1;
v='@';seg1();
delay(1000);
//1ライン目にカーソルを移動
rs=0;
v=0x80+0x00;seg1();
delay(1000);
tl = 35; //シリアル 1ビットの長さ
cursor1 = 0;
while(1){
tl_f = 0;tls=35;
while( digitalRead(in7) == 1 ) {}
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=1*2;} //1
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=2*2;} //2
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=3*2;} //3
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=4*2;} //4
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=5*2;} //5
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=6*2;} //6
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=7*2;} //7
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=8*2;} //8
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=9*2;} //9
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=10*2;} //10
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=11*2;} //11
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=12*2;} //12
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=13*2;} //13
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=14*2;} //14
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=15*2;} //15 30
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=16*2;} //16 32
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=17*2;} //17 34
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=18*2;} //18 36 *
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=19*2;} //19 38
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=20*2;} //20 40
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=21*2;} //21
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=22*2;} //22
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=23*2;} //23
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=24*2;} //24
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=25*2;} //25
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=26*2;} //26
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=27*2;} //27
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=28*2;} //28
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=29*2;} //29
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=30*2;} //30
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=31*2;} //31
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=32*2;} //32
delay(1); if(digitalRead(in7) == 1 && tl_f == 0 ) {tl_f=1;tls=33*2;} //33
if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整
a=!(digitalRead(in7));
delay(tl);
b=!(digitalRead(in7));
delay(tl);
c=!(digitalRead(in7));
delay(tl);
d=!(digitalRead(in7));
delay(tl);
e=!(digitalRead(in7)); // 5 bit
delay(tl);
f=!(digitalRead(in7)); // 6 bit
delay(tl);
g=!(digitalRead(in7)); // 7 bit
delay(tl);
s=g*64+f*32+e*16+d*8+c*4+b*2+a;
if( s=='_' ) {
//画面クリア
rs=0;
v=0x01;seg1();
delay(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} else {
//文字の表示
v=s;rs=1;seg1();cursor1++;
//delay(300);
}
if(cursor1 == 8){
//2ライン目にカーソルを移動
rs=0;
v=0x80+0x40;seg1();
//delay(1000);
} else if(cursor1 >= 16) {
//画面クリア
rs=0;
v=0x01;seg1();
delay(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} //endif
} //while
} //end loop
ichgojam側
10 'START 0.5 DATA 7BIT SOTP 1
20 OUT 11,1:WAIT 15
30 [0]=ASC("C")
40 [1]=ASC("H")
50 [2]=ASC("R")
60 [3]=ASC("I")
70 [4]=ASC("S")
80 [5]=ASC("T")
90 [6]=ASC("M")
100 [7]=ASC("A")
110 [8]=ASC("S")
120 [9]=ASC("_")
160 FOR I=0 TO 9
170 R=[I]:GOSUB 200:WAIT 60
180 NEXT
190 GOTO 160
200 '
210 OUT 11,0:WAIT 1
220 FOR S=0 TO 6
230 OUT 11,!( (R >> S)&1 )
240 WAIT 2
250 NEXT
260 OUT 11,1
270 WAIT 2
280 RETURN
stm32l010f4p6 mbed用 とりあえず移植して作ってみた。 参考程度
#include "mbed.h"
//* ***** ***** *** * *
//* * * * * * * *
//* * * * * * * *
//* * * * * * * *
//* * * * * * * *
//******** ***** ***** *** * *
#define swclk1 PA_5 //A4
#define swdio1 PA_7 //A6
#define en1 PA_4 //A3
#define in7a PA_9 //D8
DigitalOut swdclk(swclk1);
DigitalOut swdio(swdio1);
DigitalOut en(en1);
DigitalIn myin9(in7a); // for out 11 (in4) (303 D8)
//Serial pc2(USBTX, USBRX); // tx, rx
//Serial pc2(PA_9, PA_10); // tx, rx
//Serial pc4(PA_0, PA_1); // tx, rx
//Serial pc4(PA_2, PA_3);
int v;
int rs;
void seg1()
{
swdio=((v>>7)&1);swdclk=1;swdclk=0; //7
swdio=((v>>6)&1);swdclk=1;swdclk=0; //6
swdio=((v>>5)&1);swdclk=1;swdclk=0; //5
swdio=((v>>4)&1);swdclk=1;swdclk=0; //4
swdio=((v>>3)&1);swdclk=1;swdclk=0; //3
swdio=((v>>2)&1);swdclk=1;swdclk=0; //2
swdio=((v>>1)&1);swdclk=1;swdclk=0; //1
swdio=((v>>0)&1);swdclk=1;swdclk=0; //0
swdio=rs; //delay(500);
en=1; //delayMicroseconds(40);
wait_ms(1);
en=0; //delay(500);
}
int main() {
int a;
int b;
int c;
int d;
int e; //5bit
int f; //6bit
int g; //7bit
int s;
int tl_f;
int tls;
int tl;
int cursor1;
myin9.mode( PullUp ); // 内蔵プルアップを使う
//pc2.baud(9600);
//pc4.baud(115200);
//pc2.printf("Hello World!");
//pc4.printf("Hello World!4_2");
//en=0;
swdio=0;
for(int i=0;i<10;i++){
swdclk=1;
wait_ms(15);
swdclk=0;
wait_ms(15);
}
//ファンクションセット1
rs=0;
v=0x30;seg1();
wait_ms(5); //delay(1000);
//ファンクションセット2
rs=0;
v=0x30;seg1();
wait_ms(1); //delay(1000);
//ファンクションセット3
rs=0;
v=0x30;seg1(); //delay(1000);
//ファンクションセット 2ラインモード
rs=0;
v=0x38;seg1(); //delay(1000);
//表示オフ
rs=0;
v=0x08;seg1(); //delay(1000);
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2); //delay(1000);
//エントリーモードセット
rs=0;
v=0x06;seg1(); //delay(1000);
//表示オン
rs=0;
v=0x08+0x04;seg1();//delay(1000);
//@文字の表示
rs=1;
v='@';seg1();
wait_ms(2);
//1ライン目にカーソルを移動
rs=0;
v=0x80+0x00;seg1();
wait_ms(2);
tl = 33; //シリアル 1ビットの長さ
cursor1 = 0;
while(1) {
tl_f = 0;tls=33;
while( myin9 == 1 ) {}
for(int loop_i=1;loop_i <= 33;loop_i++){
wait_ms(1);if(myin9 == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;}
}
if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整
//wait_ms(tl); //debug
a=!(myin9); // 1bit
wait_ms(tl);
b=!(myin9); // 2bit
wait_ms(tl);
c=!(myin9); // 3bit
wait_ms(tl);
d=!(myin9); // 4bit 16
wait_ms(tl);
e=!(myin9); // 5bit 32
wait_ms(tl);
f=!(myin9); // 6bit 64
wait_ms(tl);
g=!(myin9); // 6bit 64
wait_ms(tl);
//a=0; // debug
s=g*64+f*32+e*16+d*8+c*4+b*2+a;
////debug
//s='o';
if( s=='_' ) {
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} else {
//文字の表示
v=s;rs=1;seg1();cursor1++;
//delay(300);
}
if(cursor1 == 8*2){
//2ライン目にカーソルを移動
rs=0;
v=0x80+0x40;seg1();
//delay(1000);
} else if(cursor1 >= 16*2) {
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} //endif
//swdio = 0; // LED is ON
//wait_ms(5); // 200 ms
//swdio = 1; // LED is OFF
//wait(0.1); // 1 sec
//swdio = 1; // LED is ON
//wait(0.2); // 200 ms
//swdio = 0; // LED is OFF
//wait(0.2); // 1 sec
}
}
f303 mbed用 とりあえず移植して作ってみた。 参考程度
#include "mbed.h"
//* ***** *****
//* * * *
//* * * *
//* * * *
//* * * *
//******** ***** *****
#define swclk1 PB_6 //D5
#define swdio1 PB_7 //D4
#define en1 PB_3 //D13
#define in7a PF_1 //D8
DigitalOut swdclk(swclk1);
DigitalOut swdio(swdio1);
DigitalOut en(en1);
DigitalIn myin9(in7a); // for out 11 (in4) (303 D8)
Serial pc2(USBTX, USBRX); // tx, rx
//Serial pc2(PA_9, PA_10); // tx, rx
//Serial pc4(PA_0, PA_1); // tx, rx
//Serial pc4(PA_2, PA_3);
int v;
int rs;
void seg1()
{
swdio=((v>>7)&1);swdclk=1;swdclk=0; //7
swdio=((v>>6)&1);swdclk=1;swdclk=0; //6
swdio=((v>>5)&1);swdclk=1;swdclk=0; //5
swdio=((v>>4)&1);swdclk=1;swdclk=0; //4
swdio=((v>>3)&1);swdclk=1;swdclk=0; //3
swdio=((v>>2)&1);swdclk=1;swdclk=0; //2
swdio=((v>>1)&1);swdclk=1;swdclk=0; //1
swdio=((v>>0)&1);swdclk=1;swdclk=0; //0
swdio=rs; //delay(500);
en=1; //delayMicroseconds(40);
wait_ms(1);
en=0; //delay(500);
}
int main() {
int a;
int b;
int c;
int d;
int e; //5bit
int f; //6bit
int g; //7bit
int s;
int tl_f;
int tls;
int tl;
int cursor1;
myin9.mode( PullUp ); // 内蔵プルアップを使う
pc2.baud(9600);
//pc4.baud(115200);
pc2.printf("Hello World!");
//pc4.printf("Hello World!4_2");
//en=0;
swdio=0;
for(int i=0;i<10;i++){
swdclk=1;
wait_ms(15);
swdclk=0;
wait_ms(15);
}
//ファンクションセット1
rs=0;
v=0x30;seg1();
wait_ms(5); //delay(1000);
//ファンクションセット2
rs=0;
v=0x30;seg1();
wait_ms(1); //delay(1000);
//ファンクションセット3
rs=0;
v=0x30;seg1(); //delay(1000);
//ファンクションセット 2ラインモード
rs=0;
v=0x38;seg1(); //delay(1000);
//表示オフ
rs=0;
v=0x08;seg1(); //delay(1000);
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2); //delay(1000);
//エントリーモードセット
rs=0;
v=0x06;seg1(); //delay(1000);
//表示オン
rs=0;
v=0x08+0x04;seg1();//delay(1000);
//@文字の表示
rs=1;
v='@';seg1();
wait_ms(2);
//1ライン目にカーソルを移動
rs=0;
v=0x80+0x00;seg1();
wait_ms(2);
tl = 33; //シリアル 1ビットの長さ
cursor1 = 0;
while(1) {
tl_f = 0;tls=33;
while( myin9 == 1 ) {}
for(int loop_i=1;loop_i <= 33;loop_i++){
wait_ms(1);if(myin9 == 1 && tl_f == 0){tl_f=1;tls=loop_i*2;}
}
if(tl_f == 1) {tl = tls - 1;} // スタートビット目の次が1の場合と調整
//wait_ms(tl); //debug
a=!(myin9); // 1bit
wait_ms(tl);
b=!(myin9); // 2bit
wait_ms(tl);
c=!(myin9); // 3bit
wait_ms(tl);
d=!(myin9); // 4bit 16
wait_ms(tl);
e=!(myin9); // 5bit 32
wait_ms(tl);
f=!(myin9); // 6bit 64
wait_ms(tl);
g=!(myin9); // 6bit 64
wait_ms(tl);
//a=0; // debug
s=g*64+f*32+e*16+d*8+c*4+b*2+a;
////debug
//s='o';
if( s=='_' ) {
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} else {
//文字の表示
v=s;rs=1;seg1();cursor1++;
//delay(300);
}
if(cursor1 == 99){
//2ライン目にカーソルを移動
rs=0;
v=0x80+0x40;seg1();
//delay(1000);
} else if(cursor1 >= 16) {
//画面クリア
rs=0;
v=0x01;seg1();
wait_ms(2);
//delay(1000);
//カーソルのクリア
cursor1 = 0;
} //endif
//swdio = 0; // LED is ON
//wait_ms(5); // 200 ms
//swdio = 1; // LED is OFF
//wait(0.1); // 1 sec
//swdio = 1; // LED is ON
//wait(0.2); // 200 ms
//swdio = 0; // LED is OFF
//wait(0.2); // 1 sec
}
}