PIC配置位生成源代码,复制到具体哪里。我用汇编,软件MPLAB X IDE v3.55 是复制到源文件里具体哪一位置

PIC配置位生成源代码,复制到具体哪里。我用汇编,软件MPLAB X IDE v3.55 是复制到源文件里具体哪一位置,第1张

PIC单片机编程,用汇编语言,那么配置位语句放在“INCLUDE ”下面那一行就可以了

见下图

1、  __CONFIG(31C4H);这一行就是配置位语句,前面空两格,不能顶格书写(CONFIG前面是两个下划线),顶格间隔位置我用的是一下“TAB”的位置

2、这句括号里的值,参考数据手册,将对应配置位的二进制代码转换成16进制代码填入即可

3、比如我是用的PIC16F676,它的配置位CONFIG是这样的,根据我的需要,最终得出“31C4H”这个值

4、好了,快点享受编程的乐趣吧!

/* * MEGA8_485_EEPROM_817_ADC_WDT.c * * Created: 2013-8-8 16:52:15 * Author: Administrator */ #define F_CPU 4000000UL #include #include #include #include #include //看门狗相关头文件 #include #define INT8U unsigned char #define ...5121

test1.cpp

-

Win32

console

app

to

read

registers

//

test1.cpp

5/23/97

//

example

Win32

C++

program

to

read

registers

from

PLC

via

gateway

//

compile

with

BC45

or

BC50

//

default

settings

for

Win32

console

app

//

empty

DEF

file

#include

<winsock.h>

#include

<stdio.h>

#include

<conio.h>

int

main(int

argc,

char

**argv)

{

if

(argc<5)

{

printf("usage:

test1

ip_adrs

unit

reg_no

num_regs\n"

"eg

test1

198.202.138.72

5

0

10\n")

return

1

}

char

*ip_adrs

=

argv[1]

unsigned

short

unit

=

atoi(argv[2])

unsigned

short

reg_no

=

atoi(argv[3])

unsigned

short

num_regs

=

atoi(argv[4])

printf("ip_adrs

=

%s

unit

=

%d

reg_no

=

%d

num_regs

=

%d\n",

ip_adrs,

unit,

reg_no,

num_regs)

//

initialize

WinSock

static

WSADATA

wd

if

(WSAStartup(0x0101,

&wd))

{

printf("cannot

initialize

WinSock\n")

return

1

}

//

set

up

socket

SOCKET

s

s

=

socket(PF_INET,

SOCK_STREAM,

IPPROTO_TCP)

struct

sockaddr_in

server

server.sin_family

=

AF_INET

server.sin_port

=

htons(502)

//

ASA

standard

port

server.sin_addr.s_addr

=

inet_addr(ip_adrs)

int

i

i

=

connect(s,

(sockaddr

*)&server,

sizeof(sockaddr_in))

if

(i<0)

{

printf("connect

-

error

%d\n",WSAGetLastError())

closesocket(s)

WSACleanup()

return

1

}

fd_set

fds

FD_ZERO(&fds)

timeval

tv

tv.tv_sec

=

5

tv.tv_usec

=

0

//

wait

for

permission

to

send

FD_SET(s,

&fds)

i

=

select(32,

NULL,

&fds,

NULL,

&tv)

//

write

if

(i<=0)

{

printf("select

-

error

%d\n",WSAGetLastError())

closesocket(s)

WSACleanup()

return

1

}

//

build

request

of

form

0

0

0

0

0

6

ui

3

rr

rr

nn

nn

unsigned

char

obuf[261]

unsigned

char

ibuf[261]

for

(i=0i<5i++)

obuf[i]

=

0

obuf[5]

=

6

obuf[6]

=

unit

obuf[7]

=

3

obuf[8]

=

reg_no

>>

8

obuf[9]

=

reg_no

&

0xff

obuf[10]

=

num_regs

>>

8

obuf[11]

=

num_regs

&

0xff

//

send

request

i

=

send(s,

obuf,

12,

0)

if

(i<12)

{

printf("failed

to

send

all

12

chars\n")

}

//

wait

for

response

FD_SET(s,

&fds)

i

=

select(32,

&fds,

NULL,

NULL,

&tv)

//read

if

(i<=0)

{

printf("no

TCP

response

received\n")

closesocket(s)

WSACleanup()

return

1

}

//

read

response

i

=

recv(s,

ibuf,

261,

0)

if

(i<9)

{

if

(i==0)

{

printf("unexpected

close

of

connection

at

remote

end\n")

}

else

{

printf("response

was

too

short

-

%d

chars\n",

i)

}

}

else

if

(ibuf[7]

&

0x80)

{

printf("

Modbus

exception

response

-

type

%d\n",

ibuf[8])

}

else

if

(i

!=

(9+2*num_regs))

{

printf("incorrect

response

size

is

%d

expected

%d\n",i,(9+2*num_regs))

}

else

{

for

(i=0i<num_regsi++)

{

unsigned

short

w

=

(ibuf[9+i+i]<<8)

+

ibuf[10+i+i]

printf("word

%d

=

%d\n",

i,

w)

}

}

//

close

down

closesocket(s)

WSACleanup()

return

0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7884919.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存