knrt.net
当前位置:首页 >> C 串口通信程序 >>

C 串口通信程序

编程原理 程序1为查询通信方式接口程序,为一典型的数据采集例程。其中bioscom()函数初始化COM1(此函数实际调用BIOS INT 14H中断0号功能)。这样在程序中就避免了具体设置波特率因子等繁琐工作,只需直接访问发送/接收寄存器(3F8H)和线路状态寄存...

//向串口发送一个字符 void send_uart( char a_s) { // TI= 0 ; while (TI!=1){;} SBUF=a_s; TI= 0 ; } 注意串口的初始化设置

#include //头文件,c语言一样 #define uchar unsigned char //定义unsigned char为uchar #define uint unsigned int unsigned char flag,a,i; //定义unsigned char变量,其实这里用uchar也行 uchar code table[]="I receive, thanks "; //定义一...

#include "reg52.h" #define uchar unsigned char #define uint unsigned int //--------------------------------------------------- sbit led = P1^0; sbit key = P0^0; sbit out1= P0^1; sbit out2= P0^2; uint run_cnt; uchar temp; //----...

#include #define uchar unsigned char #define uint unsigned int sbit ring=P3^7; sbit CASE1=P2^0; sbit CASE2=P2^1; sbit CASE3=P2^2; sbit CASE4=P2^3; uchar se=0,re=0; uchar temp=0; void wait(uint cnt) { while(--cnt); } //串口发送...

LS说的很对。其主要区别在于RS232的收发方向固定,而RS485多采用主从结构,数据链路层需要处理方向及令牌传递。

#include #include int main(void){FILE *fp;char temp;char buf[100];if((fp = fopen("com3","r")) == NULL)puts("this way doesn't work!\n");elseputs("this way works!\n");while(1){temp = 0;fscanf(fp,"%c",&temp);if(temp != 0)putchar(t...

同样的方式打开啊,只是打开的端口和参数可能不一样。比如OpenPort("COM1",19200,8,0,0,0) OpenPort("COM2",19200,8,0,0,0) OpenPort("COM3",19200,8,0,0,0) 只不过接收处理需要有单独的函数

void Send_Byte(uchar i) { WDI = ~WDI; TI = 0; SBUF = i; while(TI==0) WDI = ~WDI; TI = 0; } void Send_String(uchar *string) { while(*string!=0) { Send_Byte(*string); string ++; } } void Com_A_Int() interrupt 4 { uchar idata stat...

基本方法是使用CreateFile来建立一个串口文件,然后用overlap的方式进行读写 #define SERAIL_PORT_BUF_MAX (1024*8) typedef HRESULT (*PFN_CMD_PARSE_DATA)(HANDLE hParseApp, LPCSTR szRspCmd, int nCmdLen); class CUsbSrvApp// : public CWi...

网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com