0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

STM8のソフトウェアシリアルでHello Worldと出力 9600bps TX PD0

Last updated at Posted at 2021-09-30

目的
つくれそうだから作ってみた。

x ALレジスターが1個だからたぶん遅い
x 遅い、遅い、遅すぎる 論理値104us stm32->96us stm8->82us
x 6805みたいな、アーキテクチャで汎用レジスターがない
x メモリアクセスのコストが高い
x よつてゴミである?

o_con28.jpg



//104 9600
//208 4800
//416 2400
//832 1200

//#define UART_DELAY 1000 //  1/1000 ok
//#define UART_DELAY 833  //  1/1200 ok
//#define UART_DELAY 416  //  1/2400 ok
//#define UART_DELAY 186  //  1/4800 ok 173-200
# define UART_DELAY 82     //  1/9600 ok 81-84

# define PD_ODR *(volatile uint8_t *)0x500F

# define  on1()   PD_ODR=0b00000001
# define  off1()  PD_ODR=0b00000000

//仮想シリアルへの一文字出力 9600bps
int pc_putc1(char ch) {

  on1();
  off1(); //START
  delayMicroseconds(UART_DELAY);

  if( ch & 0b00000001){
    on1();  /*ビットが1*/   
  } else {
    off1(); /*ビットが0*/ 
  }//end if
  delayMicroseconds(UART_DELAY);//0

  if( ch & 0b00000010){
    on1();  /*ビットが1*/   
  } else {
    off1(); /*ビットが0*/
  }//end if
  delayMicroseconds(UART_DELAY);//1

  if( ch & 0b00000100){
    on1();  /*ビットが1*/  
  } else {
    off1(); /*ビットが0*/
  }//end if
  delayMicroseconds(UART_DELAY);//2

  if( ch & 0b00001000){
    on1();  /*ビットが1*/   
  } else {
    off1(); /*ビットが0*/ 
  }//end if
  delayMicroseconds(UART_DELAY);//3

///44444444444444444444444444
  if( ch & 0b00010000){
    on1();  /*ビットが1*/ 
  } else {
    off1(); /*ビットが0*/ 
  }//end if
  delayMicroseconds(UART_DELAY);//4

  if( ch & 0b00100000){
    on1();  /*ビットが1*/   
  } else {
    off1(); /*ビットが0*/ 
  }//end if
  delayMicroseconds(UART_DELAY);//5

  if( ch & 0b01000000){
    on1();  /*ビットが1*/   
  } else {
    off1(); /*ビットが0*/
  }//end if
  delayMicroseconds(UART_DELAY);//6

  if( ch & 0b10000000){
    on1();  /*ビットが1*/  
  } else {
    off1(); /*ビットが0*/
  }//end if
  delayMicroseconds(UART_DELAY);//7

  on1(); //Stop
  delayMicroseconds(UART_DELAY);

}

void setup() {

  //仮想シリアルの出力ポート

  //ポートをhiにする 初期化
  pinMode(PD0, OUTPUT);
  on1();

}//setup

char *ss1; //文字のポインター
int  ii;   //ループカウンター

//無限ループ
void loop() {

  ss1="Hello World !\r\n";
  ii=0; //ループカウンター
  while(ss1[ii]!=0){

    //一文字出力
    pc_putc1(ss1[ii]);ii++;

  } //while

  //1秒の待ち
  delay(1000);

}//loop



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?