ローエンドな私とマイコン

PIC10F200ソフト232C


割込を使わずに(って言うか使えない)どこまで送受信出来るかやってみた。
まず、ボーレート1200,2400,4800,9600bps送信出来た。凄い!
次に9600bpsで受信、これも上手くいった。
アセンブラソース リスト

; 232C_RECEIVE_TEST
;
; BAUDRATE 9600bps
; Start Bit 1bit
; DATA bit 8bit
; パリティ 無
; STOP Bit 1bit
;
; 老技師
; PIC10F200 @4MHz
; 2019/07/23

#include "p10f200.inc"

__CONFIG _WDTE_OFF & _CP_OFF & _MCLRE_ON

#define    TXPORT  GPIO,1; 送信ピン
#define    RXPORT  GPIO,2; 受信ピン

;***** 変数宣言
   cblock  0x10
t0
sbuf; 受信char
bcnt; 繰り返しCNT
   endc

OscCalVal  equ0xff; 発振校正値

;***** プログラム
RES_VECT  CODE    0x0000        ; processor reset vector
   movwf   OSCCAL; ***** 初期化
;GPWU/GPPU/T0CS/T0SE/PSA/PS<2>
   movlw   b'11010001';T0CLK=内部 プリスケラー=1/4
   option
   movlw   b'1100';GPIO2以外出力
   tris    GPIO
   clrf    sbuf

_startbit
   btfsc   RXPORT;LOWで START BIT
   goto    _startbit
   goto    $+1
   goto    $+1
   goto    $+1
   goto    $+1
   btfsc   RXPORT
   goto    _startbit;NOISEで やり直し
   call    getch
   call    _200uWait;PLC半二重双方向通信の為
   call    putch;エコーバック
   clrf    sbuf;BUFクリヤー
   goto    _startbit

; サブルーチン

putch;1文字送信
   movlw   d'9'
   movwf   bcnt; loop cnt
   goto    $+1
   nop
ptch0
   bcf    TXPORT; START Bit Set
   goto    ptch2
ptch1
   rrf    sbuf,F
   btfss   STATUS,C
   goto    ptch0
   bsf    TXPORT
   goto    $+1
   nop
ptch2
   call    _1bitWait; 1bit分遅延
   decfsz  bcnt,F
   goto    ptch1
   bsf    TXPORT; STOP Bit Set
   goto    $+1
   goto    $+1
   goto    $+1
   nop
   goto    _1bitWait

getch    ;1文字受信
   call    hf_bitW
   movlw   d'9'
   movwf   bcnt
   goto    gtch1;_startbitから52uSEC
gtch0
   bcf     STATUS,C
   btfsc   RXPORT
   bsf     STATUS,C
   rrf    sbuf,F
gtch1
   call    _1bitWait;1bit分遅延
   decfsz  bcnt,F
   goto    gtch0
   retlw   0

_1bitWait;ループデ104uSEC
   movlwd'22'
   movwft0
w1m
   nop
   decfszt0,F
   gotow1m
   nop
   retlw0

hf_bitW;ループデ34uSEC
   movlwd'7'
   movwft0
w05m
   nop
   decfszt0,F
   gotow05m
   nop
   retlw0

_200uWait;約200uSEC遅延
   movlwd'39'
   movwft0
w2m
   goto$+1
   decfszt0,F
   gotow2m
   retlw0

   END