構成としてはPCのシリアルポートからMAX232CPEを通して16F88のRB2とRB5に接続しています。
この状態での16F88がエコーを返すプログラムのサンプルを求めています。
PICを設置せずに直接配線するとエコーが帰ってきますので配線ミスは無いものと考えています。
HEXファイルの作成環境は
SourceBoost IDE Version 6.81ですので
BoostCでのサンプルだとうれしいです。
あまりいいサイトが見つからなかったのですが1番目の回答があんまりなので参考になりそうなURLを回答します。
シリアル通信させるためのPICのプログラム:シリアル通信させるときの決まり文句
http://www.kuze.jp/tamabi/B-Lab/2005_sp/page11.html
シリアル通信で、PICからパソコンへ文字を送る
http://www.kuze.jp/tamabi/B-Lab/2005_sp/page13.html
PIC16F88備忘録
http://www.geocities.jp/beery_bear/Products/IPD/PIC16F84A_88.htm
LED駆動とRS-232C駆動の部分のモジュールソース
http://www.geocities.jp/beery_bear/Products/IPD/TipsImages/SubFu...
コメント(1件)
最終的に以下のようなコードで動作確認できました。
j1960さんありがとうございました。
#include <system.h>
#include <string.h>
#include <stdlib.h>
// コンフィグワードの設定
#pragma DATA 0x2007, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_OFF & _BODEN_OFF & _LVP_OFF & _DEBUG_OFF
#pragma DATA 0x2008, _IESO_OFF & _FCMEN_OFF
#pragma CLOCK_FREQ 8000000
//Set SPBRG for 9600 baud rate
#define BAUD_RATE_DIVISOR 52
void putc(char c) // Put char function to transmit one char
{
txreg = c; // Put function parameter txc into the txreg
txsta.TXEN = 1; // start transmission
while( !txsta.TRMT ); // Wait until character transmission finished
}
char getc(void) // Getc function loop until a character is pressed
{
while( !pir1.RCIF ); // Loop until Rxflag = 1
putc( rcreg );
return rcreg; // Return rcreg
}
void puts(char *source) // put string function, return the refered string
{
do
{
char c = *source;
if( c == 0 ) // end of string
break;
putc( c ); // Send the string refered by pointer
source++;
}
while( 1 );
}
void gets(char *destination)
{
int i;
for (i=0;i<31;i++) {
destination[i] = getc();
if (destination[i] == 0x0d) {destination[i] = '\0';break;}
if (destination[i] == 0x0a) {destination[i] = '\0';break;}
}
destination[i] = '\0';
}
void serial_init()
{
trisb = 0b00000100; //Set RC5/TX as an output and RC2/RX as an input
spbrg = BAUD_RATE_DIVISOR; //Set SPBRG for 9600 baud rate
txsta = 0b00100100; // Enable uart module and set 8,n,1
rcsta = 0b10010010; // Enable set 8,n,1
}
void serial_stop()
{
rcsta = 0b00000000; // シリアルポートを禁止
}
void main()
{
osccon = 0x70; // 8MHz動作
serial_init();
char c[100];
while( 1 )
{
gets(c);
serial_stop(); // 処理中は受信禁止
// 受け取ったcの内容を適当に処理
serial_init(); // 受信再開
}
}